Find if video file has audio present in it

Kartos picture Kartos · Jan 30, 2014 · Viewed 20k times · Source

I'm trying to figure out if a video has audio present in it so as to extract the mp3 using ffmpeg. When the video contains no audio channels, ffmpeg creates an empty mp3 file which I'm using to figure out if audio was present in the video in the first place. I'm sure there is a better way to identify if audio is present in a video. Will avprobe help with this? Can anyone point me to a resource or probably a solution?

Edit: Surprisingly, the same command on my server running the latest build of ffprobe doesn't run. It throws an error saying

Unrecognized option 'select_stream'

Failed to set value 'a' for option 'select_stream'

Any ideas how to rectify this out?

Answer

AJ29 picture AJ29 · Jan 30, 2014

I would use FFprobe (it comes along with FFMPEG):

ffprobe -i INPUT -show_streams -select_streams a -loglevel error

In case there's no audio it ouputs nothing. If there is an audio stream then you get something like:

[STREAM]

index=0

codec_name=mp3

codec_long_name=MP3 (MPEG audio layer 3)

profile=unknown

codec_type=audio

codec_time_base=1/44100

etc

etc...

[/STREAM]

That should be easy enough to parse regardless of the language you're using to make this process automated.