create all frames by single call to oggThumb
[HTML5TV.git] / bin / mplayer.pl
index 326e523..5410e44 100755 (executable)
@@ -133,6 +133,13 @@ sub slide_jpg {
        sprintf "%s/s/%d/%03d.jpg", $media_dir, @_;
 }
 
+sub oggThumb {
+       my $video = shift;
+       my $file  = shift;
+       my $t = join(',', @_);
+       system "oggvideotools/src/oggThumb -t $t -o jpg -n $file $video";
+}
+
 sub html5tv {
 
        if ( ! $prop->{width} || ! $prop->{height} ) {
@@ -151,6 +158,7 @@ sub html5tv {
        my @slide_t;
 
        my @videos;
+       my @frames;
 
        foreach my $s ( @subtitles ) {
                push @{ $sync->{htmlEvents}->{'#subtitle'} }, {
@@ -166,23 +174,13 @@ sub html5tv {
                                warn "MISSING $path: $!\n";
                        } else {
                                my $frame_dir = "$media_dir/s/$video";
-                               system "mplayer -vo jpeg:outdir=$frame_dir,quality=95 -frames 1 -ss 0 -ao none -really-quiet $media_dir/$video"
+                               system "mplayer -vo jpeg:outdir=$frame_dir,quality=95 -frames 1 -ss 0 -ao null -really-quiet $media_dir/$video"
                                        if ! -e $frame_dir;
                                push @videos, [ @$s, $video ];
                        }
                } elsif ( $s->[2] =~ m{slide:(\d+)\s+shot:(\d+\.\d+)} ) {
-                       my ( $nr, $t ) = ( $1, $2 );
-
-                       my $hires = "$media_dir/s/hires";
-                       mkdir $hires unless -e $hires;
-
-                       my $shot_path = sprintf "$hires/s%03d.jpg", $nr;
-                       if ( ! -e $shot_path ) {
-                               my $frame_dir = "$media_dir/s/shot/";
-                               system "mplayer -vo jpeg:outdir=$frame_dir,quality=95 -frames 1 -ss $t -ao none -really-quiet $movie";
-                               rename "$media_dir/s/shot/00000001.jpg", $shot_path;
-                               warn "created $shot_path from $movie at $t for slide $nr\n";
-                       }
+                       push @frames, [ $2, $1 ];
+                       next;
                }
 
                next unless $s->[2] =~ m{\[(\d+)\]};
@@ -205,6 +203,18 @@ sub html5tv {
                push @slide_t, $s->[0];
        }
 
+       if ( @frames ) {
+               my $hires = "$media_dir/s/hires";
+               mkdir $hires unless -e $hires;
+               oggThumb $movie, "$hires/.f%.jpg", map { $_->[0] } @frames;
+
+               foreach my $i ( 0 .. $#frames ) {
+                       my $from = "$hires/.f$i.jpg";
+                       my $to   = "$hires/f" . $frames[$i]->[1] . '.jpg';
+                       rename $from, $to || warn "can't rename $from -> $to: $!";
+               }
+       }
+
        foreach ( 0 .. $#slide_t ) {
                my $slide_nr = $_ + 1;
                push @{ $sync->{htmlEvents}->{'#slide'} }, {
@@ -528,14 +538,14 @@ sub sub_fmt {
 
 sub prev_subtitle {
        my $pos = time_pos;
-       my $s = ( grep { $_->[0] < $pos } @subtitles )[0] || return;
+       my $s = ( grep { $_->[0] < $pos } @subtitles )[-1] || return;
        warn "<<<< subtitle ", sub_fmt $s;
        preroll $s->[0], $s->[2];
 #      print $to_mplayer "set_property time_pos $s->[0]\n";
 }
 
 sub next_subtitle {
-       my $pos = time_pos + $preroll;
+       my $pos = time_pos;
        my $s = ( grep { $_->[0] > $pos } @subtitles )[0] || return;
        warn ">>>> subtitle ", sub_fmt $s;
        preroll $s->[0], $s->[2];