Ignore:
Timestamp:
2012-04-05T15:53:05+12:00 (12 years ago)
Author:
davidb
Message:

Updates to code that take account of changes in the central PM modules

Location:
gs2-extensions/video-and-audio/trunk/src/perllib/plugins
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/video-and-audio/trunk/src/perllib/plugins/AudioConverter.pm

    r18556 r25346  
    155155
    156156
    157 sub audio_stream_cmd
     157sub audio_stream_ffmpeg_cmd
    158158{
    159159    my $self = shift (@_);
    160     my ($iaudio_filename,
     160    my ($iaudio_filename, $ofile_ext,
    161161    $streaming_bitrate,$streaming_size,
    162162    $opt_streaming_achan, $opt_streaming_arate) = @_;
     
    171171    my $iaudio_root = $self->{'cached_file_root'};
    172172
    173     my $mp3_file = "${iaudio_root}_stream.mp3";
    174     my $mp3_filename = &util::filename_cat($output_dir,$mp3_file);
     173    my $op_file = "${iaudio_root}_stream.$ofile_ext";
     174    my $op_filename = &util::filename_cat($output_dir,$op_file);
    175175
    176176    my $exp_duration = $self->{'exp_duration'};
     
    188188
    189189    my $iaudio_filename_gsdlenv = $self->gsdlhome_independent($iaudio_filename);
    190     my $mp3_filename_gsdlenv = $self->gsdlhome_independent($mp3_filename);
    191 
    192    
    193     $ffmpeg_cmd = "ffmpeg -i \"$iaudio_filename_gsdlenv\" $all_opts -y \"$mp3_filename_gsdlenv\"";
    194 
    195     return ($ffmpeg_cmd,$mp3_filename,$mp3_file);
    196 }
     190    my $op_filename_gsdlenv = $self->gsdlhome_independent($op_filename);
     191
     192   
     193    $ffmpeg_cmd = "ffmpeg -i \"$iaudio_filename_gsdlenv\" $all_opts -y \"$op_filename_gsdlenv\"";
     194
     195    return ($ffmpeg_cmd,$op_filename,$op_file);
     196}
     197
     198
     199
     200sub stream_mp4_audio_cmd
     201{
     202    my $self = shift (@_);
     203    my ($ivideo_filename,$streaming_HQ_size, $streaming_HQ_AudioBitrate) = @_;
     204
     205    my $output_dir = $self->{'cached_dir'};
     206    my $ivideo_root = $self->{'cached_file_root'};
     207
     208    my $omp4_file = "${ivideo_root}_aHQstream.mp4";
     209    my $omp4_filename = &util::filename_cat($output_dir,$omp4_file);
     210
     211
     212    #my $exp_duration = $self->{'exp_duration'};
     213    #my $t_opt = (defined $exp_duration) ? "-t $exp_duration" : "";
     214
     215    my $deinterlace = $self->{'videoDeinterlacingFilter'};
     216    my $video_processing_parameters;   
     217    # Use specific resizing algorythms depending if we need to downsize the video resolution or not
     218    if(!$streaming_HQ_size || $streaming_HQ_size eq "fullsize") {
     219        $video_processing_parameters = "--strict-anamorphic";
     220    } else {
     221        $video_processing_parameters = "-w $streaming_HQ_size --loose-anamorphic";
     222    }
     223    # Use the deinterlace video filter if enabled in the plugin
     224    if ($deinterlace eq "true")
     225    {
     226        $video_processing_parameters .= " --decomb";
     227    }
     228
     229    my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
     230    my $omp4_filename_gsdlenv = $self->gsdlhome_independent($omp4_filename);
     231   
     232    # Generate the pre and post video parameters for Handbrake v0.9.4
     233    my $pre_opts = "-t 1 -c 1";
     234    my $post_opts = "-f mp4 -O $video_processing_parameters -e x264 -a 1 -E faac -6 dpl2 -R Auto -B $streaming_HQ_AudioBitrate -D 0.0 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0";
     235
     236    my $handbrake_cmd = "HandbrakeCLI.exe -i \"$ivideo_filename_gsdlenv\" $pre_opts -o \"$omp4_filename_gsdlenv\" $post_opts";
     237
     238    #print STDERR "****\nHandbrake command: $handbrake_cmd\n****\n";
     239   
     240    return ($handbrake_cmd,$omp4_filename,$omp4_file);
     241}
     242
     243
    197244
    198245
  • gs2-extensions/video-and-audio/trunk/src/perllib/plugins/AudioPlugin.pm

    r20003 r25346  
    247247
    248248    $file = $file_unicode;
    249     my $filemeta = $self->filename_to_utf8_metadata($file);
    250     my $filemeta_url_safe = $self->url_safe($filemeta);
     249#    my $filemeta = $self->filename_to_utf8_metadata($file);
     250#    my $filemeta_url_safe = $self->url_safe($filemeta);
     251
     252    my $filemeta_url_safe = &unicode::filename_to_url($file);
    251253
    252254    $doc_obj->add_utf8_metadata ($section, "Audio", $filemeta_url_safe);
     
    254256    # Also want to set filename as 'Source' metadata to be
    255257    # consistent with other plugins
    256     $doc_obj->add_utf8_metadata ($section, "Source", $filemeta_url_safe);
     258#    $doc_obj->add_utf8_metadata ($section, "Source", $filemeta_url_safe);
    257259
    258260
     
    288290    if ($self->{'enable_streaming'}) {
    289291
     292    my $enable_streaming = $self->{'enable_streaming'};
     293
    290294    # Even if the original file or 'converttotype' is set to MP3
    291295    # we'll still go ahead and generate this MP3 as it might very
     
    295299    my $streaming_size    = $self->{'streamingsize'};
    296300   
    297    
    298     my ($stream_cmd,$mp3_filename,$mp3_file)
    299         = $self->audio_stream_cmd($originalfilename || $filename,
    300                       $streaming_bitrate, $streaming_size);
     301    my $ifilename = $originalfilename || $filename;
     302   
     303    my ($stream_cmd,$mp_filename,$mp_file);
     304    if ($enable_streaming eq "mp4") {
     305        ($stream_cmd,$mp_filename,$mp_file)
     306        = $self->audio_mp4_stream_cmd($ifilename, $streaming_size,
     307                      $streaming_bitrate);
     308    }
     309    else {
     310        ($stream_cmd,$mp_filename,$mp_file)
     311        = $self->audio_stream_ffmpeg_cmd($ifilename, $enable_streaming,
     312                      $streaming_bitrate, $streaming_size,);
     313
     314    }
    301315   
    302316   
    303317    my $streamable_options = { @{$self->{'ffmpeg_monitor'}},
    304318                   'message_prefix' => "Stream",
    305                    'message' => "Generating streamable audio: $mp3_file" };
     319                   'message' => "Generating streamable audio: $mp_file" };
    306320   
    307321    my $streamable_result;
    308322    my $streamable_had_error;
    309323    ($streamable_regenerated,$streamable_result,$streamable_had_error)
    310         = $self->$optionally_run_general_cmd($stream_cmd,$mp3_filename,$streamable_options);
     324        = $self->$optionally_run_general_cmd($stream_cmd,$ifilename,$mp_filename,$streamable_options);
    311325   
    312326    if (!$streamable_had_error) {
    313327       
    314         my $streamable_url = $mp3_file;
     328        my $streamable_url = $mp_file;
    315329        my $streamable_url_safe = $self->url_safe($streamable_url);
    316330       
    317331        $doc_obj->add_utf8_metadata ($section, "streamableaudio", $streamable_url_safe);
    318         $doc_obj->associate_file($mp3_filename,$mp3_file,"audio/mpeg",
     332        $doc_obj->associate_file($mp_filename,$mp_file,"audio/mpeg",
    319333                     $section);
    320334    }
     
    322336    # The following aren't currently used
    323337   
    324     $self->{'mp3_file'} = $mp3_file;
    325     $self->{'mp3_filename'} = $mp3_filename;
     338    $self->{'mp_file'} = $mp_file;
     339    $self->{'mp_filename'} = $mp_filename;
    326340    }
    327341
  • gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoConverter.pm

    r24188 r25346  
    717717    my $post_opts = "-f mp4 -O $video_processing_parameters -e x264 -b $streaming_HQ_VideoBitrate -a 1 -E faac -6 dpl2 -R Auto -B $streaming_HQ_AudioBitrate -D 0.0 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0";
    718718
    719     my $handbrake_cmd = "HandbrakeCLI.exe -i \"$ivideo_filename_gsdlenv\" $pre_opts -o \"$omp4_filename_gsdlenv\" $post_opts";
     719    my $handbrake_cmd = "HandBrakeCLI -i \"$ivideo_filename_gsdlenv\" $pre_opts -o \"$omp4_filename_gsdlenv\" $post_opts";
    720720
    721721    #print STDERR "****\nHandbrake command: $handbrake_cmd\n****\n";
     
    10051005    my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
    10061006
    1007      # If ever reused, then needs to change to newer hashmap method
    1008      #my ($vtype, $width, $height, $duration, $vsize,
    1009         #   $vcodec ,$fps ,$atype ,$afreq ,$achan ,$arate) = identify($ivideo_filename_gsdlenv,$outhandle,0);
     1007    # If ever reused, then needs to change to newer hashmap method
     1008    #my ($vtype, $width, $height, $duration, $vsize,
     1009    #   $vcodec ,$fps ,$atype ,$afreq ,$achan ,$arate) = identify($ivideo_filename_gsdlenv,$outhandle,0);
    10101010   
    10111011    #print STDERR "***** grabbing keyframe as 50% of $video_duration\n";
     
    10151015    $command = "ffmpeg  -ss $ss_opt -i \"$ivideo_filename_gsdlenv\" -ss 4.5 -an -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -deinterlace -y \"$thumbnailfile_gsdlenv\"";
    10161016    #$command = "ffmpeg -ss 4.5 -i \"$ivideo_filename_gsdlenv\" -ss 4.5 -an -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -deinterlace -y \"$thumbnailfile_gsdlenv\"";
     1017
     1018##  $command = "ffmpeg -i \"$ivideo_filename_gsdlenv\"  -ss 10.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -deinterlace -y \"$thumbnailfile_gsdlenv\"";
     1019
     1020    $command = "ffmpeg -i \"$ivideo_filename_gsdlenv\"  -ss 16.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -deinterlace -y \"$thumbnailfile_gsdlenv\"";
     1021
    10171022
    10181023    # fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png
  • gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoPlugin.pm

    r23406 r25346  
    156156    my $self = shift (@_);
    157157    my ($doc_obj,$filename,$convertto_regenerated,$thumbnailtype,
    158     $thumbnail_width, $thumbnail_height) = @_;
     158    $thumbnail_width, $thumbnail_height,$video_duration) = @_;
    159159
    160160    my $section = $doc_obj->get_top_section();
     
    180180    # my $ofilename = $self->get_ovideo_filename($self->{'enable_streaming'});
    181181    my ($thumb_cmd ,$othumb_filename)
    182     = $self->keyframe_thumbnail_cmd($filename,$thumbnailfile,$thumbnail_width,$thumbnail_height);
     182    = $self->keyframe_thumbnail_cmd($filename,$thumbnailfile,$thumbnail_width,$thumbnail_height,$video_duration);
    183183   
    184184    my $thumb_options = { 'verbosity' => $verbosity,
     
    261261{
    262262    my $self = shift (@_);
    263     my ($doc_obj,$filename,$convertto_regenerated, $screenviewtype, $screenview_width,$screenview_height) = @_;
     263    my ($doc_obj,$filename,$convertto_regenerated, $screenviewtype, $screenview_width,$screenview_height,$video_duration) = @_;
    264264
    265265    my $section = $doc_obj->get_top_section();
     
    279279   
    280280    my ($screenview_cmd,$oscreenview_filename)
    281     = $self->keyframe_thumbnail_cmd($filename,$screenviewfilename,$screenview_width,$screenview_height);
     281    = $self->keyframe_thumbnail_cmd($filename,$screenviewfilename,$screenview_width,$screenview_height,$video_duration);
    282282
    283283    my $screenview_options = { 'message_prefix' => "Screenview",
     
    344344    = &VideoConverter::identify($filename, $outhandle, $verbosity);
    345345
    346     if ($video_duration =~ m/^(\d\d):(\d\d):(\d\d)\.(\d+)$/) {
    347     $video_duration = $1*3600 + $2*60 + $3 + ($4/10.0);
    348     }
     346
     347#    if ($video_duration =~ m/^(\d\d):(\d\d):(\d\d)\.(\d+)$/) {
     348#   $video_duration = $1*3600 + $2*60 + $3 + ($4/10.0);
     349#    }
     350
     351    my $identify_vals = &VideoConverter::identifyMI($filename, $outhandle, $verbosity);
     352    $video_duration = $identify_vals->{'duration'};
     353    $vfps           =  $identify_vals->{'fps'};
     354    $video_width    =  $identify_vals->{'width'};
     355    $video_height   =  $identify_vals->{'height'};
     356
     357    print STDERR "**** video width x height: $video_width x $video_height\n";
    349358
    350359    if ($vfps eq "unknown") {
     
    496505
    497506    $file = $file_unicode;
    498     my $filemeta = $self->filename_to_utf8_metadata($file);
    499     my $filemeta_url_safe = $self->url_safe($filemeta);
     507#    my $filemeta = $self->filename_to_utf8_metadata($file);
     508#    my $filemeta_url_safe = $self->url_safe($filemeta);
     509
     510    my $filemeta_url_safe = &unicode::filename_to_url($file);
    500511
    501512    $doc_obj->add_utf8_metadata ($section, "Video", $filemeta_url_safe);
     
    579590    my $thumbnail_height;
    580591   
     592#   if ($video_width<$video_height) {
     593#       my $scale_ratio = $video_height / $video_width;
     594#       $thumbnail_width = $thumbnailsize;
     595#       $thumbnail_height = int($thumbnailsize * $scale_ratio);
     596#   }
     597#   else {
     598## Standardizes on height, width scaled to keep aspectc ration the same
     599#       my $scale_ratio = $video_width / $video_height;
     600#       $thumbnail_width = int($thumbnailsize * $scale_ratio);
     601#       $thumbnail_height = $thumbnailsize;
     602#   }
     603
    581604    if ($video_width<$video_height) {
     605        my $scale_ratio = $video_width / $video_height;
     606        $thumbnail_width = int($thumbnailsize * $scale_ratio);
     607        $thumbnail_height = $thumbnailsize;
     608    }
     609    else {
    582610        my $scale_ratio = $video_height / $video_width;
    583611        $thumbnail_width = $thumbnailsize;
    584612        $thumbnail_height = int($thumbnailsize * $scale_ratio);
    585613    }
    586     else {
    587         my $scale_ratio = $video_width / $video_height;
    588         $thumbnail_width = int($thumbnailsize * $scale_ratio);
    589         $thumbnail_height = $thumbnailsize;
    590     }
    591614   
    592615    # for some video formats, extracted size needs to be multiple of 2
     
    594617    $thumbnail_height = int($thumbnail_height/2) * 2;
    595618
     619##  print STDERR "*** thumbsize: $thumbnailsize";
     620##  print STDERR "*** thumbnail: $thumbnail_width x $thumbnail_height\n";
     621
    596622    $self->extract_thumbnail($doc_obj,$filename,$convertto_regenerated,
    597623                 $thumbnailtype,
    598                  $thumbnail_width,$thumbnail_height);
     624                 $thumbnail_width,$thumbnail_height,
     625                 $video_duration);
    599626    }
    600627
     
    633660    $self->extract_screenview($doc_obj,$filename, $convertto_regenerated,
    634661                  $screenviewtype,
    635                   $screenview_width,$screenview_height);
     662                  $screenview_width,$screenview_height,
     663                  $video_duration);
    636664    }
    637665
Note: See TracChangeset for help on using the changeset viewer.