ffmpeg(2) 关于AVFMT_NOFILE

转载 2016年05月31日 23:48:24


在学习ffmpeg源码时,常常看到一个Flag:AVFMT_NOFILE,这个Flag非常重要,其在avformat.h中定义:#define AVFMT_NOFILE        0x0001




 * @defgroup lavd Special devices muxing/demuxing library
 * @{
 * Libavdevice is a complementary library to @ref libavf "libavformat". It
 * provides various "special" platform-specific muxers and demuxers, e.g. for
 * grabbing devices, audio capture and playback etc. As a consequence, the
 * (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own
 * I/O functions). The filename passed to avformat_open_input() often does not
 * refer to an actually existing file, but has some special device-specific
 * meaning - e.g. for x11grab it is the display name.
 * To use libavdevice, simply call avdevice_register_all() to register all
 * compiled muxers and demuxers. They all use standard libavformat API.
 * @}

libavdevice目录中的内容是libavformat目录中内容的补充,libavdevice提供的是各种特殊平台专用的muxers和demuxers,例如grabbing devices、audio capture、playback等,


通常不是指一个实际存在的文件,而是根据特定的设备确定,例如,x11grab,就是display name?显示器名字?


     * I/O context.
     * decoding: either set by the user before avformat_open_input() (then
     * the user must close it manually) or set by avformat_open_input().
     * encoding: set by the user.
     * 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.
     * decoding: set by the user before avformat_open_input().
     * encoding: 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;


 * Callback for checking whether to abort blocking functions.
 * AVERROR_EXIT is returned in this case by the interrupted
 * function. During blocking operations, callback is called with
 * opaque as parameter. If the callback returns 1, the
 * blocking operation will be aborted.
 * No members can be added to this struct without a major bump, if
 * new elements have been added after this struct in AVFormatContext
 * or AVIOContext.
typedef struct AVIOInterruptCB 
    int (*callback)(void*);
    void *opaque;
} AVIOInterruptCB;


 * Guess the file format.
 * @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);

 * Guess the file format.
 * @param is_opened Whether the file is already opened; determines whether
 *                  demuxers with or without AVFMT_NOFILE are probed.
 * @param score_max A probe score larger that this is required to accept a
 *                  detection, the variable is set to the actual detection
 *                  score afterwards.
 *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
 *                  to retry with a larger probe buffer.
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);



 * Create and initialize a AVIOContext for accessing the
 * resource indicated by url.
 * @note When the resource indicated by url has been opened in
 * read+write mode, the AVIOContext can be used only for writing.
 * @param s Used to return the pointer to the created AVIOContext.
 * In case of failure the pointed to value is set to NULL.
 * @param flags flags which control how the resource indicated by url
 * is to be opened
 * @param int_cb an interrupt callback to be used at the protocols level
 * @param options  A dictionary filled with protocol-private options. On return
 * this parameter will be destroyed and replaced with a dict containing options
 * that were not found. May be NULL.
 * @return >= 0 in case of success, a negative value corresponding to an
 * AVERROR code in case of failure
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options);

参数const AVIOInterruptCB *int_cb,经过层层调用,最终在函数url_alloc_for_protocol中,赋值给新分配的URLContext类型变量的数据成员AVIOInterruptCB interrupt_callback;

static int url_alloc_for_protocol(URLContext **puc, struct URLProtocol *up,
                                  const char *filename, int flags,
                                  const AVIOInterruptCB *int_cb)
    URLContext *uc;


   uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);


       if (int_cb)
        uc->interrupt_callback = *int_cb;


接下来要做的事情,就是理清楚,在有AVFMT_NOFILE和没有AVFMT_NOFILE的两种情况下,avformat input open分别的流程,以及二者之间有什么差别?


ffmpeg——AVOutputFormat 输出文件格式

一:介绍 ffmpeg支持各种各样的输出文件格式,MP4,FLV,3GP等等。而 AVOutputFormat 结构体则保存了这些格式的信息和一些常规设置。 官方参考: http://ffmp...
  • u014030821
  • u014030821
  • 2016年10月21日 11:54
  • 2805


1 通用选项 -L license -h 帮助 -fromats 显示可用的格式,编解码的,协议的。 -f fmt 强迫采用格式fmt -i filename 输入文件 -y 覆盖输出文件...
  • matthew0618band
  • matthew0618band
  • 2013年08月08日 09:25
  • 5232

Centos下 ffmpeg 和opencv一起配合处理视频

默认安装的opencv 很多视频格式打不开,cvCreateFileCapture返回值为NULL,为了解决此问题,需要安装视频编解码的库,我选择安装ffmpeg,我在windows下也用过这个库。 ...
  • KUAILE123
  • KUAILE123
  • 2014年03月11日 20:57
  • 2492


无论是看过的nginx有关书还是网上看到的有关nginx 配置说明的文章(http://wiki.nginx.org/EventsModule#worker_connections),无一例外,在讲到...
  • sole_cc
  • sole_cc
  • 2016年09月04日 17:36
  • 6452

nano pi neo2 上Ubuntu-core自行编译ffmpeg 动态so库

  • 2017年11月30日 16:06
  • 34.93MB
  • 下载


  • 2014年10月25日 11:29
  • 7.03MB
  • 下载

最简单的基于FFMPEG+SDL的音频播放器 2

  • 2014年09月01日 14:16
  • 12.65MB
  • 下载

最简单的基于FFMPEG+SDL的视频播放器 2 (SDL 2.0)

  • 2014年08月27日 10:19
  • 17.22MB
  • 下载


  • 2014年07月13日 11:51
  • 6.64MB
  • 下载


  • 2012年05月11日 10:22
  • 5.58MB
  • 下载
您举报文章:ffmpeg(2) 关于AVFMT_NOFILE