2024-09-17 12:27:52 +02:00
#!/usr/bin/env bash
# Neural Network Deinterlacer weights file
NNEDI_WEIGHTS = "/usr/share/nnedi3/nnedi3_weights.bin"
# Constant Rate Factor / Global Quality
2024-09-17 13:28:51 +02:00
# If I’ ve a video/movie that was produced in HD a value between 21-23 works best and produces good results. But there are also videos/movies that where produced before HD was en vouge. When broadcasted they are scaled to HD e.g. In this case a value between 24-25 works best.
CRF = 22
2024-09-17 12:27:52 +02:00
# Encoding Preset. Veryslow == TU1 QSV
PRESET = veryslow
# Lookahead depth, used for QSV h.264
LA_DEPTH = 40
# PAL, high, nnedi3
PAL_VFILTERS = " -color_primaries bt470bg -color_trc gamma28 -colorspace bt470bg -vf nnedi=weights= ${ NNEDI_WEIGHTS } :nns=n128 -c:v libx265 -preset ${ PRESET } -crf ${ CRF } -x265-params aq-mode=3:aq-strength=0.9:psy-rd=1.2:deblock=-1,-1,level=4.1:colorprim=bt470bg:transfer=bt470bg:colormatrix=bt470bg:limit-sao=1 -pix_fmt yuv420p10le "
# NTSC, high, nnedi3
NTSC_VFILTERS = " -color_primaries smpte170m -color_trc smpte170m -colorspace smpte170m -vf nnedi=weights= ${ NNEDI_WEIGHTS } :nns=n128 -c:v libx265 -preset ${ PRESET } -crf ${ CRF } -x265-params aq-mode=3:aq-strength=0.9:psy-rd=1.2:deblock=-1,-1,level=4.1:colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m:limit-sao=1 -pix_fmt yuv420p10le "
# NTSC, high, HQ Yadif
YNTSC_VFILTERS = " -color_primaries smpte170m -color_trc smpte170m -colorspace smpte170m -vf yadif=0:deint=0 -c:v libx265 -preset ${ PRESET } -crf ${ CRF } -x265-params aq-mode=3:aq-strength=0.9:psy-rd=1.2:deblock=-1,-1,level=4.1:colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m:limit-sao=1 -pix_fmt yuv420p10le "
# NTSC, high, ivtc
IVTC_VFILTERS = " -color_primaries smpte170m -color_trc smpte170m -colorspace smpte170m -vf fieldmatch,yadif=deint=interlaced,decimate -c:v libx265 -preset ${ PRESET } -crf ${ CRF } -x265-params aq-mode=3:aq-strength=0.9:psy-rd=1.2:deblock=-1,-1,level=4.1:colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m:limit-sao=1 -pix_fmt yuv420p10le "
# Intel QSV, TU1, Rate control: ICQ, LA_ICQ (not yet) supported, but suggested for future-proofness...
QSV_VFILTERS = " -c:v hevc_qsv -preset ${ PRESET } -global_quality:v ${ CRF } -look_ahead:v 1 -g 251 "
2024-09-17 13:28:51 +02:00
VAAPI_VFILTERS = " -c:v hevc_vaapi -preset ${ PRESET } -global_quality:v ${ CRF } -qp ${ CRF } -look_ahead:v 1 -g 251 -rc_mode CQP "
2024-09-17 12:27:52 +02:00
# Intel QSV h.264, TU1, Rate control: LA_ICQ
QSV_AVC_VFILTERS = " -c:v h264_qsv -preset ${ PRESET } -global_quality:v ${ CRF } -look_ahead:v 1 -look_ahead_depth ${ LA_DEPTH } -extra_hw_frames ${ LA_DEPTH } -g 251 "
# Copy All Audio streams
2024-09-17 12:30:26 +02:00
#AFILTERS="-c:a copy -map 0"
2024-09-17 12:27:52 +02:00
# Lossless Compression
2024-09-17 13:28:51 +02:00
AFILTERS = "-c:a flac -compression_level:a 12 -map 0"
2024-09-17 12:27:52 +02:00
# Lossy, not compatible with players, transparent
#AFILTERS="-c:a libopus -b:a 192k"
# Lossy, most compatible, low quality
# AFILTERS=""
PAL_FILTERS = " ${ PAL_VFILTERS } ${ AFILTERS } "
NTSC_FILTERS = " ${ NTSC_VFILTERS } ${ AFILTERS } "
YNTSC_FILTERS = " ${ YNTSC_VFILTERS } ${ AFILTERS } "
IVTC_FILTERS = " ${ IVTC_VFILTERS } ${ AFILTERS } "
QSV_FILTERS = " ${ QSV_VFILTERS } ${ AFILTERS } "
2024-09-17 13:28:51 +02:00
VAAPI_FILTERS = " ${ VAAPI_VFILTERS } ${ AFILTERS } "
2024-09-17 12:27:52 +02:00
QSV_AVC_FILTERS = " ${ QSV_AVC_VFILTERS } ${ AFILTERS } "
# Conversion sous-titres
#ffmpeg -sub_charenc UTF-8 -i ep01.srt ep01.ass
if [ $# -ne 2 ] ; then
echo " Usage: $0 infile outfile "
exit 1
fi
2024-09-17 13:28:51 +02:00
set -x
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i " $1 " ${ VAAPI_FILTERS } " $2 "