Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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
...
share|improve this answer
    
midentify is not installed on this system, mplayer movie.avi -identify gives this kind of output, but also plays the movie. –  Bernhard Jan 14 '12 at 11:28
1  
It's just a wrapper script, I edited some information in - you could adapt that mplayer command to suit your exact needs. –  Mat Jan 14 '12 at 11:32
    
Your script does exactly what I need. Also via ssh without X11 forwarding whatsoever. Thank you! –  Bernhard Jan 14 '12 at 11:51
1  
Edited to better reflect that it's not my script, it comes with the mplayer source code. –  Mat Jan 14 '12 at 11:54
    
Nice thanks but it shows me video bitrate of 0 (this is MPEG4 AVC VBR). :-( –  lzap Apr 27 '13 at 17:21
add comment

You can use the file command.

share|improve this answer
    
Easy and fast solution, basically what I was looking for. Only bitrate information is missing here. –  Bernhard Jan 14 '12 at 11:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.