我試圖尋找一個使用ffmpeg的av_seek_frame方法的電影,但是我在確定如何生成一個時間標記來尋求最困難的。假設我想要向前或向後尋找x幀數量,並且我知道電影目前處於哪個幀,那麼我將如何去做這件事?ffmpeg av_seek_frame
15
A
回答
8
簡單的答案:你應該有一個AVFormatContext對象躺在周圍。它的duration
屬性告訴你文件在時間戳乘以1000時可以在av_seek_frame中使用多長時間,因此將其視爲100%。然後,您可以計算您想要查找的視頻的距離。
如果你想前進一幀,只需調用av_read_frame和avcodec_decode_video,直到它用非零值填充got_picture_ptr。在調用avcodec_decode_video之前,請確保來自av_read_frame的數據包來自視頻流。然後avcodec_decode_video將填寫AVFrame結構,您可以使用它來做任何事情。
13
這是我如何做的:
// Duration of one frame in AV_TIME_BASE units
int64_t timeBase;
void open(const char* fpath){
...
timeBase = (int64_t(pCodecCtx->time_base.num) * AV_TIME_BASE)/int64_t(pCodecCtx->time_base.den);
...
}
bool seek(int frameIndex){
if(!pFormatCtx)
return false;
int64_t seekTarget = int64_t(frameIndex) * timeBase;
if(av_seek_frame(pFormatCtx, -1, seekTarget, AVSEEK_FLAG_ANY) < 0)
mexErrMsgTxt("av_seek_frame failed.");
}
的AVSEEK_FLAG_ANY使尋求每一幀,而不只是關鍵幀。
相關問題
- 1. 問題:FFMPEG尋找av_seek_frame使用字節位置
- 2. FFMPEG閱讀關鍵幀
- 3. FLAC尋找與ffmpeg
- 4. ffmpeg正在尋找I幀
- 5. ffmpeg和ffmpeg-php
- 6. FFmpeg提取當前幀時間戳
- 7. ffmpeg函數的問題avformat_seek_file()
- 8. Powershell和FFMPEG - FFMPEG未執行
- 9. FFMPEG:最新ffmpeg中的av_open_input_stream
- 10. 重複ffmpeg流(libavcodec/libavformat)
- 11. FFMPEG尋求帶來音頻文物
- 12. 如何使用ffmpeg提取Xing/LAME幀?
- 13. 如何查找FFMPEG解碼給定幀號的演示時間戳?
- 14. 與FFMPEG
- 15. 與FFMPEG
- 16. 的ffmpeg
- 17. 的ffmpeg -
- 18. 我如何尋求用ffmpeg來編號X?
- 19. ffmpeg和ffmpeg-php安裝在fedora 13上
- 20. ffmpeg爲Android(使用教程:「ffmpeg和Android.mk」)
- 21. 的NodeJS - 良好 - FFMPEG找不到FFMPEG
- 22. FFMPEG Android - 將bytebuffer傳遞給ffmpeg
- 23. 使用FFMPEG Stream H264到Android使用FFMPEG
- 24. 由remux FFMPEG修剪不寫關鍵幀
- 25. 與FFmpeg的
- 26. FFmpeg DTS故障
- 27. ffmpeg textdraw.so需要
- 28. FFMpeg for Android
- 29. FFMpeg jni在Android?
- 30. iphone上的ffmpeg
難道你不能使用幀頻計算時間偏移嗎? – 2009-02-02 20:51:40
據我所知,時間偏移量需要以time_base爲單位,但我不確定如何將其轉換爲這些單位(或者即使這是我需要做的)。如果這是我需要做的,我不確定time_base的單位是什麼(秒,幀,每秒幀數)。 – 2009-02-02 20:56:10