From 791f94bb7afa58fb3e5e906c7dfe5ec6da5f0f12 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Wed, 11 Aug 2021 10:37:50 -0400 Subject: [PATCH] Update vid compression scripts --- bin/compress-video | 40 ++++++------------------------------- bin/compress-video-with-crf | 11 ++++++++-- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/bin/compress-video b/bin/compress-video index 08e761d..dcf021e 100644 --- a/bin/compress-video +++ b/bin/compress-video @@ -23,49 +23,21 @@ else NORMAL="" fi -if [[ $1 == "" ]]; then +if [[ $1 == "" || $2 == "" ]]; then printf "${BOLD}${RED}Usage: $0 ${NORMAL}\n" exit 1 fi use_gpu=$1 -filename=$(basename -- "$2") -extension="${filename##*.}" -filename="${filename%.*}" - -output_name="$3" - -use_crf=25 # Found the following to work best with vids containing text (e.g. programming vid): 25 for CPU encoding and 27 for GPU. +# Found the following to work best with vids containing text (e.g. programming vid): 25 for CPU encoding and 27 for GPU. +use_crf=25 if [[ $use_gpu -eq 1 ]]; then use_crf=27 fi -function encode() { - crf=$1 - if [[ $output_name == "" ]]; then - output="${filename}_COMPRESSED_CRF-${crf}.$extension" - else - output="${output_name}.$extension" - fi +filename=$(basename -- "$2") +output_name="$3" - printf "\n${YELLOW}${BOLD}Encoding '$filename.$extension' | GPU: $use_gpu | CRF $crf | output: $output${NORMAL}\n" - - if [[ $use_gpu -eq 1 ]]; then - # 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" - else - ffmpeg -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output" - fi - printf "\n${GREEN}${BOLD}Done encoding '$filename.$extension' (CRF $crf) | output name '$output'${NORMAL}\n\n" -} - -encode $use_crf - -#printf "\n${YELLOW}${BOLD}Encoding using a range of CRF values.${NORMAL}\n" -## Bigger crf values == bigger compression. -#for crf in {25..28} -#do -# encode $crf -#done +compress-video-with-crf $use_gpu $use_crf "$filename" "$output_name" diff --git a/bin/compress-video-with-crf b/bin/compress-video-with-crf index d9638e7..603866e 100644 --- a/bin/compress-video-with-crf +++ b/bin/compress-video-with-crf @@ -23,7 +23,7 @@ else NORMAL="" fi -if [[ $1 == "" ]]; then +if [[ $1 == "" || $2 == "" ]]; then printf "${BOLD}${RED}Usage: $0 \n\nIf you want to encode a range of CRF values then use -1 as the crf value.${NORMAL}\n" exit 1 fi @@ -49,7 +49,14 @@ function encode() { if [[ $use_gpu -eq 1 ]]; then # 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" + + #ffmpeg version N-103152-gef54590f83-20210806 + # This version of ffmpeg results in larger files than version 4.3.1 command below. + #ffmpeg -y -stats -loglevel level+error -vsync 0 -hwaccel_output_format cuda -c:v h264_cuvid -i "$filename.$extension" -c:a copy -c:v h264_nvenc -profile:v high -rc:v vbr -cq:v $crf -b:v 5M -maxrate 5M -max_muxing_queue_size 9999 "$output" + + #ffmpeg version 4.3.1-2020-11-08 + ffmpeg -y -stats -loglevel level+error -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" + else ffmpeg -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output" fi