我试图使用ffmpeg从视频文件中捕获帧,但我甚至无法获取视频的持续时间。每次当我尝试访问pFormatCtx->duration
我越来越0.我知道指针初始化,并包含正确的持续时间,因为如果我使用av_dump_format(pFormatCtx, 0, videoName, 0);
,那么我实际上得到持续时间数据以及有关视频的其他信息。 这是我所得到的,当我使用av_dump_format(pFormatCtx, 0, videoName, 0);
:FFMPEG无法显示视频的持续时间
输入#0,AVI,从 'futurama.avi':
时间:00:21:36.28,启动:0.000000,比特率:1135 KB/s的
流#0.0:视频:MPEG4(高级简单),YUV420P,512x384
[PAR 1:1 DAR 4:3],25 TBR,25 TBN,25 TBC
流#0.1:音频:ac3,48000Hz,立体声,s16,192 kb/s
我不明白为什么av_dum_format
可以显示持续时间,我不能。我检查了函数定义,显示持续时间,函数也使用pFormatCtx-> duration。这不只是时间的其他成员变量也没有,当我打电话给他们在main.cpp中
这里显示正确的数据是我的main.cpp:
extern "C" {
#include<libavcodec/avcodec.h>
#include<libavformat/avformat.h>
#include<libswscale/swscale.h>
}
int main(int argc, char *argv[]) {
AVFormatContext *pFormatCtx = NULL;
const char videoName[] = "futurama.avi";
// Register all formats and codecs.
av_register_all();
cout << "Opening the video file";
// Open video file
int ret = avformat_open_input(&pFormatCtx, videoName, NULL, NULL) != 0;
if (ret != 0) {
cout << "Couldn't open the video file." << ret ;
return -1;
}
if(avformat_find_stream_info(pFormatCtx, 0) < 0) {
cout << "problem with stream info";
return -1;
}
av_dump_format(pFormatCtx, 0, videoName, 0);
cout << pFormatCtx->bit_rate << endl; // different value each time, not initialized properly.
cout << pFormatCtx->duration << endl; // 0
return 0;
}
我不知道是否有帮助,但,我在Ubuntu上使用QtCreator并静态链接这些库。
谢谢你的帮助。
有一些东西'av_dump_format'不读取'pFormatCtv->之前duration',使得该领域有效。换句话说,在持续时间变为有效之前,必须执行额外的代码。通过一些有效的代码跟踪,你应该找到缺失的部分。顺便说一句,你仍然对这个问题的答案感兴趣吗? –
我试图在我的个人项目中使用ffmpeg的功能,但我最终使用了ffmpeg.exe的新进程。我想找出一个答案,ffmpeg是一个非常强大的工具,我相信我将在未来使用它,如果我知道如何使用库而不是使用可执行文件在新的流程中。 – Malkavian
我很可能不会很快尝试你的方法,我现在很忙,我给你的投票,如果它有效,我会告诉你。再次感谢! – Malkavian