如何FFmpeg从最后一帧解码和提取元数据?

时间:2016-08-15 15:46:09

标签: c video ffmpeg metadata decode

我正在使用FFMpeg进行解码。我正在解码的视频是使用C代码的H.264或MPEG4视频。我正在使用32位库。我已经成功解码并提取了第一帧的元数据。我现在想解码最后一帧。我有一个明确的视频持续时间,并认为这是一个安全的假设isLastFrame = duration。这是我的,有什么建议吗?

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);
    }

非常感谢任何帮助! :)

1 个答案:

答案 0 :(得分:1)

感谢大家的帮助,但我发现AV_SEEK_FRAME持续时间不起作用的原因是因为必须将它乘以1000以使其适用于读框。另请注意,我有但却解码而不是解码函数调用的原因是因为我使用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);

        }