2023-09-16, 03:32 PM
Okay, well a couple hours of trial and error -- mostly due to me not sleeping -- and I have a working "script" for ab-av1 that I'm throwing at this series. Figured I'd share here. I have one I threw together for ffmpeg prior to this that I was going to try for a whole list of series that I put in a spreadsheet I started, but I need to modify based on what I've found out here...
Code:
IPATH="/path/to/input/media" && \
OPATH="/path/to/output/encoded/media" && \
# desired output extension
EXT="mkv" && \
# strips this off the end of filenames, requires spaces and special chars to be escaped
CLEAN=".1080p.REMUX.VC-1.EAC35.1-LMAO.mkv" && \
QUAL="BDRip" && \
RES="1080p" && \
# release group or source
GRP="OctAV10" && \
# audio language/s (e.g., "EN+DE+JA")
LNG="EN" && \
# subtitle languages (see above)
SUBS="EN" && \
# desired primary audio stream index, mapped 2x by default
STAUD="0" && \
# if additional audio streams desired, map here, uncomment appropriate line
ADAUD="-map x:a:y"
# desired primary subtitle stream index
STSUB="0" && \
# if additional subtitle streams desired, map here, uncomment appropriate line
ADSUB="-map p:s:q"
# Set minimum VMAF, ab-av1 default is 95
VMAF="96" && \
# Set CRF floor, ab-av1 default is 10
LCRF="12" && \
# Set CRF ceiling, ab-av1 ceiling is MAX
XCRF="28" && \
# Set desired preset, values vary by encoder, SVT-AV1 default for ab-av1 is 8
PRESET="4" && \
# Film grain synthesis level
FGRN="4" && \
# Additional mapping, note this will be ordered AFTER all other video, audio, sub streams
ADDMP="" && \
# Doom9 'midnight dialog' stereo mixdown audio filter
AFLTR="pan=stereo|FL<FC+0.30*FL+0.30*BL|FR<FC+0.30*FR+0.30*BR" && \
# Desired metadata condensed to make main script more readable
MDATA="-metadata title=${MEDIA%${CLEAN}} | Jellyfin \
-metadata:s:v:0 title='AV1 VMAF ~${VMAF}' \
-metadata:s:a:0 title='English OPUS Stereo Dialog Mix' \
-metadata:s:s:0 title='English' \
-metadata:s:s:1 title='English (SDH)' \
-metadata:s:s:2 title='English (PGS)'" && \
#
#
# LEFT INTENTIONALLY BLANK
#
#
for MEDIA in "${IPATH}"/*.mkv; do \
# Get filename from full path
FNAME=$(basename "${MEDIA%${CLEAN}}")
ONAME="${OPATH}/${FNAME}-[${QUAL}-${RES}.AV1.OPUS.2.0][${LNG}][${SUBS}]-${GRP}" && \
TEMP="${ONAME}.temp.${EXT}" && \
OFILE="${ONAME}.${EXT}" && \
echo "Beginning auto-encode for ${FNAME}..."
# auto-encode only handles the AV1 video stream
ab-av1 auto-encode \
--encoder libsvtav1 --preset "${PRESET}" --svt tune=0 --min-vmaf "${VMAF}" \
--min-crf "${LCRF}" --max-crf "${XCRF}" --svt film-grain="${FGRN}" \
-i "${MEDIA}" -o "${TEMP}" && \
# let ffmpeg do the heavy (light?) lifting of mapping and audio encoding
ffmpeg -i "${TEMP}" -map_metadata 0 -map 0:v \
-map 0:a:"${STAUD}" \
#-map 0:s:"${STSUB}" -map 0:s:1 -map 0:s:2 \
-c:v copy -c:a libopus -c:s copy \
-b:a:0 256k -ac:a:0 2 -filter:a:0 "${AFLTR}" \
"${MDATA}"
"${OFILE}" && \
rm "${TEMP}"; done
Jellyfin 10.10.0 LSIO Docker | Ubuntu 24.04 LTS | i7-13700K | Arc A380 6 GB | 64 GB RAM | 79 TB Storage