我試圖使用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