在FFmpeg中获取MacroBlock信息

问题描述 投票:0回答:1

我有一个.mp4文件,其中包含h.264视频和AAC音频。我想在解码时提取每个帧的MacroBlock和运动矢量信息。请在下面找到我的伪代码。

avformat_open_input(file_name) //opening file 
avcodec_open2(pCodecContext, pCodec, NULL) // opening decoder
while (response >= 0) // reading each frame
    {
        response = avcodec_receive_frame(pCodecContext, pFrame);
        if (response == AVERROR(EAGAIN) || response == AVERROR_EOF || response < 0) {
            break;
        }
        // extract macroblock of pFrame here
        av_frame_unref(pFrame);
    }

[我在其他文章中看到过,我们可以通过MpegEncContext结构获取MB信息,但是我感到困惑,如何实例化该结构的对象,如何为每一帧更新该结构的MB数据。?

最终,我想使用SAD(绝对差之和)将一帧与另一帧的宏块进行比较,并在宏块级别出现任何失真时触发警报。

如果有人对此提供帮助,我将不胜感激。

ffmpeg h.264 libavcodec libav h.265
1个回答
0
投票

您可以从AVFrame结构中获取MB信息(MV和其他)。 AVFrame中有一个成员int16_t(* motion_val [2])[2],可以在其中获得MV。

© www.soinside.com 2019 - 2024. All rights reserved.