mirror of https://gitlab.com/hsmalley/convert265
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.7 KiB
Bash
35 lines
1.7 KiB
Bash
#!/bin/bash
|
|
set -o pipefail
|
|
IFS=$'\n\t'
|
|
|
|
pro_dir="/opt/amdgpu-pro/etc/vulkan/icd.d"
|
|
export LD_LIBRARY_PATH="/opt/amdgpu/libdrm/lib64:/opt/amdgpu/libdrm/lib32:$LD_LIBRARY_PATH"
|
|
export VK_ICD_FILENAMES="${pro_dir}/amd_icd32.json:${pro_dir}/amd_icd64.json"
|
|
|
|
for video; do
|
|
if [[ ! -f "${video}.json" ]]; then
|
|
ffprobe -v quiet -print_format json -show_streams "${video}" > "${video}.json"
|
|
fi
|
|
d=$(dirname "$video")
|
|
filename=$(basename "$video")
|
|
filename="${filename%.*}"
|
|
video_codec=$(jq -r '.streams[0].codec_name' < "${video}.json")
|
|
video_height=$(jq -r '.streams[0].height' < "${video}.json")
|
|
echo -e "${video} // ${video_codec} // ${video_height}"
|
|
if [[ ${video_codec} =~ "av1" ]]; then
|
|
exit
|
|
fi
|
|
if [[ ! ${video_codec} =~ "hevc" || ${video_height} -gt 1080 ]]; then
|
|
_filename=$(echo "${filename}" | sed -e 's/h264/x265/g' -e 's/x264/x265/g' -e 's/AVC/x265/g' -e 's/XviD/x265/g').mkv
|
|
nice -n 19 ffmpeg -hide_banner -loglevel info -y -threads 4 -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -analyzeduration 20000000 -probesize 20000000 \
|
|
-i "${video}" -map 0:v -map 0:a -map 0:s? -map 0:d? -map 0:t? -c:s copy -c:a copy \
|
|
-vf 'scale_vaapi=format=p010,scale_vaapi=w=1920:-2' -c:v hevc_vaapi -profile:v main10 \
|
|
-max_muxing_queue_size 1024 -movflags +faststart -movflags use_metadata_tags "/dev/shm/$_filename" || exit 1
|
|
mv -vu "/dev/shm/${_filename}" "${d}/${_filename}" || rm -f "/dev/shm/${_filename}"
|
|
if [[ -f "${d}/${_filename}" ]]; then
|
|
cmp "${d}/${_filename}" "${video}" || rm -vf "${video}" "${video}.json"
|
|
ffprobe -v quiet -print_format json -show_streams "${d}/${_filename}" > "${d}/${_filename}.json"
|
|
fi
|
|
fi
|
|
done
|