muxsa/bin/muxsa-al2fc

121 lines
4.0 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/perl -w
use warnings;
use strict;
2023-03-11 13:15:08 +01:00
use File::Slurp;
# muxsa-al2fc
#
# part of muxsa, https://git-nks-public.tik.uni-stuttgart.de/edu/muxsa
#
# this script reads a "label track" that was exported by the
# Audacity (https://www.audacityteam.org/) audio recoder/editor.
# It assumes that the labels contain slide numbers.
# It will output (to standard output) a sequence of statements that
# can be read by the ffmpeg (https://ffmpeg.org/) concat multiplexer.
#
# MIT License
#
# Copyright (c) 2023 Sebastian Kiesel <sebastian.kiesel@tik.uni-stuttgart.de>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
############################################################################
2023-03-11 13:15:08 +01:00
# get MUXSA_KVM2PNG_SLIDE_PREFIX from ~/.muxsarc, environment var overrides
2023-03-11 13:15:08 +01:00
my %muxsarc;
if( -r (my $rc=$ENV{"HOME"}.'/.muxsarc') ){
%muxsarc = read_file($rc) =~ /^(\w+)=(?:"|')?(.*?)(?:"|')?$/mg;
}
my $slide_prefix = $muxsarc{'MUXSA_KVM2PNG_SLIDE_PREFIX'}//"";
if( $ENV{'MUXSA_KVM2PNG_SLIDE_PREFIX'} ){
$slide_prefix = $ENV{'MUXSA_KVM2PNG_SLIDE_PREFIX'};
}
############################################################################
sub printf_file {
if( $_[0] =~ /^[0-9]+$/ ){
printf("file '%s%04i.png'\n", $slide_prefix, $_[0]);
}
else {
printf("file '%s%s.png'\n", $slide_prefix, $_[0]);
}
}
sub printf_duration {
printf("duration %.6f\n", $_[0]);
}
############################################################################
my @cur;
my @prev;
printf("# Beginning of ffmpeg concat sequence produced by muxsa-al2fc\n");
while(<>) {
chomp();
# label start time, label end time, label text
@cur = /^(-?[0-9]+\.[0-9]+)\t(-?[0-9]+\.[0-9]+)\t(.*)$/ or next;
if(!@prev){ # no previous label -> this is the first label we read
if( $cur[0] != 0.0 ){
printf("# Warning: 1st label ts changed: %.6f to 0.0\n", $cur[0]);
$cur[0]=0.0;
}
@prev = @cur;
next;
}
my $duration = $cur[0] - $prev[0];
printf("# Label \"%s\" from %.6f to %.6f duration %.6f\n",
$prev[2], $prev[0], $cur[0], $duration);
while( $duration > 1.0 ){
printf_file($prev[2]);
printf_duration(1.0);
$duration-=1.0;
}
printf_file($prev[2]);
printf_duration($duration);
if( uc($cur[2]) eq "END" ){
printf("# END label at %.6f\n",$cur[0]);
# known bug in the demuxer:
# the last slide name has to be repeated w/o duration
printf_file($prev[2]);
printf("# End of ffmpeg concat sequence produced by muxsa-al2fc\n");
exit(0);
}
@prev = @cur;
}
# we have reached the end of the input file without an explicit END label
# ASSUME that the last slide should be shown for 1 sec
printf("# EOF but no END label. ASSUMING a duration for the last slide.\n");
printf_file($cur[2]);
printf_duration(1.0);
printf_file($cur[2]);
printf("# End of ffmpeg concat sequence produced by muxsa-al2fc\n");
############################################################################