Changeset 21335


Ignore:
Timestamp:
2009-12-11T00:16:34+13:00 (13 years ago)
Author:
davidb
Message:

Support added for -keep_keyframes option

Location:
gs2-extensions/gsdl-video/trunk/perllib/plugins
Files:
2 edited

Legend:

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

    r20492 r21335  
    106106    'deft' => "200k",
    107107    'reqd' => "no" },
    108       { 'name' => "extractkeyframes",
     108      { 'name' => "extract_keyframes",
    109109    'desc' => "{VideoPlugin.extractkeyframes}",
    110110    'type' => "flag",
    111111    'deft' => "0",
     112    'reqd' => "no" },
     113      { 'name' => "keep_keyframes",
     114    'desc' => "{VideoPlugin.keep_keyframes}",
     115    'type' => "string",
     116    'deft' => "all",
    112117    'reqd' => "no" },
    113118      { 'name' => "streamingsize",
     
    590595    my $ivideo_root = $self->{'cached_file_root'};
    591596
     597    ## my $cue_filename = &util::filename_cat($output_dir,"on_cue.xml");
     598
     599    my $flvtool_cmd = "flvtool2 -vUP \"$oflash_filename\"";
     600
     601    return ($flvtool_cmd,$oflash_filename);
     602}
     603
     604
     605sub streamkeyframes_cmd
     606{
     607    my $self = shift (@_);
     608    my ($oflash_filename,$doc_obj,$section) = @_;
     609
     610    my $assocfilepath
     611    = $doc_obj->get_metadata_element($section,"assocfilepath");
     612
     613    my $output_dir = $self->{'cached_dir'};
     614
    592615    my $cue_filename = &util::filename_cat($output_dir,"on_cue.xml");
    593 
    594     my $flvtool_cmd = "flvtool2 -vUP \"$oflash_filename\"";
     616 
     617    my $flvtool_cmd = "flvtool2 -vAUtP \"$cue_filename\" \"$oflash_filename\"";
    595618
    596619    return ($flvtool_cmd,$oflash_filename);
     
    598621
    599622
    600 sub streamkeyframes_cmd
     623sub streamkeyframes_cmd_old
    601624{
    602625    my $self = shift (@_);
     
    633656    my $cue_filename = &util::filename_cat($output_dir,"on_cue.xml");
    634657
    635     my $video_server = $ENV{'GEXT_VIDEO_SERVER'};
    636     my $video_prefix = $ENV{'GEXT_VIDEO_PREFIX'};
    637 
    638     my $collect = $ENV{'GSDLCOLLECTION'};
     658    ##my $video_server = $ENV{'GEXT_VIDEO_SERVER'};
     659    ##my $video_prefix = $ENV{'GEXT_VIDEO_PREFIX'};
     660
     661    ## my $collect = $ENV{'GSDLCOLLECTION'};
    639662
    640663    ## my $thumbloc = "$video_server$video_prefix/collect/$collect";
     
    685708    }
    686709    else {
    687     # extractkeyframe has either not been switched on, or else had
     710    # extract_keyframe has either not been switched on, or else had
    688711    # a problem when running
    689712    # => extract a from
     
    770793    my ($self) = shift(@_);
    771794
    772     my ($doc_obj,$section) = @_;
    773 
    774     my $output_dir = $self->{'cached_dir'};
    775     my $timeline = $self->{'keyframe_timeline'};
     795    my ($doc_obj,$section,$timeline) = @_;
     796
     797    my $output_dir = $self->{'cached_dir'};
    776798   
    777799    my $count = 1;
     
    786808                 $section);
    787809    $doc_obj->add_utf8_metadata($section,"KeyframeTimestamp",$timestamp);
     810    $doc_obj->add_utf8_metadata($section,"KeyframeFrameNum",$t);
    788811
    789812    $count++;
    790813    }
    791814
    792     $doc_obj->add_utf8_metadata($section,"NumKeyframes",scalar(@{$self->{'keyframe_fnames'}}));
     815    #### $doc_obj->add_utf8_metadata($section,"NumKeyframes",scalar(@{$self->{'keyframe_fnames'}}));
     816
     817    $doc_obj->add_utf8_metadata($section,"NumKeyframes",scalar(keys %$timeline));
    793818
    794819
     
    933958    my $flashheight = $video_height + 22;
    934959
    935     if ($self->{'extractkeyframes'}) {
     960    if ($self->{'extract_keyframes'}) {
    936961    $flashheight += 100;
    937962    }
     
    10201045    my $flashheight = $video_height + 22;
    10211046
    1022     if ($self->{'extractkeyframes'}) {
     1047    if ($self->{'extract_keyframes'}) {
    10231048    $flashheight += 100;
    10241049    }
  • gs2-extensions/gsdl-video/trunk/perllib/plugins/VideoPlugin.pm

    r20492 r21335  
    141141    $self->run_cached_general_cmd($keyframe_cmd,$okeyframe_filename,$keyframe_options);
    142142    $self->parse_shot_xml();
    143     $self->associate_keyframes($doc_obj,$section);
     143
     144    my $keep_keyframe_timeline = $self->{'keep_keyframe_timeline'};
     145    $self->associate_keyframes($doc_obj,$section,$keep_keyframe_timeline);
     146
    144147}
    145148
     
    520523
    521524
    522     if ($self->{'extractkeyframes'}) {
     525    if ($self->{'extract_keyframes'}) {
    523526    $self->extract_keyframes($doc_obj,$originalfilename,$filename);
    524527    }
     
    573576
    574577
    575     if ($self->{'extractkeyframes'}) {
     578    if ($self->{'extract_keyframes'}) {
    576579    $self->extract_keyframes_montage($doc_obj,$filename,$thumbnailtype);
    577580    }
     
    628631    }
    629632
    630     if (($self->{'enablestreaming'}) && ($self->{'extractkeyframes'})) {
     633    my $enable_streaming
     634    = ($self->{'enable_flv_streaming'} || $self->{'enable_mp4_streaming'})
     635    ? 1 : 0;
     636
     637    if (($enable_streaming) && ($self->{'extract_keyframes'})) {
    631638    my $section = $doc_obj->get_top_section();
    632639    my $oflash_filename = $self->{'oflash_filename'};
     
    663670    my $num_total_frames = $self->{'num-total-frames'};
    664671
    665     my $frame_delta = $num_total_frames/$num_dist_frames;
     672    my $keep_timeline = {};
     673
     674    my $frame_delta;
     675    if ($num_dist_frames eq "all") {
     676    $frame_delta = undef;
     677    }
     678    else {
     679    $frame_delta = $num_total_frames/$num_dist_frames;
     680    }
    666681
    667682    my $closest_to = $frame_delta;
     
    670685#    print STDERR "*** num total frames  = $num_total_frames\n";
    671686#    print STDERR "*** frame delta = $frame_delta\n";
     687
     688    my $keep_keyframe_num = 1;
    672689
    673690    foreach my $curr_t (sort { $a <=> $b } keys %$timeline)
     
    675692#   print STDERR "*** curr_t = $curr_t\n";
    676693   
    677     if ($curr_t>$closest_to) {
     694    my $timeline_rec = undef;
     695
     696    if (!defined $closest_to) {
     697        $timeline_rec = $timeline->{$curr_t};
     698        $keep_timeline->{$curr_t} = $timeline_rec;
     699    }
     700    elsif ($curr_t>$closest_to) {
    678701        # decide if previous t (prev_t_ or current t (curr_t) is closest
    679 
    680         my $timeline_rec;
    681702
    682703        my $prev_t_dist = $closest_to - $prev_t;
     
    685706        if ($curr_t_dist <= $prev_t_dist)
    686707        {
    687         $timeline_rec = $timeline->{$curr_t}
     708        $timeline_rec = $timeline->{$curr_t};
     709        $keep_timeline->{$curr_t} = $timeline_rec;
     710
    688711        }
    689712        else
    690713        {
    691         $timeline_rec = $timeline->{$prev_t}
     714        $timeline_rec = $timeline->{$prev_t};
     715        $keep_timeline->{$prev_t} = $timeline_rec;
    692716        }
     717
     718        $closest_to += $frame_delta;
     719    }
     720
     721    if (defined $timeline_rec) {
    693722
    694723        my $name      = $timeline_rec->{'name'};
    695724        my $timestamp = $timeline_rec->{'timestamp'};
    696725        my $thumb     = $timeline_rec->{'thumb'};
     726        my $keyframe_num = $timeline_rec->{'keyframenum'};
    697727
    698728
     
    702732        print CUEOUT "    <parameters>\n";
    703733        print CUEOUT "      <thumb>$thumb</thumb>\n";
     734        print CUEOUT "      <keyframeNum>$keyframe_num</keyframeNum>\n";
     735        print CUEOUT "      <keepKeyframeNum>$keep_keyframe_num</keepKeyframeNum>\n";
    704736        print CUEOUT "    </parameters>\n";
    705737        print CUEOUT "    <type>navigation</type>\n";
     
    718750#       print CUEOUT "  </metatag>\n";
    719751
    720         $closest_to += $frame_delta;
     752        $keep_keyframe_num++;
     753
    721754    }
    722755    $prev_t = $curr_t;
    723756    }
     757
     758    $self->{'keep_keyframe_timeline'} = $keep_timeline;
    724759}
    725760
     
    839874                 'keyframeindex' => $keyframe_index,
    840875                 'timestamp' => $time_msec,
    841                  'thumb' => $thumb_file };
     876                 'thumb' => $thumb_file,
     877                 'keyframenum' => $keyframe_index};
    842878
    843879        $self->{'keyframe_timeline'}->{$half_frame_num}=$timeline_rec;
    844 
    845880    }
    846881
     
    867902                 'keyframeindex' => $keyframe_index,
    868903                 'timestamp' => $time_msec,
    869                  'thumb' => $thumb_file };
     904                 'thumb' => $thumb_file,
     905                 'keyframenum' => $keyframe_index};
    870906
    871907    $self->{'keyframe_timeline'}->{$avg_frame_num}=$timeline_rec;
    872 
    873908
    874909    # $self->{'flowplayer_thumblist'} .= "\\{ thumbNail: '$thumb_file', time: $time_sec \\},";
     
    884919    if ($element eq "seg") {
    885920
    886     $self->output_distributed_keyframes($self->{'keyframe_timeline'},6);
     921    $self->output_distributed_keyframes($self->{'keyframe_timeline'},$self->{'keep_keyframes'});
    887922
    888923
Note: See TracChangeset for help on using the changeset viewer.