Last active
August 29, 2015 14:26
-
-
Save sehrgut/65d447f1b60ce3121975 to your computer and use it in GitHub Desktop.
cuts a clip from a non-standard .mov file recorded by GoToMeeting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function print_usage() { | |
cat <<EOF | |
Usage: `basename "$0"` --start time --length seconds --in path --out path | |
--start time: start time in 'HH:MM:SS.mmm' format | |
--length seconds: clip length in integer seconds | |
--in path: input file, must have '.mov' extension | |
--out path: output file, must have '.mov' extension | |
--help: prints this usage statement | |
Cuts a clip from a .mov file recorded by GoToMeeting. | |
GTM creates recordings that, by default, are not capable of being properly | |
parsed and rendered by ffmpeg, vlc, and other free tools. This script sets up | |
the flags necessary for cutting these files, though the output is NOT any more | |
portable than the GTM-created input files. | |
EOF | |
} | |
function is_valid_timecode() { | |
[[ "$1" =~ ([0-9]{2}:){2}[0-9]{2}\.[0-9]{1,3} ]] | |
} | |
function is_integer() { | |
[ "$1" -eq "$1" ] 2> /dev/null | |
} | |
function ext_is_mov() { | |
[ "${1: -4}" == ".mov" ] | |
} | |
while (( "$#" )); do | |
case "$1" in | |
'--length') | |
length="$2" | |
shift | |
;; | |
'--start') | |
starttime="$2" | |
shift | |
;; | |
'--in') | |
infile="$2" | |
shift | |
;; | |
'--out') | |
outfile="$2" | |
shift | |
;; | |
'-h'|'--help'|'-u'|'--usage'|*) | |
print_usage | |
exit 0 | |
;; | |
esac | |
shift | |
done | |
if ! is_valid_timecode "$starttime"; then | |
printf "Error: Invalid start: %s\n" "$starttime" >&2 | |
print_usage | |
exit 1 | |
fi | |
if ! is_integer "$length"; then | |
printf "Error: Invalid length: %s\n" "$length" >&2 | |
print_usage | |
exit 1 | |
fi | |
if ! ext_is_mov "$infile" || [[ ! -f "$infile" ]]; then | |
printf "Error: Invalid or missing in: '%s'\n" "$infile" >&2 | |
print_usage | |
exit 1 | |
fi | |
if ! ext_is_mov "$outfile" || [[ -z "$outfile" ]]; then | |
printf "Error: Invalid or missing out: '%s'\n" "$outfile" >&2 | |
print_usage | |
exit 1 | |
fi | |
# http://stackoverflow.com/questions/22674924/problems-transcoding-gotomeeting-output-using-ffmpeg | |
ffmpeg -fflags +genpts+igndts \ | |
-i "$infile" \ | |
-ss "$starttime" -t "$length" \ | |
-c:v libx264 -preset slow -level 30 -qmin 38 -qmax 55 \ | |
-movflags faststart -r:v 10 -vsync 2 -async 1 -map 0:v,0:a -map 0:a \ | |
"$outfile" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment