diff options
author | Yaroslav <contact@yaroslavps.com> | 2020-02-17 18:02:37 +0300 |
---|---|---|
committer | Yaroslav <contact@yaroslavps.com> | 2020-02-17 18:02:37 +0300 |
commit | f8caca887f787f52271d9a5d6e06c2bdd6efcb40 (patch) | |
tree | 91c5d3c531a71e1fc669478a4c60068c1f6b8dde /dotfiles | |
parent | 13a0be470be41d67685bba83c6f10319affbaa39 (diff) | |
download | swayrice-f8caca887f787f52271d9a5d6e06c2bdd6efcb40.tar.gz swayrice-f8caca887f787f52271d9a5d6e06c2bdd6efcb40.zip |
improved screen record script, can now record screencasts and audio
Diffstat (limited to 'dotfiles')
-rw-r--r-- | dotfiles/.config/sway/config | 9 | ||||
-rwxr-xr-x | dotfiles/.local/bin/barrecstatus | 2 | ||||
-rwxr-xr-x | dotfiles/.local/bin/swayrecord | 122 | ||||
-rw-r--r-- | dotfiles/.profile | 2 |
4 files changed, 121 insertions, 14 deletions
diff --git a/dotfiles/.config/sway/config b/dotfiles/.config/sway/config index 3d4b705..3320a29 100644 --- a/dotfiles/.config/sway/config +++ b/dotfiles/.config/sway/config @@ -186,9 +186,9 @@ bindsym --to-code { $mod+Ctrl+v exec $term -e vis $mod+o exec --no-startup-id notistats $mod+c exec --no-startup-id camtoggle - $mod+grave exec --no-startup-id menuducksearch - $mod+Shift+grave exec --no-startup-id menuemoji - $mod+F1 exec --no-startup-id zathura ~/.config/i3/i3guide.pdf + $mod+grave exec --no-startup-id menuemoji + $mod+Shift+grave exec --no-startup-id menuducksearch + # $mod+F1 exec --no-startup-id zathura ~/.config/i3/i3guide.pdf # TODO: update guide # Network management $mod+Shift+c exec togglevpn @@ -198,7 +198,8 @@ bindsym --to-code { # Screenshot and recording Print exec --no-startup-id menugrim -q $mod+Print exec --no-startup-id menugrim - Shift+Print exec --no-startup-id swayrecord + Shift+Print exec --no-startup-id "swayrecord screencast" + Ctrl+Print exec --no-startup-id swayrecord # Sound $mod+Shift+m exec $term -e 'ncpamixer' 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 + diff --git a/dotfiles/.profile b/dotfiles/.profile index 5e37a2f..d2303ab 100644 --- a/dotfiles/.profile +++ b/dotfiles/.profile @@ -1,5 +1,7 @@ export PATH=$PATH:$HOME/.local/bin export SCROT_DIR=$HOME/Pictures/screenshots/ +export VREC_DIR=$HOME/Videos/recordings/ +export AREC_DIR=$HOME/Documents/audio/recordings/ #export GDK_BACKEND=wayland export EGL_PLATFORM=wayland export CLUTTER_PLATFORM=wayland |