aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.local/bin
diff options
context:
space:
mode:
authorYaroslav <contact@yaroslavps.com>2020-02-17 18:02:37 +0300
committerYaroslav <contact@yaroslavps.com>2020-02-17 18:02:37 +0300
commitf8caca887f787f52271d9a5d6e06c2bdd6efcb40 (patch)
tree91c5d3c531a71e1fc669478a4c60068c1f6b8dde /dotfiles/.local/bin
parent13a0be470be41d67685bba83c6f10319affbaa39 (diff)
downloadswayrice-f8caca887f787f52271d9a5d6e06c2bdd6efcb40.tar.gz
swayrice-f8caca887f787f52271d9a5d6e06c2bdd6efcb40.zip
improved screen record script, can now record screencasts and audio
Diffstat (limited to 'dotfiles/.local/bin')
-rwxr-xr-xdotfiles/.local/bin/barrecstatus2
-rwxr-xr-xdotfiles/.local/bin/swayrecord122
2 files changed, 114 insertions, 10 deletions
diff --git a/dotfiles/.local/bin/barrecstatus b/dotfiles/.local/bin/barrecstatus
index b7bb8b4..3e6317b 100755
--- a/dotfiles/.local/bin/barrecstatus
+++ b/dotfiles/.local/bin/barrecstatus
@@ -1,7 +1,7 @@
#!/bin/sh
if [ -f "$HOME/.cache/recordingpid" ]; then
- printf "⏺ rec"
+ printf "%s rec" "$(cat "$HOME/.cache/recordingicon")"
exit
fi
diff --git a/dotfiles/.local/bin/swayrecord b/dotfiles/.local/bin/swayrecord
index 378b46f..f93ae87 100755
--- a/dotfiles/.local/bin/swayrecord
+++ b/dotfiles/.local/bin/swayrecord
@@ -1,14 +1,118 @@
#!/bin/sh
+# Source settings from .bemenurc
+. $HOME/.bemenurc
+
+if ! [ -d $VREC_DIR ]; then
+ mkdir -p $VREC_DIR
+fi
+if ! [ -d $AREC_DIR ]; then
+ mkdir -p $AREC_DIR
+fi
+
+OUTPUT="$(date '+%y%m%d-%H%M-%S')"
+TYPE="$1"
+VIDEO_PID=""
+AUDIO_PID=""
+
+trap finishrecording SIGINT
+
+finishvideo () {
+ kill -2 "$VIDEO_PID"
+ notify-send "⏺ Recording" \
+ "Screen recording stopped and saved at "$VREC_DIR"/video-"$OUTPUT".mp4"
+}
+
+finishaudio () {
+ kill -2 "$AUDIO_PID"
+ notify-send "🎙 Recording" \
+ "Audio recording stopped and saved at "$AREC_DIR/$OUTPUT.flac""
+}
+
+finishscreencast () {
+ kill -2 "$VIDEO_PID"
+ kill -2 "$AUDIO_PID"
+ notify-send "📼 Recording" "One moment, screencast is being encoded..."
+ ffmpeg -i "$VREC_DIR/temp-$OUTPUT.mp4" \
+ -i "$VREC_DIR/temp-$OUTPUT.mp3" \
+ -codec copy \
+ -shortest \
+ "$VREC_DIR/screencast-$OUTPUT.mp4"
+ rm -f "$VREC_DIR/temp-$OUTPUT.mp4"
+ rm -f "$VREC_DIR/temp-$OUTPUT.mp3"
+ notify-send "📼 Recording" \
+ "Screencast recording stopped and saved at "$VREC_DIR/screencast-$OUTPUT.mp4""
+}
+
+finishrecording () {
+ case "$TYPE" in
+ video) finishvideo;;
+ audio) finishaudio;;
+ screencast) finishscreencast;;
+ esac
+ rm -f ~/.cache/recordingpid
+ rm -f ~/.cache/recordingicon
+ killall -39 waybar
+}
+
+killrecording () {
+ RECPID="$(cat "$HOME/.cache/recordingpid")"
+ kill -2 "$RECPID"
+ exit
+}
+
+video () {
+ wf-recorder -f "$VREC_DIR/video-$OUTPUT.mp4" &
+ VIDEO_PID=$!
+ echo $$ > ~/.cache/recordingpid
+ echo "⏺" > ~/.cache/recordingicon
+ notify-send "⏺ Recording" "Screen recording started"
+ killall -39 waybar
+ wait
+}
+
+screencast () {
+ wf-recorder -f "$VREC_DIR/temp-$OUTPUT.mp4" &
+ VIDEO_PID=$!
+ ffmpeg -f alsa -i default -c:a mp3 "$VREC_DIR/temp-$OUTPUT.mp3" &
+ AUDIO_PID=$!
+ echo $$ > ~/.cache/recordingpid
+ echo "📼" > ~/.cache/recordingicon
+ notify-send "📼 Recording" "Screencast recording started"
+ killall -39 waybar
+ wait
+}
+
+audio () {
+ ffmpeg -f alsa -i default -c:a flac "$AREC_DIR/$OUTPUT.flac" &
+ AUDIO_PID=$!
+ echo $$ > ~/.cache/recordingpid
+ echo "🎙" > ~/.cache/recordingicon
+ notify-send "🎙 Recording" "Audio recording started"
+ killall -39 waybar
+ wait
+}
+
+askrecording () {
+ TYPE="$(printf "video\nscreencast\naudio\n" | bemenu -l 6 -i -p "What should be recorded?" --tf="$BEMENU_TF" --tb="$BEMENU_NB" --fb="$BEMENU_NB" --fn="$BEMENU_FN" --nb="$BEMENU_NB" --nf="$BEMENU_NF" --hf="$BEMENU_HF" --hb="$BEMENU_HB")"
+ case "$TYPE" in
+ video) video;;
+ screencast) screencast;;
+ audio) audio;;
+ *) exit;;
+ esac
+}
+
if [ -f "$HOME/.cache/recordingpid" ]; then
- killall -SIGINT wf-recorder
- rm -f ~/.cache/recordingpid
- notify-send "⏺ Screen recording" "Recording stopped"
- killall -39 waybar
- exit
+ killrecording
+ exit
fi
-wf-recorder -f "$HOME/Videos/recordings/$(date '+%y%m%d-%H%M-%S').mp4" &
-echo $! > ~/.cache/recordingpid
-notify-send "⏺ Screen recording" "Recording started"
-killall -39 waybar
+case $1 in
+ video) video;;
+ screencast) screencast;;
+ audio) audio;;
+ kill) killrecording;;
+ *) askrecording;;
+esac
+