扩展ffmpeg extract_mvs.c示例

时间:2022-01-04 15:18:12

I'm using ffmpeg to extract motion vectors using the example doc extract_mvs.c. Issue is that this code only seems to give a few pieces of information: frame number, size of macroblock, source (future or past), source (x and y), and destination (x and y).

我正在使用ffmpeg使用示例doc extract_mvs.c提取运动矢量。问题是这段代码似乎只提供了一些信息:帧号,宏块大小,源(未来或过去),源(x和y)和目标(x和y)。

Unfortunately, this doesn't say which frame the source comes from in the past or the future (it could come from both, from several past, or several in the future). It also doesn't say what the macroblock type is (which tells similarly useful info). For example, if Source (x and y) equals Destination (x and y) it is impossible to tell if that information is the same as the last frame or if it entered completely new information.

不幸的是,这并没有说明过去或未来来源的来源(可能来自过去几年,或未来几年)。它也没有说明宏块类型是什么(它告诉了类似的有用信息)。例如,如果Source(x和y)等于Destination(x和y),则无法判断该信息是否与最后一帧相同,或者是否输入了全新信息。

See lines 60-63 in the extract_mvs.c code in ffmpeg

请参阅ffmpeg中extract_mvs.c代码中的第60-63行

Final question is that for MP4, motion vectors generally have quarter pixel resolution and the resolution given here is clearly rounded to the closest integer. How am I supposed to extract the "true" motion vector information before rounding?

最后一个问题是,对于MP4,运动矢量通常具有四分之一像素分辨率,并且此处给出的分辨率明显四舍五入为最接近的整数。如何在舍入之前提取“真实”运动矢量信息?

1 个解决方案

#1


The source (future or past) is based on a relative frame reference given by the direction parameter to add_mb(), but I'm not sure what to make of the logic:

源(未来或过去)基于add_mb()的direction参数给出的相对帧引用,但我不确定该如何构成逻辑:

mb->source = direction ? 1 : -1;

In libavutil/motion_vector.h there's a comment, XXX: set exact relative ref frame reference instead of a +/- 1 "direction", so it looks like a known TODO not addressed by the creator of the patch. The value of direction comes from ff_print_debug_info2() where add_mb() is called.

在libavutil / motion_vector.h中有一个注释,XXX:设置精确的相对参考帧参考而不是+/- 1“方向”,所以它看起来像一个已知的TODO,没有由补丁的创建者解决。方向的值来自ff_print_debug_info2(),其中调用add_mb()。

As for the quarter pixels, I think this is also in ff_print_debug_info2() but I don't know enough about motion_val to say what it means:

至于四分之一像素,我认为这也是在ff_print_debug_info2()中,但我不太了解motion_val来说明它意味着什么:

        const int shift = 1 + quarter_sample;
...
                      int mx = (motion_val[direction][xy][0]>>shift) + sx;
                      int my = (motion_val[direction][xy][1]>>shift) + sy;

The initial commit shows all the major pieces of this motion vector code. Hopefully this gets you going in the right direction (no pun intended).

初始提交显示了此运动矢量代码的所有主要部分。希望这能让你朝着正确的方向前进(没有任何双关语)。

#1


The source (future or past) is based on a relative frame reference given by the direction parameter to add_mb(), but I'm not sure what to make of the logic:

源(未来或过去)基于add_mb()的direction参数给出的相对帧引用,但我不确定该如何构成逻辑:

mb->source = direction ? 1 : -1;

In libavutil/motion_vector.h there's a comment, XXX: set exact relative ref frame reference instead of a +/- 1 "direction", so it looks like a known TODO not addressed by the creator of the patch. The value of direction comes from ff_print_debug_info2() where add_mb() is called.

在libavutil / motion_vector.h中有一个注释,XXX:设置精确的相对参考帧参考而不是+/- 1“方向”,所以它看起来像一个已知的TODO,没有由补丁的创建者解决。方向的值来自ff_print_debug_info2(),其中调用add_mb()。

As for the quarter pixels, I think this is also in ff_print_debug_info2() but I don't know enough about motion_val to say what it means:

至于四分之一像素,我认为这也是在ff_print_debug_info2()中,但我不太了解motion_val来说明它意味着什么:

        const int shift = 1 + quarter_sample;
...
                      int mx = (motion_val[direction][xy][0]>>shift) + sx;
                      int my = (motion_val[direction][xy][1]>>shift) + sy;

The initial commit shows all the major pieces of this motion vector code. Hopefully this gets you going in the right direction (no pun intended).

初始提交显示了此运动矢量代码的所有主要部分。希望这能让你朝着正确的方向前进(没有任何双关语)。