Skip to main content

ffmpeg_debug_qp

All Contributors

Authors: Werner Robitza, Steve Göring, Pierre Lebreton, Nathan Trevivian, Valerio Triolo

ffmpeg-debug-qp is based on ffmpeg and prints QP values of a video input on a per-frame, per-macroblock basis to STDERR.

The tool comes with an additional Python parser to help interpret the output.

Contents:

Download

Pre-built static binaries are available for Linux and macOS (both x86_64 and ARM64):

Download the latest release

These binaries have FFmpeg statically linked and require no additional dependencies.

Building from Source

If you prefer to build from source, follow the instructions below.

Requirements

  • Python 3.9 or higher
  • ffmpeg 8.x or higher libraries

Linux

For building:

  • libavdevice, libavformat, libavfilter, libavcodec, libswresample, libswscale, libavutil
  • C compiler

For example on Ubuntu:

sudo apt -qq update && \
sudo apt install libavdevice-dev libavformat-dev libavfilter-dev libavcodec-dev libswresample-dev libswscale-dev libavutil-dev build-essential pkg-config

macOS

For building:

Then:

brew install ffmpeg pkg-config

Building

In order to use this tool, you need to build the ffmpeg_debug_qp binary.

If you have FFmpeg libraries installed on your system, simply run:

make

The binary will be created under ffmpeg_debug_qp in the same folder.

Installation

You can add the binary to your $PATH, e.g. by copying it to /usr/local/bin:

sudo cp ./ffmpeg_debug_qp /usr/local/bin/
# or for static build:
sudo cp ./build/ffmpeg_debug_qp /usr/local/bin/

This way, you can call it from anywhere on your system.

Usage

Run this tool on any of the supported file types:

  • MPEG-2
  • MPEG-4 Part 2
  • H.264 / MPEG-4 Part 10 (AVC)

Supported formats:

  • MPEG-4 Part 14
  • H.264 Annex B bytestreams

Direct Usage

Simply call the binary with the path to a file:

./ffmpeg_debug_qp test/test.mp4
[h264 @ 0x124f043b0] New frame, type: I
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] << frame_type: I; pkt_size: 213 >>
[h264 @ 0x124f043b0] New frame, type: P
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111
[h264 @ 0x124f043b0] 1111111111111111111111111111111111111111

You will see the QP values for each macroblock of every frame. Each pair of two numbers is a QP value, hence, in the above example, the QP values are 11, 11 and so on.

Python Usage

You can run the supplied Python tool that helps you parse the results from ffmpeg_debug_qp.

First, build the binary and add it to your $PATH.

Then, from the project directory, run via uv:

uv run ffmpeg-debug-qp-parser --help

Or install locally with pip:

pip install .
ffmpeg-debug-qp-parser --help

The tool options are as follows:

usage: ffmpeg-debug-qp-parser [-h] [-f] [-of OUTPUT_FORMAT] [-p PATH_TO_TOOL] [-l | -k]
                              [-m | -a]
                              video|logfile output

Parse QP values from ffmpeg-debug-qp

positional arguments:
  video|logfile         Video file to generate output for, or existing logfile
  output                Output file

optional arguments:
  -h, --help            show this help message and exit
  -f, --force           Overwrite output
  -of OUTPUT_FORMAT, --output-format OUTPUT_FORMAT
                        Output format, one of: ld-json (default), json or csv
  -p PATH_TO_TOOL, --path-to-tool PATH_TO_TOOL
                        Path to ffmpeg_debug_qp executable (will search in $PATH by default)
  -l, --use-logfile     Use precalculated logfile instead of the video
  -k, --keep-logfile    Don't remove the temporary logfile 'video.debug'
  -m, --include-macroblock-data
                        Include macroblock-level data, such as: type, interlaced and segmentation
  -a, --compute-averages-only
                        Only compute the frame-average QPs

Python Example

To run a basic example:

ffmpeg-debug-qp-parser input.mp4 output_file.json -m -of json

This reads the file input.mp4 and produces a JSON file output_file.json, with a list of frames and each of their macroblocks in the format:

  [
      {
          "frameType": "I",
          "frameSize": 7787,
          "qpAvg": 26.87280701754386,
          "qpValues": [
              {
                  "qp": 25,
                  "type": "i",
                  "segmentation": "",
                  "interlaced": ""
              },
              {
                  "qp": 26,
                  "type": "i",
                  "segmentation": "",
                  "interlaced": ""
              }, ...

The frame and macroblock types are as per ffmpeg debug information. The same goes for segmentation and interlaced values.

For example outputs, see:

Developers: Static Build

To build a portable binary with FFmpeg statically linked, use CMake:

# Download and build minimal FFmpeg (first time only)
./util/build-ffmpeg.sh --download

# Build ffmpeg_debug_qp
cmake -B build -DUSE_VENDORED_FFMPEG=ON
cmake --build build

The binary will be created at build/ffmpeg_debug_qp. This binary only depends on system libraries and can be distributed without requiring FFmpeg to be installed.

To rebuild FFmpeg (e.g., after changes):

./util/build-ffmpeg.sh --clean    # Clean and reconfigure
./util/build-ffmpeg.sh            # Just rebuild

This is what is used inside GitHub Actions to provide prebuilt binaries for Linux and macOS.

Acknowledgements

This code is based on:

  • the code from Fredrik Pihl
  • which is adapted from the code example demuxing_decoding.c by Stefano Sabatini

See also this thread on the libav-user mailing list.

Test video part of Big Buck Bunny (c) copyright 2008, Blender Foundation / www.bigbuckbunny.org

Contributors

Werner Robitza
Werner Robitza

💻
Nathan Trevivian
Nathan Trevivian

💻
Lars The
Lars The

💻
plebreton
plebreton

💻
winking324
winking324

💻
Steve Göring
Steve Göring

💻
Valerio Triolo
Valerio Triolo

💻
Add your contributions

License

MIT License

Copyright (c) 2016-2025 Werner Robitza, Steve Göring, Fredrik Pihl, Stefano Sabatini, Nathan Trevivian, Valerio Triolo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FFmpeg libraries are licensed under the GNU Lesser General Public License, version 2.1.

Metadata

Release files for ffmpeg-debug-qp-parser 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ffmpeg-debug-qp-parser 0.3.1
File Size Uploaded
ffmpeg_debug_qp_parser-0.3.1.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ffmpeg-debug-qp-parser 0.3.1
File Interpreter ABI Platform
ffmpeg_debug_qp_parser-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.7 kB

Release files / ffmpeg_debug_qp_parser-0.3.1.tar.gz

Download URL ffmpeg_debug_qp_parser-0.3.1.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cc2f9f16c1bf365424bb9a0edb7ef92a9eb272d5424961f9d78bc0e856b4492c
BLAKE2b-256 checksum
How to use checksums
28e333ee73087e21f419d721cde9465af5a182f8c8aa5c4e05f886fd95da81ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / ffmpeg_debug_qp_parser-0.3.1-py3-none-any.whl

Download URL ffmpeg_debug_qp_parser-0.3.1-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
53903e37d8e00ff6388869beed96ea25dd5b0ed03efd92923dc8218b9de99115
BLAKE2b-256 checksum
How to use checksums
3c84fe56e7d9533c098e336d57c6d515568215f973e42540becf90ebbbe1bec5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page