Last active
August 31, 2020 14:07
-
-
Save mplinuxgeek/ab5e8ea0dec4919cc293125b8f4a3573 to your computer and use it in GitHub Desktop.
This is a simple script that uses vaapi hardware acceleration to decode and encode videos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage function, displays valid arguments | |
usage() { | |
echo "Usage: $(basename ${0}) [arguments] inputfile" 1>&2 | |
echo " -q qp, defaults to 18 for near lossless quality, higher value = lower quality." 1>&2 | |
echo -e "\nExample: $(basename ${0}) -q 22" 1>&2 | |
exit 1 | |
} | |
# Default variables | |
qp=18 | |
# getopts to process the command line arguments | |
while getopts ":q:p:" opt; do | |
case "${opt}" in | |
q) qp=${OPTARG};; | |
*) usage;; | |
esac | |
done | |
# shift out the arguments already processed with getopts | |
shift "$((OPTIND - 1))" | |
if (( $# == 0 )); then | |
printf >&2 'Missing input file\n' | |
usage >&2 | |
fi | |
# set input variable to the first option after the arguments | |
input="$1" | |
# Extract filename from input file without the extension | |
filename=${input%.*} | |
title=${1##*/} | |
echo "${filename} (qp${qp}).mkv" | |
ffmpeg -hide_banner -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "${input}" -map 0:v? -map 0:a? -map 0:s? -map 0:d? -map 0:t? -vf 'scale_vaapi=format=p010le' -c:v hevc_vaapi -qp ${qp} -profile:v main10 -max_muxing_queue_size 1024 -c:a copy -c:s copy -y "${filename} (qp${qp}) (recode).mkv" | |
RESULT=$? | |
if [ $RESULT -eq 0 ]; then | |
mkvmerge --output "${filename} (qp${qp}).mkv" "${filename} (qp${qp}) (recode).mkv" --title "${filename}" | |
RESULT=$? | |
else | |
echo "ERROR: ffmpeg failed" | |
fi | |
if [ $RESULT -eq 0 ]; then | |
rm -rf "${filename} (qp${qp}) (recode).mkv" | |
RESULT=$? | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on a Linux box running Fedora 32 with ffmpeg 4.2.4 from rpmfusion.
CPU is an Intel 10th Gen G6400.
4K HEVC 10bit HDR to 4K HEVC 10bit HDR = 14fps
1080P H264 to 1080P HEVC 10bit = 55fps
During transcodes CPU usage is ~9%
intel-gpu-top:
Render/3D/0 usage is 80-85%
Video/0 usage is 50-80%
VideoEnhance/0 usage is 6-10%