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.
This commit is contained in:
foo-dogsquared 2019-10-27 23:25:43 +08:00
parent 513d27830d
commit 0ea18e3e9c

View File

@ -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). This is more reliable than OBS Studio (since I don't how to fully utilize it yet).
Usage: $0 [-o/--output <OUTPUT_PATH>] [-s/--selection] Usage: $0 [-o/--output <OUTPUT_PATH>]
Options: Options:
-h, --help - show the help section -h, --help - show the help section
-o, --output <string> - the path of the output (default: '~/Videos') -o, --output <string> - 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 # setting up a exit trap in case of error
trap 'error_cleanup $LINENO' ERR trap 'error_cleanup $LINENO' ERR
OUTPUT=${VIDEOS:-"$HOME/Videos"} OUTPUT=${VIDEOS:-"$HOME/Videos"}
MOUSELESS=0
FOLLOW_MOUSE=0
ENABLE_NOTIFICATION=0
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
@ -45,6 +51,15 @@ do
OUTPUT="$2" OUTPUT="$2"
shift shift
shift;; shift;;
--disable-cursor)
MOUSELESS=1
shift;;
--follow-mouse)
FOLLOW_MOUSE=1
shift;;
--enable-notification)
ENABLE_NOTIFICATION=1
shift;;
*) *)
shift;; shift;;
esac esac
@ -54,15 +69,30 @@ done
RECORDING_FILE="/tmp/fds-ffmpeg-currently-recording"; RECORDING_FILE="/tmp/fds-ffmpeg-currently-recording";
if [[ ! -f $RECORDING_FILE ]]; then 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 read -r pos_x pos_y width height grid id <<< $dimensions
date_format=$(date +%F-%H-%M-%S) 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 & $recording_command &
WINDOW_ID="$!" PROCESS_ID="$!"
RETURN_CODE="$?" RETURN_CODE="$?"
sleep 1; sleep 1;
@ -71,14 +101,16 @@ if [[ ! -f $RECORDING_FILE ]]; then
exit 1; exit 1;
fi 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"; touch "$RECORDING_FILE";
echo "$WINDOW_ID" >> $RECORDING_FILE; echo "$PROCESS_ID" >> $RECORDING_FILE;
else else
WINDOW_ID=$(<"$RECORDING_FILE") PROCESS_ID=$(<"$RECORDING_FILE")
kill $WINDOW_ID kill $PROCESS_ID
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
notify-send "Recording stop failed" "There's a problem while trying to kill the process. Process ID is at $WINDOW_ID"; notify-send "Recording stop failed" "There's a problem while trying to kill the process. Process ID is at $WINDOW_ID";