【问题标题】:How to check number of channels in my audio wav file using ffmpeg command?如何使用 ffmpeg 命令检查音频 wav 文件中的通道数?
【发布时间】:2018-06-02 22:58:51
【问题描述】:

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

【问题讨论】:

    标签: audio ffmpeg


    【解决方案1】:

    如果你安装了 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

    【讨论】:

    • 直接输出命令:ffprobe in.wav -show_entries stream=channels -select_streams a -of compact=p=0:nk=1 -v 0
    • 啊,太好了,我会添加 show_entries,不知道。
    • 谢谢。我得到了答案
    猜你喜欢
    • 2019-07-03
    • 2017-08-30
    • 2019-07-06
    • 1970-01-01
    • 2012-02-02
    • 2014-09-12
    • 2013-09-29
    • 1970-01-01
    • 2017-06-14
    相关资源
    最近更新 更多