This question already has an answer here:
- Using ffprobe to check audio-only files 4 answers
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?
If it is normal video file from the local path, you can do something like this to find whether video has audio file or not.
You need to look into the MediaMetadataRetriever
By using
METADATA_KEY_HAS_AUDIO
you can check whether the video has the audio or not.Here path is your video file path.
PS: Since it is old question , i am writing this answer to help some other folks , to whom it may help.
A media file contains an audio stream returns:
A media file contains no audio stream retuns empty result.
A non-media file also returns empty result. If you want to return an error message for non-media files and on any other error case, use
-v error
instead:So, you take this instead of empty result:
I would use FFprobe (it comes along with FFMPEG):
In case there's no audio it ouputs nothing. If there is an audio stream then you get something like:
That should be easy enough to parse regardless of the language you're using to make this process automated.
If you only want to know if there is audio and don't care about the stream details you can run the following command, which will extract the duration of the audio stream in the input file. If the response is null/whitespace the input file has no audio in it.
Command:
Found a round about to solve this problem. This seems to answer the question I asked.