Changeset 18476 for extensions

Show
Ignore:
Timestamp:
09.02.2009 16:13:45 (11 years ago)
Author:
davidb
Message:

Upgrading VideoPlugin? to work with global file block

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • extensions/gsdl-video/trunk/perllib/plugins/VideoPlugin.pm

    r18425 r18476  
    1 ######################################################################## 
     1###################################################################### 
    22# 
    3 # VideoPlug.pm -- plugin for processing video largely based on ImagePlug 
     3# VideoPlugin.pm -- plugin for processing video largely based on ImagePlug 
    44# A component of the Greenstone digital library software 
    55# from the New Zealand Digital Library Project at the  
     
    2828use strict; 
    2929no strict 'refs'; # allow filehandles to be variables and viceversa 
     30no strict 'subs'; 
    3031 
    3132use videoconvert; 
     
    4344 
    4445} 
     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 
     53our $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 
    4563 
    4664my $arguments = 
     
    5068    'deft' => &get_default_process_exp(), 
    5169    '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 
    5278      { 'name' => "noscaleup", 
    5379    'desc' => "{VideoPlug.noscaleup}", 
     
    138164    'reqd' => "no" } ]; 
    139165 
    140 my $options = { 'name'     => "VideoPlug", 
     166my $options = { 'name'     => "VideoPlugin", 
    141167        'desc'     => "{VideoPlug.desc}", 
    142168        'abstract' => "no", 
     
    168194    my $result = `ffmpeg -h 2>&1`; 
    169195 
     196 
    170197    if (!defined $result || $result !~ m/^FFmpeg version/) { 
    171         $self->{'ffmpeg_not_installed'} = 1; 
     198        $self->{'ffmpeg_installed'} = 0; 
    172199        print STDERR $result; 
    173200    } 
     201    else { 
     202        $self->{'ffmpeg_installed'} = 1; 
     203    } 
     204 
    174205    } 
    175206 
     
    212243    my $self = shift (@_); 
    213244 
    214     return q^\.(?i)(mpe?g|flv|qt|vob|avi)$^;  
     245    return q^(?i)\.(mpe?g|flv|mov|qt|wmv|vob|avi|mp4|m4v)$^;  
    215246} 
    216247 
     
    247278    my $minimumsize = $self->{'minimumsize'}; 
    248279    if (defined $minimumsize && (-s $filename < $minimumsize)) { 
    249         print $outhandle "VideoPlug: \"$filename\" too small, skipping\n" 
     280        print $outhandle "VideoPlugin: \"$filename\" too small, skipping\n" 
    250281        if ($verbosity > 1); 
    251282    } 
     
    559590    } 
    560591 
     592 
    561593    if ($self->{'extractkeyframes'}) { 
    562594 
     
    584616    } 
    585617 
    586  
    587      
    588618    # Make a screen-sized version of the picture if requested 
    589619    if ($self->{'extractscreenview'}) { 
     
    626656        $doc_obj->add_utf8_metadata ($section, "screenicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Screen]\" width=[ScreenWidth] height=[ScreenHeight]>"); 
    627657    } else { 
    628         print $outhandle "VideoPlug: couldn't find \"$screenviewfilename\"\n"; 
     658        print $outhandle "VideoPlugin: couldn't find \"$screenviewfilename\"\n"; 
    629659    } 
    630660    } 
     
    636666 
    637667 
    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) = @_; 
     668sub read_into_doc_obj { 
     669    my $self = shift (@_);   
     670    my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs, $total_count, $gli) = @_; 
    650671 
    651672    my $outhandle = $self->{'outhandle'}; 
    652673 
    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" 
    659677        if $self->{'verbosity'} > 1; 
    660678 
    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    } 
    681705     
    682     # create a new document 
    683     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 info 
    689     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 processing 
    698     } 
    699  
    700     #create an empty text string so we don't break downstream plugins  
    701     my $text = &gsprintf::lookup_string("{BasePlugin.dummy_text}"); 
    702706    # include any metadata passed in from previous plugins  
    703707    # note that this metadata is associated with the top level section 
    704708    my $section = $doc_obj->get_top_section(); 
     709    # can we merge these two methods?? 
     710    $self->add_associated_files($doc_obj, $filename_full_path); 
    705711    $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); 
    717713 
    718714    # if we haven't found any Title so far, assign one 
    719715    # 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     
    732718    $self->add_OID($doc_obj); 
    733719 
    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> ### 
    740722 
    741723    if (($self->{'enablestreaming'}) && ($self->{'extractkeyframes'})) { 
     
    753735    $videoconvert->run_general_cmd($streamkeyframes_cmd,$streamkeyframes_options); 
    754736    } 
    755  
    756  
    757     $self->{'num_processed'}++; 
    758  
    759     return 1; 
    760 } 
     737    ### </Video Specific> ### 
     738     
     739    return (1,$doc_obj); 
     740} 
     741 
     742sub 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 
    761754 
    762755# do plugin specific processing of doc_obj 
    763756sub process { 
    764757    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 
    766761    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 
    768801    return 1; 
    769 } 
     802 
     803} 
     804 
    770805 
    771806