Skip to content

Instantly share code, notes, and snippets.

@rafaelglikis
Last active December 6, 2019 23:17
Show Gist options
  • Save rafaelglikis/c39906cc6df6654ad58c02a6a7ff3e25 to your computer and use it in GitHub Desktop.
Save rafaelglikis/c39906cc6df6654ad58c02a6a7ff3e25 to your computer and use it in GitHub Desktop.
Video Cutter is a small script that takes multiple cuts of multiple videos given a parameter file.
#!/bin/bash
if [[ "$#" -lt 2 ]]; then
echo "Usage:"
echo " $0 <input_file> <output_dir> [delimiter]"
echo
echo " input_file"
echo " Paramater file. Input file contents should be in the form:"
echo " <videoFileName>=<start>=<duration>=<cut_name>"i
echo " example:"
echo " Mozart Concerto no. 23 maestros.mp4=00:02:55=00:01:13=Mozart 1st movementA.mp4"
echo " output_dir"
echo " This is where the cuts would be written."
echo " delimiter (defult =)"
echo " Character used between parameters in the input_file,"
exit
fi
input_file=$1
sed -i 's/\r//' $input_file # Dos to Unix newlines
output_dir=$2
if [ -d "$output_dir" ]; then
read -p "Directory already exists. Do you want to overide $output_dir directory [y/N]?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -r $output_dir
else
exit
fi
fi
delimiter="="
if [[ "$#" -gt 3 ]]; then
delimiter="$3"
fi
mkdir $output_dir
while IFS="$delimiter" read -r name start duration cut_name; do
ffmpeg -i "${name}" -ss $start -t $duration -vcodec copy -acodec copy "$output_dir/${cut_name}" -nostdin
done < $input_file
echo
echo "Cuts:"
ls $output_dir | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment