dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

media-cut.sh (690B)


      1 #!/usr/bin/env bash
      2 
      3 # Script to cut media file without re-encoding
      4 
      5 if [[ "$#" != "4" ]]; then
      6 	echo "Usage:"
      7 	echo "  ./media_cut.sh input_file start_time end_time output_file"
      8 	exit
      9 fi
     10 
     11 input_file="$1"
     12 start_time="$2"
     13 end_time="$3"
     14 output_file="$4"
     15 
     16 # I got this from somewhere, but I can't find where, likely stackoverflow
     17 cut_time=$(awk -v start="$start_time" -v end="$end_time" '
     18 	BEGIN {
     19 		split(start, a, ":")
     20 		split(end, b, ":")
     21 		t1 = a[1]*3600 + a[2]*60 + a[3]
     22 		t2 = b[1]*3600 + b[2]*60 + b[3]
     23 		diff = t2 - t1
     24 		printf "%02d:%02d:%02d\n", diff/3600, diff%3600/60, diff%60
     25 	}
     26 ')
     27 
     28 ffmpeg -v quiet -stats -ss "$start_time" -i "$input_file" -to "$cut_time" -c copy "$output_file"