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.

How to demuxed audio and know what type it is?

When muxing an audio into a video, ffmpeg, mencoder, etc require to know what the audio's encoding is. The encoder typically uses the file name's extension as the "parameter". eg. .aac

However, when the audio to be muxed is being demuxed from another video, how can I determine the encoding type in a script?
The closest I've come to find this magic piece of info is to get the codec's 4CC string (four character code), but that is not suitable. *(UPDATE: It seems that this is not the 4CC code, and is actually mplayer's designation of "family of codec" .. listed via: mplayer -afm help

/usr/share/mplayer/midentify.sh $audio |sed -nr 's/^ID_AUDIO_CODEC=(.*)/\1/p')"

My output video uses an MP4 container, so I need to know which format the input audio is, and transcode if need be... and in any case it requres the audio encoder type, not the code output by the above command.

Even demuxing seems to require foreknowledge or the codec type!

I've tried a generic dump, using mplayer -dumpaudio $audio, but the output doesn't play even if I manually add the appropriate suffix.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

The best command-line media type identification tool I'm aware of is MediaInfo. Its project page shows it as a Windows GUI program, but there are command line versions for all three major platforms. The command line output is readable, but is fairly easy to parse from a language like Perl.

The second-best such tool I'm aware of is ffprobe, part of the ffmpeg package. Its output is harder to read than that of MediaInfo without being easier to parse. (Both require a context-sensitive parser, for example, because they do things like print multiple "codec" lines, one each for the various streams in the mux.) MediaInfo seems to put out more detailed info about the streams, too.

You might prefer ffprobe anyway if you are already using ffmpeg, since you get it for free when you install ffmpeg. Plus, because they are based on the same code, you can be sure that if ffprobe can tell you useful info about the file, ffmpeg will be able to process it.

share|improve this answer
Thanks Warren. ffprobe does give a little more info than ffmpeg -i, but for the audio type ffprobe's output is identical to that of ffmpeg -i (though ffmpeg -i is to stderr)... So this would seem as good as it gets, and it is certainly enough... –  Peter.O Dec 23 '11 at 10:10
Just discovered that MediaInfo also has a command line version. (Previously I'd used it only in its Windows GUI form.) New king of the hill, AFAICS. –  Warren Young Dec 25 '11 at 8:40
@Warren.. I've installed MediaInfo, and it does look good.. thanks. –  Peter.O Dec 26 '11 at 22:08
add comment

Your Answer


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.