如何使用ffmpeg命令检查音频wav文件中的通道数?

时间:2017-12-20 11:33:36

标签: audio ffmpeg

我有一个.wav格式的音频文件。现在我想查看这个wave文件有多少个频道?我为此安装了ffmpeg工具。但我对我必须在命令行中输入的正确语法感到困惑?任何人都可以帮我解决这个问题吗?感谢

1 个答案:

答案 0 :(得分:3)

如果你安装了ffmpeg,你很可能也有ffprobe。 使用ffprobe,这很简单:

ffprobe -i yourFile.mp4 -show_streams -select_streams a:0

这将为您提供如下输出,您可以从中读取所需内容:

[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]

请注意channels=2channel_layout=stereo。现在,您可以继续将其提供给linux上的grep或任何其他方式来过滤掉您需要的行。

但是有一种更简单的方法:
您可以使用-show_entries指定所需内容,通过-of应用打印格式以删除其他所有内容,并将详细程度设置为0,以便不打印常用的起始信息:

ffprobe -i yourFile.mp4 -show_entries stream=channels -select_streams a:0 -of compact=p=0:nk=1 -v 0

将简单地返回" 2"对于典型的立体声音频文件。 请查看compact output writer documentation了解详细信息。