Changes between Version 66 and Version 67 of Encode/HighQualityAudio


Ignore:
Timestamp:
Oct 6, 2024, 10:56:37 AM (20 months ago)
Author:
MasterQuestionable
Comment:

[m] Partial refactoring: no real content change.

Legend:

Unmodified
Added
Removed
Modified
  • Encode/HighQualityAudio

    v66 v67  
    11= Guidelines for high quality lossy audio encoding =
     2
    23This guide is meant to help people new to encoding lossy audio to use the correct encoders and settings.
    34
    4 == When should I transcode audio? ==
     5
     6== When should I transcode audio? == #When
    57
    68Avoid transcoding from a lossy format to the same or another lossy format when possible. Transcode to lossy from the lossless source (if you have it), or just copy the lossy source audio track instead of transcoding.
    79
    8 Another option if you have a lossless source is to transcode it to another lossless codec, like [[https://superuser.com/a/339031/39364|flac]] or TrueHD (last one needs -strict -2).
     10Another option if you have a lossless source is to transcode it to another lossless codec, like FLAC [ https://superuser.com/questions/339023#339031 ] or TrueHD (last one needs "-strict -2").
    911
    10 == Generation loss ==
    1112
    12 Transcoding from a lossy format like [[Encoding VBR (Variable Bit Rate) mp3 audio|MP3]], [[AACEncodingGuide|AAC]], Vorbis, Opus, WMA, etc. to the same or different lossy format might degrade the audio quality even if the bitrate stays the same (or higher). This quality degradation might not be audible to you but it might be audible to others.
     13== Generation loss == #Generation-loss
    1314
    14 This post on hydrogenaudio.org demonstrates what will happen if you re-encode a file 100 times: [[http://www.hydrogenaud.io/forums/index.php?showtopic=100067]]
     15Transcoding from a lossy format like [[Encoding VBR (Variable Bit Rate) mp3 audio|MP3]], [[AACEncodingGuide|AAC]], Vorbis, Opus, WMA, etc. to the same or different lossy format might degrade the audio quality even if the bit rate stays the same (or higher). This quality degradation might not be audible to you but it might be audible to others.
    1516
    16 == Copying audio tracks ==
     17͏    This post demonstrates what will happen if you re-encode a file 100 times:\\
     18͏    9 different codecs 100-pass recompression test\\
     19͏    https://hydrogenaud.io/?topic=100067
    1720
    18 If the target container format supports the audio codec of the source file then consider just muxing it into the output file without re-encoding. MKV supports virtually any audio codec.
    19 This can be achieved by specifying 'copy' as the audio codec.
    2021
    21 Example:[[BR]]
    22 Transcoding a WebM file (with VP8 video/Vorbis audio) to a MKV file (with H.264 video/unaltered Vorbis audio):[[BR]]
    23 {{{
    24 ffmpeg -i someFile.webm -c:a copy -c:v libx264 outFile.mkv
    25 }}}
    26 In some cases this might not be possible, because the target device/player doesn't support the codec or the target container format doesn't support the codec.
    27 Another reason to transcode might be that the source audio track is too big (it has a higher bitrate than what you want to use in the output file).
     22== Copying audio tracks == #Copying
    2823
    29 == Audio encoders FFmpeg can use ==
     24͏    If the target container format supports the audio codec of the source file then consider just muxing it into the output file without re-encoding. MKV supports any codec.\\
     25͏    This can be achieved by specifying "copy" as the audio codec.
    3026
    31 FFmpeg can encode to a wide variety of lossy audio formats.[[BR]]
     27͏    E.g.\\
     28͏    Transcoding a WebM file (VP8 video, Vorbis audio) to MKV (H.264 video, with the very audio):\\
     29͏    `ffmpeg -i "in.webm" -c:a copy -c:v libx264 "out.mkv"`\\
     30͏    .\\
     31͏    In some cases this might not be possible, because the target device/player doesn't support the codec or the target container format doesn't support the codec.\\
     32͏    Another reason to transcode might be that the source audio track is too big (it has a higher bit rate than what you want to use in the output file).
    3233
    33 Here are some popular lossy formats with encoders listed that FFmpeg can use:[[BR]]
    34 {{{
    35 Dolby Digital: ac3
    36 Dolby Digital Plus: eac3
    37 TrueHD 0xFBA: truehd
    38 MP2: libtwolame, mp2
    39 Windows Media Audio 1: wmav1
    40 Windows Media Audio 2: wmav2
    41 AAC LC: libfdk_aac, aac
    42 HE-AAC: libfdk_aac
    43 Vorbis: libvorbis, vorbis
    44 MP3: libmp3lame, libshine
    45 Opus: libopus
    46 }}}
    47 Based on quality produced from high to low:[[BR]]
    48 {{{
    49 libopus > libvorbis >= libfdk_aac > libmp3lame >= eac3/ac3 > aac > libtwolame > vorbis > mp2 > wmav2/wmav1
    50 }}}
     34
     35== Audio encoders FFmpeg can use == #Encoders
     36
     37͏    FFmpeg can encode to a wide variety of lossy audio formats.\\
     38͏    Here are some popular lossy formats with encoders listed that FFmpeg can use:\\
     39͏    **Opus**: "libopus"\\
     40͏    **Vorbis**: "libvorbis", "vorbis"\\
     41͏    **AAC LC**: "libfdk_aac", "aac"\\
     42͏    **HE-AAC**: "libfdk_aac"\\
     43͏    **MP3**: "libmp3lame", "libshine"\\
     44͏    **Dolby Digital**: "ac3"\\
     45͏    **Dolby Digital Plus**: "eac3"\\
     46͏    **TrueHD 0xFBA**: "truehd"\\
     47͏    **MP2**: "libtwolame", "mp2"\\
     48͏    **Windows Media Audio 1**: "wmav1"\\
     49͏    **Windows Media Audio 2**: "wmav2"
     50
     51͏    Based on quality produced from high to low:\\
     52͏    "libopus" > "libvorbis" >= "libfdk_aac" > "libmp3lame" >= "eac3"/"ac3" > "aac" > "libtwolame" > "vorbis" > "mp2" > "wmav2"/"wmav1"
     53
    5154{{{#!comment
    52 I think we should do a listening test between libfaac and eac3/ac3, because from my experience libfaac can't really handle 128Kbps or 160Kbps as well as ac3
     55I think we should do a listening test between libfaac and eac3/ac3, because from my experience libfaac can't really handle 128 Kbps or 160 Kbps as well as ac3
    5356libopus >= libvorbis >= aac >= libfdk_aac > libmp3lame > eac3/ac3 >= libfaac > libtwolame > mp2 > vorbis > wmav2/wmav1
    54 Both libfaac and ac3 have annoying sounds at 128Kbps. It probably depends on what one prefers, but ac3 is definitely better than libtwolame at 128Kbps. libtwolame completely breaks down at that rate.
     57Both libfaac and ac3 have annoying sounds at 128 Kbps. It probably depends on what one prefers, but ac3 is definitely better than libtwolame at 128 Kbps. libtwolame completely breaks down at that rate.
    5558}}}
    5659
    5760{{{#!comment
    58 Source for above hierarchy? 
    59 I based it on which encoder's would reach transparency first based on bitrate. libopus/libfdk_aac/libvorbis/libmp3lame/(ac3 most of the times) should all be transparent at 128Kbps. The encoders listed to the right don't achieve that.
     61Source for above hierarchy?
     62I based it on which encoder's would reach transparency first based on bit rate. libopus/libfdk_aac/libvorbis/libmp3lame/(ac3 most of the times) should all be transparent at 128 Kbps. The encoders listed to the right don't achieve that.
    6063Any ideas where I could get sources?
    61 http://www.hydrogenaudio.org/forums/index.php?showtopic=102699
    62 http://www.hydrogenaudio.org/forums/index.php?showtopic=102875
    63 http://www.hydrogenaudio.org/forums/index.php?showtopic=102876
     64https://hydrogenaud.io/?topic=102699
     65https://hydrogenaud.io/?topic=102875
     66https://hydrogenaud.io/?topic=102876
    6467}}}
    6568
    66 The '''>=''' sign means greater or the same quality.[[BR]]
    67 This list is just a general guide and there may be cases where a codec listed to the right will perform better than one listed to the left at certain bitrates. [[BR]]
    68 The highest quality internal/native encoder available in FFmpeg without any external libraries is aac.[[BR]]
     69͏    The ">=" sign means greater or the same quality.\\
     70͏    This list is just a general guide and there may be cases where a codec listed to the right will perform better than one listed to the left at certain bit rates.\\
     71͏    The highest quality internal/native encoder available in FFmpeg without any external libraries is "aac".
    6972
    7073Please note:
    71 - it is '''not recommended''' to use the experimental `vorbis` for Vorbis encoding; use `libvorbis` instead.
    72 - `wmav1` and `wmav2` don't seem to be able to reach transparency at any given bitrate.
     74- It is **not recommended** to use the experimental "vorbis" for Vorbis encoding; use "libvorbis" instead.
     75- "wmav1" and "wmav2" don't seem to be able to reach transparency at any given bit rate.
    7376
    74 == Container formats ==
    75 Only certain audio codecs will be able to fit in your target output file.
    76 ||'''Container'''||'''Audio formats supported'''||
    77 ||'''MKV/MKA'''||Opus, Vorbis, MP2, MP3, LC-AAC, HE-AAC, WMAv1, WMAv2, AC3, E-AC3, TrueHD||
    78 ||'''MP4/M4A'''||Opus, MP2, MP3, LC-AAC, HE-AAC, AC3, E-AC3, TrueHD||
    79 ||'''FLV/F4V'''||MP3, LC-AAC, HE-AAC||
    80 ||'''3GP/3G2'''||LC-AAC, HE-AAC||
    81 ||'''MPG'''||MP2, MP3||
    82 ||'''PS/TS Stream'''||MP2, MP3, LC-AAC, HE-AAC, AC3, TrueHD||
    83 ||'''M2TS'''||AC3, E-AC3, TrueHD||
    84 ||'''VOB'''||MP2, AC3||
    85 ||'''RMVB'''||Vorbis, HE-AAC||
    86 ||'''WebM'''||Vorbis, Opus||
    87 ||'''OGG'''||Vorbis, Opus||
    8877
    89 There are more container formats available than those listed above, like mxf. Also, E-AC3 is only officially (according to Dolby) supported in mp4 (for example, E-AC3 needs editlist to remove padding of initial 256 silence samples).
     78== Container formats == #Container
    9079
    91 == Recommended minimum bitrates to use ==
     80͏    Only certain audio codecs will be able to fit in your target output file:
    9281
    93 The bitrates listed here assume 2-channel stereo and a sample rate of 44.1kHz or 48kHz. Mono, speech, and quiet audio may require fewer bits.
     82͏    **Container**: **Audio formats supported**\\
     83͏    **MKV/MKA**: Opus, Vorbis, MP2, MP3, LC-AAC, HE-AAC, WMAv1, WMAv2, AC3, E-AC3, TrueHD\\
     84͏    **MP4/M4A**: Opus, MP2, MP3, LC-AAC, HE-AAC, AC3, E-AC3, TrueHD\\
     85͏    **FLV/F4V**: MP3, LC-AAC, HE-AAC\\
     86͏    **3GP/3G2**: LC-AAC, HE-AAC\\
     87͏    **MPG**: MP2, MP3\\
     88͏    **PS/TS Stream**: MP2, MP3, LC-AAC, HE-AAC, AC3, TrueHD\\
     89͏    **M2TS**: AC3, E-AC3, TrueHD\\
     90͏    **VOB**: MP2, AC3\\
     91͏    **RMVB**: Vorbis, HE-AAC\\
     92͏    **WebM**: Vorbis, Opus\\
     93͏    **OGG**: Vorbis, Opus
    9494
    95 - '''libopus''' – usable range ≥ 32Kbps. Recommended range ≥ 64Kbps.[[BR]]Transparency (music): very close at default (96 Kbps), but takes more (160+) to be real transparent.[[br]]Speech: Transparent at 32 Kbps. See [https://wiki.hydrogenaud.io/index.php?title=Opus HydrogenAudio] bitrate notes.
    96 - '''libfdk_aac default AAC LC profile''' – recommended range ≥ 128Kbps; see [[Encode/AAC|AAC Encoding Guide]].
    97 - '''libfdk_aac -profile:a aac_he_v2''' – usable range ≤ 48Kbps CBR.[[BR]]Transparency: Does not reach transparency. Use AAC LC instead to achieve transparency
    98 - '''libfdk_aac -profile:a aac_he''' – usable range ≥ 48Kbps and ≤ 80Kbps CBR.[[BR]]Transparency: Does not reach transparency. Use AAC LC instead to achieve transparency
    99 - '''libvorbis''' – usable range ≥ 96Kbps. Recommended range `-aq 4` (≥ 128Kbps). Neither high quality nor widely supported, avoid.
    100 - '''libmp3lame''' – usable range ≥ 128Kbps. Recommended range `-aq 2` (≥ 192Kbps)
    101 - '''ac3 or eac3''' – usable range ≥ 160Kbps. Recommended range ≥ 160Kbps
    102  Example of usage:
    103 {{{
    104 ffmpeg -i input.wav -c:a ac3 -b:a 160k output.m4a
    105 }}}
    106 - '''aac''' – usable range ≥ 32Kbps (depending on profile and audio). Recommended range ≥ 128Kbps[[BR]]Example of usage:
    107 {{{
    108 ffmpeg -i input.wav -c:a aac -b:a 128k output.m4a
    109 }}}
    110 - '''libtwolame''' – usable range ≥ 192Kbps. Recommended range ≥ 256Kbps
    111 - '''mp2''' – usable range ≥ 320Kbps. Recommended range ≥ 320Kbps[[BR]]
     95͏    There are more container formats available than those listed above, like MXF.\\
     96͏    Also, E-AC3 is only officially (according to Dolby) supported in MP4 (for example, E-AC3 needs editlist to remove padding of initial 256 silence samples).
    11297
    113 The '''vorbis''' and '''wmav1/wmav2''' encoders are not worth using.[[BR]]
    114 The '''wmav1/wmav2''' encoder '''does not reach transparency at any bitrate'''.[[BR]]
    115 The '''vorbis''' encoder does not use the bitrate specified in FFmpeg. On some samples it does sound reasonable, but the bitrate is very high.
    11698
    117 To calculate the bitrate to use for multi-channel audio: (bitrate for stereo) x (channels / 2).[[BR]]
    118 Example for 5.1 (6 channels) Vorbis audio: 128Kbps x (6 / 2) = 384Kbps[[BR]]
     99== Recommended minimum bit rates to use == #Recommended
     100
     101͏    The bit rates listed here assume Stereo (2 ch) and sample rate of 44.1 KHz or 48 KHz.\\
     102͏    Mono, speech, and quiet audio tend to require fewer bits.
     103
     104- **"libopus"** - Usable range ≥ 32 Kbps. Recommended range ≥ 64 Kbps.\\
     105  Transparency (music): very close at default (96 Kbps), but takes more (160+) to be real transparent.\\
     106  Transparency (speech): ~ 32 Kbps.\\
     107  See also: https://wiki.hydrogenaud.io/?title=Opus
     108- **"libfdk_aac"** (default profile AAC LC) - Recommended range ≥ 128 Kbps; see <[[Encode/AAC]]>.
     109- **"libfdk_aac" -profile:a aac_he_v2** - Usable range ≤ 48 Kbps CBR.\\
     110  Transparency: Does not reach transparency. Use AAC LC instead to achieve transparency.
     111- **"libfdk_aac" -profile:a aac_he** - Usable range ≥ 48 Kbps and ≤ 80 Kbps CBR.\\
     112  Transparency: Ditto.
     113- **"libvorbis"** - Usable range ≥ 96 Kbps. Recommended range "-aq 4" (≥ 128 Kbps).\\
     114  Neither high quality nor widely supported, avoid.
     115- **"libmp3lame"** - Usable range ≥ 128 Kbps. Recommended range "-aq 2" (≥ 192 Kbps)
     116- **"ac3"** or **"eac3"** - Usable range ≥ 160 Kbps. Recommended range ≥ 160 Kbps\\
     117  E.g. `ffmpeg -i "${In}" -c:a ac3 -b:a 160k "${Out}"`
     118- **"aac"** - Usable range ≥ 32 Kbps (depending on profile and audio). Recommended range ≥ 128 Kbps\\
     119  E.g. `ffmpeg -i "${In}" -c:a aac -b:a 128k "${Out}"`
     120- **"libtwolame"** - Usable range ≥ 192 Kbps. Recommended range ≥ 256 Kbps
     121- **"mp2"** - Usable range ≥ 320 Kbps. Recommended range ≥ 320 Kbps
     122
     123͏    "**vorbis**" and "**wmav1**"/"**wmav2**" encoders are not worth using.\\
     124͏    "**wmav1**"/"**wmav2**" encoder **does not reach transparency at any bit rate**.\\
     125͏    "**vorbis**" encoder does not use the bit rate specified in FFmpeg:\\
     126͏    On some samples it does sound reasonable, but the bit rate is very high.
     127
     128͏    To estimate the bit rate for multi-channel audio:\\
     129͏    ${Stereo Bitrate}/2 * ${Channel#}\\
     130͏    .\\
     131͏    E.g. 5.1 (6 ch) Vorbis audio: 128/2 * 6 = 384 Kbps
     132
    119133----
    120134
    121 - When compatibility with hardware players doesn't matter then use `libopus` in a MKV container when `libfdk_aac` isn't available.
    122 - When compatibility with hardware players does matter then use libmp3lame or ac3 in a MP4/MKV container when `libfdk_aac` isn't available.
     135- When compatibility with hardware players doesn't matter then use "libopus" in a MKV container when "libfdk_aac" isn't available.
     136- When compatibility with hardware players does matter then use "libmp3lame" or "ac3" in a MP4/MKV container when "libfdk_aac" isn't available.
    123137
    124138Transparency means the encoded audio sounds indistinguishable from the audio in the source file.
    125139
    126 Some codecs have a more efficient variable bitrate (VBR) mode which optimizes to a given, constant quality level rather than having variable quality at a given, constant bitrate (CBR). The info above is for CBR. VBR is more efficient than CBR but may not be as hardware-compatible (this mainly applies to older formats, i.e. not Opus).
     140͏    Some codecs have a more efficient Variable Bit Rate (VBR) mode: which optimizes to a given, constant quality level; rather than having variable quality at a given, Constant Bit Rate (CBR).\\
     141͏    The info above mainly targeted CBR.\\
     142͏    VBR is more efficient than CBR, but may not be as hardware-compatible. (mainly applies to antique formats: irrelevant Opus alike)
     143
    127144
    128145== Resources ==
    129146
    130 * [http://opus-codec.org/comparison/ Opus – Codec Landscape]
    131 * [https://ghostarchive.org/archive/UvXHR xiph.org – 64kbit/sec stereo multiformat listening test] including Opus, aoTuV Vorbis, two HE-AAC encoders, and a 48kbit/sec AAC-LC low anchor
    132 * [http://listening-test.coresv.net/results.htm#list9 Results of the public multiformat listening test (July 2014)] – Opus, AAC and Ogg Vorbis at 96 kbps against a classic MP3 128 kbps
    133 * [http://opus-codec.org/static/comparison/GoogleTest1.pdf Google Listening Test #1] – comparing Opus, Speex, and others
    134 * [http://opus-codec.org/static/comparison/GoogleTest2.pdf Google Listening Test #2] – comparing Opus, Speex, and others
     147* https://opus-codec.org/comparison/
     148* Google Listening Test !#1 - comparing Opus, Speex, and others\\
     149  https://opus-codec.org/static/comparison/GoogleTest1.pdf
     150* Google Listening Test !#2\\
     151  https://opus-codec.org/static/comparison/GoogleTest2.pdf
    135152
     153* [2011] 64 Kbps Stereo multi-format listening test\\
     154  https://web.archive.org/web/20200202080247/https://people.xiph.org/~greg/opus/ha2011/\\
     155  !^ Of Opus, aoTuV Vorbis, 2 HE-AAC encoders, and a 48 Kbps AAC-LC low anchor.
     156* [201407] Results of the public multi-format listening test\\
     157  https://listening-test.coresv.net/results.htm#list9\\
     158  !^ Opus, AAC, Vorbis at 96 Kbps against typical MP3 128 Kbps.