afconvert 命令(音频格式转换)

afconvert 命令(音频格式转换)


一、转换示例

1、wav --> acc

将 input.wav 格式音频 转换为 output.acc 格式音频为例

$ cd ~/Desktop/voice 
$ afconvert -f adts -d aac input.wav
  • -f adts 指定文件格式,acc 格式音频需要指定为 adts(文件与格式化格式见帮助信息)
  • -d acc 指定数据格式
  • input.wav 待转换文件名称

回车,即可发现目录下多了个与待转换文件同名的 input.aac 文件。


2、指定输出名称

如果需要指定文件的输出名称,可将指令做如下修改:

$ afconvert -f adts -d aac input.wav output.aac

回车,可发现目录下多了个 output.aac 文件;


3、aac --> caf

下面将刚刚转换的 input.aac 文件转换为 output.caf 文件:

$ afconvert -f caff -d aac -b 32000 input.aac output.caf

回车后,即可生成一个output.caf文件;


PS:这里的 -b 用于指定文件字节数。帮助信息里的介绍如下:

{ -b | --bitrate } total_bit_rate_bps
         e.g. 256000 will give you roughly:
             for stereo source: 128000 bits per channel
             for 5.1 source: 51000 bits per channel
                 (the .1 channel consumes few bits and can be discounted in the
                 total bit rate calculation)

4、批量转换

$ find . -name '*.aac' -exec afconvert -f caff -d aac -b 32000 {} \;

将所有的 .aac文件格式音频转换为.caf文件格式;

注意:指令最后有一分号;, \{}之间有一个空格。


二、支持格式及使用说明

1、查看支持的音频文件转换格式

$ afconvert -hf
Audio file and data formats:
    '3gpp' = 3GP Audio (.3gp)
               data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aacg' 'aach' 
                             'aacl' 'aacp' 'samr' 
    '3gp2' = 3GPP-2 Audio (.3g2)
               data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aacg' 'aach' 
                             'aacl' 'aacp' 'samr' 
    'adts' = AAC ADTS (.aac, .adts)
               data_formats: 'aac ' 'aach' 'aacp' 
    'ac-3' = AC3 (.ac3)
               data_formats: 'ac-3' 
    'AIFC' = AIFC (.aifc, .aiff, .aif)
               data_formats: I8 BEI16 BEI24 BEI32 BEF32 BEF64 UI8 'ulaw' 
                             'alaw' 'MAC3' 'MAC6' 'ima4' 'QDMC' 'QDM2' 
                             'Qclp' 'agsm' 
    'AIFF' = AIFF (.aiff, .aif)
               data_formats: I8 BEI16 BEI24 BEI32 
    'amrf' = AMR (.amr)
               data_formats: 'samr' 'sawb' 
    'm4af' = Apple MPEG-4 Audio (.m4a, .m4r)
               data_formats: '.mp1' '.mp2' '.mp3' 'aac ' 'aace' 'aacf' 
                             'aacg' 'aach' 'aacl' 'aacp' 'ac-3' 'alac' 
                             'ec-3' 'paac' 'pac3' 'pec3' 
    'm4bf' = Apple MPEG-4 AudioBooks (.m4b)
               data_formats: 'aac ' 'aace' 'aacf' 'aacg' 'aach' 'aacl' 
                             'aacp' 'paac' 
    'caff' = CAF (.caf)
               data_formats: '.mp1' '.mp2' '.mp3' 'QDM2' 'QDMC' 'Qclp' 
                             'Qclq' 'aac ' 'aace' 'aacf' 'aacg' 'aach' 
                             'aacl' 'aacp' 'ac-3' 'alac' 'alaw' 'dvi8' 
                             'ec-3' 'flac' 'ilbc' 'ima4' I8 BEI16 BEI24 
                             BEI32 BEF32 BEF64 LEI16 LEI24 LEI32 LEF32 
                             LEF64 'ms\x00\x02' 'ms\x00\x11' 'ms\x001' 
                             'opus' 'paac' 'pac3' 'pec3' 'qaac' 'qac3' 
                             'qach' 'qacp' 'qec3' 'samr' 'ulaw' 'usac' 
                             'zaac' 'zac3' 'zach' 'zacp' 'zec3' 
    'ec-3' = EC3 (.ec3)
               data_formats: 'ec-3' 
    'flac' = FLAC (.flac)
               data_formats: 'flac' 
    'loas' = LATM/LOAS (.loas, .latm, .xhe)
               data_formats: 'aac ' 'aace' 'aacf' 'aacg' 'aach' 'aacl' 
                             'aacp' 'usac' 
    'MPG1' = MPEG Layer 1 (.mp1, .mpeg, .mpa)
               data_formats: '.mp1' 
    'MPG2' = MPEG Layer 2 (.mp2, .mpeg, .mpa)
               data_formats: '.mp2' 
    'MPG3' = MPEG Layer 3 (.mp3, .mpeg, .mpa)
               data_formats: '.mp3' 
    'mp4f' = MPEG-4 Audio (.mp4)
               data_formats: '.mp1' '.mp2' '.mp3' 'aac ' 'aace' 'aacf' 
                             'aacg' 'aach' 'aacl' 'aacp' 'ac-3' 'alac' 
                             'ec-3' 'usac' 
    'NeXT' = NeXT/Sun (.snd, .au)
               data_formats: I8 BEI16 BEI24 BEI32 BEF32 BEF64 'ulaw' 'alaw' 
    'Sd2f' = Sound Designer II (.sd2)
               data_formats: I8 BEI16 BEI24 BEI32 
    'WAVE' = WAVE (.wav)
               data_formats: UI8 LEI16 LEI24 LEI32 LEF32 LEF64 'ulaw' 
                             'alaw' 
    'RF64' = WAVE (RF64 for length over 4 GB) (.wav)
               data_formats: UI8 LEI16 LEI24 LEI32 LEF32 LEF64 'ulaw' 
                             'alaw' 

