capture 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # Original source: <https://gist.github.com/naelstrof/6530959>.
  3. IMAGE_DIR="$HOME/tmp/screenshots/"
  4. VIDEO_DIR="$HOME/tmp/screenshots/"
  5. IMAGE_ENCODING=".png"
  6. VIDEO_ENCODING=".webm"
  7. IMAGE_SND="$HOME/docs/audio/small/screen-capture.oga"
  8. VIDEO_SND="$HOME/docs/audio/small/complete.oga"
  9. SLOP_IMAGE="slop --nodecorations --bordersize 3 --color 0,1,0" # green
  10. SLOP_VIDEO="slop --nodecorations --bordersize 5 --color 1,0,0" # red
  11. PID_FILE="/tmp/capture_record.pid"
  12. PLAY="play --no-show-progress"
  13. case "$1" in
  14. desktop)
  15. name="${IMAGE_DIR}$(date +%F_%T)${IMAGE_ENCODING}"
  16. maim "$name"
  17. $PLAY "$IMAGE_SND"
  18. ;;
  19. image)
  20. eval $($SLOP_IMAGE)
  21. [ "${Cancel}" = "true" ] && exit 0
  22. name="${IMAGE_DIR}$(date +%F_%T)${IMAGE_ENCODING}"
  23. maim --hidecursor --geometry $G "$name"
  24. $PLAY "$IMAGE_SND"
  25. ;;
  26. video)
  27. if [ -f "$PID_FILE" ]; then
  28. # Finish recording.
  29. pid=$(cat "$PID_FILE")
  30. kill ${pid}
  31. rm "$PID_FILE"
  32. $PLAY "$VIDEO_SND"
  33. else
  34. # Start recording.
  35. eval $($SLOP_VIDEO)
  36. [ "${Cancel}" = "true" ] && exit 0
  37. name="${VIDEO_DIR}$(date +%F_%T)${VIDEO_ENCODING}"
  38. # Populate PID_FILE when recording begins using "&" and "$!".
  39. ffmpeg -f x11grab \
  40. -s "${W}x${H}" -i "+${X},${Y}" \
  41. "$name" &
  42. pid=$!
  43. echo -n "$pid" > "$PID_FILE"
  44. fi
  45. ;;
  46. *)
  47. echo "Usage: $0 {desktop|image|video}"
  48. exit 1
  49. ;;
  50. esac