FFmpeg Muxing流程

在这里插入图片描述

介绍

FFmpeg的Muxing主要分为三步操作:

  • avformat_write_header : 写文件头
  • av_write_frame/av_interleaved_write_frame: 写packet
  • av_write_trailer : 写文件尾
1、av_format_write_head
/**
 * 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 0 on success, negative AVERROR on failure.
 *
 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
 */
int avformat_write_header(AVFormatContext *s, AVDictionary *
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
FFmpeg是一个开源的跨平台多媒体处理库,能够处理各种格式的音频和视频文件。FFmpeg在实际的应用中,通常使用它提供的各种API对音视频进行编解码、过滤、转换等处理。下面是FFmpeg函数调用的基本流程: 1. 初始化FFmpeg库:使用av_register_all函数进行初始化,注册FFmpeg支持的所有编码器、解码器、过滤器等组件。 2. 打开输入文件或设备:使用avformat_open_input函数打开输入文件或设备,并读取文件或设备的基本信息和流信息。 3. 查找音视频流:使用avformat_find_stream_info函数查找音视频流,并获取流的基本信息。 4. 打开编解码器:使用avcodec_find_decoder函数查找音视频流的编解码器,并使用avcodec_open2函数打开编解码器。 5. 解码音视频数据:使用avcodec_send_packet函数将压缩数据送入解码器,使用avcodec_receive_frame函数接收解码后的数据。 6. 过滤音视频数据:使用avfilter_graph_create_filter函数创建过滤器,并使用av_buffersrc_add_frame函数将解码后的数据送入过滤器,使用av_buffersink_get_frame函数从过滤器中获取过滤后的数据。 7. 编码音视频数据:使用avcodec_send_frame函数将原始数据送入编码器,使用avcodec_receive_packet函数接收编码后的数据。 8. 封装音视频数据:使用avformat_write_header函数写入输出文件或设备的头部信息,使用av_interleaved_write_frame函数将编码后的数据写入输出文件或设备。 9. 释放资源:使用avformat_close_input、avcodec_close、avfilter_graph_free、avformat_free_context等函数释放资源。 以上是FFmpeg函数调用的基本流程,具体实现时还需根据具体需求进行函数调用和参数设置。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值