简介本文向大家介绍FFmpeg获取视频文件详细信息,感兴趣的朋友可以参考一下。
// 显示文件信息
bool ShowFileInfos(const char* filePathIn)
{
AVFormatContext* pFormatCtx;
if (!(pFormatCtx = avformat_alloc_context())) {
sprintf(m_chLastError, "CFFmpegHelper::ShowFileInfos() avformat_alloc_context() failed: %d", AVERROR(ENOMEM));
return false;
}
int re = avformat_open_input(&pFormatCtx, filePathIn, 0, 0);
if (re != 0) // 打开文件失败
{
avformat_close_input(&pFormatCtx);
char errorbuf[1024] = { 0 };
av_strerror(re, errorbuf, sizeof(errorbuf));
sprintf(m_chLastError, "CFFmpegHelper::ShowFileInfos() open %s failed: %s", filePathIn, errorbuf);
return false;
}
re = avformat_find_stream_info(pFormatCtx, NULL);
if (re != 0)
{
avformat_close_input(&pFormatCtx);
char errorbuf[1024] = { 0 };
av_strerror(re, errorbuf, sizeof(errorbuf));
sprintf(m_chLastError, "CFFmpegHelper::ShowFileInfos() avformat_find_stream_info() failed: %s", errorbuf);
return false;
}
// 得到视频总时长的毫秒数并转换成hh:mm:ss形式
int tns, thh, tmm, tss;
tns = (pFormatCtx->duration) / AV_TIME_BASE;
thh = tns / 3600;
tmm = (tns % 3600) / 60;
tss = (tns % 60);
char timelong[100] = { 0 };
snprintf(timelong, 100, "%02d:%02d:%02d", thh, tmm, tss);
printf("================文件信息基本信息===============\n");
printf("视频时长:%s\n", timelong);
printf("开始时间:%d\n", pFormatCtx->start_time / AV_TIME_BASE);
printf("比 特 率:%d kb/s \n", pFormatCtx->bit_rate / 1000);
printf("轨道数目:%d\n", pFormatCtx->nb_streams);
printf("==============================================\n");
// 打印MetaData信息
printf("---------------- File Information ---------------\n");
av_dump_format(pFormatCtx, 0, filePathIn, 0);
printf("---------------- File Information ---------------\n");
avformat_close_input(&pFormatCtx);
return true;
}
使用:
const char* filePathIn = "C:\\Users\\Administrator\\Desktop\\城市风光.mp4";
ShowFileInfos(filePathIn);
结果示例:
本文向大家介绍一个C++实战项目:C++基于FFmpeg实现电脑屏幕录制并保存为H264,具有一定的C++实战价值,感兴趣的朋友可以参考一下。
本文向大家介绍一个C++实战项目:C++基于FFmpeg+SDL2实现USB摄像头预览/旋转/截图/亮度调节,主要涉及FFmpeg及SDL2库的使用,USB摄像头预览、旋转、截图、亮度调节等,具有一定的C++实战价值,感兴趣的朋友可以参考一下。
本文向大家介绍一个C++实战项目:C++基于FFmpeg+SDL2实现本地视频播放,具有一定的C++实战价值,感兴趣的朋友可以参考一下。
本文向大家介绍一个C++实战项目:FFmpeg+SDL2实现视频画面保存为yuv与h264,具有一定的C++实战价值,感兴趣的朋友可以参考一下。
本文向大家介绍一个C++实战项目:FFmpeg+SDL2实现视频画面保存为bmp与jpg,具有一定的C++实战价值,感兴趣的朋友可以参考一下。
本文向大家介绍一个C++实战项目:C++基于FFmpeg+SDL2实现USB摄像头预览,具有一定的C++实战价值,感兴趣的朋友可以参考一下。