Obtain .avi file info from command line

command linefilesvideo

What is the best way to obtain information as bitrate, framerate, width/height of an movie file (in my case .avi) from the command line? I am looking for a basic tool that works similarly as ImageMagicks identify.

Running mplayer already gives this information (but also does a lot more):

VIDEO:  [FMP4]  800x711  24bpp  25.000 fps  1320.9 kbps (161.2 kbyte/s)

Is there a way to make mplayer only give this output (I did not find it in the man) or is there another standard bash-command to obtain the same information?

Best Answer

mplayer comes with an midentify utility that does mostly what you want.

The output looks like variable assignments, so it is pretty easy to use in scripts/simple to parse.

If midentify isn't installed with your mplayer package, you might have an midentify.sh script in /usr/share/mplayer or something like that. If not, midenfify just runs mplayer with a specific set of arguments:

#!/bin/sh
#
# This is a wrapper around the -identify functionality.
# It is supposed to escape the output properly, so it can be easily
# used in shellscripts by 'eval'ing the output of this script.
#
# Written by Tobias Diedrich <ranma+mplayer@tdiedrich.de>
# Licensed under GNU GPL.

if [ -z "$1" ]; then
        echo "Usage: midentify.sh <file> [<file> ...]"
        exit 1
fi

mplayer -vo null -ao null -frames 0 -identify "$@" 2>/dev/null |
    sed -ne '/^ID_/ {
                      s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p
                    }'

The -ao, -vo and -frames parameters prevent mplayer from actually playing the clip. The rest is just formatting.

Example:

$ midentify some_random.avi 
ID_VIDEO_ID=0
ID_AUDIO_ID=0
...
ID_VIDEO_BITRATE=258488
ID_VIDEO_WIDTH=320
ID_VIDEO_HEIGHT=240
ID_VIDEO_FPS=29.917
...
ID_LENGTH=4216.76
...
ID_AUDIO_BITRATE=64000
ID_AUDIO_RATE=22050
...
Related Question