封装API:avformat_alloc_output_context2,avformat_free_context,avformat_new_stream,

avformat_alloc_output_context2

原型

/**

* Allocate an AVFormatContext for an output format.

* avformat_free_context() can be used to free the context and

* everything allocated by the framework within it.

*

* @param ctx pointee is set to the created format context,

* or to NULL in case of failure

* @param oformat format to use for allocating the context, if NULL

* format_name and filename are used instead

* @param format_name the name of output format to use for allocating the

* context, if NULL filename is used instead

* @param filename the name of the filename to use for allocating the

* context, may be NULL

*

* @return >= 0 in case of success, a negative AVERROR code in case of

* failure

*/

int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat,

const char *format_name, const char *filename);

函数作用

Allocate an AVFormatContext for an output format.avformat_free_context() can be used to free the context and everything allocated by the framework within it.

创建一个 avformatContext,这个avformatContext是为了 封装使用的,

最后需要使用 avformat_free_context()函数来释放 avformatContext

参数

AVFormatContext **ctx,

实际开发中 AVFormatContext *avFormatContetx = nullptr;

avformat_alloc_output_context2(&avFormatContetx ,nullptr,nullptr,"a.mp4");

const AVOutputFormat *oformat,

实际开发中传递为NULL

AVOutputFormat* oformat用来指定 avformatContext的 参数 -- (AVOutputFormat* oformat),如果设置为NULL,则会根据第三个参数 format_name 和 第四个参数 filename 决定avformatContext的 AVOutputFormat

format to use for allocating the context, if NULL format_name and filename are used instead

const char *format_name,

指定AVOutputFormat* oformat的name,进而用来指定 avformatContext的 参数 -- (AVOutputFormat* oformat),如果为null,会根据第四个参数filename 决定avformatContext的 AVOutputFormat

the name of output format to use for allocating the context, if NULL filename is used instead

const char *filename

打开那个文件,此filename一般会有后缀名,例如 a.mp4。

返回值

return >= 0 in case of success, a negative AVERROR code in case of failure

avformat_free_context

原型

/**

* Free an AVFormatContext and all its streams.

* @param s context to free

*/

void avformat_free_context(AVFormatContext *s);

函数作用

将 AVFormatContext* 指向的空间全部释放。

但是 不会将自己置为nullptr

因此使用时:一般会同时将 avformatContext设置为nullptr

avformat_free_context(avformatContext);

avformatContext = nullptr;

参数

返回值

avformat_new_stream

原型

/**

* Add a new stream to a media file.

*

* When demuxing, it is called by the demuxer in read_header(). If the

* flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also

* be called in read_packet().

*

* When muxing, should be called by the user before avformat_write_header().

*

* User is required to call avformat_free_context() to clean up the allocation

* by avformat_new_stream().

*

* @param s media file handle

* @param c unused, does nothing

*

* @return newly created stream or NULL on error.

*/

AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);

函数作用

new一个avstream,

参数

AVFormatContext *s,

const AVCodec *c

创建的avstream是 那种avcodec的。

返回值

成功返回一个 avstream *, 失败返回nullptr

相关推荐
Eiceblue36 分钟前
【免费.NET方案】CSV到PDF与DataTable的快速转换
开发语言·pdf·c#·.net
好奇的菜鸟1 小时前
如何在IntelliJ IDEA中设置数据库连接全局共享
java·数据库·intellij-idea
m0_555762901 小时前
Matlab 频谱分析 (Spectral Analysis)
开发语言·matlab
DuelCode2 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
浪裡遊2 小时前
React Hooks全面解析:从基础到高级的实用指南
开发语言·前端·javascript·react.js·node.js·ecmascript·php
优创学社22 小时前
基于springboot的社区生鲜团购系统
java·spring boot·后端
幽络源小助理2 小时前
SpringBoot基于Mysql的商业辅助决策系统设计与实现
java·vue.js·spring boot·后端·mysql·spring
猴哥源码2 小时前
基于Java+springboot 的车险理赔信息管理系统
java·spring boot
lzb_kkk3 小时前
【C++】C++四种类型转换操作符详解
开发语言·c++·windows·1024程序员节
YuTaoShao3 小时前
【LeetCode 热题 100】48. 旋转图像——转置+水平翻转
java·算法·leetcode·职场和发展