Skip to content

Instantly share code, notes, and snippets.

@KokeCacao
Created January 26, 2019 20:31
Show Gist options
  • Save KokeCacao/532094c2a20dc5a197536c9bcb041e54 to your computer and use it in GitHub Desktop.
Save KokeCacao/532094c2a20dc5a197536c9bcb041e54 to your computer and use it in GitHub Desktop.
A Bad Written Video Cutter for Data Preperation
#!/bin/bash
function vidcut2() {
if (( $# < 3 )); then
echo "Illegal number of parameters. It should be greater than 3."
fi
name=`basename "$1"`
name_0="${name}_0"
name_1="${name}_1"
name_2="${name}_2"
name_3="${name}_3"
name_4="${name}_4"
ffmpeg -i $1 -c copy -map 0 -ss 00:00:00.00 -to 00:$2 $PWD/$name_0.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$2 -to 00:$3 $PWD/$name_1.avi
}
function vidcut3() {
if (( $# < 4 )); then
echo "Illegal number of parameters. It should be greater than 4."
fi
name=`basename "$1"`
name_0="${name}_0"
name_1="${name}_1"
name_2="${name}_2"
name_3="${name}_3"
name_4="${name}_4"
ffmpeg -i $1 -c copy -map 0 -ss 00:00:00.00 -to 00:$2 ~/$name_0.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$2 -to 00:$3 $PWD/$name_1.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$3 -to 00:$4 $PWD/$name_2.avi
}
function vidcut4() {
if (( $# < 5 )); then
echo "Illegal number of parameters. It should be greater than 5."
fi
name=`basename "$1"`
name_0="${name}_0"
name_1="${name}_1"
name_2="${name}_2"
name_3="${name}_3"
name_4="${name}_4"
ffmpeg -i $1 -c copy -map 0 -ss 00:00:00.00 -to 00:$2 ~/$name_0.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$2 -to 00:$3 $PWD/$name_1.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$3 -to 00:$4 $PWD/$name_2.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$4 -to 00:$5 $PWD/$name_3.avi
}
function vidcut5() {
if (( $# < 6 )); then
echo "Illegal number of parameters. It should be greater than 6."
fi
name=`basename "$1"`
name_0="${name}_0"
name_1="${name}_1"
name_2="${name}_2"
name_3="${name}_3"
name_4="${name}_4"
ffmpeg -i $1 -c copy -map 0 -ss 00:00:00.00 -to 00:$2 ~/$name_0.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$2 -to 00:$3 $PWD/$name_1.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$3 -to 00:$4 $PWD/$name_2.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$4 -to 00:$5 $PWD/$name_3.avi
ffmpeg -i $1 -c copy -map 0 -ss 00:$5 -to 00:$6 $PWD/$name_4.avi
}
@KokeCacao
Copy link
Author

How To Use It

  1. add this file to ~/bin
  2. in ~/.bashrc: add the following
# For custom commands
export PATH=$PATH:~/bin
source ~/bin/vidcut.sh
  1. open a command prompt in the directory where you store your input file
  2. do command `vidcut{number_of_cut} {absolute_file_name} {the_end_of_firt_cut} {the_end_of_second_cut}

Complains

I hate this tedious data prep!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment