LinuxScrips/Linux Desktop scripts/encode_video_hevc.sh

64 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2022-02-01 23:49:29 +01:00
#!/bin/bash
INPUT_FILE="$1"
OUTPUT_FILE="$2"
GPU="$3"
[[ -f "${INPUT_FILE}" ]] || exit 1
ffmpeg_input_opts_amd=(
-init_hw_device vaapi=amdgpu:/dev/dri/renderD128
-hwaccel vaapi
-hwaccel_output_format vaapi
-hwaccel_device amdgpu
)
ffmpeg_output_opts_amd=(
-vaapi_device /dev/dri/renderD128
-map 0
-c:v hevc_vaapi
-c:a copy
-c:s copy
-vtag hvc1
)
ffmpeg_input_opts_nv=(
)
ffmpeg_output_opts_nv=(
-map 0
-c:s copy
-c:a copy
-c:v hevc_nvenc
)
ffmpeg_input_opts_intel=(
-hwaccel qsv
)
ffmpeg_output_opts_intel=(
-map 0
-c:v hevc_qsv
-c:a copy
-c:s copy
)
case ${GPU} in
nv)
echo -n "Using nVidia cuda"
ffmpeg ${ffmpeg_input_opts_nv[@]} -i "${INPUT_FILE}" ${ffmpeg_output_opts_nv[@]} "${OUTPUT_FILE}"
;;
amd)
echo -n "using AMDGPU"
ffmpeg ${ffmpeg_input_opts_amd[@]} -i "${INPUT_FILE}" ${ffmpeg_output_opts_amd[@]} "${OUTPUT_FILE}"
;;
intel)
echo -n "Using Intel QSV"
ffmpeg ${ffmpeg_input_opts_intel[@]} -i "${INPUT_FILE}" ${ffmpeg_output_opts_intel[@]} "${OUTPUT_FILE}"
;;
*)
echo -n "Using CPU encoding"
;;
esac