====== ffprobe - Bitrate ======
The bit rate of a video influences both the video quality and file size.
* Understanding the bit rate of a video is critical for encoding decisions, ensuring compatibility with bandwidth limits, or addressing quality issues caused by insufficient bit rates.
* It also helps when re-encoding videos for specific distribution channels.
----
===== Determine the bit rate =====
# For MP4
ffprobe -v quiet -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 input.mp4
# For MKV
ffprobe -v quiet -select_streams v:0 -show_entries format=bit_rate -of default=noprint_wrappers=1:nokey=1 input.mkv
returns:
4717811
**NOTE:** The output will be in bits.
* To get this as Kbps divide by 1024.
* To get this as Kbps divide by 1048576.
That data is not required to be written to the stream, and MKV does not support it.
* MKV stores that info in the container, meaning you need to replace **stream=bit_rate** with **format=bit_rate** for MKV containers.
Options:
* **-v quiet**: sets the log level as quiet meaning show no logs.
* **-v error**: Limits output to errors to avoid any unnecessary information display.
* **-select_streams v:0**: selects the first video stream, if you have multiple video streams use this to target the one you want.
* Removing this means the bitrate will be shown for all video streams.
* **-show_entries stream=bit_rate**: shows the bitrate value for the specified stream (for MP4 files).
* **-show_entries format=bit_rate**: shows the bitrate value for the specified stream (for MKV files).
* **-of default=noprint_wrappers=1:nokey=1**: Formats the output to not print the header and section information.
* **input.mp4**: The file under examination.
----
===== Determine the bit rate manually =====
ffprobe -v quiet -select_streams v -show_entries packet=size -of compact=p=0:nk=1 input.mp4 | awk '{s+=$1} END {print s}'
1772586389
ffprobe -v quiet -select_streams v -show_entries stream=duration -of compact=p=0:nk=1 video.mp4 # format=duration if MKV
3592.544000
echo 1772586389/3592.544000 | bc # B/s
493407
echo '1772586389/3592.544000/1024' | bc # kB/s
481
----
===== References =====
https://ffmpeg.org/ffprobe.html