0

If I execute a command like this:

$ ffmpeg -i video.mp4 -qphist -vf codecview=qp=true video_qp.mp4

I get the QP histogram of averages across frame types, like so:

[libx264 @ 0x7f8386803c00] frame I:5     Avg QP:21.65  size:  5960
[libx264 @ 0x7f8386803c00] frame P:172   Avg QP:23.90  size:  3449
[libx264 @ 0x7f8386803c00] frame B:204   Avg QP:26.77  size:  1168

I want to extract the QP for each individual frame in the video, rather than get overall averages.

Is there a way to do this with (or even without, actually) ffmpeg or associated tools (such as ffprobe)?

ndtreviv
  • 3,473
  • 1
  • 31
  • 45

1 Answers1

2

It doesn't look like ffmpeg will do this out of the box.

HOWEVER: This tool here: https://github.com/slhck/ffmpeg-debug-qp is very useful.

You can request a per-macroblock print out:

./ffmpeg_debug_qp video.mp4 2> qp-values.txt

And then convert into more friendly json:

./parse-qp-output.py -o qp-values.json -f qp-values.txt

or ask for an average for each frame:

./parse-qp-output.py -o qp-values-avg.json -a -f qp-values.txt
ndtreviv
  • 3,473
  • 1
  • 31
  • 45
  • 3
    The tool essentially does `ffmpeg -debug:v qp -i input -an -v 48 -f null -` – Gyan Dec 13 '19 at 18:48
  • So it does. The tool in the answer does a nice job of parsing that output and presenting it nicely, though. – ndtreviv Dec 16 '19 at 14:55
  • @Gyan I can't work out how to include the other macroblock level debug info, such as type, interlaced, segmentation etc in that command. I should be able to do it by setting the log level to 56, but it doesn't seem to work. Do you know how? – ndtreviv Feb 25 '20 at 14:26
  • ie: something like this: `[h264 @ 0x7f93ba800000] New frame, type: I [h264 @ 0x7f93ba800000] 24i 24i 24i 24i 24i 24I 24I 24i 24` – ndtreviv Feb 25 '20 at 14:33
  • Including `-nostats` in Gyan's command will remove stray status logs in the output frames. However ndtreviv is right in that the tool has good formatting options. – blahreport Mar 11 '20 at 06:48
  • The tool is very useful, but it seems like not support 265... – Yuechuan Xiao Mar 28 '23 at 03:49
  • To all future commenters: In the end I actually forked ffmpeg, modified it to reveal the qp values and retrieved the data I wanted at the point of decoding. It was considerably faster, albeit with the usual risks of forking a moving project. – ndtreviv Mar 28 '23 at 09:12