2、使用说明

挑一个具有代表性的说明下其具体含义,以及在实际转换过程中参数该怎么选择。

在这里插入图片描述


比如桌面有个input_file.m4a,我需要转换成caf格式的。命令为:

$ afconvert -d aac -f 'caff' input_file.m4a output_file.caf
  • 红色区域找到你要转换的文件后缀例如 .caf
  • 然后-d 的参数(编码格式) 从黄色区域选择;
  • -f 的参数(文件格式)从绿色区域选择;

三、手册

常用说明

  • d 代表 data_format,是数据的编码格式
  • f 代表file_format,是文件格式
  • c 代表channels,是声道
 % afconvert -h

    Audio File Convert
    Version: 2.0
    Copyright 2003-2013, Apple Inc. All Rights Reserved.
    Specify -h (-help) for command options

Usage:
afconvert [option...] input_file [output_file]
    Options may appear before or after the direct arguments. If output_file
    is not specified, a name is generated programmatically and the file
    is written into the same directory as input_file.
afconvert input_file [-o output_file [option...]]...
    Output file options apply to the previous output_file. Other options
    may appear anywhere.

General options:
    { -d | --data } data_format[@sample_rate][/format_flags][#frames_per_packet]
        [-][BE|LE]{F|[U]I}{8|16|24|32|64}          (PCM)
            e.g.   BEI16   F32@44100
        or a data format appropriate to file format (see -hf)
        format_flags: hex digits, e.g. '80'
        Frames per packet can be specified for some encoders, e.g.: samr#12
        A format of "0" specifies the same format as the source file,
            with packets copied exactly.
        A format of "N" specifies the destination format should be the
            native format of the lossless encoded source file (alac, FLAC only)
    { -c | --channels } number_of_channels
        add/remove channels without regard to order
    { -m | --channelmap } list of input channels in output
        set a channel map, mapping which input channel goes to each output one.
        channel number starts at zero. -1 makes a silent output channel.
        For example, to reverse a stereo stream: -m 1 0
    { -l | --channellayout } layout_tag
        layout_tag: name of a constant from CoreAudioTypes.h
          (prefix "kAudioChannelLayoutTag_" may be omitted)
        if specified once, applies to output file; if twice, the first
          applies to the input file, the second to the output file
    { -b | --bitrate } total_bit_rate_bps
         e.g. 256000 will give you roughly:
             for stereo source: 128000 bits per channel
             for 5.1 source: 51000 bits per channel
                 (the .1 channel consumes few bits and can be discounted in the
                 total bit rate calculation)
    { -q | --quality } codec_quality
        codec_quality: 0-127
    { -r | --src-quality } src_quality
        src_quality (sample rate converter quality): 0-127 (default is 127)
    { --src-complexity } src_complexity
        src_complexity (sample rate converter complexity): line, norm, bats minp
    { -s | --strategy } strategy
        bitrate allocation strategy for encoding an audio track
        0 for CBR, 1 for ABR, 2 for VBR_constrained, 3 for VBR
    --prime-method method
        decode priming method (see AudioConverter.h)
    --prime-override samples_prime samples_remain
        can be used to override the priming information stored in the source
        file to the specified values. If -1 is specified for either, the value
        in the file is used.
    --no-filler
        don't page-align audio data in the output file
    --soundcheck-generate
        analyze audio, add SoundCheck data to the output file
    --media-kind "media kind string"
        media kinds are: "Audio Ad", "Video Ad" 
    --anchor-loudness
        set a single precision floating point value to
        indicate the anchor loudness of the content in dB
        Note that for MP4 and M4* file types, this requires that the 
        --soundcheck-generate option is also enabled.
    --anchor-generate
        Analyze audio and add dialogue anchor level data to output file
        Note that for MP4 and M4* file types, this requires that the 
        --soundcheck-generate option is also enabled.
    --generate-hash
        generate an SHA-1 hash of the input audio data and add it to the output
        file.
    --codec-manuf codec_manuf
        specify the codec with the specified 4-character component manufacturer
        code
    --dither algorithm
        algorithm: 1-2
    --mix
        enable channel downmixing
    { -u | --userproperty } property value
        set an arbitrary AudioConverter property to a given value
        property is a four-character code; value can be a signed
        32-bit integer or a single precision floating point value.
        e.g. '-u vbrq <sound_quality>' sets the sound quality level
             (<sound_quality>: 0-127)
        May not be used in a transcoding situation.
    -ud property value
        identical to -u except only applies to a decoder. Fails if there is no
        decoder.
    -ue property value
        identical to -u except only applies to an encoder. Fails if there is no
        encoder.

Input file options:
    --decode-formatid data_format_id
        For input audio files with multiple data format layers (e.g. AAC_HE), 
        specify by format id (e.g. 'aach') which layer of the input file to
        decode.
    --read-track track_index
        For input files containing multiple tracks, the index (0..n-1)
        of the track to read and convert.
    --offset number_of_frames
        the starting offset in the input file in frames. (The first frame is
        frame zero.)
    --soundcheck-read
         read SoundCheck data from source file and set it on any destination
         file(s) of appropriate filetype (.m4a, .caf).
    --copy-hash
         copy an SHA-1 hash chunk, if present, from the source file to the
         output file.
    --check-hash
         if input file is integer linear PCM or lossless encoded, and has hash
         chunk embedded, check its integrety by comparing its hash chunk to the
         hash calculated from its audio data. Fails if mismatching.
    --gapless-before filename
        file coming before the current input file of a gapless album
    --gapless-after filename
        file coming after the current input file of a gapless album

Output file options:
    -o filename
        specify an (additional) output file.
    { -f | --file } file_format
        use -hf for a complete list of supported file/data formats
    --condensed-framing field_size_in_bits
        specify storage size in bits for externally framed packet sizes.
        Supported value is 16 for aac in m4a and m4b file format.

Other options:
    { -v | --verbose }
        print progress verbosely
    { -t | --tag }
        If encoding to CAF, store the source file's format and name in a user
        chunk. If decoding from CAF, use the destination format and filename
        found in a user chunk.
    { --leaks }
        run leaks at the end of the conversion
    { --profile }
        collect and print performance information

Help options:
    { -hf | --help-formats }
        print a list of supported file/data formats
    { -h | --help }
        print this help


NAME
     afconvert -- Audio File Convert

SYNOPSIS
     afconvert [option] src_audiofile dest_audiofile

DESCRIPTION
     Audio File Convert will convert a source audio file to a new audio file with the specified
     file and data types

OPTIONS
     -h       print help text

Darwin                         February 13, 2007                        Darwin

2020-03-06

发布了43 篇原创文章 · 获赞 8 · 访问量 4549

猜你喜欢

转载自blog.csdn.net/weixin_45390999/article/details/104704720