FFmpeg函数简单分析:avformat

FFmpeg函数简单分析:avformat,第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, ff_const59 AVInputFormat *fmt, AVDictionary **options);

该函数用于打开多媒体数据并且获得一些相关的信息
参数分析:
1.AVFormatContext **ps:
指向用户提供的AVFormatContext的指针(由avformat_alloc_context分配,avformat_free_context释放)或者指向NULL的指针,在这种情况下,AVFormatContext由函数并写入ps
注意:两种情况:如果是自己申请空间的要自己释放,如果传入NULL只需要调用关闭就会自动释放
2.const char *url:打开的视音频流的url,并会保存到AVFormatContext的url中
3.AVInputFormat *fmt:强制指定AVFormatContext中AVInputFormat的。这个参数一般情况下可以设置为NULL,这样FFmpeg可以自动检测AVInputFormat。
4.AVDictionary **options:附加的一些选项,一般情况下可以设置为NULL。

//第一种自己申请
AVFormatContext *pFormatCtx = avformat_alloc_context();
if(avformat_open_input(&pFormatCtx,filepath,NULL,NULL)!=0){
        printf("Couldn't open input stream.\n");
        return -1;
}
avformat_close_input(&pFormatCtx);
avformat_free_context(pFormatCtx);
//第二种传入NULL
AVFormatContext *pFormatCtx = NULL;
if(avformat_open_input(&pFormatCtx,filepath,NULL,NULL)!=0){
        printf("Couldn't open input stream.\n");
        return -1;
}
avformat_close_input(&pFormatCtx);//会自动释放

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/716695.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存