adamsgaard.dk

my academic webpage
git clone git://src.adamsgaard.dk/adamsgaard.dk
Log | Files | Refs | README | LICENSE Back to index

commit 21ba4444566d0ae4e5ad48dab4b2a014d5c296fb
parent 0751ae67a20ec95e7264ad43bf95ef53f5e07d9c
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Tue, 17 Mar 2020 11:11:50 +0100

Add screencasts post

Diffstat:
MMakefile | 3+--
Mideas.txt | 4++--
Apages/004-screencasts.cfg | 7+++++++
Apages/004-screencasts.html | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apages/004-screencasts.txt | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 219 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,6 @@ default: generate output = output/ -# w3m -dump -T text/html generate: mkdir -p $(output) saait `ls -1r pages/*.cfg` @@ -15,7 +14,7 @@ generate: done sed -i 's,|\([A-Za-z-]*\)\.html|server|port,|/\1.txt|server|port,' $(output)/index.gph cp style.css print.css $(output)/ - rsync -rav --progress \ + rsync -ra \ $(output)/ \ pages/*.txt \ /var/gopher/ diff --git a/ideas.txt b/ideas.txt @@ -1,5 +1,5 @@ - Gopherhole setup -- Desktop setup -- Lego processor +- Git hosting and stagit +- Lego film processor - Granular.jl: Modeling sea ice with particles - sphere: Requirements and examples diff --git a/pages/004-screencasts.cfg b/pages/004-screencasts.cfg @@ -0,0 +1,7 @@ +filename=screencasts.html +title=Recording screencasts and lectures on OpenBSD and Linux +description=A quick tip for remote lecturing +id=screencasts +tags=teaching, ffmpeg, openbsd +created=2020-03-17 +updated=2020-03-17 diff --git a/pages/004-screencasts.html b/pages/004-screencasts.html @@ -0,0 +1,112 @@ +<p>On Monday 2020-03-16 the buildings of the danish public +sector were closed as an emergency response to COVID-19. This +includes Aarhus University where I teach two undergraduate courses. +The university asks lecturers to move their teaching to digital +platforms. As many times before, this requires creative thinking +for those of us who do not use Microsoft and Apple products.</p> + +<p>I needed a way to record my pdf slideshows while talking over +the presentation. Ideally, I also wanted the ability to show the +video of my webcam as an overlay in an attempt to make the presentation +a bit more engaging when explaining more complex parts.</p> + +<p>Fortunately, <a href="https://ffmpeg.org">ffmpeg(1)</a> makes +it easy to record the screen and laptop audio. I want to keep the +fan noise low during recording by applying minimal compression and +encoding. The following shell script serves the purpose of starting +and stopping recording:</p> + +<pre><code>#!/bin/sh +lockfile=/tmp/screenrecord.pid + +startrecording() { + out="$HOME/tmp/screenrecord-$(date '+%Y-%m-%d_%H:%M:%S').mkv" + ffmpeg -y \ + -f x11grab \ + -framerate 60 \ + -s "$(xdpyinfo | grep dimensions | awk '{print $2}')" \ + -i $DISPLAY \ + -f sndio -i default \ + -r 30 \ + -c:v libx264rgb -crf 0 -preset ultrafast -c:a flac \ + "$out" >/dev/null 2>&1 & + printf '%s' "$!" > "$lockfile" + + sleep 1 + if [ ! -f "$out" ]; then + echo 'error: ffmpeg recording did not start' >&2 + notify-send -u CRITICAL "${0##*/}" 'ffmpeg recording did not start' + rm -f "$lockfile" + exit 1 + fi +} + +stoprecording() { + kill "$(cat "$lockfile")" + rm -f "$lockfile" + notify-send "${0##*/}" 'recording ended' +} + +if [ -f "$lockfile" ]; then + stoprecording +else + startrecording +fi +</code></pre> + +<p>On Linux systems, the sound driver <b>sndio</b> should be replaced +by <b>alsa</b> in the above ffmpeg(1) command. I have bound the +above script to the key binding Alt+r which makes it easy to start +and stop recording in my X session.</p> + +<p>On OpenBSD I can show the webcam video feed with the <a +href="https://man.openbsd.org/man1/video.1">video(1)</a> command. +The following script toggles the video feed:<p> + +<pre><code>#!/bin/sh +# remember to `chown $USER /dev/video0` +if pgrep video >/dev/null 2>&1; then + pkill video +else + nohup video -s 320 >/dev/null 2>&1 & +fi +</code></pre> + +<p>On Linux, the command <strong>mpv /dev/video0</strong> can take +place of the video(1) command above. I have the above script bound +to the keybinding Alt+v so I can quickly show and hide my face while +recording.</p> + +<p>When I am done recording a lecture, I encode and compress the +video file to save bandwidth during upload. The following script +encodes all input files and reduces file size to roughly 15% without +concievable loss in quality:</p> + +<pre><code>#!/bin/sh + +encode() { + ffmpeg -y -i "$1" \ + -c:v libx264 -threads 0 -preset faster -pix_fmt yuv420p \ + -c:a aac -crf 10 \ + "${1%%.*}_out.mp4" +} + +for f in "$@"; do + encode "$f" +done +</code></pre> + +<figure class="pagefigure"> + <video poster="video/screencast.jpg" + controls preload="none" class="mediaframe"> + <source src="video/screencast.webm" type="video/webm"> + <source src="video/screencast.ogv" type="video/ogg"> + <source src="video/screencast.mp4" type="video/mp4"> + <a href="video/screencast.mp4">Link</a> + </video> + <figcaption> + Example screen recording using ffmpeg(1) and video(1) + with the above scripts. + </figcaption> +</figure> + diff --git a/pages/004-screencasts.txt b/pages/004-screencasts.txt @@ -0,0 +1,97 @@ +On Monday 2020-03-16 the buildings of the danish public sector were closed as +an emergency response to COVID-19. This includes Aarhus University where I +teach two undergraduate courses. The university asks lecturers to move their +teaching to digital platforms. As many times before, this requires creative +thinking for those of us who do not use Microsoft and Apple products. + +I needed a way to record my pdf slideshows while talking over the presentation. +Ideally, I also wanted the ability to show the video of my webcam as an overlay +in an attempt to make the presentation a bit more engaging when explaining more +complex parts. + +Fortunately, [1]ffmpeg(1) makes it easy to record the screen and laptop audio. +I want to keep the fan noise low during recording by applying minimal +compression and encoding. The following shell script serves the purpose of +starting and stopping recording: + +#!/bin/sh +lockfile=/tmp/screenrecord.pid + +startrecording() { + out="$HOME/tmp/screenrecord-$(date '+%Y-%m-%d_%H:%M:%S').mkv" + ffmpeg -y \ + -f x11grab \ + -framerate 60 \ + -s "$(xdpyinfo | grep dimensions | awk '{print $2}')" \ + -i $DISPLAY \ + -f sndio -i default \ + -r 30 \ + -c:v libx264rgb -crf 0 -preset ultrafast -c:a flac \ + "$out" >/dev/null 2>&1 & + printf '%s' "$!" > "$lockfile" + + sleep 1 + if [ ! -f "$out" ]; then + echo 'error: ffmpeg recording did not start' >&2 + notify-send -u CRITICAL "${0##*/}" 'ffmpeg recording did not start' + rm -f "$lockfile" + exit 1 + fi +} + +stoprecording() { + kill "$(cat "$lockfile")" + rm -f "$lockfile" + notify-send "${0##*/}" 'recording ended' +} + +if [ -f "$lockfile" ]; then + stoprecording +else + startrecording +fi + +On Linux systems, the sound driver sndio should be replaced by alsa in the +above ffmpeg(1) command. I have bound the above script to the key binding Alt+r +which makes it easy to start and stop recording in my X session. + +On OpenBSD I can show the webcam video feed with the [2]video(1) command. The +following script toggles the video feed: + +#!/bin/sh +# remember to `chown $USER /dev/video0` +if pgrep video >/dev/null 2>&1; then + pkill video +else + nohup video -s 320 >/dev/null 2>&1 & +fi + +On Linux, the command mpv /dev/video0 can take place of the video(1) command +above. I have the above script bound to the keybinding Alt+v so I can quickly +show and hide my face while recording. + +When I am done recording a lecture, I encode and compress the video file to +save bandwidth during upload. The following script encodes all input files and +reduces file size to roughly 15% without concievable loss in quality: + +#!/bin/sh + +encode() { + ffmpeg -y -i "$1" \ + -c:v libx264 -threads 0 -preset faster -pix_fmt yuv420p \ + -c:a aac -crf 10 \ + "${1%%.*}_out.mp4" +} + +for f in "$@"; do + encode "$f" +done + +[3]Example screen recording using ffmpeg(1) and video(1) with the above +scripts. + +References: + +[1] https://ffmpeg.org/ +[2] https://man.openbsd.org/man1/video.1 +[3] https://adamsgaard.dk/video/screencast.mp4