FFmpeg AVFMT_NOFILE宏定义剖析

简介:

使用说明
    当前为了避免在调用init_input函数的时候,读取缓存区的数据,从而设置了该标志位,但是最终在avformat_open_input的其他地方还是读取了缓冲区的数据

        pAVInputFormat = av_find_input_format("h264");
        pAVInputFormat->flags |= AVFMT_NOFILE;

宏定义
/// Demuxer will use avio_open, no opened file should be provided by the caller.
//解复用器将调用avio_open函数,调用者提供一个没有打开的文件,估计是打开的文件会被占用
#define AVFMT_NOFILE        0x0001
#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */


AVFMT_NOFILE formats will not have a AVIOContext
当设置了AVFMT_NOFILE标志,将不会携带AVIOContext


/* Open input file and probe the format if necessary. */
static int init_input(AVFormatContext *s, const char *filename,
                      AVDictionary **options)
{
    int ret;
    AVProbeData pd = { filename, NULL, 0 };
    int score = AVPROBE_SCORE_RETRY;

    //这里探测码流的方式,企图通过AVIOContext结构体中的read_packet函数
    //如果码流格式已经指定并且指定了标志位,直接返回
    if (s->pb) {
        s->flags |= AVFMT_FLAG_CUSTOM_IO;
    //如果没有指定输入格式,开始探测码流格式
        if (!s->iformat)
            return av_probe_input_buffer2(s->pb, &s->iformat, filename,
                                         s, 0, s->format_probesize);
        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;
    }
   //这里探测码流的方式,企图通过通过进来的文件名称
   //如果码流格式已经指定并且指定了标志位,直接返回
   //这里非常明显网络RTSP流,肯定是不会走到这里
    if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
        (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score))))
        return score;

    //如果指定了iformat结构体,并且没有设置标志位,肯定执行下面的语句,该语句会调用read_packet函数
    //进行分析码流
    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);
}


从下面的说明可以得知,当添加了AVFMT_NOFILE标志位,AVIOContext *pb会设置为空
    /**
     * I/O context.
     *
     * - demuxing: either set by the user before avformat_open_input() (then
     *             the user must close it manually) or set by avformat_open_input().
     * - muxing: set by the user before avformat_write_header(). The caller must
     *           take care of closing / freeing the IO context.
     *
     * Do NOT set this field if AVFMT_NOFILE flag is set in
     * iformat/oformat.flags. In such a case, the (de)muxer will handle
     * I/O in some other way and this field will be NULL.
     */
    AVIOContext *pb;

    /**
     * Custom interrupt callbacks for the I/O layer.
     *
     * demuxing: set by the user before avformat_open_input().
     * muxing: set by the user before avformat_write_header()
     * (mainly useful for AVFMT_NOFILE formats). The callback
     * should also be passed to avio_open2() if it's used to
     * open the file.
     */
    AVIOInterruptCB interrupt_callback;

/**
 * Guess the file format.
 *
 * @param pd        data to be probed
 * @param is_opened Whether the file is already opened; determines whether
 *                  demuxers with or without AVFMT_NOFILE are probed.
 */
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);


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

相关文章
|
编解码 Linux 开发工具
ffmpeg的基本用法(下)
ffmpeg的基本用法的下篇来喽!
1025 0
|
6天前
|
移动开发 Unix Linux
ffmpeg编译so
ffmpeg编译so
17 0
|
6天前
|
算法
FFmpeg关键函数介绍
FFmpeg关键函数介绍
29 0
|
9月前
|
Ubuntu Linux
ffmpeg编译x265
ffmpeg编译x265
277 0
ffmpeg编译x265
|
9月前
超简洁ffmpeg编译ffplay
超简洁ffmpeg编译ffplay
59 0
超简洁ffmpeg编译ffplay
|
Windows
ffmpeg不提供自己的编译结果了
ffmpeg不提供自己的编译结果了
96 0
ffmpeg不提供自己的编译结果了
FFMPEG编译ffplay
FFMPEG编译ffplay
118 0
编译ffmpeg没有生成编译后ffplay
编译ffmpeg没有生成编译后ffplay
214 0
FFMPEG libfdk-aac编译
FFMPEG libfdk-aac编译
82 0