avformat_open_input
原型
/**
* 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);
node:调用前确保 av_register_all avformat_network_init 已经调用。现在input 数据也可以是http网络url
参数介绍:
AVFormatContext : 格式化上下文
node: 动态链接库的空间只能在动态链接库里面清理,因此这里初始化 指向一个空的指针,然后,将指针地址传入动态链接库,在里面初始化,指针的地址的值就会发生变化,因此可以用 动态链接库close清理 ,如果这里自己初始化好 AVFormatContext 则要自己清理。
如:
AVFormatContext *ic = NULL;
int re = avformat_open_input(&ic,videoPath,0,0);
url 是视频地址,当然也可以是网络流,会存储AVFormatContext 里面,以便rtsp等断开重连。
fmt: 输入封装的根式,可以不传入,让其自己去探测。
options: 一组key value。 也可以不传递。想看哪些可以传入,可以去源文件libavformat/options_table.h 里查看。如打开rtsp的时候掺入最大延迟等。头文件如下: