Debugging Macroblocks and Motion Vectors
You can use ffmpeg or ffplay to analyze the macroblocks / coding tree units and motion vectors in a video file.
Analyzing Macroblock Types
MPEG videos use various macroblock types, depending on whether they are intra- or inter-predicted and what specific prediction type or partitioning is used. In order to show them, you need to specify the -debug vis_mb_type option. For example:
ffplay -debug vis_mb_type input.mp4 ffmpeg -debug vis_mb_type -i input.mp4 output.mp4
The output would look something like this:
In the output video, each macroblock will be colored according to its type. Additionally, you can see the macroblock partitions as small lines. The following table lists the possible colors and the associated macroblock types. Note that these are parsed in order (from top to bottom), and if one condition matches, the color will be chosen.
If none matches, the macroblock will be rendered as grey. Note that the decoding of macroblock types is MPEG-specific, so this option will not work for VP8 video, for example.
Analyzing QP Values
The QP (quantization parameter) of a macroblock is a main factor in controlling the quality. Lower QPs result in higher quality and are tinted greener using this filter. Use the -vis_qp option to show the macroblock QPs:
ffplay -debug vis_qp input.mp4 ffmpeg -debug vis_qp -i input.mp4 output.mp4
Analyzing Motion Vectors
The `codecview` filter can be used to show motion vectors as small arrows for each macroblock. It takes one option called mv, which specifies the type of motion vector to be drawn:
- pf – forward predicted motion vectors of P pictures
- bf – forward predicted motion vectors of B pictures
- bb – backward predicted motion vectors of B pictures
For example, you can use:
ffplay -flags2 +export_mvs input.mp4 -vf codecview=mv=pf+bf+bb ffmpeg -flags2 +export_mvs -i input.mp4 -vf codecview=mv=pf+bf+bb output.mp4
- Earlier versions of ffmpeg do not have this filter, but support the now deprecated -vismv option.
- This option does not work for codecs which do not export motion vectors (most non-MPEG based codecs)
- patch1.png (1.1 KB) - added by slhck 3 years ago.
- patch2.png (1.1 KB) - added by slhck 3 years ago.
- patch3.png (1.1 KB) - added by slhck 3 years ago.
- patch4.png (1.1 KB) - added by slhck 3 years ago.
- patch5.png (1.1 KB) - added by slhck 3 years ago.
- patch6.png (1.1 KB) - added by slhck 3 years ago.
- patch7.png (1.1 KB) - added by slhck 3 years ago.
- patch8.png (1.1 KB) - added by slhck 3 years ago.
- patch9.png (1.1 KB) - added by slhck 3 years ago.
- vismv_pf.png (187.1 KB) - added by slhck 3 years ago.
- visqp.png (143.1 KB) - added by slhck 2 years ago.
- vis_mb_type.png (199.5 KB) - added by slhck 2 years ago.
Download all attachments as: .zip