I'm using ASCIInema.
And I try to speed it up. asciinema --speed
solves this problem. But how to set the speed in the file.cast
itself, so that it could be published and the user can execute asciinema play
without an additional parameter?
-
@zx485, very good edit. thank you. – kyb Aug 23 '19 at 05:49
3 Answers
To make the speed change persistent you need to adjust the timing of each event in the cast file.
jq based solution proposed by @kyb is one way. Another is to re-record the cast with this command:
asciinema rec -c 'asciinema play -s 4 file.cast' faster-file.cast
This will create a new recording, but instead of recording a new interactive shell it will record the sped up playback of the old cast.
You don't need jq for this, however the downside is that it's not instant - it takes as much time as the playback at a desired speed.
I found a simple way: edit file with jq
:
in bash
cat file.cast | { read; echo "$REPLY"; jq -c '.[0]=.[0]/4'; } > fast.cast
in fish
cat file.cast | begin read; echo "$REPLY"; jq -c '.[0]=.[0]/4'; end > fast.cast
read
stands to read first line which contains json object - short description about this cast, this object should not be passed to jq
. jq
processes arrays, zeroth element is timestamp, to speed up payback script divides every timestamp by a specified ratio, here it is 4
.
example
file.cast
{"version": 2, "width": 182, "height": 28, "timestamp": 1566499237, "env": {"SHELL": "/usr/local/bin/fish", "TERM": "xterm-256color"}}
[0.027813, "o", "\u001b]1337;RemoteHost=kyb@kyb-mbo.local\u0007\u001b]1337;CurrentDir=/Users/kyb/devel/git-rev-label\u0007\u001b]1337;ShellIntegrationVersion=6;shell=fish\u0007"]
[0.046757, "o", "\u001b]1337;RemoteHost=kyb@kyb-mbo.local\u0007\u001b]1337;CurrentDir=/Users/kyb/devel/git-rev-label\u0007"]
[0.050038, "o", "\u001b]0;fish /Users/kyb/devel/git-rev-label\u0007\u001b[30m\u001b(B\u001b[m"]
[0.058719, "o", "\u001b[?2004h"]
[0.162696, "o", "\u001b]0;fish /Users/kyb/devel/git-rev-label\u0007\u001b[30m\u001b(B\u001b[m"]
[0.162909, "o", "\u001b[38;5;237m⏎\u001b(B\u001b[m \r⏎ \r\u001b[K"]
[0.164234, "o", "\u001b]133;D;0\u0007\u001b]133;A\u0007\u001b[44m\u001b[30m ~/d/git-rev-label \u001b[42m\u001b[34m \u001b[42m\u001b[30m➦ d0e4dc8 \u001b[30m\u001b(B\u001b[m\u001b[32m \u001b[30m\u001b(B\u001b[m\u001b]133;B\u0007\u001b[K"]
[2.316447, "o", "g"]
[2.316686, "o", "\b\u001b[38;5;167mg\u001b[30m\u001b(B\u001b[m"]
[2.318507, "o", "\u001b[38;5;246mit rev-label\u001b[12D\u001b[30m\u001b(B\u001b[m"]
[2.43537, "o", "\u001b[38;5;167mi\u001b[38;5;246mt rev-label\u001b[11D\u001b[30m\u001b(B\u001b[m"]
[2.464359, "o", "\u001b[38;5;167mt\u001b[38;5;246m rev-label\u001b[10D\u001b[30m\u001b(B\u001b[m"]
[2.464657, "o", "\b\b\b\u001b[38;5;176mgit\u001b[38;5;246m rev-label\u001b[10D\u001b[30m\u001b(B\u001b[m"]
[2.599488, "o", "\u001b[38;5;176m \u001b[38;5;246mrev-label\u001b[9D\u001b[30m\u001b(B\u001b[m"]
[2.599678, "o", "\b \u001b[38;5;246mrev-label\u001b[9D\u001b[30m\u001b(B\u001b[m"]
[2.737237, "o", "r\u001b[38;5;246mev-label\b\b\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[2.737514, "o", "\b\u001b[38;5;110m\u001b[4mr\u001b[38;5;246m\u001b[24mev-label\b\b\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[2.817482, "o", "\u001b[38;5;110m\u001b[4me\u001b[38;5;246m\u001b[24mv-label\b\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[3.033631, "o", "\u001b[38;5;110m\u001b[4mv\u001b[38;5;246m\u001b[24m-label\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[3.033812, "o", "\b\b\b\u001b[38;5;110mrev\u001b[38;5;246m-label\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[3.951287, "o", "\u001b[38;5;110m-label\u001b[30m\u001b(B\u001b[m"]
[4.581453, "o", "\r\n"]
[4.581681, "o", "\u001b[30m\u001b(B\u001b[m\u001b[?2004l"]
[4.58185, "o", "\u001b]133;C;\u0007"]
[4.582158, "o", "\u001b]0;git /Users/kyb/devel/git-rev-label\u0007\u001b["]
[4.582306, "o", "30m\u001b(B\u001b[m\r"]
[4.689255, "o", "brantozyabra-c136-gd0e4dc8\r\n"]
[4.690204, "o", "\u001b]1337;RemoteHost=kyb@kyb-mbo.local\u0007\u001b]1337;CurrentDir=/Users/kyb/devel/git-rev-label\u0007"]
[4.690383, "o", "\u001b[?2004h"]
[4.772316, "o", "\u001b]0;fish /Users/kyb/devel/git-rev-label\u0007\u001b[30m\u001b(B\u001b[m"]
[4.772502, "o", "\u001b[38;5;237m⏎\u001b(B\u001b[m \r⏎ \r\u001b[K\u001b]133;D;0\u0007\u001b]133;A\u0007\u001b[44m\u001b[30m ~/d/git-rev-label \u001b[42m\u001b[34m \u001b[42m\u001b[30m➦ d0e4dc8 \u001b[30m\u001b(B\u001b[m\u001b[32m \u001b[30m\u001b(B\u001b[m\u001b]133;B\u0007\u001b[K"]
[6.901142, "o", "\r\n\u001b[30m\u001b(B\u001b[m\u001b[30m\u001b(B\u001b[m"]
[6.901321, "o", "\u001b[?2004l"]
fast.cast
{"version": 2, "width": 182, "height": 28, "timestamp": 1566499237, "env": {"SHELL": "/usr/local/bin/fish", "TERM": "xterm-256color"}}
[0.00695325,"o","\u001b]1337;RemoteHost=kyb@kyb-mbo.local\u0007\u001b]1337;CurrentDir=/Users/kyb/devel/git-rev-label\u0007\u001b]1337;ShellIntegrationVersion=6;shell=fish\u0007"]
[0.01168925,"o","\u001b]1337;RemoteHost=kyb@kyb-mbo.local\u0007\u001b]1337;CurrentDir=/Users/kyb/devel/git-rev-label\u0007"]
[0.0125095,"o","\u001b]0;fish /Users/kyb/devel/git-rev-label\u0007\u001b[30m\u001b(B\u001b[m"]
[0.01467975,"o","\u001b[?2004h"]
[0.040674,"o","\u001b]0;fish /Users/kyb/devel/git-rev-label\u0007\u001b[30m\u001b(B\u001b[m"]
[0.04072725,"o","\u001b[38;5;237m⏎\u001b(B\u001b[m \r⏎ \r\u001b[K"]
[0.0410585,"o","\u001b]133;D;0\u0007\u001b]133;A\u0007\u001b[44m\u001b[30m ~/d/git-rev-label \u001b[42m\u001b[34m \u001b[42m\u001b[30m➦ d0e4dc8 \u001b[30m\u001b(B\u001b[m\u001b[32m \u001b[30m\u001b(B\u001b[m\u001b]133;B\u0007\u001b[K"]
[0.57911175,"o","g"]
[0.5791715,"o","\b\u001b[38;5;167mg\u001b[30m\u001b(B\u001b[m"]
[0.57962675,"o","\u001b[38;5;246mit rev-label\u001b[12D\u001b[30m\u001b(B\u001b[m"]
[0.6088425,"o","\u001b[38;5;167mi\u001b[38;5;246mt rev-label\u001b[11D\u001b[30m\u001b(B\u001b[m"]
[0.61608975,"o","\u001b[38;5;167mt\u001b[38;5;246m rev-label\u001b[10D\u001b[30m\u001b(B\u001b[m"]
[0.61616425,"o","\b\b\b\u001b[38;5;176mgit\u001b[38;5;246m rev-label\u001b[10D\u001b[30m\u001b(B\u001b[m"]
[0.649872,"o","\u001b[38;5;176m \u001b[38;5;246mrev-label\u001b[9D\u001b[30m\u001b(B\u001b[m"]
[0.6499195,"o","\b \u001b[38;5;246mrev-label\u001b[9D\u001b[30m\u001b(B\u001b[m"]
[0.68430925,"o","r\u001b[38;5;246mev-label\b\b\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[0.6843785,"o","\b\u001b[38;5;110m\u001b[4mr\u001b[38;5;246m\u001b[24mev-label\b\b\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[0.7043705,"o","\u001b[38;5;110m\u001b[4me\u001b[38;5;246m\u001b[24mv-label\b\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[0.75840775,"o","\u001b[38;5;110m\u001b[4mv\u001b[38;5;246m\u001b[24m-label\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[0.758453,"o","\b\b\b\u001b[38;5;110mrev\u001b[38;5;246m-label\b\b\b\b\b\b\u001b[30m\u001b(B\u001b[m"]
[0.98782175,"o","\u001b[38;5;110m-label\u001b[30m\u001b(B\u001b[m"]
[1.14536325,"o","\r\n"]
[1.14542025,"o","\u001b[30m\u001b(B\u001b[m\u001b[?2004l"]
[1.1454625,"o","\u001b]133;C;\u0007"]
[1.1455395,"o","\u001b]0;git /Users/kyb/devel/git-rev-label\u0007\u001b["]
[1.1455765,"o","30m\u001b(B\u001b[m\r"]
[1.17231375,"o","brantozyabra-c136-gd0e4dc8\r\n"]
[1.172551,"o","\u001b]1337;RemoteHost=kyb@kyb-mbo.local\u0007\u001b]1337;CurrentDir=/Users/kyb/devel/git-rev-label\u0007"]
[1.17259575,"o","\u001b[?2004h"]
[1.193079,"o","\u001b]0;fish /Users/kyb/devel/git-rev-label\u0007\u001b[30m\u001b(B\u001b[m"]
[1.1931255,"o","\u001b[38;5;237m⏎\u001b(B\u001b[m \r⏎ \r\u001b[K\u001b]133;D;0\u0007\u001b]133;A\u0007\u001b[44m\u001b[30m ~/d/git-rev-label \u001b[42m\u001b[34m \u001b[42m\u001b[30m➦ d0e4dc8 \u001b[30m\u001b(B\u001b[m\u001b[32m \u001b[30m\u001b(B\u001b[m\u001b]133;B\u0007\u001b[K"]
[1.7252855,"o","\r\n\u001b[30m\u001b(B\u001b[m\u001b[30m\u001b(B\u001b[m"]
[1.72533025,"o","\u001b[?2004l"]

- 7,233
- 5
- 52
- 105
-
1`jq -sc '.[0], (.[1:][] | .[0]/=4)' file.cast > fast.cast` Nice to do all within jq, but took a bit of mucking about, so not sure it's really "better". BTW compacts the first line. – hyperpallium Feb 08 '20 at 10:46
-
-
1Make the lines into an array, then break down the array. `-s` slurps in lines as if they were an array. `.[0]` is then the first line, and `.[1:]` is an array of all the other lines. `[]` gives us each element in that array (i.e. the rest of the lines). `\=` is division operation and assign, like `+=` etc in C. `,` means that both sides get the same input (the whole array). Parentheses are because `,` binds tighter than `|`, and we want the `\=4` to only apply to the rest of the lines. I like jq but always find it confusing to use. – hyperpallium Feb 09 '20 at 15:16
The tool asciinema-edit seems to do just that (among other post-processing of asciinema recordings). From the README:
EXAMPLES:
Make the whole cast ("123.cast") twice as fast:
asciinema-edit speed --factor 2 ./123.cast
Cut the duration in half:
asciinema-edit speed --factor 0.5 ./123.cast

- 458
- 5
- 6