繁体   English   中英

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

任何帮助深表感谢! :)

感谢大家的帮助,但我发现AV_SEEK_FRAME持续时间不起作用的原因是,您必须将其乘以1000才能使其适用于读取帧。 另外请注意,我拥有的是decode_video,而不是decode函数,这是因为我使用的是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);

        }

这可能是您要寻找的:

设置了CODEC_CAP_DELAY功能的编解码器在输入和输出之间有延迟,需要在末尾输入avpkt-> data = NULL,avpkt-> size = 0来返回其余帧。

链接到FFmpeg文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM