Skip to content

Instantly share code, notes, and snippets.

@endreszabo
Created June 28, 2018 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endreszabo/3f7e95ee0a1f21fac16b7723e193852b to your computer and use it in GitHub Desktop.
Save endreszabo/3f7e95ee0a1f21fac16b7723e193852b to your computer and use it in GitHub Desktop.
asciinema asciicast recording absolute/relative time converter for fine adjustments of output delays in post-production
#!/usr/bin/env perl
#===============================================================================
#
# FILE: asciicast-timestamp-converter.pl
#
# USAGE: ./asciicast-timestamp-converter.pl [filename]
# USAGE: cat filename | ./asciicast-timestamp-converter.pl
#
# DESCRIPTION: asciinema asciicast recording absolute/relative time converter
# for fine adjustments of output delays in post-production
#===============================================================================
use strict;
use warnings;
use utf8;
$_=<>;
my $lt=0;
if (m/"version": 2/) { #native version
s/"version": 2/"version": "2r"/;
print;
while(<>) {
s/^\[(\d+(?:\.\d+)?),/sprintf "[%s,", $1-$lt/e;
$lt=$1;
print;
}
} elsif (m/"version": "2r"/) { #relative version
s/"version": "2r"/"version": 2/;
print;
while(<>) {
s/^\[(\d+(?:\.\d+)?),/sprintf "[%s,", $1+$lt/e;
$lt+=$1;
print;
}
}
@2chg
Copy link

2chg commented Dec 13, 2022

To prevent the occasional display of scientific notation during the conversion, replace format mask %s with %f in lines 24 and 32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment