用FFmpeg SDK计算MP3文件的时长
2017-05-09 08:59
405 查看
说明
首先需要编译FFmpeg,这个网上已经有很多资料了,这里略过。可参见:VS编译FFmpeg关于FFmpeg SDK的使用,可以参见:An ffmpeg and SDL Tutorial
计算MP3文件时长
主要利用avformat_find_stream_info读取文件信息,
AVFormatContext中的成员变量
duration用来描述MP3文件的时长。注意
duration的值为
实际秒数*AV_TIME_BASE。
extern "C" { #include "libavformat/avformat.h" }; double duration(const char *filename) { av_register_all(); AVFormatContext *pFormatCtx = NULL; // Open video file if(avformat_open_input(&pFormatCtx, filename, NULL, NULL) != 0) { return -1; // Couldn't open file } avformat_find_stream_info(pFormatCtx, NULL); double duration = (double)pFormatCtx->duration / AV_TIME_BASE; avformat_close_input(&pFormatCtx); avformat_free_context(pFormatCtx); return duration; }
相关文章推荐
- mp3文件总播放时长计算方法
- MP3格式分析(五)---计算CBR和VBR的MP3文件的播放时间的步骤
- FFMpeg 解码标准电影文件 时间计算方式
- 关于MP3文件播放时间的计算
- ffmpeg将flv解封装为h264和mp3文件测试代码
- 【FFMpeg视频开发与应用基础】六、调用FFMpeg SDK实现视频文件的转封装
- ffmpeg实现转码一个普通视频文件为视频mpeg4,音频mp3的
- ffmpeg 实现转码一个普通视频文件为视频mpeg4,音频mp3的功能的程序(摘)
- 用ffmpeg将aac转成mp3 的.bat文件
- 采用FFmpeg从视频中提取音频(声音)保存为mp3文件
- ffmpeg代码笔记5:MP4文件读取packet,计算DTS
- 利用ffmpeg在linux下将mp3文件转换为wma
- MP3文件如何计算总播放时间
- ffmpeg 将1张图片和1个MP3音频文件转为MP4
- linux下安装ffmpeg 语音amr文件为MP3 包含各依赖
- 【FFMpeg视频开发与应用基础】五、调用FFMpeg SDK封装音频和视频为视频文件
- ffmpeg获取文件的总时长(mp3/mp4/flv等)
- ffmpeg实现转码一个普通视频文件为视频mpeg4,音频mp3的功能的程序
- 如何通过ffmpeg将音频文件转换成Mp3 转
- 关于MP3文件播放时间的计算