Changeset 18476 for extensions
- Timestamp:
- 2009-02-09T16:13:45+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/gsdl-video/trunk/perllib/plugins/VideoPlugin.pm
r18425 r18476 1 ###################################################################### ##1 ###################################################################### 2 2 # 3 # VideoPlug .pm -- plugin for processing video largely based on ImagePlug3 # VideoPlugin.pm -- plugin for processing video largely based on ImagePlug 4 4 # A component of the Greenstone digital library software 5 5 # from the New Zealand Digital Library Project at the … … 28 28 use strict; 29 29 no strict 'refs'; # allow filehandles to be variables and viceversa 30 no strict 'subs'; 30 31 31 32 use videoconvert; … … 43 44 44 45 } 46 47 48 # Customized from BasePlugin. Make 'incremental' the default 49 # to avoid Greenstone hashing on the file (which in the case of video 50 # is HUGE) to generate OID. Also supress 'hash' as option so the user 51 # can't choose it. 52 53 our $oidtype_list = 54 [ { 'name' => "auto", 55 'desc' => "{BasePlugin.OIDtype.auto}" }, 56 { 'name' => "assigned", 57 'desc' => "{import.OIDtype.assigned}" }, 58 { 'name' => "incremental", 59 'desc' => "{import.OIDtype.incremental}" }, 60 { 'name' => "dirname", 61 'desc' => "{import.OIDtype.dirname}" } ]; 62 45 63 46 64 my $arguments = … … 50 68 'deft' => &get_default_process_exp(), 51 69 'reqd' => "no" }, 70 { 'name' => "OIDtype", 71 'desc' => "{import.OIDtype}", 72 'type' => "enum", 73 'list' => $oidtype_list, 74 'deft' => "incremental", 75 'reqd' => "no", 76 'modegli' => "2" }, 77 52 78 { 'name' => "noscaleup", 53 79 'desc' => "{VideoPlug.noscaleup}", … … 138 164 'reqd' => "no" } ]; 139 165 140 my $options = { 'name' => "VideoPlug ",166 my $options = { 'name' => "VideoPlugin", 141 167 'desc' => "{VideoPlug.desc}", 142 168 'abstract' => "no", … … 168 194 my $result = `ffmpeg -h 2>&1`; 169 195 196 170 197 if (!defined $result || $result !~ m/^FFmpeg version/) { 171 $self->{'ffmpeg_ not_installed'} = 1;198 $self->{'ffmpeg_installed'} = 0; 172 199 print STDERR $result; 173 200 } 201 else { 202 $self->{'ffmpeg_installed'} = 1; 203 } 204 174 205 } 175 206 … … 212 243 my $self = shift (@_); 213 244 214 return q^ \.(?i)(mpe?g|flv|qt|vob|avi)$^;245 return q^(?i)\.(mpe?g|flv|mov|qt|wmv|vob|avi|mp4|m4v)$^; 215 246 } 216 247 … … 247 278 my $minimumsize = $self->{'minimumsize'}; 248 279 if (defined $minimumsize && (-s $filename < $minimumsize)) { 249 print $outhandle "VideoPlug : \"$filename\" too small, skipping\n"280 print $outhandle "VideoPlugin: \"$filename\" too small, skipping\n" 250 281 if ($verbosity > 1); 251 282 } … … 559 590 } 560 591 592 561 593 if ($self->{'extractkeyframes'}) { 562 594 … … 584 616 } 585 617 586 587 588 618 # Make a screen-sized version of the picture if requested 589 619 if ($self->{'extractscreenview'}) { … … 626 656 $doc_obj->add_utf8_metadata ($section, "screenicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Screen]\" width=[ScreenWidth] height=[ScreenHeight]>"); 627 657 } else { 628 print $outhandle "VideoPlug : couldn't find \"$screenviewfilename\"\n";658 print $outhandle "VideoPlugin: couldn't find \"$screenviewfilename\"\n"; 629 659 } 630 660 } … … 636 666 637 667 638 639 # The VideoPlug read() function. 640 # VideoPlug overrides read() because there is no need to read the actual 641 # text of the file in, because the contents of the file is not text... 642 # 643 # Return number of files processed, undef if can't process 644 # Note that $base_dir might be "" and that $file might 645 # include directories 646 647 sub read { 648 my $self = shift (@_); 649 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_; 668 sub read_into_doc_obj { 669 my $self = shift (@_); 670 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs, $total_count, $gli) = @_; 650 671 651 672 my $outhandle = $self->{'outhandle'}; 652 673 653 #check process and block exps, smart block, etc 654 my ($block_status,$filename) = $self->read_block(@_); 655 return $block_status if ((!defined $block_status) || ($block_status==0)); 656 657 print STDERR "<Processing n='$file' p='VideoPlug'>\n" if ($gli); 658 print $outhandle "VideoPlug processing $file\n" 674 # should we move this to read? What about secondary plugins? 675 print STDERR "<Processing n='$file' p='$self->{'plugin_type'}'>\n" if ($gli); 676 print $outhandle "$self->{'plugin_type'} processing $file\n" 659 677 if $self->{'verbosity'} > 1; 660 678 661 # None of this works very well on Windows 95/98... 662 if ($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT()) { 663 if ($gli) { 664 print STDERR "<ProcessingError n='$file' r='Windows 95/98 not supported'>\n"; 665 } 666 print $outhandle "VideoPlug: Windows 95/98 not supported\n"; 667 return -1; 668 } 669 670 # None of this is going to work very well without ffmpeg 671 if ($self->{'ffmpeg_not_installed'}) { 672 if ($gli) { 673 print STDERR "<ProcessingError n='$file' r='ffmpeg not installed'>\n"; 674 } 675 print $outhandle "VideoPlug: ffmpeg not installed\n"; 676 return -1; 677 } 678 679 #if there's a leading directory name, eat it... 680 $file =~ s/^.*[\/\\]//; 679 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file); 680 681 # create a new document 682 my $doc_obj = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'}); 683 684 685 my $top_section = $doc_obj->get_top_section(); 686 687 ### <Video Specific> ### 688 $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'}); 689 ### </Video Specific> ### 690 691 692 $doc_obj->add_utf8_metadata($top_section, "Plugin", "$self->{'plugin_type'}"); 693 $doc_obj->add_utf8_metadata($top_section, "FileSize", (-s $filename_full_path)); 694 695 # sets the UTF8 filename (Source) for display and sets the url ref to URL encoded version 696 # of the UTF8 filename (SourceFile) for generated files 697 $self->set_Source_metadata($doc_obj, $filename_no_path); 698 699 700 # plugin specific stuff - what args do we need here?? 701 unless (defined ($self->process($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli))) { 702 print STDERR "<ProcessingError n='$file'>\n" if ($gli); 703 return (-1,undef); 704 } 681 705 682 # create a new document683 my $doc_obj = new doc ($filename, "indexed_doc");684 685 $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});686 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");687 688 #run convert to get the thumbnail and extract size and type info689 my $result = $self->run_convert($base_dir, $filename, $file, $doc_obj);690 691 if (!defined $result)692 {693 if ($gli) {694 print STDERR "<ProcessingError n='$file'>\n";695 }696 print $outhandle "VideoPlug: couldn't process \"$filename\"\n";697 return -1; # error during processing698 }699 700 #create an empty text string so we don't break downstream plugins701 my $text = &gsprintf::lookup_string("{BasePlugin.dummy_text}");702 706 # include any metadata passed in from previous plugins 703 707 # note that this metadata is associated with the top level section 704 708 my $section = $doc_obj->get_top_section(); 709 # can we merge these two methods?? 710 $self->add_associated_files($doc_obj, $filename_full_path); 705 711 $self->extra_metadata ($doc_obj, $section, $metadata); 706 707 # do plugin specific processing of doc_obj 708 unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) { 709 print STDERR "<ProcessingError n='$file'>\n" if ($gli); 710 return -1; 711 } 712 713 714 715 # do any automatic metadata extraction 716 $self->auto_extract_metadata ($doc_obj); 712 $self->auto_extract_metadata($doc_obj); 717 713 718 714 # if we haven't found any Title so far, assign one 719 715 # this was shifted to here from inside read() 720 $self->title_fallback($doc_obj,$section,$file); 721 722 # add an OID 723 # 724 # Caveat: Don't want to hash on the source/converted video as typically 725 # prohibitively large => temporarily set source/converted filename 726 # to 'undef' (causes set_OID to hash on metadata and text stored within 727 # $doc_ob) then restore to previous value. 728 # 729 my $stored_gsdlsourcefilename = $doc_obj->get_source_filename(); 730 $doc_obj->set_source_filename(undef); 731 716 $self->title_fallback($doc_obj,$section,$filename_no_path); 717 732 718 $self->add_OID($doc_obj); 733 719 734 $doc_obj->set_source_filename($stored_gsdlsourcefilename); 735 736 $doc_obj->add_text($section, $text); 737 738 # process the document 739 $processor->process($doc_obj); 720 721 ### <Video Specific> ### 740 722 741 723 if (($self->{'enablestreaming'}) && ($self->{'extractkeyframes'})) { … … 753 735 $videoconvert->run_general_cmd($streamkeyframes_cmd,$streamkeyframes_options); 754 736 } 755 756 757 $self->{'num_processed'}++; 758 759 return 1; 760 } 737 ### </Video Specific> ### 738 739 return (1,$doc_obj); 740 } 741 742 sub add_dummy_text { 743 my $self = shift(@_); 744 my ($doc_obj, $section) = @_; 745 746 # add NoText metadata so we can hide this dummy text in format statements 747 $doc_obj->add_metadata($section, "NoText", "1"); 748 $doc_obj->add_text($section, &gsprintf::lookup_string("{BasePlugin.dummy_text}",1)); 749 750 } 751 752 753 761 754 762 755 # do plugin specific processing of doc_obj 763 756 sub process { 764 757 my $self = shift (@_); 765 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_; 758 # options?? 759 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_; 760 766 761 my $outhandle = $self->{'outhandle'}; 767 762 763 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file); 764 765 766 if ($self->{'ffmpeg_installed'}) { 767 my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path); 768 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'}); 769 770 771 #run convert to get the thumbnail and extract size and type info 772 my $result = $self->run_convert($base_dir, $filename_full_path, 773 $url_encoded_filename, $doc_obj); 774 775 if (!defined $result) { 776 if ($gli) { 777 print STDERR "<ProcessingError n='$file'>\n"; 778 } 779 print $outhandle "VideoPlugin: couldn't process \"$filename_full_path\"\n"; 780 return (-1,undef); # error during processing 781 } 782 } 783 else { 784 if ($gli) { 785 &gsprintf(STDERR, "<Warning p='VideoPlugin' r='{VideoConverter.noconversionavailable}: {VideoConverter.".$self->{'no_image_conversion_reason'}."}'>"); 786 } 787 # all we do is add the original video file as an associated file, and set up srclink etc 788 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile(); 789 my $section = $doc_obj->get_top_section(); 790 791 $doc_obj->associate_file($filename_full_path, $assoc_file, "", $section); 792 793 $doc_obj->add_metadata ($section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">"); 794 $doc_obj->add_metadata ($section, "/srclink", "</a>"); 795 $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\" width=\"100\">"); 796 797 } 798 #we have no text - adds dummy text and NoText metadata 799 $self->add_dummy_text($doc_obj, $doc_obj->get_top_section()); 800 768 801 return 1; 769 } 802 803 } 804 770 805 771 806
Note:
See TracChangeset
for help on using the changeset viewer.