====== ffmpeg - Encoding - h265 - Two-Pass Encoding ======
Used if targeting a specific output file size and output quality from frame to frame is of less importance.
This is best explained with an example.
* A video is 10 minutes (600 seconds) long and an output of 200 MiB is desired.
* Since bitrate = file size / duration:
(200 MiB * 8388.608 [converts MiB to kBit; note: not 8192 as 1 kBit is always 1000 bit]) / 600 seconds = ~2796 kBit/s total bitrate
2796 - 128 kBit/s (desired audio bitrate) = 2668 kBit/s video bitrate
* The bitrate calculation can be forgo-ed, if the final (average) bitrate wanted is already known.
For two-pass, ffmpeg is run twice, with almost the same settings, except for:
* In pass 1 and 2, use the **-x265-params pass=1** and **-x265-params pass=2** options, respectively.
* 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.)
* In pass 1, the audio can be left out by specifying **-an**.
For libx265, the **-pass** option (that you would use for libx264) is not applicable.
----
===== Example =====
ffmpeg -y -i input -c:v libx265 -b:v 8000k -x265-params pass=1 -an -f null /dev/null && \
ffmpeg -i input -c:v libx265 -b:v 8000k -x265-params pass=2 -c:a aac -b:a 320k output.mp4
**NOTE:**
* Windows users should use **NUL** instead of **/dev/null** and **^** instead of **\**.
* As with CRF, choose the slowest **-preset** you can tolerate, and optionally apply a **-tune** setting.
* When using faster presets with the same target bitrate, the resulting quality will be lower and vice-versa.
----
====== References ======