文档章节

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

andrew810810
 andrew810810
发布于 2016/12/09 15:02
字数 980
阅读 229
收藏 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
利用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
学习FFmpeg API – 解码视频

ffmpeg是编解码的利器,用了很久,以前看过dranger 的教程,非常精彩,受益颇多,是学习ffmpeg api很好的材料。可惜的是其针对的ffmpeg版本已经比较老了,而ffmpeg的更新又很快,有些API已经...

霄霄月月
2012/05/08
0
32

没有更多内容

加载失败,请刷新页面

加载更多

下一页

人生苦短:Python里的17个“超赞操作

人生苦短,我选Python”。那么,你真的掌握了Python吗? 1. 交换变量 有时候,当我们要交换两个变量的值时,一种常规的方法是创建一个临时变量,然后用它来进行交换。比如: # 输入 a = 5 b ...

糖宝lsh
39分钟前
4
0
咕泡-spring中常用设计模式概述

设计模式就是经验之谈,供后人借鉴,解决一些具有代表性的问题 设计模式来源于生活,反过来帮助我们更好生活 设计模式提升代码的可读性、可扩展性、维护成本、复杂业务问题 千万不要死记硬背...

职业搬砖20年
今天
2
0
day59-20180817-流利阅读笔记-待学习

假·照骗,真·社交焦虑 雪梨 2018-08-17 1.今日导读 发朋友圈之前,不少人为了展现更美好的生活状态会对照片加以“微调”,或是加个滤镜显得逼格更高,或是磨个皮瘦个脸拉个大长腿。现在,国...

aibinxiao
今天
19
0
OSChina 周五乱弹 —— 姑娘在这个节日里表白你接受么?

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @Sharon啊:完全被这个小姐姐圈粉了,学两首她的歌去哈哈 分享王贰浪的单曲《往后余生(翻自 马良)》 《往后余生(翻自 马良)》- 王贰浪 手...

小小编辑
今天
949
16
为什么HashMap要自己实现writeObject和readObject方法?

为什么HashMap要自己实现writeObject和readObject方法? 如果你有仔细阅读过HashMap的源码,那么你一定注意过一个问题:HashMap中有两个私有方法。 private void writeObject(java.io.Objec...

DemonsI
今天
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部