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

How to FFmpeg decode and extract metadata from last frame?

我正在使用 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);
    }

非常感谢任何帮助! :)

这可能是您要找的:

Codecs which have the CODEC_CAP_DELAY capability set have a delay between input and output, these need to be fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.

Link to FFmpeg documentation

感谢大家的帮助,但我发现 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);

        }