Changeset 19828


Ignore:
Timestamp:
2009-06-12T23:07:30+12:00 (12 years ago)
Author:
davidb
Message:

Continued development of plugins to work smoothly with Flash player

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

Legend:

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

    r19785 r19828  
    626626
    627627   
    628 ###    my $videoconvert
    629 ### = new videoconvert($base_dir,$src_filename,$verbosity,$outhandle,$exp_duration);
    630 ###    $self->{'videoconvert'} = $videoconvert;
    631 # ******
    632 
    633628    $self->init_cache_for_file($src_filename);
    634629
     630    # TimedHTML streaming isn't as complicated as VideoPlugin or AudioPlugin
     631    # => src file is never converted beforehand to another type
     632
     633    my $convertto_regenerated = 0;
     634    my $originalfilename = $src_filename;
     635
     636    my $streamable_regenerated = 0;
     637
     638    if ($media_type eq "audio") {
     639    $streamable_regenerated =
     640        $self->enable_audio_streaming($doc_obj,
     641                      $originalfilename,$src_filename,
     642                      $convertto_regenerated);
     643    }
     644    else {
     645    # generate streamable video and audio
     646    $streamable_regenerated =
     647        $self->enable_full_streaming($doc_obj,
     648                     $originalfilename,$src_filename,
     649                     $convertto_regenerated,
     650                     $video_width,$video_height);
     651    }
     652
     653    $self->{'streamable_regenerated'} = $streamable_regenerated;
     654
     655    my $base_url = "_httpstreamserverprefix_/collect/[collection]/index/assoc/{If}{[assocfilepath],[assocfilepath],[parent(Top):assocfilepath]}/";
     656
     657    $doc_obj->add_metadata ($section, "baseurl",$base_url);
     658
     659    return;
     660
     661#*********************
    635662    #---
    636663    # Generate the Flash FLV format for streaming purposes
     
    655682                   'message' => "Generating streamable video: $oflash_file" };
    656683
    657     my ($streamable_regenerated,$streamable_result,$streamable_had_error)
     684    my ($streamable_regenerated2,$streamable_result,$streamable_had_error)
    658685    = $self->run_cached_general_cmd($stream_cmd,$oflash_filename,$streamable_options);
    659686
    660     $self->{'streamable_regenerated'} = $streamable_regenerated;
     687    $self->{'streamable_regenerated2'} = $streamable_regenerated2;
    661688
    662689    if (!$streamable_had_error) {
     
    670697                       'message' => "Reprocessing video stream to be seekable by timeline: $oflash_file" };
    671698
    672     if ($streamable_regenerated) {
     699    if ($streamable_regenerated2) {
    673700        $self->run_general_cmd($streamseekable_cmd,$streamseekable_options);
    674701    }
     
    688715    # FlowPlayerWhite.swf  height+26 pixels
    689716    if ($media_type eq "audio") {
    690     $doc_obj->add_metadata ($section, "flashwidth",    $video_width);
    691     $doc_obj->add_metadata ($section, "flashheight",   22 + 100);
     717    $doc_obj->add_metadata ($section, "audioflashwidth",    $video_width);
     718    $doc_obj->add_metadata ($section, "audioflashheight",   22 + 100);
    692719    }
    693720    else {
     
    697724
    698725   
    699     my $base_url = "_httpstreamserverprefix_/collect/[collection]/index/assoc/{If}{[assocfilepath],[assocfilepath],[parent(Top):assocfilepath]}/";
    700 
    701     $doc_obj->add_metadata ($section, "baseurl",$base_url);
     726    my $base_url2 = "_httpstreamserverprefix_/collect/[collection]/index/assoc/{If}{[assocfilepath],[assocfilepath],[parent(Top):assocfilepath]}/";
     727
     728    $doc_obj->add_metadata ($section, "baseurl",$base_url2);
    702729   
    703730    $self->{'oflash_file'} = $oflash_file;
     
    815842                 'message' => "Reprocessing video stream to add cuepoints on timeline: $oflash_file" };
    816843
    817     my $streamable_regenerated = $self->{'streamable_regenerated'};
    818 
    819     if ($streamable_regenerated) {
     844    my $streamable_regenerated2 = $self->{'streamable_regenerated'};
     845
     846    if ($streamable_regenerated2) {
    820847    $self->run_general_cmd($streamcuepts_cmd,$streamcuepts_options);
    821848    }
  • extensions/gsdl-video/trunk/perllib/plugins/VideoConverter.pm

    r19785 r19828  
    373373
    374374
    375 sub stream_cmd
     375sub stream_flv_video_cmd
    376376{
    377377    my $self = shift (@_);
     
    390390    my $ivideo_root = $self->{'cached_file_root'};
    391391
    392     my $oflash_file = "${ivideo_root}_stream.flv";
     392    my $oflash_file = "${ivideo_root}_vstream.flv";
    393393    my $oflash_filename = &util::filename_cat($output_dir,$oflash_file);
    394394
     
    441441    return ($ffmpeg_cmd,$oflash_filename,$oflash_file);
    442442}
     443
     444
     445
     446
     447sub stream_flv_audio_cmd
     448{
     449    # AudioConverter also has a routine for doing this
     450    # => merge into one!
     451    # **************
     452
     453    my $self = shift (@_);
     454    my ($ivideo_filename, $opt_streaming_achan, $opt_streaming_arate) = @_;
     455
     456    # Convert either audio or video to streamable audio format
     457
     458    my $streaming_achan
     459    = (defined $opt_streaming_achan) ? $opt_streaming_achan : 2;
     460
     461    my $streaming_arate
     462    = (defined $opt_streaming_arate) ? $opt_streaming_arate : 22050;
     463
     464    my $output_dir = $self->{'cached_dir'};
     465    my $ivideo_root = $self->{'cached_file_root'};
     466
     467    my $ofla_file = "${ivideo_root}_astream.flv";
     468    my $ofla_filename = &util::filename_cat($output_dir,$ofla_file);
     469
     470    my $exp_duration = $self->{'exp_duration'};
     471    my $t_opt = (defined $exp_duration) ? "-t $exp_duration" : "";
     472
     473    my $main_opts = "-vn -y $t_opt";
     474
     475    my $stream_opts .= " -ac $streaming_achan -ar $streaming_arate";
     476
     477    my $all_opts = "$main_opts $stream_opts";
     478
     479    my $ffmpeg_cmd;
     480
     481    my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
     482    my $ofla_filename_gsdlenv = $self->gsdlhome_independent($ofla_filename);
     483    $ffmpeg_cmd = "ffmpeg -i \"$ivideo_filename_gsdlenv\" $all_opts -y \"$ofla_filename_gsdlenv\"";
     484
     485    return ($ffmpeg_cmd,$ofla_filename,$ofla_file);
     486}
     487
    443488
    444489
     
    698743
    699744
     745sub enable_audio_streaming
     746{
     747    my $self = shift (@_);
     748    my ($doc_obj,$originalfilename,$filename,$convertto_regenerated) = @_;
     749
     750    my $section = $doc_obj->get_top_section();
     751
     752    my $output_dir   = $self->{'cached_dir'};
     753    my $ivideo_root  = $self->{'cached_file_root'};
     754   
     755    # Generate FLV audio-only format for streaming purposes
     756
     757    my $optionally_run_general_cmd = "run_uncached_general_cmd";
     758    if ($self->{'enable_cache'}) {
     759    $optionally_run_general_cmd
     760        = ($convertto_regenerated) ? "regenerate_general_cmd" : "run_cached_general_cmd";
     761    }
     762
     763   
     764    my ($stream_cmd,$ofla_filename,$ofla_file)
     765    = $self->stream_flv_audio_cmd($originalfilename || $filename);
     766   
     767   
     768    my $streamable_options = { @{$self->{'ffmpeg_monitor'}},
     769                   'message_prefix' => "Stream",
     770                   'message' => "Generating streamable audio: $ofla_file" };
     771   
     772
     773    my ($streamable_regenerated,$streamable_result,$streamable_had_error)
     774    = $self->$optionally_run_general_cmd($stream_cmd,$ofla_filename,
     775                         $streamable_options);
     776
     777
     778    if (!$streamable_had_error) {
     779    my ($streamseekable_cmd,$ostreamseekable_filename) = $self->streamseekable_cmd($ofla_filename);
     780   
     781    my $streamseekable_options = { @{$self->{'flvtool2_monitor'}},
     782                       'message_prefix' => "Stream Seekable",
     783                       'message' => "Reprocessing audio stream to be seekable by timeline: $ofla_file" };
     784   
     785    if ($streamable_regenerated) {
     786        $self->run_general_cmd($streamseekable_cmd,$streamseekable_options);
     787    }
     788   
     789    my $streamable_url = $ofla_file;
     790    my $streamable_url_safe = $self->url_safe($streamable_url);
     791
     792    $doc_obj->add_utf8_metadata ($section, "streamableaudio", $streamable_url_safe);
     793    $doc_obj->associate_file($ofla_filename,$ofla_file,"audio/flash",
     794                 $section);
     795    }
     796
     797    $doc_obj->add_metadata ($section, "audioflashwidth",    400);
     798    $doc_obj->add_metadata ($section, "audioflashheight",   22 + 100);
     799
     800    $self->{'ofla_file'} = $ofla_file;
     801    $self->{'ofla_filename'} = $ofla_filename;
     802
     803    return $streamable_regenerated;
     804}
     805
     806
     807
     808
     809
     810sub enable_video_streaming
     811{
     812    my $self = shift (@_);
     813    my ($doc_obj,$originalfilename,$filename,$convertto_regenerated,
     814    $video_width,$video_height) = @_;
     815
     816    my $section = $doc_obj->get_top_section();
     817
     818    my $output_dir   = $self->{'cached_dir'};
     819    my $ivideo_root  = $self->{'cached_file_root'};
     820   
     821    # Generate the Flash FLV format for streaming purposes
     822
     823    my $optionally_run_general_cmd = "run_uncached_general_cmd";
     824    if ($self->{'enable_cache'}) {
     825    $optionally_run_general_cmd
     826        = ($convertto_regenerated) ? "regenerate_general_cmd" : "run_cached_general_cmd";
     827    }
     828
     829
     830    my $streaming_bitrate = $self->{'streamingbitrate'};
     831    my $streaming_size    = $self->{'streamingsize'};
     832   
     833    my $streaming_quality = "high";
     834   
     835    my ($stream_cmd,$oflash_filename,$oflash_file)
     836    = $self->stream_flv_video_cmd($originalfilename || $filename,
     837                     $video_width,$video_height,
     838                     $streaming_quality,
     839                     $streaming_bitrate, $streaming_size);
     840   
     841   
     842    my $streamable_options = { @{$self->{'ffmpeg_monitor'}},
     843                   'message_prefix' => "Stream",
     844                   'message' => "Generating streamable video: $oflash_file" };
     845   
     846
     847    my ($streamable_regenerated,$streamable_result,$streamable_had_error)
     848    = $self->$optionally_run_general_cmd($stream_cmd,$oflash_filename,$streamable_options);
     849   
     850    if (!$streamable_had_error) {
     851    my ($streamseekable_cmd,$ostreamseekable_filename) = $self->streamseekable_cmd($oflash_filename);
     852   
     853    my $streamseekable_options = { @{$self->{'flvtool2_monitor'}},
     854                       'message_prefix' => "Stream Seekable",
     855                       'message' => "Reprocessing video stream to be seekable by timeline: $oflash_file" };
     856   
     857    if ($streamable_regenerated) {
     858        $self->run_general_cmd($streamseekable_cmd,$streamseekable_options);
     859    }
     860   
     861    my $streamable_url = $oflash_file;
     862    my $streamable_url_safe = $self->url_safe($streamable_url);
     863   
     864    $doc_obj->add_utf8_metadata ($section, "streamablevideo", $streamable_url_safe);
     865    $doc_obj->associate_file($oflash_filename,$oflash_file,"video/flash",
     866                 $section);
     867    }
     868
     869
     870    #
     871    # FlowPlayer.swf       height+22 pixels
     872    # FlowPlayerBlack.swf  height+16 pixels
     873    # FlowPlayerThermo.swf height+16 pixels
     874    # FlowPlayerWhite.swf  height+26 pixels
     875
     876    my $flashwidth = $video_width;
     877    my $flashheight = $video_height + 22;
     878
     879    if ($self->{'extractkeyframes'}) {
     880    $flashheight += 100;
     881    }
     882
     883    $doc_obj->add_metadata ($section, "flashwidth",    $flashwidth);
     884    $doc_obj->add_metadata ($section, "flashheight",   $flashheight);
     885     
     886    $self->{'oflash_file'} = $oflash_file;
     887    $self->{'oflash_filename'} = $oflash_filename;
     888
     889    return $streamable_regenerated;
     890}
     891
     892
     893sub enable_full_streaming
     894{
     895    my $self = shift (@_);
     896    my ($doc_obj,$originalfilename,$filename,$convertto_regenerated,
     897    $video_width,$video_height) = @_;
     898
     899    my $video_streamable_regenerated
     900    = $self->enable_video_streaming($doc_obj,$originalfilename,$filename,
     901                    $convertto_regenerated,
     902                    $video_width,$video_height);
     903
     904    my $audio_streamable_regenerated
     905    = $self->enable_audio_streaming($doc_obj,$originalfilename,$filename,
     906                    $convertto_regenerated);
     907
     908    return ($video_streamable_regenerated || $audio_streamable_regenerated);
     909}
     910
     911
     912
    700913sub flvtool2_monitor_line
    701914{
  • extensions/gsdl-video/trunk/perllib/plugins/VideoPlugin.pm

    r19785 r19828  
    145145
    146146
    147 sub enable_streaming
    148 {
    149     my $self = shift (@_);
    150     my ($doc_obj,$originalfilename,$filename,$convertto_regenerated,
    151     $video_width,$video_height) = @_;
    152 
    153     my $section = $doc_obj->get_top_section();
    154 
    155     my $output_dir   = $self->{'cached_dir'};
    156     my $ivideo_root  = $self->{'cached_file_root'};
    157    
    158     # Generate the Flash FLV format for streaming purposes
    159     my $streamable_regenerated = 0;
    160 
    161     my $optionally_run_general_cmd = "run_uncached_general_cmd";
    162     if ($self->{'enable_cache'}) {
    163     $optionally_run_general_cmd
    164         = ($convertto_regenerated) ? "regenerate_general_cmd" : "run_cached_general_cmd";
    165     }
    166 
    167     my $streaming_bitrate = $self->{'streamingbitrate'};
    168     my $streaming_size    = $self->{'streamingsize'};
    169    
    170     my $streaming_quality = "high";
    171    
    172     my ($stream_cmd,$oflash_filename,$oflash_file)
    173     = $self->stream_cmd($originalfilename || $filename,
    174                 $video_width,$video_height,
    175                 $streaming_quality,
    176                 $streaming_bitrate, $streaming_size);
    177    
    178    
    179     my $streamable_options = { @{$self->{'ffmpeg_monitor'}},
    180                    'message_prefix' => "Stream",
    181                    'message' => "Generating streamable video: $oflash_file" };
    182    
    183     my $streamable_result;
    184     my $streamable_had_error;
    185     ($streamable_regenerated,$streamable_result,$streamable_had_error)
    186     = $self->$optionally_run_general_cmd($stream_cmd,$oflash_filename,$streamable_options);
    187    
    188     if (!$streamable_had_error) {
    189     my ($streamseekable_cmd,$ostreamseekable_filename) = $self->streamseekable_cmd($oflash_filename);
    190    
    191     my $streamseekable_options = { @{$self->{'flvtool2_monitor'}},
    192                        'message_prefix' => "Stream Seekable",
    193                        'message' => "Reprocessing video stream to be seekable by timeline: $oflash_file" };
    194    
    195     if ($streamable_regenerated) {
    196         $self->run_general_cmd($streamseekable_cmd,$streamseekable_options);
    197     }
    198    
    199     my $streamable_url = $oflash_file;
    200     ## $streamable_url =~ s/ /%20/g;
    201     my $streamable_url_safe = $self->url_safe($streamable_url);
    202    
    203     $doc_obj->add_utf8_metadata ($section, "streamablevideo", $streamable_url_safe);
    204     $doc_obj->associate_file($oflash_filename,$oflash_file,"video/flash",
    205                  $section);
    206     }
    207 
    208 ##    my $video_width = $doc_obj->get_metadata_element($section,"VideoWidth");
    209 ##    my $video_height = $doc_obj->get_metadata_element($section,"VideoHeight");
    210    
    211     #
    212     # FlowPlayer.swf       height+22 pixels
    213     # FlowPlayerBlack.swf  height+16 pixels
    214     # FlowPlayerThermo.swf height+16 pixels
    215     # FlowPlayerWhite.swf  height+26 pixels
    216     my $flashwidth = $video_width;
    217     my $flashheight = $video_height + 22;
    218     if ($self->{'extractkeyframes'}) {
    219     $flashheight += 100;
    220     }
    221     $doc_obj->add_metadata ($section, "flashwidth",    $flashwidth);
    222     $doc_obj->add_metadata ($section, "flashheight",   $flashheight);
    223  
    224 #### *****   
    225     # No longer used
    226 #    my $video_server = $ENV{'GEXT_VIDEO_SERVER'};
    227 #    my $video_prefix = $ENV{'GEXT_VIDEO_PREFIX'};
    228 #    my $base_url = "$video_server$video_prefix/collect/[collection]/index/assoc/[assocfilepath]/";
    229 #    my $base_url_safe = $self->url_safe($base_url);
    230 #    $doc_obj->add_utf8_metadata ($section, "baseurl",$base_url_safe);
    231    
    232     $self->{'oflash_file'} = $oflash_file;
    233     $self->{'oflash_filename'} = $oflash_filename;
    234 
    235     return $streamable_regenerated;
    236 }
    237147
    238148sub extract_thumbnail
     
    608518    if ($self->{'enable_streaming'}) { 
    609519    $streamable_regenerated
    610         = $self->enable_streaming($doc_obj,$originalfilename,$filename,
    611                       $convertto_regenerated,
    612                       $video_width,$video_height);
     520        = $self->enable_full_streaming($doc_obj,
     521                       $originalfilename,$filename,
     522                       $convertto_regenerated,
     523                       $video_width,$video_height);
    613524    }
    614525
Note: See TracChangeset for help on using the changeset viewer.