Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Create timelapse. Stop recording with any key.
- # Requires ImageMagick (Linux only) and MPlayer's MEncoder.
- #
- # @param 1 - interval in seconds (optional, default is 1)
- timelapse()
- {
- local CAPTURE=
- if type import &>/dev/null
- then
- CAPTURE='import -window root'
- elif type screencapture &>/dev/null
- then
- CAPTURE='screencapture'
- else
- echo 'error: no screen capture tool available' >&2
- return 1
- fi
- if ! type mencoder &>/dev/null
- then
- echo 'error: mencoder not available' >&2
- return 1
- fi
- local CACHE=${CACHE:-`mktemp -d ${BIN}.XXXXXXXXXX`}
- local N=0
- cd "$CACHE" || return $?
- echo 'recording, press any key to stop'
- while ! read -n 1 -s -t ${INTERVAL:-1}
- do
- $CAPTURE $(( ++N )).jpg || return $?
- done
- # don't use ImageMagick's convert to make the video
- # because it's slow and the video will be of bad quality
- mencoder \
- mf://*.jpg \
- -mf fps=${FPS:-25}:type=jpg \
- -ovc lavc \
- -lavcopts vcodec=mpeg4:mbd=2:trell \
- -oac copy \
- -o ${TIMELAPSE:-../timelapse-`date +%s`.mpg} || return $?
- rm -f *.jpg
- cd .. && rm -rf "$CACHE"
- }
- if [ "$BASH_SOURCE" == "$0" ]
- then
- timelapse "$@"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement