diff options
| author | Arpit Chakladar <arpitchakladar@proton.me> | 2026-03-31 22:21:03 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar@proton.me> | 2026-03-31 22:21:03 +0530 |
| commit | fd3bfac76484b684bc03922e0c121d946ce94694 (patch) | |
| tree | 921b12500fe3acfe16c2c4e9a28ddd2baf16d881 /modules | |
| parent | dcd2d79d6ab0be2565b17cce2a3008f6815d5115 (diff) | |
| download | home-manager-config-fd3bfac76484b684bc03922e0c121d946ce94694.tar.gz home-manager-config-fd3bfac76484b684bc03922e0c121d946ce94694.zip | |
Improved screen recording script
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/scripts/default.nix | 2 | ||||
| -rw-r--r-- | modules/scripts/screen-recording.sh | 85 | ||||
| -rw-r--r-- | modules/tools/default.nix | 1 | ||||
| -rw-r--r-- | modules/tools/slop/default.nix | 18 |
4 files changed, 91 insertions, 15 deletions
diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix index 734243f..ca555c7 100644 --- a/modules/scripts/default.nix +++ b/modules/scripts/default.nix @@ -24,7 +24,7 @@ in { "scripts/deep-clean" = shellScript ./deep-clean.sh; - "scripts/screen-recording" = lib.mkIf config.tools.ffmpeg.enable ( + "scripts/screen-recording" = lib.mkIf (config.tools.ffmpeg.enable && config.tools.slop.enable) ( shellScript ./screen-recording.sh ); "scripts/system-monitor" = lib.mkIf ( diff --git a/modules/scripts/screen-recording.sh b/modules/scripts/screen-recording.sh index a5968a1..374e2cb 100644 --- a/modules/scripts/screen-recording.sh +++ b/modules/scripts/screen-recording.sh @@ -1,18 +1,75 @@ -PID_FILE="/tmp/ffmpeg-screenrecord.pid" OUT_DIR="$HOME/Videos/Recordings" +mkdir -p "$OUT_DIR" -if [ -f "$PID_FILE" ]; then - kill -INT "$(cat "$PID_FILE")" && rm "$PID_FILE" - echo "Stopping screen recording" +# Colors +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' + +# --- 1. ARGUMENT PARSING --- +SELECT_MODE=false +while [[ "$#" -gt 0 ]]; do + case $1 in + -s|--select) SELECT_MODE=true ;; + esac + shift +done + +# --- 2. GEOMETRY SELECTION --- +# Attempt to get screen resolution using xwininfo, fallback to a safe default if it fails +if command -v xwininfo >/dev/null 2>&1; then + WIDTH=$(xwininfo -root | grep 'Width:' | awk '{print $2}') + HEIGHT=$(xwininfo -root | grep 'Height:' | awk '{print $2}') else - mkdir -p "$OUT_DIR" - echo "Starting screen recording" - ffmpeg \ - -f x11grab \ - -i "$DISPLAY" \ - -framerate 30 \ - -c:v libx264 \ - -preset ultrafast \ - -crf 23 \ - "$OUT_DIR/recording-$(date +%Y%m%d-%H%M%S).mp4" + # Fallback: Try to use a common default or let ffmpeg handle it + # If xwininfo is missing, we'll just omit -video_size for full screen + WIDTH="" + HEIGHT="" +fi + +X_OFF=0 +Y_OFF=0 + +if [ "$SELECT_MODE" = true ]; then + if command -v slop >/dev/null 2>&1; then + echo -e "${YELLOW}Select a window or draw a box...${NC}" + read -r WIDTH HEIGHT X_OFF Y_OFF < <(slop -f "%w %h %x %y" --nokeyboard) + [ -z "$WIDTH" ] && exit 1 + else + echo -e "${RED}Error: 'slop' is not installed. Cannot select area.${NC}" + echo "Defaulting to full screen..." + sleep 1 + fi fi + +# Construct the video size argument only if we have values +SIZE_ARG="" +if [ -n "$WIDTH" ] && [ -n "$HEIGHT" ]; then + # Ensure even dimensions + WIDTH=$(( WIDTH + WIDTH % 2 )) + HEIGHT=$(( HEIGHT + HEIGHT % 2 )) + SIZE_ARG="-video_size ${WIDTH}x${HEIGHT}" +fi + +# --- 3. START RECORDING --- +FILENAME="$OUT_DIR/recording-$(date +%Y%m%d-%H%M%S).mp4" + +echo -e "${GREEN}Recording started!${NC}" +echo -e "Press ${YELLOW}'q'${NC} in this terminal to stop." +echo "File: $FILENAME" +echo "------------------------------------------------" + +# Using ${DISPLAY:-:0} to ensure we have a display target +ffmpeg -hide_banner \ + -f x11grab \ + $SIZE_ARG \ + -framerate 30 \ + -i "${DISPLAY:-:0.0}+${X_OFF},${Y_OFF}" \ + -c:v libx264 \ + -preset ultrafast \ + -crf 23 \ + -pix_fmt yuv420p \ + "$FILENAME" + +echo -e "\n${GREEN}Done!${NC} Video saved to $FILENAME" diff --git a/modules/tools/default.nix b/modules/tools/default.nix index 5080743..deabe2f 100644 --- a/modules/tools/default.nix +++ b/modules/tools/default.nix @@ -29,6 +29,7 @@ ./pamixer ./playerctl ./rofi + ./slop ./starship ./systemctl-tui ./tmux diff --git a/modules/tools/slop/default.nix b/modules/tools/slop/default.nix new file mode 100644 index 0000000..3196251 --- /dev/null +++ b/modules/tools/slop/default.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + pkgs, + ... +}: + +{ + options.tools.slop = { + enable = lib.mkEnableOption "Enables slop."; + }; + + config = lib.mkIf config.tools.slop.enable { + home.packages = with pkgs; [ + slop + ]; + }; +} |
