2022-02-02 18:00:05 +01:00
|
|
|
#!/bin/bash
|
2022-02-02 22:54:08 +01:00
|
|
|
|
|
|
|
GPU=nv #Which Hardware to use? nv = nvidia, amd = amdgpu; intel = intel qsv; cpu = CPU encoding
|
|
|
|
|
2022-02-02 18:00:05 +01:00
|
|
|
BASEFOLDER_SOURCE="/path/to/source"
|
|
|
|
BASEFOLDER_DESTIN="/path/to/destination"
|
|
|
|
FOLDERS_TO_SCAN=(
|
|
|
|
"Folder"
|
|
|
|
"Folder 2"
|
|
|
|
"Also a Folder"
|
|
|
|
)
|
|
|
|
|
2022-02-02 22:54:08 +01:00
|
|
|
#---------- DO NOT EDIT BELOW HERE EXCEPT YOU KNOW WHAT YOU ARE DOING ----------
|
2022-02-02 18:00:05 +01:00
|
|
|
BFSL=$(expr length ${BASEFOLDER_SOURCE})
|
|
|
|
BFSL=$((BFSL + 1))
|
|
|
|
|
|
|
|
ffmpeg_input_opts_amd=(
|
|
|
|
-init_hw_device vaapi=amdgpu:/dev/dri/renderD128
|
|
|
|
-hwaccel vaapi
|
|
|
|
-hwaccel_output_format vaapi
|
|
|
|
-hwaccel_device amdgpu
|
2022-02-02 22:54:08 +01:00
|
|
|
-nostdin
|
|
|
|
-stats
|
2022-02-02 18:00:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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=(
|
2022-02-02 22:54:08 +01:00
|
|
|
-nostdin
|
|
|
|
-stats
|
|
|
|
|
2022-02-02 18:00:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
ffmpeg_output_opts_nv=(
|
|
|
|
-map 0
|
|
|
|
-c:s copy
|
|
|
|
-c:a copy
|
|
|
|
-c:v hevc_nvenc
|
|
|
|
)
|
|
|
|
|
|
|
|
ffmpeg_input_opts_intel=(
|
|
|
|
-hwaccel qsv
|
2022-02-02 22:54:08 +01:00
|
|
|
-nostdin
|
|
|
|
-stats
|
2022-02-02 18:00:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
ffmpeg_output_opts_intel=(
|
|
|
|
-map 0
|
|
|
|
-c:v hevc_qsv
|
|
|
|
-c:a copy
|
|
|
|
-c:s copy
|
|
|
|
)
|
|
|
|
|
2022-02-02 22:54:08 +01:00
|
|
|
ffmpeg_input_opts_cpu=(
|
|
|
|
-nostdin
|
|
|
|
-stats
|
|
|
|
)
|
|
|
|
|
|
|
|
ffmpeg_output_opts_cpu=(
|
|
|
|
-map 0
|
|
|
|
-c:v libx265
|
|
|
|
-c:a copy
|
|
|
|
-c:s copy
|
|
|
|
)
|
|
|
|
|
2022-02-02 18:00:05 +01:00
|
|
|
for i in "${FOLDERS_TO_SCAN[@]}"; do
|
|
|
|
find ${BASEFOLDER_SOURCE}/"${i}" -type f >temp.txt
|
|
|
|
while IFS= read -r LINE; do
|
|
|
|
SPATH=$(dirname "${LINE}")
|
|
|
|
DPATH="${BASEFOLDER_DESTIN}$(cut -c${BFSL}- <<<${SPATH})"
|
|
|
|
FILE="$(basename "${LINE}")"
|
|
|
|
if [ ! -d "${DPATH}" ]; then mkdir -p "${DPATH}"; fi
|
|
|
|
|
|
|
|
case ${GPU} in
|
|
|
|
nv)
|
|
|
|
echo -n "Using nVidia cuda"
|
2022-02-02 22:54:08 +01:00
|
|
|
echo "Encoding file ${FILE}"
|
2022-02-02 18:00:05 +01:00
|
|
|
ffmpeg ${ffmpeg_input_opts_nv[@]} -i "${SPATH}/${FILE}" ${ffmpeg_output_opts_nv[@]} "${DPATH}/${FILE}"
|
2022-02-02 22:54:08 +01:00
|
|
|
echo -e "------------------\n\n"
|
2022-02-02 18:00:05 +01:00
|
|
|
;;
|
|
|
|
amd)
|
|
|
|
echo -n "using AMDGPU"
|
2022-02-02 22:54:08 +01:00
|
|
|
echo "Encoding file ${FILE}"
|
2022-02-02 18:00:05 +01:00
|
|
|
ffmpeg ${ffmpeg_input_opts_amd[@]} -i "${SPATH}/${FILE}" ${ffmpeg_output_opts_amd[@]} "${DPATH}/${FILE}"
|
2022-02-02 22:54:08 +01:00
|
|
|
echo -e "------------------\n\n"
|
2022-02-02 18:00:05 +01:00
|
|
|
;;
|
|
|
|
intel)
|
|
|
|
echo -n "Using Intel QSV"
|
2022-02-02 22:54:08 +01:00
|
|
|
echo "Encoding file ${FILE}"
|
2022-02-02 18:00:05 +01:00
|
|
|
ffmpeg ${ffmpeg_input_opts_intel[@]} -i "${SPATH}/${FILE}" ${ffmpeg_output_opts_intel[@]} "${DPATH}/${FILE}"
|
2022-02-02 22:54:08 +01:00
|
|
|
echo -e "------------------\n\n"
|
2022-02-02 18:00:05 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo -n "Using CPU encoding"
|
|
|
|
;;
|
2022-02-02 22:54:08 +01:00
|
|
|
echo -n "Using CPU"
|
|
|
|
echo "Encoding file ${FILE}"
|
|
|
|
ffmpeg ${ffmpeg_input_opts_cpu[@]} -i "${SPATH}/${FILE}" ${ffmpeg_output_opts_cpu[@]} "${DPATH}/${FILE}"
|
|
|
|
echo -e "------------------\n\n"
|
2022-02-02 18:00:05 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
done < temp.txt
|
|
|
|
rm temp.txt
|
|
|
|
done
|