2023-08-25, 04:48 AM
(This post was last modified: 2023-08-25, 04:49 AM by bitmap. Edited 1 time in total.)
(2023-08-23, 09:11 PM)TheDreadPirate Wrote: Continuing our convo from the other thread. I'm not at home yet to post my Handbrake json. But here is the gist of my two Handbrake presents.
"Blurays" preset
MKV container
no filters
Automatically detect and trim black bars, otherwise don't change resolution
Variable frame rate, match source (always results in constant frame rate)
NVENC HEVC 8-bit, CQ26, slow preset, main profile, auto level
Direct copy all audio streams
Direct copy all subtitles
Direct copy chapters
Okay, back at it. I had the main stuff put together with a few things to go. Note that this is untested at the moment as I just wrote it. I'll grab something like Big Buck Bunny or something to throw at it later, but I can't test the NVENC version, but I'm sure most of it is right aside from the pix_fmt option as I don't know which formats are supported by the encoder...since it's not documented on the ffmpeg site and I had to find a Github page with the help printout to get what I needed. Anyway. Here's the NVENC version. All that's going to change are a few options between this and the QSV version.
Code:
# Written to emulate Handbrake Bluray rip preset for HEVC NVENC, crop black bars, auto-level, main8
for i in *.mkv; do \
crop=$(ffmpeg -ss 10 -i 'input_media.mkv' -t 1 -vf cropdetect -f null - 2>&1 | awk '/crop=/ {a=$NF} END{print a}') \
ffmpeg -hwaccel_output_format cuda [-gpu <index>] \
-i "${i}" -vf "pp=al, ${crop}" -map 0:v -map 0:a -map 0:s -map_chapters 0 \
-c:v hevc_nvenc -profile main -preset slow -cq 26 -pix_fmt yuv420p \
-c:a copy -c:s copy "${$i%mkv}_processed.mkv"; done
So we get the crop value, start the encode by telling ffmpeg we're using NVENC -- if you only have one device, leave out the GPU option. From there, specify the input file and apply two video filters. The first is a sort of crude auto-leveling analog (I have not used this one before, so testing it would be advised before using it on something you cherish). Next is the black bar cropping with a call to our crop variable, which is already formatted exactly as we need. From there, we map all the video, audio, subs, and chapters to make sure we don't miss anything. Specify the video codec, profile, preset, CQ, pix_fmt (standard pix_fmt for 8-bit video), then specify the codec is COPY for audio and subs, and put our output file with "_processed" at the end of the file name. You can also specify a different directory or whatever you like here, this is where I'm sure you don't need help.
Frame rate is always matched, unless your source is variable framerate. You can specify -vsync (which is technically deprecated, but still works) or -fps_mode (which replaced -vsync) if you run across this issue.
I'll tackle the DVD preset soon. Deinterlacing is personal preference, but YADIF does a good job, I just ran Mission Hill through it and got great results. So I have something to go off, and since it's essentially the same preset, just adding that filter, it will look very similar. For reference, here's the QuickSync version, but I won't explain that one in detail:
Code:
# Written to emulate Handbrake Bluray rip preset for HEVC QSV, crop black bars, auto-level, main8
for i in *.mkv; do \
crop=$(ffmpeg -ss 10 -i 'input_media.mkv' -t 1 -vf cropdetect -f null - 2>&1 | awk '/crop=/ {a=$NF} END{print a}') \
ffmpeg -hwaccel_output_format -qsv_device /dev/dri/renderD128 \
-i "${i}" -vf "pp=al, ${crop}" -map 0:v -map 0:a -map 0:s -map_chapters 0 \
-c:v hevc_qsv -profile main -preset slow -global_quality:v 26 -pix_fmt yuv420p \
-c:a copy -c:s copy "${$i%mkv}_processed.mkv"; done
Please ask any questions you have or if there are things I missed, more customizations you're interested in, things you don't know that you might want, etc... This was fun, it stretched me a little bit!
Jellyfin 10.10.0 LSIO Docker | Ubuntu 24.04 LTS | i7-13700K | Arc A380 6 GB | 64 GB RAM | 79 TB Storage