ffmpeg-hardware-transcoding.../work.sh
2024-11-09 21:52:31 +01:00

60 lines
3.3 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Neural Network Deinterlacer weights file
NNEDI_WEIGHTS="/usr/share/nnedi3/nnedi3_weights.bin"
# Constant Rate Factor / Global Quality
# If Ive 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
# 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"
VAAPI_VFILTERS="-c:v hevc_vaapi -preset ${PRESET} -global_quality:v ${CRF} -qp ${CRF} -look_ahead:v 1 -g 251 -rc_mode CQP"
# 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
#AFILTERS="-c:a copy -map 0"
# Lossless Compression
AFILTERS="-c:a flac -compression_level:a 12 -map 0"
# 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}"
VAAPI_FILTERS="${VAAPI_VFILTERS} ${AFILTERS}"
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
set -x
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "$1" ${VAAPI_FILTERS} "$2"