Add gpu support to compress-video script

This commit is contained in:
2020-12-16 10:56:06 -05:00
parent 862ad96ee3
commit 1c85fe3fac
2 changed files with 30 additions and 20 deletions

View File

@@ -34,8 +34,8 @@ filename="${filename%.*}"
use_crf=$2
default_crf=25 # Programming vids have pretty crisp text @ crf 25.
output_name="$3"
use_cpu=$4
function encode() {
crf=$1
@@ -46,7 +46,14 @@ function encode() {
fi
printf "\n${YELLOW}${BOLD}Encoding '$filename.$extension' with CRF $crf | output: $output${NORMAL}\n"
ffmpeg -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output"
if [[ $use_cpu -eq 1 ]]; then
ffmpeg -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output"
else
# File will be slightly larger than CPU encoding, but it's much faster to transcode and doesn't max out the CPU cores.
ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i "$filename.$extension" -c:a copy -c:v h264_nvenc \
-profile:v high -rc:v vbr_hq -cq:v $crf -b:v 5M -maxrate 5M -max_muxing_queue_size 9999 "$output"
fi
printf "\n${GREEN}${BOLD}Done encoding '$filename.$extension' with CRF $crf${NORMAL}\n\n"
}