FFmpeg init_input函数剖析

简介:

函数调用逻辑
avformat_open_input
       init_input
            av_probe_input_buffer2


函数原型 

static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options)

函数说明
该函数主要是初始化AVInputFormat结构体,主要是调用av_probe_input_buffer2函数探测码流格式。AVFormatContext结构体flags变量,在经过avformat_alloc_context创建AVFormatContext结构体对象指针之后,flags值是0x200000(AVFMT_FLAG_AUTO_BSF),含义是等待包数据然后确定码流的文件格式,或者是添加一个字节流的过滤器(Wait for packet data before writing a header, and add bitstream filters as requested by the muxer) 
AVFMT_FLAG_DISCARD_CORRUPT  0x0100 ///< Discard frames marked corrupted
AVInputFormat结构体flags变量,在经过av_find_input_format("h264"),返回之后flags的值是0x0100(AVFMT_FLAG_DISCARD_CORRUPT)(Discard frames marked corrupted)

函数代码
static int init_input(AVFormatContext *s, const char *filename,
                      AVDictionary **options)
{
    int ret;
    AVProbeData pd = { filename, NULL, 0 };
    int score = AVPROBE_SCORE_RETRY;

    if (s->pb) {
//当前的flags是0x200000
        s->flags |= AVFMT_FLAG_CUSTOM_IO;
//iformat指定h264码流格式之后,不为NULL
        if (!s->iformat)
            return av_probe_input_buffer2(s->pb, &s->iformat, filename,
                                         s, 0, s->format_probesize);
//s->iformat->flags & AVFMT_NOFILE值为真,但是并没有在日志文件中打印出来Custom AVIOContext makes no sense
        else if (s->iformat->flags & AVFMT_NOFILE)
            av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
                                      "will be ignored with AVFMT_NOFILE format.\n");
        return 0;
    }

    if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
        (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score))))
        return score;

    if ((ret = s->io_open(s, &s->pb, filename, AVIO_FLAG_READ | s->avio_flags, options)) < 0)
        return ret;

    if (s->iformat)
        return 0;
    return av_probe_input_buffer2(s->pb, &s->iformat, filename,
                                 s, 0, s->format_probesize);
}




     本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/2055123,如需转载请自行联系原作者




相关文章
|
1月前
|
算法
FFmpeg关键函数介绍
FFmpeg关键函数介绍
28 0
|
4月前
|
API 开发工具 C语言
解决新版本ffmpeg找不到avpriv_io_delete函数等问题
解决新版本ffmpeg找不到avpriv_io_delete函数等问题
30 0
使用FFMPEG的sws_scale函数实现各种原始颜色格式互转(YUV\RGB\)
使用FFMPEG的sws_scale函数实现各种原始颜色格式互转(YUV\RGB\)
728 0

热门文章

最新文章