use YAML;
use JSON;
use HTML::TreeBuilder;
+use Imager;
my $movie = shift @ARGV
my $preroll = 3;
+my $slide_factor = 4; # 1/4 size of video
+
our $to_mplayer;
our $from_mplayer;
our $err_mplayer;
our @subtitles;
sub html5tv {
+
+ if ( ! $prop->{width} || ! $prop->{height} ) {
+ warn "SKIP no size yet\n";
+ return;
+ }
+
+
my $sync;
my @slide_t;
next unless $s->[2] =~ m{\[(\d+)\]};
- my $res = ( $prop->{width} / 4 ) . 'x' . ( $prop->{height} / 4 );
push @{ $sync->{customEvents} }, {
startTime => $s->[0],
args => {
carousel => 'theCarousel',
id => "chapter$1",
- index => $1,
title => $s->[2],
description => $s->[2],
- src => sprintf('media/s/%s/p%03d.jpg', $res, $1),
+ src => sprintf('media/s/%dx%d/p%03d.jpg', $prop->{width} / $slide_factor, $prop->{height} / $slide_factor, $1),
href => '',
},
};
};
}
- my $html5tv = {
- sync => $sync,
- video => $prop,
- };
+ my ( $slide_width, $slide_height );
+
+ foreach my $factor ( 4, 2, 1 ) {
+ my $w = $prop->{width} / $factor;
+ my $h = $prop->{height} / $factor;
+
+ my $path = "www/media/s/${w}x${h}";
+
+ if ( ! -d $path ) {
+ mkdir $path;
+ warn "created $path\n";
- if ( $prop->{width} && $prop->{height} ) {
- foreach my $factor ( 4, 2, 1 ) {
- my $w = $prop->{width} / $factor;
- my $h = $prop->{height} / $factor;
+ foreach my $hires ( glob 'www/media/s/hires/p*.jpg' ) {
- $html5tv->{slide} = {
- width => $w,
- height => $h,
- } if $factor == 4;
+ my $file = $hires;
+ $file =~ s{^.+/(p\d+\.\w)}{$path/$1};
- my $path = "www/media/s/${w}x${h}";
- if ( ! -d $path ) {
- mkdir $path;
- warn "created $path\n";
+ my $im = Imager->new( file => $hires );
+ $im->scale( xpixels => $w, ypixels => $h, type => 'min' );
+ $im->write( file => $file );
+ warn "resized $file ", -s $file, " bytes\n";
}
}
+
+ if ( $factor == $slide_factor ) {
+ my $im = Imager->new( file => "$path/p001.jpg" );
+ $slide_width = $im->getwidth;
+ $slide_height = $im->getheight;
+ }
+
}
+ my $html5tv = {
+ sync => $sync,
+ video => $prop,
+ slide => {
+ width => $slide_width,
+ height => $slide_height,
+ },
+ };
+
$html5tv->{video_tags} =
join("\n",
map {
write_file 'www/media.html', $html;
- my $carousel_width = ( $html5tv->{slide}->{width} + 6 ) * 6; # 6 = left(2)+right(2)+border(2*1)
- my $carousel_height = $html5tv->{slide}->{height} + 2;
+ my $carousel_width = $prop->{width} + Imager->new( file => "www/media/s/$res/p001.jpg" )->getwidth - 80;
+ $carousel_width -= $carousel_width % ( $slide_width + 6 ); # round to full slide
+ my $carousel_height = $slide_height + 2;
write_file 'www/media/video.css', qq|
}
.jcarousel-skin-ie7 .jcarousel-item {
- width: $html5tv->{slide}->{width}px;
- height: $html5tv->{slide}->{height}px;
+ width: ${slide_width}px;
+ height: ${slide_height}px;
margin: 0 2px 0 2px;
}
}
div#videoContainer {
- width: $html5tv->{video}->{width}px;
- height: $html5tv->{video}->{height}px;
+ width: $prop->{width}px;
+ height: $prop->{height}px;
font-family: Arial, Helvetica, sans-serif;
margin: 0 10px 0px 0;
position: relative;
text-align: center;
z-index: 10;
padding: 2px 0 2px 0;
- width: $html5tv->{slide}->{width}px;
+ width: ${slide_width}px;
}
|;
+ return 1;
}
}
sub save_subtitles {
+
+ html5tv || return;
+
my $nr = 0;
my $srt = "\n";
foreach my $s ( @subtitles ) {
print $to_mplayer "sub_remove\n";
print $to_mplayer qq|sub_load "$subtitles"\n|;
print $to_mplayer "sub_select 1\n";
-
- html5tv;
}
sub load_subtitles {