Jellyfin Forum
Encoding Discussion Megathread (ffmpeg, Handbrake, AV1, etc...) - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Off Topic (https://forum.jellyfin.org/f-off-topic)
+--- Forum: General Discussion (https://forum.jellyfin.org/f-general-discussion)
+--- Thread: Encoding Discussion Megathread (ffmpeg, Handbrake, AV1, etc...) (/t-encoding-discussion-megathread-ffmpeg-handbrake-av1-etc)

Pages: 1 2 3 4 5 6 7 8 9 10 11


RE: Encoding Discussion Megathread (ffmpeg, Handbrake, AV1, etc...) - TheDreadPirate - 2024-11-08

Our chat over in troubleshooting got me to come back here and update my process.  Now that jf-ffmpeg7 has Dolby Vision removal bundled, it turned a multi-step workflow into a "one liner".  This also removed a bunch of steps I needed to take to keep video, audio, and subtitles in sync.

I had some additional discussions with Nyanmisaka about how to handle video with a lot of film grain, which caused significantly reduced quality due to the randomness.  I had considered your de-noise approach, but ended up choosing to preserve the film grain.   So I explored some additional parameters Nyanmisaka had suggested to try to better use the available bit rate.

Code:
        ffmpeg \               
                -y \
                -init_hw_device vaapi=va:,driver=iHD,kernel_driver=i915 \
                -hide_banner \
                -stats \
                -fflags +genpts+igndts \
                -loglevel error \
                -init_hw_device qsv=qs@va \
                -filter_hw_device qs \
                -hwaccel qsv \ 
                -hwaccel_output_format qsv \
                -extra_hw_frames 40 \
                -i "$INPUTFILE" \
                $chapterSelect \       # only used when splitting one file into many, usually TV shows
                -map_chapters 0 \
                -map 0:v \
                -c:v av1_qsv \ 
                -pix_fmt yuv420p10le \
                -q:v 22 \
                -look_ahead_depth 40 \
                -preset veryslow \
                -vf vpp_qsv="$FILTERS" \
                $audioCommand \   # dynamically selected English and Japanese tracks (anime only), converts to OPUS w/VBR.  If lossless tracks present, ignore lossy tracks.
                $subCommand \      # dynamically selected English and Japanese tracks (anime only), copies unmodified.
                -map 0:t? \
                -disposition:s 0 \
                -low_delay_brc 1 \
                -extbrc 1 \
                -adaptive_i 1 \
                -adaptive_b 1 \
                -b_strategy 1 \
                -bf 39 \
                -max_muxing_queue_size 2048 \
                -max_interleave_delta 0 \
                -avoid_negative_ts disabled \
                "$outputFile"

Specifically

Code:
### decode side
                -extra_hw_frames 40 \  # new to me.  the same as -filter:v:0 "hwupload=extra_hw_frames=64 in your command???
### encode side
                -look_ahead_depth 40 \
                -low_delay_brc 1 \
                -extbrc 1 \ 
                -adaptive_i 1 \   # new
                -adaptive_b 1 \  #new
                -b_strategy 1 \  #new
                -bf 39 \  #new

The last four made a huge difference, both in terms of quality and just general bit rate.

Here is a file size comparison with and without just those last four lines.  Everything else is the same.

Code:
-rw-rw-r--  1 chris jellyfin  4751175286 Nov  8 15:00 Jinroh-adaptiveFrames.mkv
-rw-rw-r--  1 chris jellyfin 13693462719 Nov  8 15:16 Jinroh-noAdaptiveFrames.mkv
-rw-rw-r--  1 chris jellyfin 27340883707 Oct  2 20:19 Jinroh-original.mkv

My git has my full automation script. Still a WIP. I think I've got it to where it will handle just about any edge case. At least edge cases I've encountered. Now comes clean up, finding efficiencies, and making it pretty.

https://github.com/solidsnake1298/Arc-Encoding-Automator