ffmpeg-cut-clip.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. display_help(){
  4. echo "Usage: ${0##*/} -b ${start_time} -e ${end_time[1]} [input-media-file/s]"
  5. exit 2
  6. }
  7. convert_int2time(){
  8. # date -u -d@$(( $1 * 10 * 60 )) +'%H:%M:%S'
  9. date -u -d@"$1" +'%H:%M:%S'
  10. }
  11. start_time='00:00:05'
  12. end_time=(-t '00:00:10')
  13. while getopts 'b:e:d:h' opt; do
  14. case "$opt" in
  15. b)start_time="${OPTARG}" ;;
  16. e)end_time=(-to "${OPTARG}") ;;
  17. d)end_time=(-t "${OPTARG}") ;;
  18. h|\?|:|*) display_help ;;
  19. esac
  20. done
  21. shift $((OPTIND-1)) # next parameters without flags
  22. infile="$1"
  23. filetype=$(file --mime-type -b "$infile" | cut -d/ -f1)
  24. # cheks if nessesary variables are correctly specified
  25. [[ $filetype != 'video' || -z $start_time || -z ${end_time[1]} || $# -ne 1 ]] && display_help
  26. outfile="${infile%.*}_clip-begin_${start_time}_clip-dur_${end_time[1]}.${infile##*.}"
  27. ffmpeg -y -i "$infile" -ss "$start_time" "${end_time[@]}" -c copy "$outfile"
  28. # ff(){
  29. # ffmpeg -y \
  30. # -ss "$start_time" \
  31. # -i "$1" \
  32. # "${end_time[@]}" \
  33. # -c copy \
  34. # "$2"
  35. # }
  36. # ff "$infile" "$outfile"
  37. # # or
  38. # ffmpeg -y -ss "$start_time" -i "$infile" "${end_time[@]}" -c copy "$outfile"