[FFmpeg-devel] [PATCH] Macroblocks modes extraction

Timothee timothee.informatique at regaud-chapuy.fr
Wed Jul 2 13:57:46 EEST 2025


Hello,

I am working on a modification toextract per-macroblock prediction modes 
(H.264 for now). The goal is to make this information available to 
vf_codecview and print it in a log file (for now).

This are what I have added:

 1.

    A new H264MBInfostruct holding the prediction modes.

 2.

    An AVBufferRef *mb_info_refis added to the H264Picturestruct to
    store this data for each picture.

 3.

    This buffer is allocated with av_buffer_allocz()in
    alloc_picture()and its reference is released with
    av_buffer_unref()in ff_h264_unref_picture().

 4.

    A new function, ff_h264_collect_mb_info(), is called after
    macroblock decoding to populate the buffer.

 5.

    In output_frame(), a new side data (AV_FRAME_DATA_H264_MB_INFO)
    buffer is allocated, and the contents of srcp->mb_info_ref->dataare
    copied into it.

 6. A new function to log the result in vf_codecview.c

This implementation results in a segmentation fault. I guess it is a 
race condition, but I am struggling to fix it.

The patch provided should result in the same error when running 
`./ffmpeg -loglevel debug -i input.mp4 -vf codecview=show_modes=1 -f null -`

Are side data the right thing to use in this context ? Is there a better 
approach to do it ?

I am new to FFmpeg and, in general, to large open-source projects, but I 
am willing to learn so please do not hesitate to correct me.

Thank you for your guidance.

Timothée

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mb_modes_extraction_not_working.patch
Type: text/x-patch
Size: 18211 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250702/109dde73/attachment.bin>


More information about the ffmpeg-devel mailing list