From 0ea18e3e9c7b6196f180296ddf7491603b4d96b1 Mon Sep 17 00:00:00 2001 From: foo-dogsquared Date: Sun, 27 Oct 2019 23:25:43 +0800 Subject: [PATCH] Update the screen recording script Since I'm more familiar with ffmpeg now, I thought of adding the option to follow the mouse and disabling it. At this point, the notification for starting the recording has been moved into an option since it can be annoying at times. --- .scripts/screen-record.sh | 48 ++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/.scripts/screen-record.sh b/.scripts/screen-record.sh index 8c9cc95..726ec94 100644 --- a/.scripts/screen-record.sh +++ b/.scripts/screen-record.sh @@ -23,17 +23,23 @@ Simply captures a recording with ffmpeg. This is more reliable than OBS Studio (since I don't how to fully utilize it yet). -Usage: $0 [-o/--output ] [-s/--selection] +Usage: $0 [-o/--output ] Options: -h, --help - show the help section -o, --output - the path of the output (default: '~/Videos') +--disable-cursor - disable rendering of the mouse cursor in the recording +--follow-mouse - enable following of the mouse in the center of the recording +--enable-notification - disable success notification " # setting up a exit trap in case of error trap 'error_cleanup $LINENO' ERR OUTPUT=${VIDEOS:-"$HOME/Videos"} +MOUSELESS=0 +FOLLOW_MOUSE=0 +ENABLE_NOTIFICATION=0 while [[ $# -gt 0 ]] do @@ -45,6 +51,15 @@ do OUTPUT="$2" shift shift;; + --disable-cursor) + MOUSELESS=1 + shift;; + --follow-mouse) + FOLLOW_MOUSE=1 + shift;; + --enable-notification) + ENABLE_NOTIFICATION=1 + shift;; *) shift;; esac @@ -54,15 +69,30 @@ done RECORDING_FILE="/tmp/fds-ffmpeg-currently-recording"; if [[ ! -f $RECORDING_FILE ]]; then - dimensions=$(slop -f "%x %y %w %h %g %i") || exit 1; + notify-send --expire-time=1500 "Screen capture selection" "Select a region to record."; + + dimensions=$(slop -f "%x %y %w %h %g %i") || { + notify-send --expire-time=1500 "Screen capture failed" "Selection mode has been exited. Cancelling the recording."; + exit 1; + }; read -r pos_x pos_y width height grid id <<< $dimensions date_format=$(date +%F-%H-%M-%S) - recording_command="ffmpeg -y -f x11grab -s ${width}x${height} -i :0.0+${pos_x},$pos_y ${OUTPUT}/$date_format.mkv -nostdin" + recording_command="ffmpeg -y -f x11grab " + + if [[ $MOUSELESS == 1 ]]; then + recording_command+="-draw_mouse 0 "; + fi + + if [[ $FOLLOW_MOUSE == 1 ]]; then + recording_command+="-follow_mouse centered "; + fi + + recording_command+="-s ${width}x${height} -i :0.0+${pos_x},$pos_y ${OUTPUT}/$date_format.mkv -nostdin" $recording_command & - WINDOW_ID="$!" + PROCESS_ID="$!" RETURN_CODE="$?" sleep 1; @@ -71,14 +101,16 @@ if [[ ! -f $RECORDING_FILE ]]; then exit 1; fi - notify-send "Recording started successfully" "Process ID is at "$WINDOW_ID""; + if [[ $ENABLE_NOTIFICATION == 1 ]]; then + notify-send --expire-time=1000 "Recording started successfully" "Process ID is at "$PROCESS_ID""; + fi touch "$RECORDING_FILE"; - echo "$WINDOW_ID" >> $RECORDING_FILE; + echo "$PROCESS_ID" >> $RECORDING_FILE; else - WINDOW_ID=$(<"$RECORDING_FILE") + PROCESS_ID=$(<"$RECORDING_FILE") - kill $WINDOW_ID + kill $PROCESS_ID if [[ $? != 0 ]]; then notify-send "Recording stop failed" "There's a problem while trying to kill the process. Process ID is at $WINDOW_ID";