Skip to content

Instantly share code, notes, and snippets.

@Clement-Jean
Last active January 19, 2022 14:15
Show Gist options
  • Save Clement-Jean/8f2d2572e62a145e5004e639b4e47141 to your computer and use it in GitHub Desktop.
Save Clement-Jean/8f2d2572e62a145e5004e639b4e47141 to your computer and use it in GitHub Desktop.
Batch execution for FFMPEG
#! /bin/bash
# Usage:
# ./ffmpeg_batch.sh mp4 mp4 original/ compressed/ "-vcodec libx265 -crf 28"
# ./ffmpeg_batch.sh mp4 m3u8 video_old/ video_new/ "-vcodec libx265 -crf 28 -start_number 0 -hls_time 3 -hls_list_size 0 -f hls"
if [ "$#" -ne 5 ]; then
echo "Usage: INPUT_FORMAT OUTPUT_FORMAT INPUT_DIR OUPUT_DIR FFMPEG_OPTIONS" >&2
exit 1
fi
srcExt=$1
destExt=$2
srcDir=$3
destDir=$4
opts=$5
for filename in "$srcDir"/*.$srcExt; do
basePath=${filename%.*}
baseName=${basePath##*/}
ffmpeg -i "$filename" $opts "$destDir"/"$baseName"."$destExt"
done
echo "Conversion from ${srcExt} to ${destExt} complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment