Changes between Version 8 and Version 9 of Encode/H.265


Ignore:
Timestamp:
Oct 31, 2017, 12:19:50 PM (3 weeks ago)
Author:
slhck
Comment:

minor improvements and formatting, add tune options

Legend:

Unmodified
Added
Removed
Modified
  • Encode/H.265

    v8 v9  
    11= FFmpeg and H.265 Encoding Guide = 
    22 
    3 H.265 (also known as HEVC) offers 50-75% more compression efficiency compared to H.264 video, while retaining the same visual quality. ffmpeg has support for HEVC encoding using the x265 encoder. '''Note:''' libx265 is under heavy development. The API may change. 
     3H.265 (also known as HEVC) can offer 50–75% more compression efficiency compared to H.264 video, while retaining the same visual quality. ffmpeg has support for HEVC encoding using the [http://x265.org/ x265 encoder]. 
    44 
    55== Getting ffmpeg with libx265 support == 
    66 
    7 In order to obtain a copy of ffmpeg with libx265 support, you need to build it yourself, adding the `--enable-libx265` configuration flag, with `x265` being installed on your system. 
     7ffmpeg needs to be built with the `--enable-libx265` configuration flag and requires `x265` to be installed on your system. The [[CompilationGuide|Compilation Guides]] show you how to do that. 
    88 
    99You can also [http://ffmpeg.org/download.html download a static build], all of which bundle libx265. 
     
    1313 Similar to x264, the x265 encoder has multiple rate control algorithms, including: 
    1414 
    15 * 1-pass constant bitrate (by setting `-b:v`) 
    16 * 2-pass constant bitrate (see [[H.264#twopass]]) 
     15* 1-pass target bitrate (by setting `-b:v`) 
     16* 2-pass target bitrate (see [[H.264#twopass]]) 
    1717* Constant Rate Factor (CRF) 
    1818 
    19 In this guide we are going to focus on CRF and Two-Pass encoding. 
     19In this guide we are going to focus on CRF and Two-Pass encoding, as 1-pass target bitrate encoding is not recommended. 
    2020 
    2121=== Constant Rate Factor (CRF) === 
    2222 
    23 Use this mode if you want to retain good visual quality and don't care about the exact bitrate or filesize of the encoded file. The mode works exactly the same as in x264, so please read the [[H.264]] guide for more info. 
     23Use this mode if you want to retain good visual quality and don't care about the exact bitrate or filesize of the encoded file. The mode works exactly the same as in x264, so please read the [[H.264#crf|H.264]] guide for more info. 
    2424 
    25 In this example, we will use the following settings: 
    26 * default CRF of 28. The CRF of 28 should visually correspond to libx264 video at CRF 23, but result in about half the file size. 
    27 * `medium` preset. The preset determines how fast the encoding process will be – at the expense of compression efficiency. Put differently, if you choose `ultrafast`, the encoding process is going to run fast, but the file size will be larger when compared to `medium`. The visual quality will be the same. Valid presets are `ultrafast`, `superfast`, `veryfast`, `faster`, `fast`, `medium`, `slow`, `slower`, `veryslow` and `placebo`. 
    28 * AAC audio at 128 kBit/s. This uses the ffmpeg-internal encoder, but under [[AAC]] you will find info about more options. 
     25As with x264, you need to make two choices: 
     26 
     27* Choose a CRF. The default is 28, and it should visually correspond to libx264 video at CRF 23, but result in about half the file size. Other than that, CRF works just like in x264. 
     28 
     29* Choose a preset. The default is `medium`. The preset determines how fast the encoding process will be – at the expense of compression efficiency. Put differently, if you choose `ultrafast`, the encoding process is going to run fast, but the file size will be larger when compared to `medium`. The visual quality will be the same. Valid presets are `ultrafast`, `superfast`, `veryfast`, `faster`, `fast`, `medium`, `slow`, `slower`, `veryslow` and `placebo`. 
     30 
     31* Choose a tune. By default, this is disabled, and it is generally not required to set a tune option. x265 supports the following `-tune` options: `psnr`, `ssim`, `grain`, `zerolatency`, `fastdecode`. They are rexplained in the [[H.264#crf|H.264 guide]]. 
     32 
     33For example: 
    2934 
    3035{{{ 
    31 ffmpeg -i input -c:v libx265 -preset medium -crf 28 -c:a aac -b:a 128k output.mp4 
     36ffmpeg -i input -c:v libx265 -crf 28 -c:a aac -b:a 128k output.mp4 
    3237}}} 
     38 
     39This example uses AAC audio at 128 kBit/s. This uses the ffmpeg-internal encoder, but under [[AAC]] you will find info about more options. 
    3340 
    3441=== Two-Pass Encoding === 
     
    4552=== Two-Pass Example === 
    4653 
    47 For libx265, the `-pass` option (that you would use for libx264) is not applicable. Instead, use the private `pass` option with `-x265-params` (see below for more details): 
     54For two-pass, you need to run `ffmpeg` twice, with almost the same settings, except for: 
     55 
     56* In pass 1 and 2, use the `-x265-params pass=1` and `-x265-params pass=2` options, respectively. 
     57* In pass 1, output to a null file descriptor, not an actual file. (This will generate a logfile that ffmpeg needs for the second pass.) 
     58* In pass 1, you need to specify an output format (with `-f`) that matches the output format you will use in pass 2. 
     59* In pass 1, specify the audio codec used in pass 2; in many cases, `-an` in pass 1 will not work. 
     60 
     61For libx265, the `-pass` option (that you would use for libx264) is not applicable. 
    4862 
    4963{{{ 
    50 ffmpeg -y -i input -c:v libx265 -preset medium -b:v 2600k -x265-params pass=1 -c:a aac -b:a 128k -f mp4 /dev/null && \ 
    51 ffmpeg -i input -c:v libx265 -preset medium -b:v 2600k -x265-params pass=2 -c:a aac -b:a 128k output.mp4 
     64ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params pass=1 -c:a aac -b:a 128k -f mp4 /dev/null && \ 
     65ffmpeg -i input -c:v libx265 -b:v 2600k -x265-params pass=2 -c:a aac -b:a 128k output.mp4 
    5266}}} 
    5367 
    5468{{{ 
    55 #!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;" 
    56 '''Note:''' Windows users should use `NUL` instead of `/dev/null`. 
     69#!div style="border: 1px solid #e5e5c7; margin: 1em; background-color: #ffd;" 
     70'''Note:''' Windows users should use `NUL` instead of `/dev/null` and `^` instead of `\`. 
    5771}}} 
    5872 
    59 As with CRF, choose the slowest preset you can tolerate. 
    60  
    61 In pass 1 specify a output format with `-f` that matches the output format in pass 2. Also in pass 1, specify the audio codec used in pass 2; in many cases `-an` in pass 1 will not work. 
    62  
     73As with CRF, choose the slowest `-preset` you can tolerate, and optionally apply a `-tune` setting and `-profile:v`. Note that when using faster presets with the same target bitrate, the resulting quality will be lower and vice-versa. 
    6374 
    6475=== Passing Options === 
     
    6677Generally, options are passed to x265 with the `-x265-params` argument. For fine-tuning the encoding process, you can therefore pass any option that is listed in the [http://x265.readthedocs.org/en/default/ x265 documentation]. Keep in mind that fine-tuning any of the options is generally not necessary, unless you absolutely know what you need to change. 
    6778 
    68  
    69 === Setting profiles === 
     79=== Setting Profiles === 
    7080 
    7181Currently, ffmpeg [https://lists.ffmpeg.org/pipermail/ffmpeg-user/2015-July/027592.html does not support setting profiles] (main, high, ...) via the `profile:v` option, as libx264 does. However, the profile options can be set manually, as shown [http://superuser.com/questions/935930/setting-the-profile-level-for-libx265-using-ffmpeg in this Super User post]. 
    72  
    7382 
    7483