i3wm screencasting gifs
May 24, 2019 Updated: May 25, 2019 #blogI read an amazing comment on reddit about how to very easily record the screen into gifs and I'll report it here with some improvements. All of this can be used in any other window manager, as long as you can create keyboard shortcuts.
Create shortcut to start and stop screenrecording
First we create a shortcut to start and stop the screenrecording
record-screen.sh
This is the file where most things happen.
Dependencies: byzanz-record
, slop
.
It uses byzanz
to record the screen, and slop
to select which screen to record from, as well as the --exec
flag. --exec
makes it so byzanz
records until that process exists. This allows us to control exactly for how long the recording will last since we can simply kill it using our shortcut.
#!/usr/bin/env bash
DIR=""
IS_RECORDING_PID=
IS_RECORDING_SH=
/.files/i3/is-recording.shif ; then
FILE_NAME=
/Videos/Screencast- .
else
fi
is-recording.sh
This is the process that when killed stops the recording.
#!/usr/bin/env bash
while ; do
done
Improvements and changes
Making the gif smaller
Recording a gif using the above files will result in files that are unreasonably large. A 10s recording might take 10mb!
Therefore the first thing we should do is optimize the gif so that it is smaller. Luckily there is a program that does just that: gifsicle. Since there are very few changes between each frame in a screencast, this can turn 10mb files into 100kb files!
This is the relevant change:
;
)
;
Copying the file to the clipboard
After you've save the file, it is useful to have it copied to the clipboard, so you can you use it in another place. In my case, I like being able to paste the screencast directly to my orgmode files by using my clipboard2org package, but you can use other programs.
This depends on xclip
.
|
Displaying a notification when you finish recording
I do not use polybar. So instead I use notify-send.sh to send a notification when we finish the recording so I know that the command worked:
fi
Recording webms
Webms are better than gifs when supported. They are supported by basically everything, except IOS devices and internet explorer. In other words, it is even better than being supported everywhere haha.
;
)
;
Putting it all together
This is the end result. The Dependencies: byzanz-record
, slop
, gifsicle
, notify-send.sh
.
All of the paths are based on the paths I've setup here, you should adapt them to your case.
#!/usr/bin/env bash
#!/usr/bin/env bash
DIR=""
IS_RECORDING_PID=
IS_RECORDING_SH=
/.tools/is-recording.shif ; then
FILE_NAME=
/Videos/Screencast- .
|
else
#polybar-msg hook is-recording 1
fi