record.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. [[ -f ~/.config/user-dirs.dirs ]] && source ~/.config/user-dirs.dirs
  3. OUTPUT_DIR="${OMARCHY_SCREENRECORD_DIR:-${XDG_VIDEOS_DIR:-$HOME/Videos}}"
  4. if [[ ! -d "$OUTPUT_DIR" ]]; then
  5. notify-send "Screen recording directory does not exist: $OUTPUT_DIR" -u critical -t 3000
  6. exit 1
  7. fi
  8. # Selects region or output
  9. SCOPE="$1"
  10. # Selects audio inclusion or not
  11. AUDIO=$([[ $2 == "audio" ]] && echo "--audio")
  12. start_screenrecording() {
  13. local filename="$OUTPUT_DIR/screenrecording-$(date +'%Y-%m-%d_%H-%M-%S').mp4"
  14. if lspci | grep -qi 'nvidia'; then
  15. wf-recorder $AUDIO -f "$filename" -c libx264 -p crf=23 -p preset=medium -p movflags=+faststart "$@" &
  16. else
  17. wl-screenrec $AUDIO -f "$filename" --ffmpeg-encoder-options="-c:v libx264 -crf 23 -preset medium -movflags +faststart" "$@" &
  18. fi
  19. toggle_screenrecording_indicator
  20. }
  21. stop_screenrecording() {
  22. pkill -x wl-screenrec
  23. pkill -x wf-recorder
  24. notify-send "Screen recording saved to $OUTPUT_DIR" -t 2000
  25. sleep 0.2 # ensures the process is actually dead before we check
  26. toggle_screenrecording_indicator
  27. }
  28. toggle_screenrecording_indicator() {
  29. pkill -RTMIN+8 waybar
  30. }
  31. screenrecording_active() {
  32. pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null
  33. }
  34. if screenrecording_active; then
  35. stop_screenrecording
  36. elif [[ "$SCOPE" == "output" ]]; then
  37. output=$(slurp -o) || exit 1
  38. start_screenrecording -g "$output"
  39. else
  40. region=$(slurp) || exit 1
  41. start_screenrecording -g "$region"
  42. fi