FFMPEG-avformat_open_input

850 阅读1分钟

函数原型

/**
 * Open an input stream and read the header. The codecs are not opened.
 * The stream must be closed with avformat_close_input().
 *
 * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
 *           May be a pointer to NULL, in which case an AVFormatContext is allocated by this
 *           function and written into ps.
 *           Note that a user-supplied AVFormatContext will be freed on failure.
 * @param url URL of the stream to open.
 * @param fmt If non-NULL, this parameter forces a specific input format.
 *            Otherwise the format is autodetected.
 * @param options  A dictionary filled with AVFormatContext and demuxer-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 on success, a negative AVERROR on failure.
 *
 * @note If you want to use custom IO, preallocate the format context and set its pb field.
 */
 
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options);

参数

AVFormatContext** ps:格式化上下文

动态链接库的空间只能在动态链接库里面清理,因此这里初始化 指向一个空的指针,然后,将指针地址传入动态链接库,在里面初始化,指针的地址的值就会发生变化,因此可以用 动态链接库close清理 ,这里分配的空间在程序退出时通过avformat_close_input函数释放。

const char *url:音视频流的url

可以是文件名,也可以是网络流url,会存储AVFormatContext 里面,以便rtsp等断开重连

AVInputFormat *fmt:音视频的封装格式

可以传NULL,让ffmpeg自己去探测

AVDictionary **options:选项参数

一组key value。 可以传NULL递。具体定义在源文件libavformat/options_table.h 里说明。

返回值

0 成功 负值 失败