ffmpeg——转音视视频格式

主要的API输出时所用的函数1. avformat_alloc_output_contex2() : 分配输出时所用的上下文的空间3. avformat_free_context():将分配的上下文空间释放(防止内存泄漏)5. avformat_new_stream():创建输出的多媒体文件中码流(多媒体文件中含有多种轨)4.avcodec_parameters_copy():拷贝音...
摘要由CSDN通过智能技术生成

目的

将一段音视频的格式转换为另一种格式(如:.mp4转成flv)

思路

  1. 转换音视频的格式其实就是转封装格式,与其内容数据编码方式无关,只需要copy过来,但是在copy数据是需要来考虑转换时间基的问题;
  2. 刻度转换:比如说copy音频流 ,原数据采样率为44100hz,其刻度大小为1/44100,然而新的输出文件默认的刻度为1/1000;若不进行刻度转换,则会产生音视频同步的问题;(利用av_rescale_q_rnd进行转换)

主要的API

输出时所用的函数

1. avformat_alloc_output_contex2()  :  分配输出时所用的上下文的空间
3. avformat_free_context():将分配的上下文空间释放(防止内存泄漏)
5. avformat_new_stream():创建输出的多媒体文件中码流(多媒体文件中含有多种轨)
4. avcodec_parameters_copy():拷贝音视频(sps/pps)的信息(不改变音视频编解码的方式)

生成多媒体文件所用的函数

1. avformat_write_header():生成多媒体文件头
2. av_write_frame()/av_interleaved_write_frame():写入数据(交织写入数据)
3. av_write_trailer():写入多媒体文件的尾部信息

代码

#include<stdio.h>
#include<libavformat/avformat.h>
#include<libavutil/log.h>

int main(int argc , char* argv[])
{
   	
	AVFormatContext *ifmt_ctx =NULL, *ofmt_ctx=NULL;
	AVOutputFormat *ofmt = NULL;
	AVPacket pkt;
	const char* in_filename,*out_filename;
	int ret,i;
	int stream_index=0;
	int *stream_mapping = NULL;
	int stream_mapping_size= 0 ;



	if(argc<3){
   
		av_log(NULL,AV_LOG_ERROR,"pamaters should be more than three!\n");
	return -1;
	}

	in_filename=argv[1];
	out_filename=argv[2];

	/*input */

	//open input file	
	if((ret=avformat_open_input(&ifmt_ctx,in_filename,0,0))<0){
   
	
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值