Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.7 KiB

  1. #!/bin/sh
  2. # Usage:
  3. # `$0`: Ask for recording type via dmenu
  4. # `$0 screencast`: Record both audio and screen
  5. # `$0 video`: Record only screen
  6. # `$0 audio`: Record only audio
  7. # `$0 kill`: Kill existing recording
  8. #
  9. # If there is already a running instance, user will be prompted to end it.
  10. updateicon() { \
  11. echo "$1" > /tmp/recordingicon
  12. #pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}"
  13. }
  14. killrecording() {
  15. recpid="$(cat /tmp/recordingpid)"
  16. # kill with SIGTERM, allowing finishing touches.
  17. kill -15 "$recpid"
  18. rm -f /tmp/recordingpid
  19. updateicon ""
  20. # even after SIGTERM, ffmpeg may still run, so SIGKILL it.
  21. sleep 3
  22. kill -9 "$recpid"
  23. exit
  24. }
  25. screencast() {
  26. audio="$(printf "none\nscreen\nmicrophone\nboth" | dmenu -p "Audio Type:")"
  27. case "$audio" in
  28. none)
  29. ffmpeg -y \
  30. -f x11grab \
  31. -framerate 60 \
  32. -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
  33. -i "$DISPLAY" \
  34. -r 30 \
  35. -c:v h264 -crf 0 -preset ultrafast -c:a aac \
  36. "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" &
  37. echo $! > /tmp/recordingpid
  38. updateicon "⏺️🎙️"
  39. ;;
  40. screen)
  41. ffmpeg -y \
  42. -f x11grab \
  43. -framerate 60 \
  44. -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
  45. -i "$DISPLAY" \
  46. -f pulse -i default \
  47. -r 30 \
  48. -c:v h264 -crf 0 -preset ultrafast -c:a aac \
  49. "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" &
  50. echo $! > /tmp/recordingpid
  51. updateicon "⏺️🎙️"
  52. ;;
  53. microphone)
  54. ffmpeg -y \
  55. -f x11grab \
  56. -framerate 60 \
  57. -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
  58. -i "$DISPLAY" \
  59. -f alsa -i default \
  60. -r 30 \
  61. -c:v h264 -crf 0 -preset ultrafast -c:a aac \
  62. "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" &
  63. echo $! > /tmp/recordingpid
  64. updateicon "⏺️🎙️"
  65. ;;
  66. both)
  67. ffmpeg -y \
  68. -f x11grab \
  69. -framerate 60 \
  70. -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
  71. -i "$DISPLAY" \
  72. -f alsa -i default \
  73. -r 30 \
  74. -c:v h264 -crf 0 -preset ultrafast -c:a aac \
  75. "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" &
  76. echo $! > /tmp/recordingpid
  77. updateicon "⏺️🎙️"
  78. ;;
  79. esac
  80. }
  81. video() { ffmpeg \
  82. -f x11grab \
  83. -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
  84. -i "$DISPLAY" \
  85. -c:v libx264 -qp 0 -r 30 \
  86. "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" &
  87. echo $! > /tmp/recordingpid
  88. updateicon "⏺️"
  89. }
  90. webcamhidef() { ffmpeg \
  91. -f v4l2 \
  92. -i /dev/video0 \
  93. -video_size 1920x1080 \
  94. "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
  95. echo $! > /tmp/recordingpid
  96. updateicon "🎥"
  97. }
  98. webcam() { ffmpeg \
  99. -f v4l2 \
  100. -i /dev/video0 \
  101. -video_size 640x480 \
  102. "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
  103. echo $! > /tmp/recordingpid
  104. updateicon "🎥"
  105. }
  106. audio() { \
  107. ffmpeg \
  108. -f alsa -i default \
  109. -c:a flac \
  110. "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
  111. echo $! > /tmp/recordingpid
  112. updateicon "🎙️"
  113. }
  114. askrecording() { \
  115. choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:")
  116. case "$choice" in
  117. screencast) screencast;;
  118. audio) audio;;
  119. video) video;;
  120. *selected) videoselected;;
  121. webcam) webcam;;
  122. "webcam (hi-def)") webcamhidef;;
  123. esac
  124. }
  125. asktoend() { \
  126. response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") &&
  127. [ "$response" = "Yes" ] && killrecording
  128. }
  129. videoselected()
  130. {
  131. slop -f "%x %y %w %h" > /tmp/slop
  132. read -r X Y W H < /tmp/slop
  133. rm /tmp/slop
  134. ffmpeg \
  135. -f x11grab \
  136. -framerate 60 \
  137. -video_size "$W"x"$H" \
  138. -i :0.0+"$X,$Y" \
  139. -c:v libx264 -qp 0 -r 30 \
  140. "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" &
  141. echo $! > /tmp/recordingpid
  142. updateicon "⏺️"
  143. }
  144. case "$1" in
  145. screencast) screencast;;
  146. audio) audio;;
  147. video) video;;
  148. *selected) videoselected;;
  149. kill) killrecording;;
  150. *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;;
  151. esac