Skip to content

Instantly share code, notes, and snippets.

@catleeball
Created June 19, 2024 04:56
Show Gist options
  • Save catleeball/b4e15e744469a022f7063a31b7457921 to your computer and use it in GitHub Desktop.
Save catleeball/b4e15e744469a022f7063a31b7457921 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eux
# deinterlace with `-vf yadif_cuda=1` after the -i line
HWACCEL="nvdec"; # https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDANVENCNVDEC
HWACCEL_DEVICE="/dev/dri/renderD129"; # on beppo 128=amd, 129=nvidia
CRF="23"; # Perceptually lossless (see: https://trac.ffmpeg.org/wiki/Encode/AV1#ConstantQuality )
PRESET="3"; # 0 - 13 (higher is faster encode / worse qual)
TUNE="0";
# SVT-AV1 params (colon delimited): https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDANVENCNVDEC
# film grain param: ":film-grain=10"
# film grain doc: https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Appendix-Film-Grain-Synthesis.md
# quanization matricies: ":enable-qm=1:qm-min=0:qm-max=15"
# variance boost: ":enable-variance-boost=1:variance-boost-strength=[1-4]:variance-octile=[1-8]"
# variance boost doc: https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Appendix-Variance-Boost.md#parameters
# """ The default value is 2.
# - Strength 1 tends to be best for simple, untextured, or smooth animation.
# - Strength 2 is a highly compatible curve, great for most live-action content and animation with detailed textures.
# - Strength 3 is best for still images or videos with a balanced mix of very high-contrast and low-contrast scenes (like traditional horror or thriller movies).
# - Strength 4 is very aggressive and only useful under very specific circumstances where low-contrast detail retention is an extremely high priority.
#
# See also: https://gist.github.com/BlueSwordM/86dfcb6ab38a93a524472a0cbe4c4100
VARIANCE_BOOST_ENABLE="1";
VARIANCE_BOOST_STR="2"; # [1-4]
VARIANCE_OCTILE="3"; # [1-7]
ENABLE_OVERLAYS="1";
ENABLE_SCD="1";
ENABLE_SCM="0"; # 0=off; 1=on; 2=auto
ENABLE_TF="1";
ENC_PARAMS="tune=$TUNE:enable-overlays=$ENABLE_OVERLAYS;scd=$ENABLE_SCD:scm=$ENABLE_SCM:enable-tf=$ENABLE_TF:enable-variance-boost=$VARIANCE_BOOST_ENABLE:variance-boost-strength=$VARIANCE_BOOST_STR:variance-octile=$";
# DEINTERLACE="-vf yadif_cuda=1";
PROBESIZE="10000000";
echo "[$(date +%F_%r)] Encoding $1"
ffmpeg \
-nostats \
-hwaccel "$HWACCEL" -hwaccel_device "$HWACCEL_DEVICE" \
-probesize = "$PROBESIZE" \
-i "$1" \
-c:a copy -c:s copy -c:v libsvtav1 \
-pix_fmt yuv420p10le \
-crf "$CRF" -preset "$PRESET" -tune "$TUNE" \
-svtav1-params $ENC_PARAMS \
"av1_$1"
echo "[$(date +%F_%r)] Finished encoding $1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment