Skip to content

Instantly share code, notes, and snippets.

@dmacsuibhne
Last active December 5, 2023 18:20
Show Gist options
  • Save dmacsuibhne/d5a99788e4330b0a2aa83b9d57ce8681 to your computer and use it in GitHub Desktop.
Save dmacsuibhne/d5a99788e4330b0a2aa83b9d57ce8681 to your computer and use it in GitHub Desktop.
Compress videos with ffmpeg
#!/bin/bash
encoder=libx265
crf_value=35
preset_value="medium"
directory_original=./keep
directory_new="$directory_original/conv$crf_value$preset_value"
for filepath in ${directory_original}/*; do
if [ ! -d "$filepath" ]; then #exclude directories
filename_with_extension="${filepath##*/}"
filename_no_extension="${filename_with_extension%.*}"
new_path="$directory_new/${filename_no_extension}_${encoder}_crf${crf_value}_${preset_value}.mp4"
( # Subshell so set -x only prints inside of loop
set -x
ffmpeg -i "$filepath" -c:v ${encoder} -crf ${crf_value} -preset ${preset_value} -vtag hvc1 $new_path
)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment