2016-08-15 29 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