29

I am trying to determine video bitrate(For transcoding) using ffmpeg command,I tried following command.

ffmpeg -i 28572615.wmv

and it produces the following output

    Input #0, asf, from '28572615.wmv':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    encoder         : Lavf57.36.100
  Duration: 00:02:50.92, start: 0.000000, bitrate: 1982 kb/s
    Stream #0:0: Video: wmv2 (WMV2 / 0x32564D57), yuv420p, 640x360, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 1k tbc
    Stream #0:1: Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, 2 channels, fltp, 128 kb/s
At least one output file must be specified

If I use another video

ffmpeg -i with_out_sound.mp4

then i get the following output

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'with_out_sound.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    creation_time   : 2015-04-21 05:14:57
  Duration: 00:00:27.86, start: 0.000000, bitrate: 500 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 622x480 [SAR 1:1 DAR 311:240], 100 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
    Metadata:
      creation_time   : 2015-04-21 05:14:57
      handler_name    : VideoHandler
At least one output file must be specified

The point I am confuse is that should I look in Duration metadata line or Video Stream metadata line(Stream #0:0) for video bitrate?

4
  • For the 2nd file, what's the file size?
    – Gyan
    Commented Jul 29, 2016 at 7:02
  • @Mulvya 2nd video file size is 1.66 MB Commented Jul 29, 2016 at 12:43
  • So both of the readings are wrong - actual bitrate is 61 kb/s. This is probably because it's a DASH segment.
    – Gyan
    Commented Jul 29, 2016 at 14:55
  • How does ffmpeg determine individual stream bitrates? explains how the rates are determined.
    – creidhne
    Commented Aug 8, 2016 at 7:35

2 Answers 2

26
+50

The video bitrate is displayed in the video stream info. The format info contains the bitrate for all streams plus muxing overhead.

If the video bitrate is missing, then a dirty way to get that value is by subtracting the bitrate of all other streams from the total bitrate.

If that's not viable, run ffprobe to show packet sizes and add them together, show the stream duration and then calculate the bitrate by dividing the first number by the second.

$ ffprobe -v quiet -select_streams v -show_entries packet=size -of compact=p=0:nk=1 video.ext | awk '{s+=$1} END {print s}'
496797924
$ ffprobe -v quiet -select_streams v -show_entries stream=duration -of compact=p=0:nk=1 video.mp4  # format=duration if MKV
1501.761000
$ echo 496797924/1501.761000 | bc   # B/s
330810
$ echo '496797924/1501.761000/1024' | bc   # kB/s
323

Of course, this is only applicable if the video stream info does not sport a bitrate and estimating the bitrate by discounting the rate of all other streams is not possible either.

1
  • Note that you do not need nk=1 when you use csv as the format (instead of compact). Also I had to use 2>/dev/null to not get the default header about the stream. Commented Apr 6, 2021 at 15:47
8

Edit: See Cliff's note below if you have an MKV video instead of MP4.

The easiest way to get the bitrate of a video in proper format is to use FFMPEG's utility ffprobe

$ ffprobe -v quiet -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 inputvideo.mp4

This prints the raw bitrate value on its own so that you can easily use it in some kind of script.

Taken from here: https://write.corbpie.com/getting-video-bitrate-with-ffprobe/

6
  • 2
    it results N/A .
    – ben
    Commented Sep 5, 2022 at 9:56
  • Can you post the output of $ ffprobe <your-video-here>? It could have something to do with the format of your video. @benyamin
    – rlittles
    Commented Sep 6, 2022 at 7:10
  • @rlittles I get the same; this is with a video that I encoded in h.264 CRF from a formerly lossless ffv1 video capture that I inverse telecine'd. Stream #0:0: Video: h264 (High 4:2:2), yuv422p(tv, progressive), 720x480, 23.98 fps, 23.98 tbr, 1k tbn
    – Wyatt Ward
    Commented May 8, 2023 at 16:47
  • 1
    @rlittles Your command pulls bitrate from the video stream header metadata. That data is not required to be written to the stream, and MKV doesn't support it, IIRC. MKV stores that info in the container, meaning you need to replace stream=bit_rate with format=bit_rate in your example for MKV containers.
    – Cliff
    Commented Sep 12, 2023 at 5:16
  • 1
    @Cliff Thank you. I was thinking in MP4 mode since that's what the original question was about but you are completely right.
    – rlittles
    Commented Jan 2 at 5:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .