3

I have an MP4 file input.mp4 which is encoded in libx264. By ffprobe command:

ffprobe -v error -show_streams input.mp4

I can know the bit rate of input.mp4, but it does not give the information of max bit rate (max_bit_rate=N/A ).

Is there any ffmpeg (ffprobe) command for getting max bit rate of a video?

3 Answers 3

7

That max_bit_rate is a a tag written by some encoders, when set by the user in the export dialog box. It is not an indication of the maximum bitrate found if you were to survey the encoded bitstream.


It's possible to get a good idea of the maximum bitrate of a stream this way:

ffmpeg -i in.mp4 -map 0:v -c copy
       -f segment -segment_time 1 -break_non_keyframes 1 folder\seg%d.264

This will break up the video stream into 1 second segments. Sort the directory listing by size to find out the largest file. That's your maximum bitrate. Not totally accurate as it's not a rolling survey but should be close enough.

3
  • I see, so is there any way to know the 'real' max_bit_rate? I need to know the value so that I can choose a suitable parameter for libx264
    – shintaroid
    Jun 14, 2017 at 1:39
  • Possible, but it requires some work.
    – Gyan
    Jun 14, 2017 at 4:25
  • Great, thanks! Now I learned another ffmpeg trick!
    – shintaroid
    Jun 14, 2017 at 8:53
2

See https://github.com/zeroepoch/plotbitrate

It uses ffprobe under the hood and can output an xml file. Here's an example output.svg:

enter image description here

(Although it is slow - almost as slow as transcoding, because it scans the whole video.)

1

I wrote a simple tool to do this, called ffmpeg-bitrate-stats. It requires Python and ffmpeg installed. Install it via pip:

pip3 install --user ffmpeg-bitrate-stats

Then run it on a file:

ffmpeg_bitrate_stats /path/to/file.mp4

It will output a valid JSON object containing summary statistics like the maximum bitrate:

{
    "input_file": "file.mp4",
    "stream_type": "video",
    "avg_fps": 23.976,
    "num_frames": 150802,
    "avg_bitrate": 2249.534,
    "avg_bitrate_over_chunks": 2244.912,
    "max_bitrate": 2993.706,
    "min_bitrate": 1865.406,
    "max_bitrate_factor": 1.331,
    "bitrate_per_chunk": [
        2433.07,
        2329.958,
        2171.362,
        2227.863,
        2470.798,
        1978.106,
        2089.184,
        2993.706,
        1988.095,
        1865.406,
        2146.482
    ],
    "aggregation": "time",
    "chunk_size": 600.0,
    "duration": 6289.65
}

The maximum bitrate in the above file would be roughly 3000 kBit/s (max_bitrate). It is 1.3⨉ as much as the average bitrate (max_bitrate_factor).

Note that the meaning of maximum bitrate depends on the time frame over which it is calculated. You can calculate the bitrate every second (the default in my tool), or choose a different chunk size with the -c parameter. This means you'll get "smoothed" estimates, for instance when you set -c 10, it only looks at 10 second chunks of video, and picks the maximum based on that.

To just obtain that value, you can use jq:

ffmpeg_bitrate_stats /path/to/file.mp4 -c 600 | jq -r '.max_bitrate'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.