FFMpeg — кодирование AAC

В этой статье приведены примеры для кодирования аудиопотока в формат AAC.

В FFMpeg разумно пользоваться следующими кодировщиками:

  • libfdk_aac (Fraunhofer FDK AAC)
  • Является предпочтительным кодировщиком в FFMpeg. Кодирует во всех профилях (AAC LC, HE-AACv1/v2, AAC LD и далее) и на разных режимах (битрейт / vbr). Однако, он является non-free, поэтому распространен не везде (ffmpeg должен быть собран с ним; в билде под windows от zeranoe его нет). В репозитории deb-multimedia FFMpeg поставляется с ним. Подключается через ключ -c:a libfdk_aac .

  • FFMpeg AAC (native FFMpeg AAC encoder)
  • Этот кодировщик является родным для FFMpeg. До версии FFMpeg 3.0 был экспериментальным, не рекомендуется его использовать (ключ -strict -2 для использования). В версии 3.0 он стал сравним по качеству с libfdk_aac. Плохо умеет кодировать в режиме vbr, профиль только один — AAC LC. Кодирование осуществляется через ключ -strict -2 -c:a aac. Из-за минимального функционала я его почти не использую (только в windows, там деваться некуда), поэтому на данной странице будут описаны почти все ключи и примеры для libfdk_aac.

    Также, ffmpeg может включать другие кодировщики AAC (на текущий момент уже не включает):

  • libfaac (развитие остановлено);
  • libvo_aacenc (развитие остановлено);
  • libaacplus (развитие остановлено).
  • Кроме того, есть высококачественный (наравне с libfdk_aac) кодировщик qaac (Apple Core Audio AAC Encoder), который доступен на платформах Windows и Mac OS X. Умеет кодировать в AAC LC, HE-AAC v1 (SBR) и v2 (по идее должен быть SBR+PS, но параметрического стерео там не обнаруживается — сломано? :( ). Из-за отсутствия на Linux, я его не использую.
    Кодирование с помощью libfdk_aac (Fraunhofer FDK AAC)
    HE-AAC v1 VBR 4:

    ffmpeg -i "input.flac"\
     -c:a libfdk_aac -profile:a aac_he -vbr 4\
     -cutoff 20000 -afterburner 1\
     -y 'output.m4a';
    

    man ffmpeg-codecs:

    libfdk_aac
    libfdk-aac AAC (Advanced Audio Coding) encoder wrapper.
    
    The libfdk-aac library is based on the Fraunhofer FDK AAC code from the Android project.
    
    Requires the presence of the libfdk-aac headers and library during configuration. You need to explicitly configure the build with "--enable-libfdk-aac". The library is also incompatible with GPL, so if you allow the use of GPL, you should configure with "--enable-gpl --enable-nonfree --enable-libfdk-aac".
    
    This encoder is considered to be of higher quality with respect to both the native experimental FFmpeg AAC encoder and libfaac.
    
    VBR encoding, enabled through the vbr or flags +qscale options, is experimental and only works with some combinations of parameters.
    
    Support for encoding 7.1 audio is only available with libfdk-aac 0.1.3 or higher.
    
    For more information see the fdk-aac project at .
    
    Options
    
    The following options are mapped on the shared FFmpeg codec options.
    
    b
        Set bit rate in bits/s. If the bitrate is not explicitly specified, it is automatically set to a suitable value depending on the selected profile.
        In case VBR mode is enabled the option is ignored. 
    
    ar
        Set audio sampling rate (in Hz). 
    
    channels
        Set the number of audio channels. 
    
    flags +qscale
        Enable fixed quality, VBR (Variable Bit Rate) mode. Note that VBR is implicitly enabled when the vbr value is positive. 
    
    cutoff
        Set cutoff frequency. If not specified (or explicitly set to 0) it will use a value automatically computed by the library. Default value is 0. 
    
    profile
        Set audio profile.
        The following profiles are recognized:
            aac_low
                Low Complexity AAC (LC) 
            aac_he
                High Efficiency AAC (HE-AAC) 
            aac_he_v2
                High Efficiency AAC version 2 (HE-AACv2) 
            aac_ld
                Low Delay AAC (LD) 
            aac_eld
                Enhanced Low Delay AAC (ELD) 
    
            If not specified it is set to aac_low. 
    The following are private options of the libfdk_aac encoder.
    
    afterburner
        Enable afterburner feature if set to 1, disabled if set to 0. This improves the quality but also the required processing power.
    aacenc_lib.h:
    This parameter controls the use of the afterburner feature. The afterburner is a type of analysis by synthesis algorithm which increases the audio quality but also the required processing power. It is recommended to always activate this if additional memory consumption and processing power consumption is not a problem. If increased MHz and memory consumption are an issue then the MHz and memory cost of this optional module need to be evaluated against the improvement in audio quality on a case by case basis.
     - 0: Disable afterburner.
     - 1: Enable afterburner.
        Default value is 1. 
    
    eld_sbr
        Enable SBR (Spectral Band Replication) for ELD if set to 1, disabled if set to 0.
        Default value is 0. 
    
    signaling
        Set SBR/PS signaling style.
        It can assume one of the following values:
            default
                choose signaling implicitly (explicit hierarchical by default, implicit if global header is disabled) 
            implicit
                implicit backwards compatible signaling 
            explicit_sbr
                explicit SBR, implicit PS signaling 
            explicit_hierarchical
                explicit hierarchical signaling 
            Default value is default. 
    
    aacenc_lib.h:
    Signaling mode of the extension AOT:
    Implicit backward compatible signaling (default for non-MPEG-4 based AOT's and for the transport formats ADIF and ADTS) - A stream that uses implicit signaling can be decoded by every AAC decoder, even AAC-LC-only decoders - An AAC-LC-only decoder will only decode the low-frequency part of the stream, resulting in a band-limited output - This method works with all transport formats - This method does not work with downsampled SBR
    
    Explicit backward compatible signaling - A stream that uses explicit backward compatible signaling can be decoded by every AAC decoder, even AAC-LC-only decoders - An AAC-LC-only decoder will only decode the low-frequency part of the stream, resulting in a band-limited output - A decoder not capable of decoding PS will only decode the AAC-LC+SBR part. If the stream contained PS, the result will be a a decoded mono downmix - This method does not work with ADIF or ADTS. For LOAS/LATM, it only works with AudioMuxVersion==1 - This method does work with downsampled SBR
    
    Explicit hierarchical signaling (default for MPEG-4 based AOT's and for all transport formats excluding ADIF and ADTS) - A stream that uses explicit hierarchical signaling can be decoded only by HE-AAC decoders - An AAC-LC-only decoder will not decode a stream that uses explicit hierarchical signaling - A decoder not capable of decoding PS will not decode the stream at all if it contained PS - This method does not work with ADIF or ADTS. It works with LOAS/LATM and the MPEG-4 File format - This method does work with downsampled SBR
    
    For making sure that the listener always experiences the best audio quality, explicit hierarchical signaling should be used. This makes sure that only a full HE-AAC-capable decoder will decode those streams. The audio is played at full bandwidth.
    For best backwards compatibility, it is recommended to encode with implicit SBR signaling. A decoder capable of AAC-LC only will then only decode the AAC part, which means the decoded audio will sound band-limited. 
    
    latm
        Output LATM/LOAS encapsulated data if set to 1, disabled if set to 0.
        Default value is 0. 
    
    header_period
        Set StreamMuxConfig and PCE repetition period (in frames) for sending in-band configuration buffers within LATM/LOAS transport layer.
        Must be a 16-bits non-negative integer.
        Default value is 0. 
    
    vbr
        Set VBR mode, from 1 to 5. 1 is lowest quality (though still pretty good) and 5 is highest quality. A value of 0 will disable VBR, and CBR (Constant Bit Rate) is enabled.
        Currently only the aac_low profile supports VBR encoding.
        VBR modes 1-5 correspond to roughly the following average bit rates:
            1            32 kbps/channel 
            2            40 kbps/channel 
            3            48-56 kbps/channel 
            4            64 kbps/channel 
            5            about 80-96 kbps/channel 
            Default value is 0. 
    
    Examples:
    • Use ffmpeg to convert an audio file to VBR AAC in an M4A (MP4) container:
    ffmpeg -i input.wav -codec:a libfdk_aac -vbr 3 output.m4a
    
    • Use ffmpeg to convert an audio file to CBR 64k kbps AAC, using the High-Efficiency AAC profile:
    ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he -b:a 64k output.m4a
    Реклама

    Добавить комментарий

    Заполните поля или щелкните по значку, чтобы оставить свой комментарий:

    Логотип WordPress.com

    Для комментария используется ваша учётная запись WordPress.com. Выход /  Изменить )

    Фотография Twitter

    Для комментария используется ваша учётная запись Twitter. Выход /  Изменить )

    Фотография Facebook

    Для комментария используется ваша учётная запись Facebook. Выход /  Изменить )

    Connecting to %s