【问题标题】:How to FFmpeg decode and extract metadata from last frame?如何 FFmpeg 从最后一帧解码和提取元数据?
【发布时间】:2016-08-16 03:55:15
【问题描述】:

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

非常感谢任何帮助! :)

【问题讨论】:

    标签: c video ffmpeg metadata decode


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这可能是您正在寻找的:

      具有 CODEC_CAP_DELAY 功能集的编解码器有延迟 在输入和输出之间,这些需要输入 avpkt->data=NULL, avpkt->size=0 最后返回剩余的帧。

      Link to FFmpeg documentation

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-24
        • 2012-07-05
        • 2022-01-03
        • 1970-01-01
        • 2018-10-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多