verify uploads and playout
check if attributes for uploaded audio match expected ranges and mark them by colors to help finding issues with duration, channels, RMS, mode (CBR, ABR), bitrate. increase upload limit to 400 MB for audio
This commit is contained in:
98
lib/calcms/audio.pm
Normal file
98
lib/calcms/audio.pm
Normal file
@@ -0,0 +1,98 @@
|
||||
package audio;
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
sub durationToSeconds($) {
|
||||
my $duration = shift;
|
||||
|
||||
if ( $duration =~ /(\d+):(\d\d):(\d\d).(\d\d)/ ) {
|
||||
return $1 * 3600 + $2 * 60 + $3 + $4 / 100;
|
||||
}
|
||||
return $duration;
|
||||
}
|
||||
|
||||
sub formatDuration($$$) {
|
||||
my $audioDuration = shift;
|
||||
my $eventDuration = shift;
|
||||
my $value = shift;
|
||||
|
||||
return '' unless $audioDuration;
|
||||
return '' unless $eventDuration;
|
||||
return '' unless $value;
|
||||
|
||||
$audioDuration = durationToSeconds($audioDuration);
|
||||
$eventDuration = durationToSeconds($eventDuration);
|
||||
|
||||
my $delta = 100 * $audioDuration / $eventDuration;
|
||||
my $class = "ok";
|
||||
my $title = '';
|
||||
if ( $delta > 101 ) {
|
||||
$class = "warn";
|
||||
$title = sprintf(
|
||||
qq{ title="file is too long! It should be %d minutes, but is %d"},
|
||||
$eventDuration / 60,
|
||||
$audioDuration / 60
|
||||
);
|
||||
}
|
||||
if ( $delta < 99.99 ) {
|
||||
$class = "error";
|
||||
$title = sprintf(
|
||||
qq{ title="file is too short! should be %d minutes, but is %d"},
|
||||
$eventDuration / 60,
|
||||
$audioDuration / 60
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return sprintf( qq{<div class="%s"%s>%s</div>}, $class, $title, $value );
|
||||
}
|
||||
|
||||
sub formatChannels($) {
|
||||
my $channels = shift;
|
||||
return '' unless $channels;
|
||||
my $class = "ok";
|
||||
$class = "error" if $channels != 2;
|
||||
return sprintf( qq{<div class="%s">%d ch.</div>}, $class, $channels );
|
||||
}
|
||||
|
||||
sub formatSamplingRate($) {
|
||||
my $samplingRate = shift;
|
||||
return '' unless $samplingRate;
|
||||
my $class = "ok";
|
||||
$class = "error" if $samplingRate != 44100;
|
||||
return sprintf( qq{<div class="%s">%s</div>}, $class, $samplingRate );
|
||||
}
|
||||
|
||||
sub formatBitrate($) {
|
||||
my $bitrate = shift;
|
||||
return '' unless $bitrate;
|
||||
my $class = 'ok';
|
||||
$class = 'warn' if $bitrate >= 200;
|
||||
$class = 'error' if $bitrate < 192;
|
||||
return sprintf( qq{<div class="%s">%s kBit/s</div>}, $class, $bitrate );
|
||||
}
|
||||
|
||||
sub formatBitrateMode($) {
|
||||
my $mode = shift;
|
||||
return '' unless $mode;
|
||||
my $class = 'ok';
|
||||
$class = 'error' if $mode ne 'CBR';
|
||||
return sprintf( qq{<div class="%s">%s</div>}, $class, $mode );
|
||||
}
|
||||
|
||||
sub formatLoudness {
|
||||
my $value = shift;
|
||||
return '' unless $value;
|
||||
|
||||
$value = sprintf( "%.1f", $value );
|
||||
my $class = 'ok';
|
||||
$class = 'warn' if $value > -18.5;
|
||||
$class = 'error' if $value > -16.0;
|
||||
$class = 'warn' if $value < -24.0;
|
||||
$class = 'error' if $value < -27.0;
|
||||
|
||||
return qq{<div class="$class">$value dB</div>};
|
||||
}
|
||||
|
||||
# do not delete this line
|
||||
1;
|
||||
Reference in New Issue
Block a user