FFmpeg源代码:avformat_write_header/av_write_frame/av_interleaved_write_frame/av_write_trailer
跟写视频文件相关的三个配套接口是
avformat_write_header()用于写视频文件头
av_write_frame()用于写视频数据
av_interleaved_write_frame() 用于交错写视频数据
av_write_trailer()用于写视频文件尾
avformat_write_header
接口声明位于ffmpeg/libavformat/avformat.h中
/*** Allocate the stream private data and write the stream header to* an output media file.** @param s Media file handle, must be allocated with avformat_alloc_context().* Its oformat field must be set to the desired output format;* Its pb field must be set to an already opened AVIOContext.* @param options An AVDictionary filled with AVFormatContext and muxer-private options.* On return this parameter will be destroyed and replaced with a dict containing* options that were not found. May be NULL.** @return AVSTREAM_INIT_IN_WRITE_HEADER on success if the codec had not already been fully initialized in avformat_init,* AVSTREAM_INIT_IN_INIT_OUTPUT on success if the codec had already been fully initialized in avformat_init,* negative AVERROR on failure.** @see av_opt_find, av_dict_set, avio_open, av_oformat_next, avformat_init_output.*/
av_warn_unused_result
int avformat_write_header(AVFormatContext *s, AVDictionary **options);
参数含义:
s:用于输出的AVFormatContext。
options:额外的选项,目前没有深入研究过,一般为NULL。
avformat_write_header()的调用关系如下图所示。
avformat_write_header()完成了以下工作:
(1)调用init_muxer()初始化复用器
(2)调用AVOutputFormat的write_header()
具体可以参见:
FFmpeg源代码简单分析:avformat_write_header()
av_write_frame
av_write_frame()用于输出一帧视音频数据,它的声明位于libavformat\avformat.h
/*** Write a packet to an output media file.** This function passes the packet directly to the muxer, without any buffering* or reordering. The caller is responsible for correctly interleaving the* packets if the format requires it. Callers that want libavformat to handle* the interleaving should call av_interleaved_write_frame() instead of this* function.** @param s media file handle* @param pkt The packet containing the data to be written. Note that unlike* av_interleaved_write_frame(), this function does not take* ownership of the packet passed to it (though some muxers may make* an internal reference to the input packet).* <br>* This parameter can be NULL (at any time, not just at the end), in* order to immediately flush data buffered within the muxer, for* muxers that buffer up data internally before writing it to the* output.* <br>* Packet's @ref AVPacket.stream_index "stream_index" field must be* set to the index of the corresponding stream in @ref* AVFormatContext.streams "s->streams".* <br>* The timestamps (@ref AVPacket.pts "pts", @ref AVPacket.dts "dts")* must be set to correct values in the stream's timebase (unless the* output format is flagged with the AVFMT_NOTIMESTAMPS flag, then* they can be set to AV_NOPTS_VALUE).* The dts for subsequent packets passed to this function must be strictly* increasing when compared in their respective timebases (unless the* output format is flagged with the AVFMT_TS_NONSTRICT, then they* merely have to be nondecreasing). @ref AVPacket.duration* "duration") should also be set if known.* @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush** @see av_interleaved_write_frame()*/
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
参数含义:
s:用于输出的AVFormatContext。
pkt:等待输出的AVPacket。
具体实现参见:FFmpeg源代码简单分析:av_write_frame()
av_interleaved_write_frame
av_interleaved_write_frame 用于将数据包写入输出媒体文件,确保交错正确。确保包按照dts递增的顺序正确交错
该函数无论成功还是失败,其内部都会调用av_packet_unref
解引用
它的声明位于libavformat\avformat.h
/*** Write a packet to an output media file ensuring correct interleaving.** This function will buffer the packets internally as needed to make sure the* packets in the output file are properly interleaved in the order of* increasing dts. Callers doing their own interleaving should call* av_write_frame() instead of this function.** Using this function instead of av_write_frame() can give muxers advance* knowledge of future packets, improving e.g. the behaviour of the mp4* muxer for VFR content in fragmenting mode.** @param s media file handle* @param pkt The packet containing the data to be written.* <br>* If the packet is reference-counted, this function will take* ownership of this reference and unreference it later when it sees* fit.* The caller must not access the data through this reference after* this function returns. If the packet is not reference-counted,* libavformat will make a copy.* <br>* This parameter can be NULL (at any time, not just at the end), to* flush the interleaving queues.* <br>* Packet's @ref AVPacket.stream_index "stream_index" field must be* set to the index of the corresponding stream in @ref* AVFormatContext.streams "s->streams".* <br>* The timestamps (@ref AVPacket.pts "pts", @ref AVPacket.dts "dts")* must be set to correct values in the stream's timebase (unless the* output format is flagged with the AVFMT_NOTIMESTAMPS flag, then* they can be set to AV_NOPTS_VALUE).* The dts for subsequent packets in one stream must be strictly* increasing (unless the output format is flagged with the* AVFMT_TS_NONSTRICT, then they merely have to be nondecreasing).* @ref AVPacket.duration "duration") should also be set if known.** @return 0 on success, a negative AVERROR on error. Libavformat will always* take care of freeing the packet, even if this function fails.** @see av_write_frame(), AVFormatContext.max_interleave_delta*/
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
参数含义:
- AVFormatContext *s:媒体文件对应的结构上下文
- AVPacket *pkt:包含要写入数据的数据包
av_write_trailer
av_write_trailer
函数写入文件结束符,并关闭文件, 声明位于libavformat\avformat.h
/*** Write the stream trailer to an output media file and free the* file private data.** May only be called after a successful call to avformat_write_header.** @param s media file handle* @return 0 if OK, AVERROR_xxx on error*/
int av_write_trailer(AVFormatContext *s);
FFmpeg源代码:avformat_write_header/av_write_frame/av_interleaved_write_frame/av_write_trailer相关推荐
- FFmpeg源代码简单分析:av_write_trailer()
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- FFmpeg源代码简单分析-编码-av_write_trailer()
参考链接: FFmpeg源代码简单分析:av_write_trailer()_雷霄骅的博客-CSDN博客_av_malloc av_write_trailer() av_write_trailer() ...
- FFmpeg源代码简单分析:av_write_frame()
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- FFmpeg源代码简单分析:avformat_write_header()
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- FFmpeg源代码简单分析:libavdevice的gdigrab
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- FFmpeg源代码简单分析:libavdevice的avdevice_register_all()
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- FFmpeg源代码简单分析:configure
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- FFmpeg源代码简单分析:makefile
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- FFmpeg源代码简单分析:libswscale的sws_getContext()
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
最新文章
- SAP Spartacus里的injector
- vue从入门到进阶:简介(一)
- java接口方法实现_Java接口的简单定义与实现方法示例
- numpy 矩阵与向量相乘_有人把NumPy画成了花,生动又形象
- 基于SSH2做一个24小时订单分析表格
- 数据结构之哈夫曼编码
- mysql 配置root密码_Mysql安装与配置调优及修改root密码的方法
- spring实战第五版总结
- 如何导出微信的小视频
- ⒔Bash 内部命令
- 第二个暴力猴脚本- 改写后用iframe抓取携程某个城市所有起飞、到达航班并保存
- 数据仓库经典销售案例
- linux 查看ip
- linux添加jetdirect协议,Linux系统中如何打印
- Mac出现共享网络/wifi问题
- 工行智能客服服务量突破1.7亿笔;迪拜机场拟用人脸识别技术替代护照检查
- AirPods声音越来越小问题
- usb接口多少钱_新款本田CRV正式上市,落地价多少钱?
- 【松岩早盘视点】2019-09-30
- 为什么我们要从MySQL迁移到TiDB?
热门文章
- Java的 “万物皆对象“
- C++多线程开发之actor model
- ROS学习-tf介绍
- 奔驰商务租车|奔驰V260商务车
- 跟我学UDS(ISO14229) ———— 0x19 服务参数介绍
- 趣来宝机器人_App Store 上的“管家机器人”
- Windows 一键关闭UAC、防火墙、IE配置脚本
- 赣州java培训_赣州java工资一般多少,赣州java工资在什么水平,赣州java工资待遇有多少...
- 如何用JuiceSSH玩转Linux与Windows
- STC8A系列单片机ADC的使用