Skip to content

Instantly share code, notes, and snippets.

@mislav
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mislav/8723348 to your computer and use it in GitHub Desktop.
Save mislav/8723348 to your computer and use it in GitHub Desktop.
ffmpeg wrapper script to transcode select portions of original file as h264. WARNING: I have no idea what I'm doing [insert dog meme here]
#!/bin/bash
# Usage: h264 <infile> <HH:MM:SS-HH:MM:SS> [<outfile>]
set -e
infile="$1"
fromto="$2"
if [ -n "$3" ]; then
outfile="$3"
else
outfile="${infile%.*}.mov"
fi
seconds() {
local parts=( ${1//:/ } )
while [ "${#parts[@]}" -lt 3 ]; do parts=( 0 ${parts[*]} ); done
echo $(( parts[2] + parts[1] * 60 + parts[0] * 3600 ))
}
from="$(seconds "${fromto%-*}")"
to="$(seconds "${fromto#*-}")"
duration=$(( to - from ))
exec ffmpeg -loglevel warning -ss "$from" -i "$infile" -to "$duration" "$outfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment