source: extensions/gsdl-video/trunk/perllib/plugins/TimedHTMLPlugin.pm@ 18982

Last change on this file since 18982 was 18982, checked in by davidb, 15 years ago

Some mods to work with Windows version of ffmpeg

File size: 26.8 KB
Line 
1###########################################################################
2#
3# TimedHTMLPlug.pm --
4#
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# Copyright (C) 1999 New Zealand Digital Library Project
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24#
25###########################################################################
26
27
28package TimedHTMLPlugin;
29
30use HTMLPlugin;
31use VideoConverter;
32
33sub BEGIN {
34 @TimedHTMLPlugin::ISA = ('HTMLPlugin', 'VideoConverter');
35}
36
37
38use strict; # every perl program should have this!
39no strict 'refs'; # make an exception so we can use variables as filehandles
40
41my $arguments =
42 [
43 { 'name' => "video_excerpt_duration",
44 'desc' => "{VideoPlug.video_excerpt_duration}",
45 'type' => "string",
46 'reqd' => "no" }
47 ];
48
49
50
51
52my $options = { 'name' => "TimedHTMLPlugin",
53 'desc' => "{TimedHTMLPlugin.desc}",
54 'abstract' => "no",
55 'inherits' => "yes",
56 'args' => $arguments };
57
58
59sub new {
60 my ($class) = shift (@_);
61 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
62 push(@$pluginlist, $class);
63
64 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
65 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
66
67 new VideoConverter($pluginlist, $inputargs, $hashArgOptLists);
68
69 my $self = (defined $hashArgOptLists)
70 ? new HTMLPlugin($pluginlist,$inputargs,$hashArgOptLists)
71 : new HTMLPlugin($pluginlist,$inputargs);
72
73 my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
74
75 my $collect_bin = &util::filename_cat($collect_dir,"bin");
76 my $collect_script = &util::filename_cat($collect_bin,"script");
77
78 $ENV{'PATH'} .= ":" if (defined $ENV{'PATH'});
79 $ENV{'PATH'} .= "$collect_bin:$collect_script";
80
81 return bless $self, $class;
82}
83
84sub begin {
85 my $self = shift (@_);
86 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
87
88 $self->SUPER::begin(@_);
89 $self->VideoConverter::begin(@_);
90}
91
92
93sub init {
94 my $self = shift (@_);
95 my ($verbosity, $outhandle, $failhandle) = @_;
96
97 $self->SUPER::init(@_);
98 $self->VideoConverter::init(@_);
99}
100
101
102sub html_to_text
103{
104 my ($self, $text) = @_;
105
106 $text =~ s/<\/?[^>]*>//g;
107
108 $text =~ s/&nbsp;/ /g;
109
110 $text =~ s/\s+/ /gs;
111 $text =~ s/^\s+//;
112 $text =~ s/\s+$//;
113
114 return $text;
115}
116
117
118sub extract_metadata_table
119{
120 my ($self, $textref) = @_;
121
122 my $metatable_store = {};
123
124 my $metatable_re = "<table([^>]*)>(.*?<p class=\"?Metadata\"?>.*?)<\\/table>";
125
126 if ($$textref =~ m/$metatable_re/gsi) {
127 my $metatable_attr = $1;
128 my $metatable_body = $2;
129
130 my @tr_list = ($metatable_body =~ m/(<tr[^>]*>.*?<\/tr>)/gsi);
131
132 my @filtered_tr_list = ();
133
134 foreach my $tr (@tr_list) {
135
136 my $in_filtered_tr = 1;
137
138 my @td_list = ($tr =~ m/<td[^>]*>(.*?)<\/td>/gsi);
139 my $td_list_num = scalar(@td_list);
140
141 if ($td_list_num == 2) {
142 my $meta_name = $self->html_to_text($td_list[0]);
143 my $meta_value = $self->html_to_text($td_list[1]);
144
145 $meta_name =~ s/\s*//g;
146
147
148 if ($meta_value =~ m/^(\s*|\?+)$/) {
149 $in_filtered_tr = 0;
150 }
151 else {
152 my $meta_name_label = $meta_name;
153 $meta_name_label =~ s/\s+//g;
154
155 $metatable_store->{$meta_name_label} = $meta_value;
156
157 if ($meta_name_label =~ m/^GS\./) {
158 # even though we want to store this as metadata, we
159 # don't want this going into table presented at top of document
160 $in_filtered_tr = 0;
161 }
162
163 }
164 }
165 else {
166 print STDERR "Warning: Metadata table does not consist of two cells (metadata name : metadata value)\n";
167 print STDERR " Skipping\n";
168 }
169
170
171 if ($in_filtered_tr) {
172 push(@filtered_tr_list,$tr);
173 }
174 }
175
176 my $filtered_tr_block = join("\n",@filtered_tr_list);
177 my $filtered_table = "<table$metatable_attr>$filtered_tr_block</table>";
178
179
180 ### my $metatable_re = "<table[^>]*>.*?<p class=\"?Metadata\"?>.*?<\\/table>";
181
182### print STDERR "*** filtered table = $filtered_table\n";
183
184 $$textref =~ s/$metatable_re/$filtered_table/si;
185
186 }
187
188 return $metatable_store;
189
190}
191
192
193
194
195
196my $only_num = 0;
197my $only_limit = 100;
198
199sub hms_to_secs
200{
201 my $self = shift @_;
202 my ($hh,$mm,$ss) = @_;
203
204 return $hh*3600 + $mm*60 + $ss;
205}
206
207
208
209sub timed_event
210{
211 my $self = shift (@_);
212
213 my ($front, $tape, $hh, $mm, $ss, $back) = @_;
214
215 my $time_encoded = "$hh:$mm:$ss";
216 my $time_encoded_file = "$hh$mm$ss";
217
218 my $time_pos = $self->{'time_pos'};
219 my $time_num = scalar(@{$self->{'time_seq'}});
220
221#### my $videoconvert = $self->{'videoconvert'};
222
223 # excerpt from tim_pos -> time_pos + 2;
224 my $adv_time_pos = $time_pos+2;
225 $adv_time_pos = $time_num-1 if ($adv_time_pos>=$time_num);
226
227 my $adv_time_elem = $self->{'time_seq'}->[$adv_time_pos];
228
229# print STDERR "*** ", substr($adv_time_elem,0,800), "\n";
230
231 my ($atape,$ah,$am,$as) = ($adv_time_elem =~ m/(T\d+:) ?(\d\d):(\d\d):(\d\d)(?:\:\d\d)?/);
232
233 my $excerpt_len = undef;
234 my $time_in_secs = $self->hms_to_secs($hh,$mm,$ss);
235
236 if (!defined $tape) {
237 if (defined $self->{'ptape'}) {
238 $tape = $self->{'ptape'};
239 }
240 else {
241 print STDERR "Warning: First time offset does not define tape side\n";
242 print STDERR " Defaulting to 1\n";
243 $tape = "T1:";
244 }
245 }
246
247 if (!defined $atape) {
248 $atape = "T1";
249 }
250
251# print STDERR "**** atape = $atape\n";
252# print STDERR "*** tape = $tape\n";
253
254 if ($atape eq $tape) {
255 my $adv_time_in_secs = $self->hms_to_secs($ah,$am,$as);
256
257 $excerpt_len = $adv_time_in_secs - $time_in_secs;
258 }
259
260 my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
261
262 my $media_type = $self->{'media_type'};
263 my $media_dir = $self->{'media_dir'};
264 my $media_root = $self->{'media_root'};
265
266 my $media_base_dir = $self->{'media_base_dir'};
267
268 my $mp3_html;
269 my $avi_html;
270
271 my $tape_num = "1";
272
273 if (defined $media_type) {
274
275 my $src_file;
276 my $src_filename;
277
278 if ($media_type eq "video") {
279 $src_file = "$media_root\_01_$tape_num.VOB";
280 $src_filename
281 = &util::filename_cat($media_base_dir, $src_file);
282 }
283 elsif ($media_type =~ m/^audio$/) {
284 $src_file = "$media_root\_Tape$tape_num.mp3";
285 $src_filename
286 = &util::filename_cat($media_base_dir, $src_file);
287 }
288 else {
289 print STDERR "Warning: Unrecognised media type: $media_type\n";
290 }
291
292
293 if ($media_type eq "video") {
294
295 # video excerpt
296
297 my $encoded_file = "$media_dir\_$time_encoded_file.avi";
298
299 my $ve_filename
300 = &util::filename_cat($collect_dir,"media","video_excerpt",$encoded_file);
301
302 if ($only_num < $only_limit) {
303 if (! -e $ve_filename) {
304 # my $args = "-vcodec mpeg2video";
305 my $args = "-vcodec msmpeg4";
306
307 my $ve_cmd = "gsmpeg.sh -v 1 -i $src_filename $args -ss $time_encoded ";
308
309 if (defined $excerpt_len) {
310 $ve_cmd .= "-t $excerpt_len ";
311 }
312
313 $ve_cmd .= $ve_filename;
314
315## print STDERR "$ve_cmd\n";
316
317## `$ve_cmd`;
318 }
319
320## my $avi_url = "http://mcgonagall.cs.waikato.ac.nz:8201/gsdl/collect/hauraki2/media/video_excerpt/$media_dir\_$time_encoded_file.avi";
321 my $avi_url = "_httpprefix_/collect/hauraki2/media/video_excerpt/$media_dir\_$time_encoded_file.avi";
322
323## $avi_html = "<a class=\"mm\" href=\"$avi_url\"><img border=1 src=\"_httpcimages_\/video5.gif\"></a>";
324
325
326 ## my $stream_url = "_httpstreamserver_/$local_root.asf";
327## my $stream_url = "http://mcgonagall.cs.waikato.ac.nz:8090/$local_root.avi";
328## $avi_html .= "<a class=\"mm\" href=\"$stream_url\">Stream</a>";
329
330
331 ## $avi_html .= "<a class=\"mm\" href=\"_httpcurrentdocumentwithvplayer_\"><img border=1 src=\"_httpcimages_\/video5.gif\"></a>";
332
333 $avi_html .= "<a class=\"mm\" href=\"javascript:videoplayerseek($hh,$mm,$ss)\"><img border=1 src=\"_httpcimages_\/video5.gif\"></a>";
334
335 # save 'time-stamp' as metadata???
336
337
338
339 }
340 else {
341 $avi_html = "<img src=\"_httpcimages_\/video5.gif\">";
342 }
343 }
344
345 if ($media_type =~ m/^(video|audio)$/) {
346
347 # audio excerpt
348# my $encoded_file = "$media_dir\_$time_encoded_file.mp3";
349
350# ## my $src_file = "$media_root\_Tape$tape_num.avi";
351
352# #my $src_filename
353# # = &util::filename_cat($collect_dir,"media",$media_type ,$media_dir, $src_file);
354
355# my $ae_filename
356# = &util::filename_cat($collect_dir,"media","audio_excerpt",$encoded_file);
357
358
359 if ($only_num < $only_limit) {
360
361 $excerpt_len = 120 if (!defined $excerpt_len); #######
362
363 my ($ae_cmd,$omp3_filename,$omp3_file)
364 = $self->audio_excerpt_cmd($src_filename,
365 $hh,$mm,$ss,$excerpt_len);
366
367 my $ae_options = { @{$self->{'ffmpeg_monitor'}},
368 'message_prefix' => "Audio Excerpt",
369 'message' => "Generating audio excerpt: $omp3_file" };
370
371 my ($ae_regenerated,$ae_result,$ae_had_error)
372 = $self->run_cached_general_cmd($ae_cmd,$omp3_filename,$ae_options);
373
374 push(@{$self->{'mp3_excerpts'}}, { 'omp3_file' => $omp3_file, 'omp3_filename' => $omp3_filename} );
375
376 }
377
378
379
380
381 # if (! -e $ae_filename) {
382 if ($only_num < $only_limit) {
383# if (! -e $ae_filename) {
384
385# my $args = "-acodec mp3";
386
387# ## my $src_filename = "media/video/mirth/VTS_01_1.avi";
388# my $ae_cmd = "gsmpeg.sh -v 1 -i $src_filename $args -ss $time_encoded ";
389
390# if (defined $excerpt_len) {
391# $ae_cmd .= "-t $excerpt_len ";
392# }
393
394# $ae_cmd .= $ae_filename;
395
396## print STDERR "$ae_cmd\n";
397
398## `$ae_cmd`;
399# }
400
401
402## my $mp3_url = "http://mcgonagall.cs.waikato.ac.nz:8201/gsdl/collect/hauraki2/media/audio_excerpt/$media_dir\_$time_encoded_file.mp3";
403# my $mp3_url = "_httpprefix_/collect/hauraki2/media/audio_excerpt/$media_dir\_$time_encoded_file.mp3";
404
405 my ($voa_root) = ($src_file =~ m/^(.*)\..*?$/);
406
407 my $mp3_url = "javascript:audioexcerptplay('$voa_root','$hh','$mm','$ss')";
408
409# my $mp3_url = "_httpcollection_/index/assoc/{If}{[assocfilepath],[assocfilepath],[parent(Top):assocfilepath]}/$media_dir\_$time_encoded_file.mp3";
410
411 $mp3_html = "<a class=\"mm\" href=\"$mp3_url\"><img border=1 src=\"_httpcimages_\/audio2.gif\"></a>";
412
413# my $baseexcerpt_url = "_httpcollection_/index/assoc/{If}{[assocfilepath],[assocfilepath],[parent(Top):assocfilepath]}";
414
415##### $doc_obj->add_metadata ($section, "audioexcerpturl",$mp3_url);
416
417
418 }
419 else {
420 $mp3_html = "<img src=\"_httpcimages_\/audio2.gif\">";
421
422 }
423 }
424 }
425 else {
426 print STDERR "Warning: no media type defined.\n";
427 }
428
429
430 $only_num++;
431
432 $self->{'time_pos'}++;
433
434 my $table = "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"0\"><tr valign=\"middle\">";
435 $table .= "<td>$avi_html</td>" if (defined $avi_html);
436 $table .= "<td>$mp3_html</td>";
437 $table .= "<td>$time_encoded</td>";
438 $table .= "</tr></table>";
439
440 # my $line = "$front$avi_html&nbsp;$mp3_html&nbsp;$time_encoded$back";
441
442 my $line = "$front$table$back";
443
444 # Remember tape prefix for next call
445 $self->{'ptape'} = $tape;
446
447 return $line;
448}
449
450
451sub hyperlink_timing_info
452{
453 my ($self, $textref) = @_;
454
455 my $media_type = $self->{'media_type'};
456 my $media_dir = $self->{'media_dir'};
457 my $media_root = $self->{'media_root'};
458
459 my $front_re = "<p class=Timing><span\\s+.*?>";
460 my $tape_re = "T\\d+:";
461 my $tt_re = "\\d\\d";
462 my $back_re = ".*?<\\/span>";
463
464 my $time_match_re = "$front_re$tt_re:$tt_re:$tt_re$back_re(?:\:$tt_re)?";
465 # my $time_sub_re = "($front_re)($tape_re)? ?($tt_re):($tt_re):($tt_re)(?:\:$tt_re)?($back_re)";
466
467 my $tape_match_re = "$front_re($tape_re)? ?$tt_re:$tt_re:$tt_re(?:\:$tt_re)?$back_re";
468 my $tape_sub_re = "($front_re)($tt_re):($tt_re):($tt_re)(?:\:$tt_re)?($back_re)";
469
470
471
472 my @time_seq = ($$textref =~ m/$time_match_re/sgi);
473
474 # artifically add tape information into all time indexes
475 my $extrapolate_tape = "";
476 my $num_seq = scalar(@time_seq);
477 for (my $i=0; $i<$num_seq; $i++) {
478 my ($curr_tape) = ($time_seq[$i] =~ m/$tape_match_re/sgi);
479 if (!defined $curr_tape) {
480 $time_seq[$i] =~ s/$tape_sub_re/$1$extrapolate_tape$2:$3:$4$5/sgi;
481 }
482 else {
483 if ($curr_tape ne $extrapolate_tape) {
484 $extrapolate_tape = $curr_tape;
485 }
486 }
487 }
488
489
490 $self->{'time_seq'} = \@time_seq;
491 $self->{'time_pos'} = 0;
492
493 $$textref =~ s/(<p class=Timing><span\s+.*?>)(T\d+:)? ?(\d\d):(\d\d):(\d\d)(?:\:\d\d)?.*?(<\/span>)/$self->timed_event($1,$2,$3,$4,$5,$6)/sgie;
494
495
496 # knock out any div tags as they interfere with document broken up into sections
497 $$textref =~ s/<\/?div.*?>//gi;
498
499 # Embedded word style infomation is lost by HTMLPlug => make Question
500 # style use HTML italics
501
502 $$textref =~ s/<p class=\"Question\">(.*?)<\/p>/<p><i>$1<\/i><\/p>/gsi;
503
504}
505
506
507
508sub store_block_files
509{
510 my $self =shift (@_);
511 my ($filename_full_path, $block_hash) = @_;
512
513 # Would be better if this were tied to particular HTML docs that
514 # this plugin has processed.
515
516 # For now block all files native to DVD format
517
518 if (($filename_full_path =~ m/\.(IFO|BUP)$/) # block info and backup-info data
519 || ($filename_full_path =~ m/VIDEO_TS\..*?$/) # block top-level files
520 || ($filename_full_path =~ m/VTS_\d\d_\d\.VOB$/) #
521 ) {
522
523 $block_hash->{'file_blocks'}->{$filename_full_path} = 1;
524 }
525}
526
527sub read_block {
528 my $self = shift (@_);
529
530 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
531
532 print STDERR "***** TimedHTMLPlugin read_block\n";
533
534 my $filename = $file;
535 $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
536
537 if (($filename =~ m/\.(IFO|BUP)$/) # block info and backup-info data
538 || ($filename =~ m/VIDEO_TS\..*?$/) # block top-level files
539 || ($filename =~ m/VTS_\d\d_\d\.VOB$/) #
540 ) {
541 $self->{'num_blocked'} ++;
542 return (0,undef); # blocked
543 }
544
545
546##### || ($filename =~ m/VTS_\d\d_0\.VOB$/) # block menu item for this track
547
548
549 if (defined $self->{'file_blocks'}->{$filename} && $self->{'file_blocks'}->{$filename} == 1){
550 $self->{'num_blocked'} ++;
551 return (0,undef); # blocked
552 }
553
554
555 if (defined $self->{'re_file_block'}) {
556 my $re_file_blocks = $self->{'re_file_block'};
557 foreach my $re_file_block (@$re_file_blocks) {
558### print STDERR "**** re file block: $filename =~ m $re_file_block\n";
559 if ($filename =~ m/$re_file_block/) {
560### print STDERR "*** blocking $filename\n";
561
562 $self->{'num_blocked'} ++;
563 return (0,undef); # blocked
564 }
565 }
566 }
567
568
569 return $self->SUPER::read_block(@_);
570
571}
572
573
574sub read_file {
575 my $self = shift @_;
576 my ($filename, $encoding, $language, $textref) = @_;
577
578 $only_num = 0;
579
580 $self->SUPER::read_file(@_);
581
582 my $metatable_store = $self->extract_metadata_table($textref);
583 $self->{'metatable_store'} = $metatable_store;
584
585 my ($root, $dirname, $suffix)
586 = &File::Basename::fileparse($filename, "\\.[^\\.]+\$");
587
588 # media defaults
589 my $media_type = undef;
590 my $media_dir = $root;
591 ## my $media_root = "VTS_%02d_%02d";
592 my $media_root = "VTS";
593
594 if (defined $metatable_store->{'GS.Media'}) {
595 $media_type = $metatable_store->{'GS.Media'};
596 $media_type = lc($media_type);
597 }
598 if (defined $metatable_store->{'GS.MediaDirectory'}) {
599 $media_dir = $metatable_store->{'GS.MediaDirectory'};
600 }
601 if (defined $metatable_store->{'GS.MediaRoot'}) {
602 $media_root = $metatable_store->{'GS.MediaRoot'};
603 }
604
605 $self->{'media_type'} = $media_type;
606 $self->{'media_dir'} = $media_dir;
607 $self->{'media_root'} = $media_root;
608
609 my $media_base_dir = &util::filename_cat($dirname,$media_dir);
610 $self->{'media_base_dir'} = $media_base_dir;
611
612 $self->{'vob_duration_info'} = &VideoConverter::vob_durations($media_base_dir,"1",$self->{'outhandle'});
613
614## $self->hyperlink_timing_info($textref);
615
616 # Convert entities to their UTF8 equivalents
617 $$textref =~ s/&(lt|gt|amp|quot|nbsp);/&z$1;/go;
618 $$textref =~ s/&([^;]+);/&ghtml::getcharequiv($1,1)/gseo;
619 $$textref =~ s/&z(lt|gt|amp|quot|nbsp);/&$1;/go;
620}
621
622
623sub streamable_video
624{
625 my $self = shift (@_);
626
627 my ($base_dir,$filename,$doc_obj,$section) = @_;
628
629 my $outhandle = $self->{'outhandle'};
630 my $verbosity = $self->{'verbosity'};
631
632 my $media_base_dir = $self->{'media_base_dir'};
633
634 #---
635 # Determine size of input video
636
637 my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
638
639 my $media_type = $self->{'media_type'};
640 my $media_dir = $self->{'media_dir'};
641 my $media_root = $self->{'media_root'};
642
643 my $tape_num = "1";
644
645 my $src_file;
646 my $src_filename;
647
648 if ($media_type eq "video") {
649 $src_file = "$media_root\_01_$tape_num.VOB";
650 $src_filename
651 = &util::filename_cat($media_base_dir, $src_file);
652 }
653 elsif ($media_type =~ m/^audio$/) {
654 $src_file = "$media_root\_Tape$tape_num.mp3";
655 $src_filename
656 = &util::filename_cat($media_base_dir, $src_file);
657 }
658 else {
659 print STDERR "Warning: Unrecognised media type: $media_type\n";
660 }
661
662 if (-e $src_filename) {
663 $self->{'file_blocks'}->{$src_filename} = 1;
664
665 my $re_file_block = $src_filename;
666 $re_file_block =~ s/_01_$tape_num.VOB$/_\\d+_\\d+.VOB\$/;
667
668
669 push(@{$self->{'re_file_block'}},$re_file_block);
670 }
671
672 my ($video_type, $video_width, $video_height, $video_duration, $video_size,
673 $vcodec,$vfps,$atype,$afreq,$achan,$arate)
674 = &VideoConverter::identify($src_filename, $outhandle, $verbosity);
675
676 if ($vfps eq "unknown") {
677 print $outhandle "Unknown framerate, defaulting to 25 frames per second.\n";
678 $vfps = 25;
679 }
680
681### print STDERR "*** video duration = $video_duration\n";
682 my ($dur_hour,$dur_min,$dur_sec)
683 = ($video_duration =~ m/(\d+):(\d+):(\d+\.\d+)/);
684 my $total_dur_secs = $dur_hour*3600 + $dur_min*60 + $dur_sec;
685
686 $self->{'video-fps'} = $vfps;
687 $self->{'num-total-frames'} = $total_dur_secs * $vfps;
688
689
690 # shorten duration prcessed for experimentation purposes
691 my $exp_duration = undef;
692
693 my $video_excerpt_duration = $self->{'video_excerpt_duration'};
694
695 print STDERR "**** video duration (secs) = $total_dur_secs\n";
696
697
698 if ((defined $video_excerpt_duration) && ($video_excerpt_duration ne "")) {
699 $exp_duration = $video_excerpt_duration;
700 my ($hh,$mm,$ss,$ms) = ($exp_duration =~ m/^(\d\d):(\d\d):(\d\d)\.?(\d\d)?/);
701 my $excerpt_dur_in_secs = $hh * 3600 + $mm * 60 + $ss;
702
703 if ($excerpt_dur_in_secs < $total_dur_secs) {
704 $self->{'num-total-frames'} = $excerpt_dur_in_secs * $vfps; # override calculation for full length duration
705 }
706 else {
707 # clip is already shorter than requested video excerpt duration
708 # set exp_duration back to undefined
709 $exp_duration = undef;
710 }
711 }
712
713 print $outhandle "TimedHTMLPlug: Preparing video files associated with $filename for HTMLPlug\n";
714
715 if (defined $exp_duration)
716 {
717 print $outhandle "Only encoding first $exp_duration of video.\n";
718 $self->{'exp_duration'} = $exp_duration;
719 }
720
721
722### my $videoconvert
723### = new videoconvert($base_dir,$src_filename,$verbosity,$outhandle,$exp_duration);
724### $self->{'videoconvert'} = $videoconvert;
725# ******
726
727 $self->init_cache_for_file($src_filename);
728
729 #---
730 # Generate the Flash FLV format for streaming purposes
731
732 my $streaming_bitrate = "256k"; # used to be 192k
733 my $streaming_size = "360"; # used to be 352 (CIF?)
734 my $streaming_achan = "1";
735 my $streaming_arate = "44100";
736 my $streaming_quality = "high";
737
738 #---
739 # Convert video to flash
740 #---
741 my ($stream_cmd,$oflash_filename,$oflash_file)
742 = $self->stream_cmd($src_filename,
743 $video_width,$video_height,
744 $streaming_quality, $streaming_bitrate, $streaming_size,
745 $streaming_achan, $streaming_arate);
746
747 my $streamable_options = { @{$self->{'ffmpeg_monitor'}},
748 'message_prefix' => "Stream",
749 'message' => "Generating streamable video: $oflash_file" };
750
751 my ($streamable_regenerated,$streamable_result,$streamable_had_error)
752 = $self->run_cached_general_cmd($stream_cmd,$oflash_filename,$streamable_options);
753
754 $self->{'streamable_regenerated'} = $streamable_regenerated;
755
756 if (!$streamable_had_error) {
757 #---
758 # Make video seekable
759 #---
760 my ($streamseekable_cmd,$ostreamseekable_filename) = $self->streamseekable_cmd($oflash_filename);
761
762 my $streamseekable_options = { @{$self->{'flvtool2_monitor'}},
763 'message_prefix' => "Stream Seekable",
764 'message' => "Reprocessing video stream to be seekable by timeline: $oflash_file" };
765
766 if ($streamable_regenerated) {
767 $self->run_general_cmd($streamseekable_cmd,$streamseekable_options);
768 }
769
770 my $streamable_url = $oflash_file;
771## $streamable_url =~ s/ /%20/g;
772
773 $doc_obj->add_metadata ($section, "streamablevideo", $streamable_url);
774 $doc_obj->associate_file($oflash_filename,$oflash_file,"video/flash",
775 $section);
776 }
777
778 #
779 # FlowPlayer.swf height+22 pixels
780 # FlowPlayerBlack.swf height+16 pixels
781 # FlowPlayerThermo.swf height+16 pixels
782 # FlowPlayerWhite.swf height+26 pixels
783 $doc_obj->add_metadata ($section, "flashwidth", $video_width);
784 $doc_obj->add_metadata ($section, "flashheight", $video_height + 22 + 100);
785
786 my $base_url = "_httpstreamserverprefix_/collect/[collection]/index/assoc/{If}{[assocfilepath],[assocfilepath],[parent(Top):assocfilepath]}/";
787
788 $doc_obj->add_metadata ($section, "baseurl",$base_url);
789
790 $self->{'oflash_file'} = $oflash_file;
791 $self->{'oflash_filename'} = $oflash_filename;
792
793}
794
795
796
797sub add_cuepoints
798{
799 my ($self) = shift @_;
800 my ($doc_obj) = @_;
801
802 my $section = $doc_obj->get_top_section();
803 my $chapters = $doc_obj->get_children($section);
804
805
806 # open file
807 my $output_dir = $self->{'cached_dir'};
808 my $cue_filename = &util::filename_cat($output_dir,"on_cue.xml");
809
810 open(CUEOUT,">$cue_filename")
811 || die "Unable to open $cue_filename: $!\n";
812 print CUEOUT "<tags>\n";
813
814
815 my $cc = 0;
816
817 foreach my $chap (@$chapters)
818 {
819 $cc++;
820
821 my $chap_text = $doc_obj->get_text($chap);
822
823 my @cuepoints
824 = ($chap_text =~ m/<p class=Timing><span\s+.*?>(?:T\d+:)? ?(\d\d:\d\d:\d\d)(?:\:\d\d)?/gsi);
825
826 my $count = 0;
827
828 foreach my $cuepoint (@cuepoints)
829 {
830 my ($hh,$mm,$ss) = ($cuepoint =~ m/(\d\d):(\d\d):(\d\d)/);
831
832 my $cuept_insecs = $self->hms_to_secs($hh,$mm,$ss);
833
834 if ($cuept_insecs < 2) {
835 $cuept_insecs += 2;
836 }
837 my $cuept_inmsecs = 1000 * $cuept_insecs;
838
839 $doc_obj->add_metadata($section,"cuepoint",$cuept_inmsecs);
840 my $chap_title = $doc_obj->get_metadata_element($chap,"Title");
841
842 # Navigation point (used in seeking)
843# print CUEOUT " <metatag event=\"onCuePoint\" overwrite=\"true\">\n";
844# print CUEOUT " <name>$chap_title</name>\n";
845# print CUEOUT " <timestamp>$cuept_inmsecs</timestamp>\n";
846# print CUEOUT " <parameters>\n";
847# print CUEOUT " <thumb>dummy</thumb>\n";
848# print CUEOUT " <sectionnum>$chap</sectionnum>\n";
849# print CUEOUT " <subsectionnum>$count</subsectionnum>\n";
850# print CUEOUT " <cuept>$cuept_inmsecs</cuept>\n";
851# print CUEOUT " </parameters>\n";
852# print CUEOUT " <type>navigation</type>\n";
853# print CUEOUT " </metatag>\n";
854
855
856# print CUEOUT " <metatag event=\"onCuePoint\" overwrite=\"true\">\n";
857# print CUEOUT " <name>$chap_title</name>\n";
858# print CUEOUT " <timestamp>$cuept_inmsecs</timestamp>\n";
859# print CUEOUT " <parameters>\n";
860# print CUEOUT " <thumb>foo.jpg</thumb>\n";
861# print CUEOUT " </parameters>\n";
862# print CUEOUT " <type>navigation</type>\n";
863# print CUEOUT " </metatag>\n";
864
865 if ($count==0)
866 {
867 # Event (used to hook in to javascipt callback)
868 # Only do for the first in each chapter
869
870 print CUEOUT " <metatag event=\"onCuePoint\" overwrite=\"true\">\n";
871## print CUEOUT " <name>Test $cc</name>\n";
872 print CUEOUT " <name>$chap_title</name>\n";
873 print CUEOUT " <timestamp>$cuept_inmsecs</timestamp>\n";
874 print CUEOUT " <parameters>\n";
875 print CUEOUT " <cuept>$cuept_inmsecs</cuept>\n";
876 print CUEOUT " <sectionnum>$chap</sectionnum>\n";
877 print CUEOUT " </parameters>\n";
878 print CUEOUT " <type>event</type>\n";
879## print CUEOUT " <type>actionscript</type>\n";
880 print CUEOUT " </metatag>\n";
881 }
882
883 $count++;
884 }
885 }
886
887
888 print CUEOUT "</tags>\n";
889 close(CUEOUT);
890
891#### my $videoconvert = $self->{'videoconvert'};
892 my $oflash_filename = $self->{'oflash_filename'};
893 my $oflash_file = $self->{'oflash_file'};
894
895 my ($streamcuepts_cmd,$ostreamcuepts_filename) = $self->streamcuepts_cmd($oflash_filename);
896
897 my $verbosity = $self->{'verbosity'};
898 my $outhandle = $self->{'outhandle'};
899
900 my $streamcuepts_options = { @{$self->{'flvtool2_monitor'}},
901 'message_prefix' => "Stream Cue Points",
902 'message' => "Reprocessing video stream to add cuepoints on timeline: $oflash_file" };
903
904 my $streamable_regenerated = $self->{'streamable_regenerated'};
905
906 if ($streamable_regenerated) {
907 $self->run_general_cmd($streamcuepts_cmd,$streamcuepts_options);
908 }
909
910
911
912}
913
914
915
916sub process {
917 my $self = shift (@_);
918 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
919
920 my $filename = $file;
921 $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
922
923 my $top_section = $doc_obj->get_top_section();
924
925 $self->streamable_video($base_dir,$filename,$doc_obj,$top_section);
926
927 $self->hyperlink_timing_info($textref);
928
929 foreach my $mp3_excerpt (@{$self->{'mp3_excerpts'}}) {
930 my $omp3_file = $mp3_excerpt->{'omp3_file'};
931 my $omp3_filename = $mp3_excerpt->{'omp3_filename'};
932
933 $doc_obj->associate_file($omp3_filename,$omp3_file,"audio/mp3",
934 $top_section);
935 }
936 $self->{'mp3_excerpts'} = undef;
937
938 my $metatable_store = $self->{'metatable_store'};
939 foreach my $metaname (keys %$metatable_store) {
940 my $metadata = $metatable_store->{$metaname};
941 $doc_obj->add_metadata($top_section,$metaname,$metadata);
942 }
943 $self->{'metatable_store'} = undef;
944
945 my $ret_val = $self->SUPER::process(@_);
946
947 $self->add_cuepoints($doc_obj);
948
949
950 return $ret_val;
951
952}
953
954
955
956sub replace_images {
957 my $self = shift (@_);
958 my ($front, $link, $back, $base_dir,
959 $file, $doc_obj, $section) = @_;
960
961 if ($link =~ m/^"?_.*?_"?\//) {
962 # variety of greenstone macro, so let through unchanged
963 return $front . $link . $back ;
964 }
965
966 return $self->SUPER::replace_images(@_);
967}
968
969
970
971
972
973sub replace_href_links {
974 my $self = shift (@_);
975 my ($front, $link, $back, $base_dir, $file, $doc_obj, $section) = @_;
976
977
978 if ($link =~ m/^"?_.*?_"?/) {
979 # variety of greenstone macro, so let through unchanged
980 return $front . $link . $back ;
981 }
982
983 return $self->SUPER::replace_href_links(@_);
984}
985
9861;
Note: See TracBrowser for help on using the repository browser.