?

Log in

 
 
11 April 2008 @ 08:04 am
aviid: List movie file information  
Originally timestamped 2005-10-18 but again trivially cleaned up while writing this entry, aviid (which works on more than just AVI files) prints informational parameters about a movie file.  It even works on audio files.  Here's some sample output

BEGIN OUTPUT

Star Wars: The Legacy Revealed.mpg
ID_VIDEO_ID=0
ID_AUDIO_ID=0
ID_FILENAME=Star Wars: The Legacy Revealed.mpg
ID_DEMUXER=mpegps
ID_VIDEO_FORMAT=0x10000002
ID_VIDEO_BITRATE=6000000
ID_VIDEO_WIDTH=720
ID_VIDEO_HEIGHT=480
ID_VIDEO_FPS=29.970
ID_VIDEO_ASPECT=0.0000
ID_AUDIO_FORMAT=80
ID_AUDIO_BITRATE=0
ID_AUDIO_RATE=0
ID_AUDIO_NCH=0
ID_LENGTH=7192.19
ID_VIDEO_CODEC=mpegpes
ID_AUDIO_BITRATE=384000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=2
ID_AUDIO_CODEC=mad
ID_VIDEO_ASPECT=1.3333

END OUTPUT


Offhand I don't know how to interpret some of the parameters (e.g. ID_VIDEO_ID), but I find others very useful (like ID_VIDEO_ASPECT, ID_VIDEO_HEIGHT, ID_VIDEO_FPS). 

BEGIN aviid

#!/bin/sh

while [ $# -gt 0 ]; do
 i="$1";
 shift
 echo $i
 mplayer -identify -vo null -ao null -frames 1 "$i" 2>&1 | grep ID_
 echo
done

END aviid

As you can see, this is a very simple wrapper around mplayer. In fact, mplayer's man page refers to a "standard" wrapper called midentify found in the TOOLS directory of the mplayer distribution, but that script isn't included in the mplayer package for Ubuntu.  The -identify flag is the important one causing the parameters to be printed.  The -vo null -ao null part makes sure mplayer doesn't try to render video or play audio, important because this is intended to be a command-line tool not a GUI/multimedia tool.  Similarly, without the -frames 1 option mplayer will happily play the entire file, even with audio and video output set to null.

mplayer prints some stuff to standard error and other stuff to standard output, so the '2>&1' construct redirects all error to output, making sure it all gets piped to the grep command.  As it turns out, none of the ID information is on error, so redirecting it to /dev/null would have been just as effective, but I find this approach more elegant, should I ever want to extend the grep pattern or even process it with some other command.  Finally, the grep command filteres out everything but the informational parameters.