Hi Habr.
Actually I decided to write the first post after reading
this . In it, the author tried to set out his vision, but, in my opinion, did not succeed.
So, given: BDRemux, 1080p, 25 episodes.
Task: Make the highest quality rip 480p (or 720p), in 10 bits.
Immediately make a reservation that we will encode anime.
For the work we need:
1.
x264 , for encoding video stream.
2.
ffmpeg , we will use it only for audio coding, so in my opinion it is easier.
3.
mkvtoolnix , for assembling this miracle into the mkv container.
')
Since we have a lot of episodes, we will write a simple batch file, which is useful for subsequent rips.
Video
First I will give the code, then I will explain the parameters:
"...\x264-10b.exe" "...\ .m2ts" --input-res 1920x1080 --fps 23.976 --profile high10 --preset medium --tune animation --crf=15.5 --me=umh --ref=9 --deblock=-1,-1 --merange=24 --bframes=12 --trellis=1 --video-filter resize:width=854,height=480,method=lancoz --output "...\ .264"
Options
--input-res 1920x1080 --fps 23.976
We suggest x264 resolution and source frame rate. (can be peeped in MediaInfo)
--profile high10
Options: baseline, main, high, high10, high422, high444.
Specify the profile. In this case, we encode in 10 bits, so high10, if in 8 - high.
--preset medium
Options: ultrafast, superfast, veryfast, faster, medium, slow, slower, veryslow, placebo.
Balance coding speed and quality. Those. higher speed - worse quality.
I mainly use medium, slow and sometimes veryslow.
--tune animation
Options: film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency.
Presets based on video input. For movies one thing, for anime another.
--crf=15.5
Range: 1-50.
The mode of constant quality and its level. The less - the better the quality. Allows each frame to use its own QP, based on the complexity of the frame.
More in English can be read
here .
This is the best method for single pass coding.
Possible options for replacement: --bitrate or --qp, we will not consider them.
Next, override some parameters, since not all of them from the medium preset fit us: --me=umh
Options: dia, hex, umh, esa, tesa.
Method for estimating the motion of a full pixel. I recommend umh.
--ref=9
Range: 1-16.
The number of reference frames. The more, the slower the coding will be. If you follow the specifications for home appliance support, 4 is maximum for 1080p, and 9 is maximum for 720p.
With 6 and above, you will not see much difference in quality, and the coding rate will drop dramatically.
--deblock=-1,-1.
Deblocking, in the format of
:
. In short, the higher the deblocking force, the more it is applied, the higher the threshold, the more blocks it comes across.
Well painted
here .
Since we encode BDRemux anime, it is desirable to reduce the strength and threshold to reduce the blurring of the lines. I use -1: -1, but there were rips and with -2: -2.
--merange=24
Range: 4-64.
Determines the maximum number of attempts to find the optimal variant when searching for the motion vector of a macroblock. The more, the better the quality.
It does not make much sense to put more than 24.
--bframes=12
Range: 1-16.
Sets the maximum number of parallel B-frames. Great importance can lead to a significant improvement in the efficiency of the compression ratio.
--trellis=1
Range: 0-2.
Trellis quantization to increase compression efficiency. 0 - disabled. 1 - Option "on macroblocks". 2 - "everywhere."
1 is a good compromise between loss of speed and compression efficiency. Best of all, 2, but in conjunction with
--psy-rd
, otherwise zamyla small details.
Resize
--video-filter resize:width=854,height=480,method=lancoz
Specify the width and height, as well as the method. I use lancoz.
Options: fastbilinear, bilinear, bicubic, experimental, point, area, bicublin, gauss, sinc, lanczos, spline.
Audio
For coding we will use ffmpeg.
"...\ffmpeg\bin\ffmpeg.exe" -i "...\ .m2ts" -vn -c:a libvorbis -qscale:a 6 "...\ .ogg"
Everything is simple:
-vn
Disable video encoding.
-c:a libvorbis -qscale:a 6
Specify the encoder and quality.
Range: 0-10.
The more, the better the quality.
6 is ~ 192 Kbps.
Assembly:
We encode the first series.
Open the mkvtoolnix GUI, select the resulting video and audio, set the parameters (for example, for video it will be useful to set the aspect and frame rate, and for audio, the language of the track) and click copy to the clipboard, we get something like:
"...\mkvtoolnix\mkvmerge.exe" -o "...\ .mkv" "--default-track" "0:yes" "--forced-track" "0:no" "--aspect-ratio" "0:16/9" "--default-duration" "0:23.976fps" "-d" "0" "-A" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "...\ .264" ")" "--language" "0:jpn" "--default-track" "0:yes" "--forced-track" "0:no" "-a" "0" "-D" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "...\ .ogg" ")" "--track-order" "0:0,1:0"
Full code for 25 episodes:
@echo off for /L %%i in (1,1,9) do ( "...\ffmpeg\bin\ffmpeg.exe" -y -i "...\ 0%%i.m2ts" -vn -map 0:2 -c:a libvorbis -qscale:a 6 "...\ 0%%i.ogg" "...\x264\x264-10b.exe" "...\ 0%%i.m2ts" --input-res 1920x1080 --fps 23.976 --profile high10 --preset medium --tune animation --crf=15.5 --me=umh --ref=9 --deblock=-1,-1 --merange=24 --bframes=12 --trellis=1 --video-filter resize:width=854,height=480,method=lancoz --output "...\ 0%%i.264" "...\mkvtoolnix\mkvmerge.exe" -o "...\ 0%%i.mkv" "--default-track" "0:yes" "--forced-track" "0:no" "--aspect-ratio" "0:16/9" "--default-duration" "0:23.976fps" "-d" "0" "-A" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "...\ 0%%i.264" ")" "--language" "0:jpn" "--default-track" "0:yes" "--forced-track" "0:no" "-a" "0" "-D" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "...\ 0%%i.ogg" ")" "--track-order" "0:0,1:0" ) for /L %%i in (10,1,25) do ( "...\ffmpeg\bin\ffmpeg.exe" -y -i "...\ %%i.m2ts" -vn -map 0:2 -c:a libvorbis -qscale:a 6 "...\ %%i.ogg" "...\x264\x264-10b.exe" "...\ %%i.m2ts" --input-res 1920x1080 --fps 23.976 --profile high10 --preset medium --tune animation --crf=15.5 --me=umh --ref=9 --deblock=-1,-1 --merange=24 --bframes=12 --trellis=1 --video-filter resize:width=854,height=480,method=lancoz --output "...\ %%i.264" "...\mkvtoolnix\mkvmerge.exe" -o "...\ %%i.mkv" "--default-track" "0:yes" "--forced-track" "0:no" "--aspect-ratio" "0:16/9" "--default-duration" "0:23.976fps" "-d" "0" "-A" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "...\ %%i.264" ")" "--language" "0:jpn" "--default-track" "0:yes" "--forced-track" "0:no" "-a" "0" "-D" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "...\ %%i.ogg" ")" "--track-order" "0:0,1:0" ) pause
Since I have two crooked hands, the same code was written twice.
Thank you all for your attention.
UPD: --input-res 1920x1080 --fps 23.976
You can not specify. This is only necessary if you feed the x264 pure raw stream.
--profile high10
You can also not specify, because
Bit rate is determined at the compilation stage and it will not work out to code in 8 and 10 with a single binary. So it makes no sense to put a profile in principle (unless you need 4: 2: 2 or 4: 4: 4).
Thanks
tp7 .
Also, in my opinion, it makes sense to raise
--subme to 9.
More information about all the parameters can be read
here in English.