Reputation: 151
I have one audio file in .wav format .Now i want to check how many channels this wave file has? I have installed ffmpeg tool for this purpose. But i am confused about the proper syntax that i must enter in my Command line? Can anybody help me in solving this issue ? thanks
Upvotes: 14
Views: 27880
Reputation: 3132
If you have installed ffmpeg, you most likely also have ffprobe. With ffprobe, this is rather simple:
ffprobe -i yourFile.mp4 -show_streams -select_streams a:0
This will give you an output like follows, from which you can already read what you need:
[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_time_base=1/48000
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/48000
start_pts=0
start_time=0.000000
duration_ts=1242528
duration=25.886000
bit_rate=118831
max_bit_rate=118831
bits_per_raw_sample=N/A
nb_frames=1211
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=und
TAG:handler_name=SoundHandler
[/STREAM]
Note the channels=2
and channel_layout=stereo
. Now, you could go ahead and feed that to a grep on linux or any other way to filter out only the lines that you need.
There is an even easier way, though:
You can use -show_entries
to specify what you want, apply print formatting via -of
to strip everything else as well and set verbosity to 0 to not print the usual starting information, either:
ffprobe -i yourFile.mp4 -show_entries stream=channels -select_streams a:0 -of compact=p=0:nk=1 -v 0
Will simply return "2" for a typical stereo audio file. Have a look at the compact output writer documentation for specifics.
Upvotes: 28