函数调用逻辑
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 corruptedAVInputFormat结构体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);}