我有一个 .wav 格式的音频文件。现在我想检查这个波形文件有多少个频道?为此,我安装了 ffmpeg 工具。但是我对必须在命令行中输入的正确语法感到困惑?有人可以帮我解决这个问题吗?谢谢
The*_*EEP 11
如果您安装了 ffmpeg,那么您很可能也安装了 ffprobe。使用 ffprobe,这很简单:
ffprobe -i yourFile.mp4 -show_streams -select_streams a:0
Run Code Online (Sandbox Code Playgroud)
这将为您提供如下输出,您已经可以从中读取您需要的内容:
[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]
Run Code Online (Sandbox Code Playgroud)
注意channels=2和channel_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
Run Code Online (Sandbox Code Playgroud)
对于典型的立体声音频文件,将简单地返回“2”。有关详细信息,请查看紧凑型输出编写器文档。