Create a gist now

Instantly share code, notes, and snippets.

screencaps to video
#!/bin/bash
# OSX requires Quicktime Pro, linux requires scrot and mencoder
# jpg faster/png higher quality
FORMAT=jpg
usage() {
cat <<!
use: $(basename $0) -c <path/to/empty/folder> [seconds]
$(basename $0) -o <path/to/empty/folder>
-c take screenshot every n seconds in a 1 hour loop
default 5 seconds
-o make 12fps video of stored screenshots
OSX: must specify absolute path to folder
!
exit
}
capture() {
[ -d "$1" ] || return
case $(uname) in
Darwin) CAP="screencapture -Cm";;
Linux) CAP="scrot";;
*) return;;
esac
while :; do
local i="$1"/$(date +%s).$FORMAT
$CAP "$i"
# delete *.$FORMAT older than 1 hour (be careful!!)
find "$1" -name *.$FORMAT -mmin +60 -delete
sleep ${2:-5}
# maximum res mplayer will play is 2046x2046
[ "$(identify -format "%w" $i)" -gt 2046 ] && mogrify -resize 2046 $i
done
}
Darwin_mkvid() {
[ -d "$1" ] || return
[ "${1:0:1}" = "/" ] || {
echo "path to folder [$1] must be absolute"
return
}
osascript -e "tell application \"Finder\" to set f to first file of folder (POSIX file \"$1\" as string) as string" -e "tell application \"QuickTime Player\"" -e "open image sequence f frames per second 12" -e "save self contained document \"Untitled\" in \"$1/output.mov\"" -e "quit" -e "end tell"
echo $1/output.mov | pbcopy | pbpaste
}
Linux_mkvid() {
[ -d "$1" ] || return
cd $1
# motion png/jpg - fast, good quality, relatively small
mencoder mf://*.$FORMAT -mf fps=12:type=$FORMAT -ovc copy -oac copy -o output.avi
echo $1/output.avi
# xclip?
}
if [ $1 ]; then
case $1 in
-c) shift; capture $*;;
-o) shift; $(uname)_mkvid $*;;
*) usage;;
esac
else
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment