Home » Questions » Computers [ Ask a new question ]

How can I obtain the bitrate of a video from a command line in Linux?

How can I obtain the bitrate of a video from a command line in Linux?

What is a good command line tool to get the video bitrate of a divx or xvid avi file for linux?

Asked by: Guest | Views: 97
Total answers/comments: 4
Guest [Entry]

"You can use MPlayer to get that information.

$ mplayer -vo null -ao null -identify -frames 0 foo.avi

In particular, you want the -identify option. The option -frames 0 tells it not to playback the file, and -vo null -ao null give it null drivers for video & audio (so you can use this command via SSH or another non-X-enabled terminal).

You can combine this with grep or other tools to pull out the specific line you want:

$ mplayer -vo null -ao null -identify -frames 0 foo.avi | grep kbps
VIDEO: [XVID] 512x384 24bpp 29.970 fps 990.9 kbps (121.0 kbyte/s)

The full output looks like this:

$ mplayer -vo null -ao null -identify -frames 0 foo.avi
MPlayer dev-SVN-r26940 © 2000-2007 MPlayer Team
CPU: [hw dependent]
CPUflags: [hw dependent]
Compiled with runtime CPU detection.

Playing foo.avi.
AVI file format detected.
ID_VIDEO_ID=0
[aviheader] Video stream found, -vid 0
ID_AUDIO_ID=1
[aviheader] Audio stream found, -aid 1
VIDEO: [XVID] 512x384 24bpp 29.970 fps 990.9 kbps (121.0 kbyte/s)
Clip info:
Software: transcode-1.0.2
ID_CLIP_INFO_NAME0=Software
ID_CLIP_INFO_VALUE0=transcode-1.0.2
ID_CLIP_INFO_N=1
ID_FILENAME=foo.avi
ID_DEMUXER=avi
ID_VIDEO_FORMAT=XVID
ID_VIDEO_BITRATE=990928
ID_VIDEO_WIDTH=512
ID_VIDEO_HEIGHT=384
ID_VIDEO_FPS=29.970
ID_VIDEO_ASPECT=0.0000
ID_AUDIO_FORMAT=85
ID_AUDIO_BITRATE=135104
ID_AUDIO_RATE=0
ID_AUDIO_NCH=0
ID_LENGTH=1288.95
ID_SEEKABLE=1
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)
==========================================================================
ID_VIDEO_CODEC=ffodivx
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 48000 Hz, 2 ch, s16le, 128.0 kbit/8.33% (ratio: 16000->192000)
ID_AUDIO_BITRATE=128000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=2
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
AO: [null] 48000Hz 2ch s16le (2 bytes per sample)
ID_AUDIO_CODEC=mp3
Starting playback...

Exiting... (End of file)"
Guest [Entry]

avprobe -show_streams file.avi
Guest [Entry]

"Here is a copy-paste bash answer using avprobe (which comes with avconv and maybe ffmpeg) in case you want only the number (for further scripting)

function bitrate () { avprobe -show_format ""$1"" 2> /dev/null | grep ""bit_rate"" | sed 's/.*bit_rate=\([0-9]\+\).*/\1/g'; }

It works like this. This line gets info about the file (removing extra info on stdout):

avprobe -show_format test.mp4 2> /dev/null

Then grep selects the line which mentions bitrate

grep ""bit_rate""

From which sed then extracts the bitrate (in bits/second)

sed 's/.*bit_rate=\([0-9]\+\).*/\1/g';

Long story short, copy the function in the first line and then you can do

$ bitrate test.mp4
593567

(that's not a high-quality video, 593 kb/s, since bitrate uses 1000 instead of 1024 apparently)"
Guest [Entry]

"I've been trying to get same info but just that data to use it in a bash loop .. and I've got it ! Using FFPROBE !

FFPROBE : hide_banner : hide header info, loglevel 0 give us only our required info, select_streams specify which stream (video) we're working on , show_entries let us specify which data specifically we want

fer@FerPC:~/Downloads/TEMP$ ffprobe -hide_banner -loglevel 0 -of flat -i 'Eng_Sub_EP.1_1_4.mkv' -select_streams v -show_entries 'format=bit_rate'

you get : format.bit_rate=""1085360"""