Determine video bitrate using ffmpeg

17

6

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?

user2528012

Posted 2016-07-29T05:27:31.090

Reputation: 229

For the 2nd file, what's the file size? – Gyan – 2016-07-29T07:02:43.000

@Mulvya 2nd video file size is 1.66 MB – user2528012 – 2016-07-29T12:43:45.420

So both of the readings are wrong - actual bitrate is 61 kb/s. This is probably because it's a DASH segment. – Gyan – 2016-07-29T14:55:56.610

How does ffmpeg determine individual stream bitrates? explains how the rates are determined. – creidhne – 2016-08-08T07:35:31.747

Answers

16

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, a cumbersome method is to run ffprobe to show packet sizes and stream duration and then calculating the bitrate by summing all lines except the last one, and dividing by the value in the last line.

ffprobe -select_streams v -show_entries packet=size:stream=duration -of compact=p=0:nk=1 video.mp4

Output:

4199      
2627      
1792      
3921      
2993      
...  
2301      
3076
2879
1543.00000

Of course, this is a last resort solution, and 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.

Gyan

Posted 2016-07-29T05:27:31.090

Reputation: 21 016