FFmpeg获取文件参数

一 、获取文件时长

  ffmpeg在打开文件成功后就在 文件上下文结构体 AVFormatContext 中保存了文件的总时长。 但是ffmpeg中各种时间参数通常不是直接通过以秒或者毫秒为单位的,而是以多少个时间基来表示的,文件上下文中的时间基是秒和毫秒的换算单位,而音视频流中则是采样率,下面通过具体的代码来展示通过文件上下文,音视频流信息分别来获取总时长。
①通过文件参数获取时长

//  AVFormatContext 中的 duration保存的时长是微妙,
   AVFormatContext* m_filefmt_ctx;
   int64_t total_second = m_filefmt_ctx->duration / AV_TIME_BASE;
	//int64_t total_second = m_filefmt_ctx->duration * AV_TIME_BASE_Q;
   cout<<"file hour:"<< total_second /3600<<endl;
   cout <<"file min:" << (total_second %3600)/60 << endl;
   cout << "file s:" << total_second % 60 << endl;

②通过音视频流信息获取时长

	//视频流 time_base
	int64_t = total_second = m_vdecode.m_stream->duration* av_q2d(m_vdecode.m_stream->time_base);
	cout << "video hour:" << total_second / 3600 << endl;
	cout << "video min:" << (total_second % 3600) / 60 << endl;
	cout << "video s:" << total_second % 60 << endl;
	
	//音频流 time_base是音频采样率
	total_second = m_adecode.m_stream->duration * av_q2d(m_adecode.m_stream->time_base);
	cout << "audio hour:" << total_second / 3600 << endl;
	cout << "audio min:" << (total_second % 3600) / 60 << endl;
	cout << "audio s:" << total_second % 60 << endl;

二、获取视频编码参数

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值