Skip to content

Instantly share code, notes, and snippets.

@mahdavipanah
Last active November 26, 2018 17:04
Show Gist options
  • Save mahdavipanah/ad20fe750ae52362ae3502dca9debdc6 to your computer and use it in GitHub Desktop.
Save mahdavipanah/ad20fe750ae52362ae3502dca9debdc6 to your computer and use it in GitHub Desktop.
A script to cut a video into multiple parts

Requirements

How to Use

First create a text files that looks like this:

00:00:58 00:01:21
00:05:43 00:06:27
00:08:03 00:09:37
00:10:03 00:11:22
00:13:06 00:13:30

In each line write the start time and end time of the parts that you want to cut.
Then make sure the script is executable:

$ chmod +x cut-parts.sh

And then run the script:

$ ./cut-parts.sh input.mp4 times.txt ./parts-folder
  • The first argument is the address of the video file.
  • The second argument is the address of the text file which contains the parts' times.
  • The third argument is the address of a directory which the parts' files will be created in.
while IFS='' read -r line || [[ -n "$line" ]]; do
start=$(echo $line | cut -d' ' -f1);
end=$(echo $line | cut -d' ' -f2);
ffmpeg -i $1 -ss $start -to $end "$3/$start-$end.mp4";
done < "$2";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment