2016-08-15 315 views
0

我解碼使用FFMpeg。我正在解碼的視頻是使用C代碼的H.264或MPEG4視頻。我正在使用32位庫。我已經成功解碼並提取了第一幀的元數據。我現在想解碼最後一幀。我有一個確定的視頻持續時間,並認爲這是一個安全的假設,說isLastFrame = duration。這是我的,有什麼建議嗎?如何FFmpeg解碼並從最後一幀提取元數據?

AVFormatContext* pFormatCtx = avformat_alloc_context(); 
avformat_open_input(&pFormatCtx, filename, NULL, NULL); 
int64_t duration = pFormatCtx->duration; 
i=0; 
while(av_read_frame(pFormatCtx, &packet)>=0) { 
    /* Is this a packet from the video stream? */ 
    if(packet.stream_index==videoStream) { 
    /* Decode video frame*/ 
     avcodec_decode_video2(pCodecCtx, pFrame, &duration, &packet); 
    } 

任何幫助非常感謝! :)

回答

0

謝謝大家對你的幫助,但我發現,函數av_seek_frame時間是不工作的原因是因爲你必須用1000乘以它是適用於讀取幀。另外請注意,我有,但decode_video而不是解碼函數調用的原因是因爲我使用32位,並創建了我自己的,但如果你插入video_decode()或我相信它是decode_video2它也可以。希望這將有助於未來的其他解碼器。

AVFormat Format; 
int64_t duration = Format->duration; 
duration = duration * 1000; 
if (av_seek_frame(Format, Packet->stream_index, duration, AVSEEK_FLAG_ANY) <= 0) 
    { 
     /* read the frame and decode the packet */ 
     if (av_read_frame(FormatContext, &Packet) >= 0) 
     { 
      /*decode the video frame*/ 
      decode_video(CodecContext, Frame, &duration, &Packet); 

     } 
0

這可能是你在找什麼:

編解碼器,因爲他們CODEC_CAP_DELAY能力集輸入和輸出之間的延遲 ,這些都需要與avpkt->數據= NULL喂, avpkt-> size = 0結束時返回剩餘的幀。

Link to FFmpeg documentation