Skip to content

Instantly share code, notes, and snippets.

@robbplo
Last active June 28, 2022 14:03
Show Gist options
  • Save robbplo/0278ad0ecc019f09674699b1abf3dbc8 to your computer and use it in GitHub Desktop.
Save robbplo/0278ad0ecc019f09674699b1abf3dbc8 to your computer and use it in GitHub Desktop.
Bash script for recording terminal sessions and converting them to MP4 files. Download the file and place it in `/usr/local/bin` to make it globally available in the terminal.
#!/bin/bash
export BIT_RECORD=1
if [[ -z $1 ]]; then
echo "usage: bit-record [filename]"
echo "e.g. bit-record video.mp4"
exit 1
fi
if [[ ! -d ~/bit-academy ]]; then
mkdir ~/bit-academy
fi
cd ~/bit-academy
tempdir="/tmp/bit-record"
if [[ -d $tempdir ]]; then
rm -r $tempdir
fi
mkdir $tempdir
# record terminal session, limit time between keystrokes to 2.5 seconds
asciinema rec -c "/bin/zsh" -i 2.5 "$tempdir/recording.cast"
echo "converting asciicast to gif"
docker run --rm -v $tempdir:/data:delegated asciinema/asciicast2gif -w 80 -h 20 "recording.cast" "recording.gif"
#asciicast2gif -w 80 -h 24 "$tempdir/recording.cast" "$tempdir/recording.gif"
echo "converting gif to mp4"
docker run -v $tempdir:$tempdir -w $tempdir \
jrottenberg/ffmpeg \
-loglevel 16 -i "recording.gif" -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" $1
mv "$tempdir/$1" ~/bit-academy
echo "video file stored at ~/bit-academy/$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment