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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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{
Note: See TracChangeset for help on using the changeset viewer.