Resources
Terminal Recorders: A Comprehensive Guide

Recorders

util notes
asciinema rec May save locally. High fidelity. Json (large size).
ttyrec Preservation of original input. Has provenance.
ttystudio Inhouse json output. Long build duration.

Gif converters

util input notes
seq2gif ttyrec Extremely fast converter.
asciicast2gif asciicast runs in docker, uses phantomjs and imagemagic. low quality.
ttystudio inhouse json gif output of highest fidelity and most greatly compressed size. Longest build duration.

mp4 converters

util input notes
ffmpeg gif often results in lower file size. more portable

</ox-hugo/ttyrec-11.04.20__1586583595.studio.mp4>

Create tmux bindings for different pipelines

1
2
3
4
5
6
m  tm ttystudio-gif
r  tm asciinema
c  tm asciinema
C  tm asciinema-local
y  tm-attach-localhost-and-record
q  tm ttyrec-auto

tm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ttyrec-auto|recterm|ttystudio-gif|ascl|asciinema-local) {
    swidth="$(tmux display -t "$CALLER_TARGET" -p "#{session_width}")"
    sheight="$(tmux display -t "$CALLER_TARGET" -p "#{session_height}")"
    sheight="$(( sheight + 2 ))"

    caller_slug="$(printf -- "%s" "$CALLER_TARGET" | slugify)"

    tmsessionname="${f}-$caller_slug-$(date-ts)"

    server="$(tm-get-server)"

    cmd="unset TTY; x -s \"${f}\" -c m -e \"\$\" -s \"TMUX= tmux attach -t $(aqf \"$CALLER_TARGET\":)\" -c m -i"

    TMUX= tmux new-session -d -c "$CWD" -x "$swidth" -y "$sheight" -A -s "$tmsessionname"

    xt -b -E "tmux setenv -t $(aqf "$tmsessionname") WINDOWID $(aqf "\$WINDOWID") \\; respawnp -k -t $(aqf "$tmsessionname:1") $(aqf "$cmd") \\; attach -t $(aqf "$tmsessionname")"
}

The bash script above spawns a new tmux session that wraps the current session and starts recording.

When the tmux session is detached, it will convert the recording into the necessary output file.

ttyrec-auto

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

recname="ttyrec-$(date-ts-hr).ttyrec"

cd $DUMP/programs/ttyrec

ttyrec "$recname"

zcd $DUMP/programs/ttyrec

The ttyrec-auto script creates a ttyrec recording. It’s my preferred option as it records instantly and replaying a ttyrec recording enables me to rerecord/convert with a different pipeline instead.

open-ttyrec

Upon opening the ttyrec recording in ranger, I’m presented with this menu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

fp="$1"
test -f "$fp" || exit 1

rp="$(realpath "$fp")"
dn="$(dirname "$rp")"

cd "$dn"
bn="$(basename "$fp")"
ext="${bn##*.}"
fn="${bn%.*}"

ans="$(qa -. edit \
          -h ttyplay \
          -n ttyplay \
          -p tm-ttyplay \
          -t ttyrec-ttystudio \
          -s seq2gif \
          )"

case "$ans" in
    edit) { vs $0; } ;;
    ttyplay) { ttyplay "$fp"; } ;;
    tm-ttyplay) { nw ttyplay "$rp"; } ;;
    ttyrec-ttystudio) { ttyrec-ttystudio "$rp" & } ;;
    seq2gif) { seq2gif "$fp" && eog "${fn}.gif"; } ;;
    *) ;;
esac

ttyrec-ttystudio

This is a converter script that runs ttyrec recordings through ttystudio. ttystudio rerecords and produces its own record format plus some very nice gif output.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

ttyrecpath="$1"
test -f "$ttyrecpath" || exit 1

fp="$ttyrecpath"
rp="$(realpath "$fp")"
dn="$(dirname "$rp")"

cd "$dn"
bn="$(basename "$fp")"
ext="${bn##*.}"
fn="${bn%.*}"

if test -f "${fn}.env.sh"; then
    LINES="$(cat "${fn}.env.sh" | grep LINES= | grep -oP "[0-9]+")"
    COLUMNS="$(cat "${fn}.env.sh" | grep COLUMNS= | grep -oP "[0-9]+")"
fi

: "${LINES:="$(resize | grep LINES= | grep -oP "[0-9]+")"}"
: "${COLUMNS:="$(resize | grep COLUMNS= | grep -oP "[0-9]+")"}"

# Firstly get the columns and rows
# Skip that for now, but it's important

rm -f "${fn}.studio.gif"

unset TTY

tm-new-with-size -wait "$COLUMNS" "$(( LINES + 1 ))" \
    x -sh "cd $(aqf "$dn"); ttystudio $(aqf "${fn}.studio.gif")" \
    -e "ยป" -s "cd $(aqf "$dn"); ttyplay $(aqf "$bn") && echo \\TTYSTUDIO_\\DONE" \
    -c m -e "TTYSTUDIO_DONE" -c q -i

test -s "${fn}.studio.gif" || rm "${fn}.studio.gif"
rm -f "${fn}.studio.frames.json"

Sequence

graph TD;
    ttyrec-->ttystudio;
    ttystudio-->gif;
    gif-->mp4;