Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Create timelapse. Stop recording with any key.
  4. # Requires ImageMagick (Linux only) and MPlayer's MEncoder.
  5. #
  6. # @param 1 - interval in seconds (optional, default is 1)
  7. timelapse()
  8. {
  9. local CAPTURE=
  10.  
  11. if type import &>/dev/null
  12. then
  13. CAPTURE='import -window root'
  14. elif type screencapture &>/dev/null
  15. then
  16. CAPTURE='screencapture'
  17. else
  18. echo 'error: no screen capture tool available' >&2
  19. return 1
  20. fi
  21.  
  22. if ! type mencoder &>/dev/null
  23. then
  24. echo 'error: mencoder not available' >&2
  25. return 1
  26. fi
  27.  
  28. local CACHE=${CACHE:-`mktemp -d ${BIN}.XXXXXXXXXX`}
  29. local N=0
  30.  
  31. cd "$CACHE" || return $?
  32. echo 'recording, press any key to stop'
  33.  
  34. while ! read -n 1 -s -t ${INTERVAL:-1}
  35. do
  36. $CAPTURE $(( ++N )).jpg || return $?
  37. done
  38.  
  39. # don't use ImageMagick's convert to make the video
  40. # because it's slow and the video will be of bad quality
  41. mencoder \
  42. mf://*.jpg \
  43. -mf fps=${FPS:-25}:type=jpg \
  44. -ovc lavc \
  45. -lavcopts vcodec=mpeg4:mbd=2:trell \
  46. -oac copy \
  47. -o ${TIMELAPSE:-../timelapse-`date +%s`.mpg} || return $?
  48.  
  49. rm -f *.jpg
  50. cd .. && rm -rf "$CACHE"
  51. }
  52.  
  53. if [ "$BASH_SOURCE" == "$0" ]
  54. then
  55. timelapse "$@"
  56. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement