文档章节

FFMPEG调用函数init_input()初始化流时日志说明

andrew810810
 andrew810810
发布于 2016/12/09 15:02
字数 980
阅读 240
收藏 0

日志示例:

[root@andrew ffmpeg-3.2]# ./ffmpeg -i rtmp://180.97.184.107:1936/live?vhost=cc.com/stream_1 -c copy -y -f flv test_out1.flv -v 56 -t 10
ffmpeg version 3.2-static Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
  configuration: --enable-gpl --enable-nonfree --disable-shared --enable-postproc --enable-bzlib --enable-zlib --enable-parsers --enable-libx264 --enable-libx265 --enable-libmp3lame --enable-libfdk-aac --enable-pthreads --extra-ldflags=-static --disable-ffserver --enable-ffplay --enable-asm --enable-yasm --enable-optimizations --pkg-config-flags=--static --extra-cflags=--static --extra-version=static --enable-libspeex --extra-ldflags=-L/usr/local/lib --extra-cflags=-I/usr/local/include --extra-libs=-lrtmp
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.100 / 57. 64.100
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Splitting the commandline.
Reading option '-i' ... matched as input file with argument 'rtmp://180.97.184.107:1936/live?vhost=cc.com/stream_1'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'.
Reading option 'test_out1.flv' ... matched as output file.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '56'.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '10'.
Trailing options were found on the commandline.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option v (set logging level) with argument 56.
Successfully parsed a group of options.
Parsing a group of options: input file rtmp://180.97.184.107:1936/live?vhost=cc.com/stream_1.
Successfully parsed a group of options.
Opening an input file: rtmp://180.97.184.107:1936/live?vhost=cc.com/stream_1.
[rtmp @ 0x3a615e0] No default whitelist set
[tcp @ 0x3a61ac0] No default whitelist set
[rtmp @ 0x3a615e0] Handshaking...
[rtmp @ 0x3a615e0] Type answer 3
[rtmp @ 0x3a615e0] Server version 13.14.10.13
[rtmp @ 0x3a615e0] Proto = rtmp, path = /live?vhost=cc.com/stream_1, app = live?vhost=cc.com, fname = stream_1
[rtmp @ 0x3a615e0] Server bandwidth = 5000000
[rtmp @ 0x3a615e0] Client bandwidth = 5000000
[rtmp @ 0x3a615e0] New incoming chunk size = 4096
[rtmp @ 0x3a615e0] Creating stream...
[rtmp @ 0x3a615e0] Sending play command for 'stream_1'
Probing flv score:100 size:2048
Probing mp3 score:1 size:2048
[flv @ 0x3a60c80] Format flv probed with size=2048 and score=100
[flv @ 0x3a60c80] Before avformat_find_stream_info() pos: 13 bytes read:33294 seeks:0 nb_streams:0
[flv @ 0x3a60c80] type:18, size:405, last:-1, dts:0 pos:21
[flv @ 0x3a60c80] type:8, size:7, last:-1, dts:1614036 pos:441
[flv @ 0x3a60c80] audio stream discovered after head already parsed
[flv @ 0x3a60c80] 1 AF 0 
[flv @ 0x3a60c80] type:9, size:56, last:-1, dts:1614046 pos:463
[flv @ 0x3a60c80] video stream discovered after head already parsed
[flv @ 0x3a60c80] 0 17 0 
[flv @ 0x3a60c80] type:9, size:52148, last:-1, dts:1614088 pos:534
[flv @ 0x3a60c80] 0 17 0 
[NULL @ 0x3a74ee0] nal_unit_type: 7, nal_ref_idc: 3
[NULL @ 0x3a74ee0] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 0x3a74ee0] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 0x3a74ee0] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 0x3a74ee0] nal_unit_type: 5, nal_ref_idc: 3
[h264 @ 0x3a74ee0] Reinit context to 1920x1088, pix_fmt: yuv420p
[h264 @ 0x3a74ee0] no picture

 

日志函数av_log()

void av_log(void* avcl, int level, const char *fmt, ...)
{
    AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
    va_list vl;
    va_start(vl, fmt);
    if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
        avc->log_level_offset_offset && level >= AV_LOG_FATAL)
        level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset);
    av_vlog(avcl, level, fmt, vl);
    va_end(vl);
}

 

av_log()第一个参数为NULL

例如:

av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");

直接输出日志内容

av_log()第一个参数有明确的类型

例如:

av_log(uc, AV_LOG_DEBUG, "No default whitelist set\n");

其中URLContext *uc。

根据av_log定义,输出class_name的内容。

其中libavformat/rtmpproto.c,对于rtmp协议,item_name()函数回调av_default_item_name函数(),而class_name为rtmp

const char *av_default_item_name(void *ptr)
{
    return (*(AVClass **) ptr)->class_name;
}


#define RTMP_PROTOCOL(flavor)                    \
static const AVClass flavor##_class = {          \
    .class_name = #flavor,                       \
    .item_name  = av_default_item_name,          \
    .option     = rtmp_options,                  \
    .version    = LIBAVUTIL_VERSION_INT,         \
};                                               \
                                                 \
const URLProtocol ff_##flavor##_protocol = {     \
    .name           = #flavor,                   \
    .url_open       = rtmp_open,                 \
    .url_read       = rtmp_read,                 \
    .url_read_seek  = rtmp_seek,                 \
    .url_read_pause = rtmp_pause,                \
    .url_write      = rtmp_write,                \
    .url_close      = rtmp_close,                \
    .priv_data_size = sizeof(RTMPContext),       \
    .flags          = URL_PROTOCOL_FLAG_NETWORK, \
    .priv_data_class= &flavor##_class,           \
};


RTMP_PROTOCOL(rtmp)
RTMP_PROTOCOL(rtmpe)
RTMP_PROTOCOL(rtmps)
RTMP_PROTOCOL(rtmpt)
RTMP_PROTOCOL(rtmpte)
RTMP_PROTOCOL(rtmpts)

其中libavformat/tcp.c,对于tcp协议,item_name()函数回调av_default_item_name函数(),而class_name为tcp

const char *av_default_item_name(void *ptr)
{
    return (*(AVClass **) ptr)->class_name;
}


static const AVClass tcp_class = {
    .class_name = "tcp",
    .item_name  = av_default_item_name,
    .option     = options,
    .version    = LIBAVUTIL_VERSION_INT,
};

const URLProtocol ff_tcp_protocol = {
    .name                = "tcp",
    .url_open            = tcp_open,
    .url_accept          = tcp_accept,
    .url_read            = tcp_read,
    .url_write           = tcp_write,
    .url_close           = tcp_close,
    .url_get_file_handle = tcp_get_file_handle,
    .url_shutdown        = tcp_shutdown,
    .priv_data_size      = sizeof(TCPContext),
    .flags               = URL_PROTOCOL_FLAG_NETWORK,
    .priv_data_class     = &tcp_class,
};

av_log()第一个参数使用默认类型

例如:

av_log(logctx, AV_LOG_DEBUG,
                       "Format %s probed with size=%d and score=%d\n",
                       (*fmt)->name, probe_size, score);

static const char* format_to_name(void* ptr)
{
    AVFormatContext* fc = (AVFormatContext*) ptr;
    if(fc->iformat) return fc->iformat->name;
    else if(fc->oformat) return fc->oformat->name;
    else return "NULL";
}

static const AVClass av_format_context_class = {
    .class_name     = "AVFormatContext",
    .item_name      = format_to_name,
    .option         = avformat_options,
    .version        = LIBAVUTIL_VERSION_INT,
    .child_next     = format_child_next,
    .child_class_next = format_child_class_next,
    .category       = AV_CLASS_CATEGORY_MUXER,
    .get_category   = get_category,
};


static void avformat_get_context_defaults(AVFormatContext *s)
{
    memset(s, 0, sizeof(AVFormatContext));

    s->av_class = &av_format_context_class;

    s->io_open  = io_open_default;
    s->io_close = io_close_default;

    av_opt_set_defaults(s);
}

static const AVClass flv_class = {
    .class_name = "flvdec",
    .item_name  = av_default_item_name,
    .option     = options,
    .version    = LIBAVUTIL_VERSION_INT,
};

AVInputFormat ff_flv_demuxer = {
    .name           = "flv",
    .long_name      = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
    .priv_data_size = sizeof(FLVContext),
    .read_probe     = flv_probe,
    .read_header    = flv_read_header,
    .read_packet    = flv_read_packet,
    .read_seek      = flv_read_seek,
    .read_close     = flv_read_close,
    .extensions     = "flv",
    .priv_class     = &flv_class,
};

其中函数item_name()回调函数format_to_name(),所以打印出:[flv @ 0x3a60c80] Format flv probed with size=2048 and score=100

© 著作权归作者所有

共有 人打赏支持
andrew810810
粉丝 3
博文 141
码字总数 117648
作品 0
朝阳
Twitch如何实现转码比FFmpeg性能提升65%?(下)

文 / Jeff Gong, Sahil Dhanju, Chih-Chiang Lu, Yueshi Shen 编者按:超过220万创作者在Twitch发布海量的视频,这对实时转码业务造成了巨大压力,Twitch团队通过优化多线程的转码服务以及I...

livevideostack
2017/12/13
0
0
PHP基础知识之————PHP Web脚本中使用FFmpeg

使用PHP调用系统命令实现ffmpeg的调用 . https://blog.csdn.net/weyla/article/details/46756897 测试用例: 简介 本文将尝试指出在PHP Web脚本中使用FFmpeg时需要了解的所有重要事项。它还将...

james_laughing
09/05
0
0
利用FFmpeg和管道(pipe),解决非URL和非文件的输入形式

利用FFmpeg和管道(pipe),解决非URL和非文件的输入形式 问题描述:利用FFmpeg来解码,但是输入方式不是URL,也不是文件系统中的文件,而是内存中的buffer。 解决此问题有两个思路,首先明确...

Michael_Yuan
2012/07/10
0
1
android端采用FFmpeg进行音频混合与拼接剪切

接触FFmpeg有一段时间了,它是音视频开发的开源库,几乎其他所有播放器、直播平台都基于FFmpeg进行二次开发。本篇文章来总结下采用FFmpeg进行音频处理:音频混合、音频剪切、音频拼接与音频转...

mp624183768
05/13
0
0
FFmpeg命令行工具学习(五):FFmpeg 编解码 API 分析

在上一篇文章 FFmpeg命令行工具学习(四):FFmpeg API 介绍与通用 API 分析 中,我们简单的讲解了一下FFmpeg 的API基本概念,并分析了一下通用API,本文我们将分析 FFmpeg 在编解码时使用的A...

灰色飘零
07/20
0
0

没有更多内容

加载失败,请刷新页面

加载更多

学习设计模式——单例模式

1. 认识单例模式 1. 定义:一个类中仅有一个实例,并提供一个访问它的全局访问点。 2. 结构:仅一个Singleton类,其中包含一个static类变量,而类变量的类型就是Singleton类,而且Singleton...

江左煤郎
15分钟前
0
0
前端安全系列之二:如何防止CSRF攻击?

背景 随着互联网的高速发展,信息安全问题已经成为企业最为关注的焦点之一,而前端又是引发企业安全问题的高危据点。在移动互联网时代,前端人员除了传统的 XSS、CSRF 等安全问题之外,又时常...

talen
17分钟前
0
0
Mysql数据库大量删除操作及谈面向对象中的封装继承和多态原理(图)

Mysql数据库大量删除操作及谈面向对象中的封装继承和多态原理(图) 最近进行数据库操作,遇到一个问题,就是大量删除一个数据表中的数据后,由于设定了id是自增的,导致再插入时,默认生成的...

原创小博客
18分钟前
0
0
Springboot + mongoDB : So easy

1. dependancy compile('org.springframework.boot:spring-boot-starter-data-mongodb') 2. config # mongodbspring.data.mongodb.host=***.mongodb.rds.aliyuncs.comspring.data.mongod......

园领T
29分钟前
1
0
centos 7( linux )下安装elasticsearch教程

目录 概述 环境准备 elaticsearch简介 安装elasticsearch 彩蛋 概述 很久没有写博客了,最近在做全文检索的项目,发现elasticsearch踩了不少坑,百度点进去又是坑,在此记录一下自己的踩坑历程。...

java_龙
35分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部