2023-09-07, 06:37 PM
Okay, so what I figured out after trying out a few things is that our friend nyanmisaka, as always, was right. The -global_quality flag doesn't work and causes issues a failure with the av1_qsv encoder. Works great with the hevc_qsv encoder, particularly when used with the -look_ahead option (suggest playing around there). So I tried -qp and everything worked just fine! Did a few 1080p encodes and the quality was alright and the compression was decent. So I tried a 4K encode and the quality was absolute garbage.
I went back and watched through the entire 1080p encode and there were a LOT of issues. So I tried a MUCH lower QP value. And I got -- what I thought was -- roughly the same file size. Turns out it was the exact same file size because -qp has no effect. Same with -crf. So you can only run av1_qsv by specifying bit rates. Which pretty much kills my mass scripting aims, but this can still be used to batch encode series. The documentation for av1_qsv on the ffmpeg docs absolutely sucks. The options they have listed 100% do not work.
So if you're looking to do any AV1 encoding with QSV, here are a few tricks I have figured out so far, with some nice ffmpeg and bash tips I threw in because I wanted to know how to do them! Hopefully this is helpful to somebody. I have a few things I want to figure out how to do and there are a few tricks in Python I know how to make happen that I don't know in bash (that might be possible) so I'll see what's up when I have a little free time.
I went back and watched through the entire 1080p encode and there were a LOT of issues. So I tried a MUCH lower QP value. And I got -- what I thought was -- roughly the same file size. Turns out it was the exact same file size because -qp has no effect. Same with -crf. So you can only run av1_qsv by specifying bit rates. Which pretty much kills my mass scripting aims, but this can still be used to batch encode series. The documentation for av1_qsv on the ffmpeg docs absolutely sucks. The options they have listed 100% do not work.
So if you're looking to do any AV1 encoding with QSV, here are a few tricks I have figured out so far, with some nice ffmpeg and bash tips I threw in because I wanted to know how to do them! Hopefully this is helpful to somebody. I have a few things I want to figure out how to do and there are a few tricks in Python I know how to make happen that I don't know in bash (that might be possible) so I'll see what's up when I have a little free time.
Code:
for i in *.mkv; do \
# Step 1 is to strip a year from these media files all in the 20XX range
j="${i#20[0-1][0-6].}" && \
# Step 2 strips the crap afterwards leaving us with "Media.Name" not ideal, but easily scripted
k="${j%.1920x810.BDRip.x264.DTS-HD.MA.mkv}" && \
# Keep ffmpeg quiet, but this is too quiet and only shows stats and QSV initialization
ffmpeg -hide_banner -loglevel warning -v quiet -stats \
-hwaccel qsv -hwaccel_output_format qsv -qsv_device /dev/dri/renderD129 \
# Map streams -- you can map a single stream multiple times to create copies for stereo + 5.1
-i "${i}" -map 0:v -map 0:a:1 -map 0:a:2 -map 0:a:1 -map 0:s:0 -map 0:s:1 \
# Set default streams -- set mapped audio stream 0 as default, turn off default flag on audio stream 1
-disposition:a:0 default -disposition:a:1 0 \
# (Over)write the file's metadata if it's junk -- can be plaintext
-metadata title="${j}" \
# Set bit rates -- all subjective, need to experiment with individual media
# I have been using 4, 6, 10, and 12 as arbitrary test points and setting max at 2x -b:v, bufsize at 4x
-c:v av1_qsv -preset slower -b:v 12M -maxrate:v 24M -bufsize:v 48M \
# Look ahead offers better bit rate control but slows down encoding I believe (AV1 limits depth to 100 frames)
-look_ahead 1 -look_ahead_depth 100 \
# Set metadata stream data (s=stream v=video 0=index title=key
-metadata:s:v:0 title='1080p FHD 24FPS AV1 12Mbps ABR' \
# Even w/ multiple audio streams, set the codec once if you only use one codec
-c:a libopus -ac:a:0 2 -b:a:0 192k \
# Don't use -af, use -filter:[stream] if using pan or other filters, as you need stream index
# if multiple streams exist (e.g., two audio streams and one is 2.0, one is 5.1).
-filter:a:0 "pan=stereo|FL<FC+0.30*FL+0.30*BL|FR<FC+0.30*FR+0.30*BR" \
# Writing these because they display in Jellyfin on the media page...
-metadata:s:a:0 title='English OPUS Stereo Dialog Mix' \
-ac:a:1 6 -b:a:1 256k -metadata:s:a:1 title='English OPUS 5.1' \
-c:s copy -metadata:s:s:0 title='English' -metadata:s:s:1 title='English (SDH)' \
"${k} [Extra Info You.Definitely.Need]-AwesomeReleaseGroup.mkv"
Jellyfin 10.10.0 LSIO Docker | Ubuntu 24.04 LTS | i7-13700K | Arc A380 6 GB | 64 GB RAM | 79 TB Storage