Encoding
Today I would like to search how to encode video using x264/x265 command line on Linux. And here my research about it.
x264 (for the video)
I do not use ffmpeg because of encoding in 8bit or 10bit.
It seems that the easiest way is to download the official binaries from VLC: x264 binaries.
I choose the most up to date version on this list of the x264
and x264-10b
binaire.
After that, you must to chmod +x
theses binaires.
Encode Video
There are three ways to encode:
- 1 pass = you select a bitrate for your video
- 2 pass = you do a 1 pass to check and organize the bitrate and then you encode
- crf = define a global quality of the video. The visual lossless is
--crf 18
- if you set a higher number, the quality will be worst, but the size will be lower.
- if you set a lower number, the quality will be better, but the size will be higher.
Example:
x264 --preset veryslow --crf 18 --bframes 10 -o 'output.mkv' 'input.mkv'
x264-10b --preset veryslow --crf 18 --bframes 10 -o 'output.mkv' 'input.mkv'
x265 (for the video)
For this one, I’ve used a tarball version, and compiled it:
- Download the last version here: x265 tarball
- Extract it:
tar -xvzf x265.tar.gz
and go tobuild/linux
- Run
sh multilib.sh
- Your binarie is on
build/linux/8bit
and is compiled to use--output-depth
with the number 8/10 or even 12. - Because x265 only run with input files in the YUV or Y4M format, you should to use ffmpeg (install it on your system)
- Now you can encode!
Encode video
Same than x264, 3 ways to encode the video. CRF 20.0 is the same to CRF 18.0 for X264.
x265 want the --input-res
with the resolution of the input video.
Example:
ffmpeg -i 'input.mkv' -an -f yuv4mpegpipe - | x265 --y4m --input - --input-res 1280x720 --output-depth 10 --preset slower --crf 20.0 --output 'output.hevc'
And after that, you can mux to have a .mkv :)