Created
June 28, 2018 08:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To prevent the occasional display of scientific notation during the conversion, replace format mask
%s
with%f
in lines 24 and 32.