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
A digital audio file can contain multiple channels of data. Music that is mixed for headphone listening is saved as a file with two channels - one sent to the left ear, one sent to the right, while surround-sound movie audio is often mixed for 6 channels.
The position of each audio source within the audio signal is called a channel. Each channel contains a sample indicating the amplitude of the audio being produced by that source at a given moment in time. For instance, in stereo sound, there are two audio sources: one speaker on the left, and one on the right.
FFmpeg can be used to convert a huge WAV file into a tiny MP3 file that allows the user to listen to the same song but downloading just a portion of the original size of the WAV file. In this article, I will explain to you how to easily convert a WAV file to MP3 using FFmpeg from the command line.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With