Changeset 24188


Ignore:
Timestamp:
2011-06-22T15:07:40+12:00 (13 years ago)
Author:
max
Message:

Use MediaInfo by default,
can now successfully seek into the video very fast in order to extract a frame,
for now grab a frame at 35% of the video for thumbnail and screenview

File:
1 edited

Legend:

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

    r23407 r24188  
    113113    'deft' => "200k",
    114114    'reqd' => "no" },
    115       { 'name' => "extract_keyframes",
     115   
     116      { 'name' => "create_keyframes",
    116117    'desc' => "{VideoPlugin.extractkeyframes}",
    117     'type' => "flag",
    118     'deft' => "0",
    119     'reqd' => "no" },
    120       { 'name' => "keep_keyframes",
     118    'type' => "enum",
     119    'list' => [{'name' => "true", 'desc' => "{common.true}"},
     120            {'name' => "false", 'desc' => "{common.false}"}],
     121    'deft' => "false",
     122    'reqd' => "no" },
     123       { 'name' => "keyframes_algorithm",
     124    'desc' => "{VideoPlugin.keyframesAlgorithm}",
     125    'type' => "enum",
     126    'list' => [{'name' => "mtn", 'desc' => "{keyframesAlgorithm.mtn}"},
     127        {'name' => "ffkeyframe", 'desc' => "{keyframesAlgorithm.ffkeyframe}"}],
     128    'deft' => "mtn",
     129    'reqd' => "no" },
     130   
     131      { 'name' => "ffkeyframe_num_shots",
    121132    'desc' => "{VideoPlugin.keep_keyframes}",
    122133    'type' => "string",
    123134    'deft' => "all",
    124135    'reqd' => "no" },
     136   
     137     { 'name' => "mtn_skip_intro",
     138    'desc' => "{VideoPlugin.mtnSkipIntro}",
     139    'type' => "int",
     140    'deft' => "0",
     141    'reqd' => "no" },
     142     { 'name' => "mtn_skip_end",
     143    'desc' => "{VideoPlugin.mtnSkipEnd}",
     144    'type' => "int",
     145    'deft' => "0",
     146    'reqd' => "no" },
     147     { 'name' => "mtn_timestep",
     148    'desc' => "{VideoPlugin.mtnTimestep}",
     149    'type' => "int",
     150    'deft' => "120",
     151    'reqd' => "no" },
     152     { 'name' => "mtn_detect_blanks",
     153    'desc' => "{VideoPlugin.mtnDetectBlanks}",
     154    'type' => "int",
     155    'deft' => "80",
     156    'range' => "0,100",
     157    'reqd' => "no" },
     158#   { 'name' => "mtn_detect_sharpness",
     159#   'desc' => "{VideoPlugin.mtnDetectSharpness}",
     160#   'type' => "enum",
     161#   [{'name' => "off", 'desc' => "{mtnDetectSharpness.off}"},
     162#   {'name' => "low", 'desc' => "{mtnDetectSharpness.low}"},
     163#   {'name' => "medium", 'desc' => "{mtnDetectSharpness.medium}"},
     164#   {'name' => "high", 'desc' => "{mtnDetectSharpness.high}"},
     165#   {'name' => "highest", 'desc' => "{mtnDetectSharpness.highest}"}],
     166#   'deft' => "highest",
     167#   'reqd' => "no" },   
     168   
     169    { 'name' => "create_montage",
     170    'desc' => "{VideoPlugin.createMontage}",
     171    'type' => "enum",
     172    'list' => [{'name' => "true", 'desc' => "{common.true}"},
     173            {'name' => "false", 'desc' => "{common.false}"}],
     174    'deft' => "false",
     175    'reqd' => "no" },
     176   
    125177      { 'name' => "streamingsize",
    126178    'desc' => "{VideoPlugin.streamingsize}",
     
    405457    }
    406458
     459   
     460    my $identify_vals = { "vtype" => $vtype, "width" => $width, "height" => $height, "duration" => $duration, "filesize" => -s $video, "vcodec" => $vcodec,
     461    "fps" => $fps, "acodec" => $atype, "afreq" => $afreq, "achan" => $achan, "arate" => $arate };
     462
     463    return $identify_vals;
     464   
    407465    # Return the specs
    408466    return ($vtype, $width, $height, $duration, -s $video,
     
    426484        my $full_v = &util::filename_cat($media_base_dir,$v);
    427485
    428         my ($vtype, $width, $height, $duration, $vsize,
    429             $vcodec ,$fps ,$atype ,$afreq ,$achan ,$arate) = identify($full_v,$outhandle,0);
     486        my $identify_hash = identifyMI($full_v,$outhandle,0);
     487       
     488        my $duration = $identify_hash->{'duration'};
    430489
    431490        my ($vob_num) = ($v =~ m/^VTS_\d\d_(\d)\.VOB$/);
     
    507566
    508567
    509 sub keyframe_cmd
     568sub ffKeyframe_cmd
    510569{
    511570    my $self = shift (@_);
     
    538597    return ($ffmpeg_cmd,$oflash_filename);
    539598}
     599
     600
     601sub mtnKeyframe_cmd
     602{
     603    my $self = shift (@_);
     604    my ($ivideo_filename) = @_;
     605
     606    my $video_ext_dir = &util::filename_cat($ENV{'GSDLHOME'},"ext","video");
     607
     608    my $output_dir = $self->{'cached_dir'};
     609    my $ivideo_root = $self->{'cached_file_root'};
     610
     611    my $frames_output_dir = &util::filename_cat($output_dir,"frames");
     612
     613    my $main_opts = "-z -P -I -O \"$frames_output_dir\"";
     614     
     615    my $mtn_skip_intro_secs   = $self->{'mtn_skip_intro'};
     616    my $mtn_skip_end_secs     = $self->{'mtn_skip_end'};
     617    my $mtn_timestep_secs     = $self->{'mtn_timestep'};
     618    my $mtn_detect_blank_perc = $self->{'mtn_detect_blanks'};
     619   
     620    my $mtn_detect_blank = $mtn_detect_blank_perc/100.0;
     621   
     622    my $keyframe_height;
     623    if ($self->{'create_screenview'} eq "true") {
     624        $keyframe_height = $self->{'screenviewsize'};
     625    }
     626    else {
     627        # assume thumbnail size
     628        $keyframe_height = $self->{'thumbnailsize'};
     629    }
     630       
     631    $main_opts .= " -B $mtn_skip_intro_secs";
     632    $main_opts .= " -E $mtn_skip_end_secs";
     633    $main_opts .= " -s $mtn_timestep_secs";
     634    $main_opts .= " -b $mtn_detect_blank";
     635    $main_opts .= " -h $keyframe_height";
     636   
     637    my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
     638 
     639    my $mtn_cmd = "mtn  $main_opts \"$ivideo_filename_gsdlenv\"";
     640
     641    my $output_s_filename = &util::filename_cat($frames_output_dir,$ivideo_root."_s.jpg");
     642
     643    return ($mtn_cmd,$output_s_filename);
     644}
     645
    540646
    541647sub get_ovideo_file
     
    871977{
    872978    my $self = shift (@_);
    873     my ($ivideo_filename,$thumbnailfile,$thumbnailwidth,$thumbnailheight) = @_;
     979    my ($ivideo_filename,$thumbnailfile,$thumbnailwidth,$thumbnailheight,$video_duration) = @_;
    874980
    875981    my $output_dir = $self->{'cached_dir'};
     
    893999    }
    8941000    else {
    895     # extract_keyframe has either not been switched on, or else had
    896     # a problem when running
     1001    # create_keyframe is either false, or else had a problem when running
    8971002    # => extract a from
    8981003    # my $frame_rate = 1.0 / 60.0;
     
    9001005    my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
    9011006
    902     $command = "ffmpeg -i \"$ivideo_filename_gsdlenv\"  -ss 4.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -deinterlace -y \"$thumbnailfile_gsdlenv\"";
     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);
     1010   
     1011    #print STDERR "***** grabbing keyframe as 50% of $video_duration\n";
     1012    my $ss_opt = ($video_duration / 1000.0) * 0.35;
     1013    #print STDERR "*** ssopt = $ss_opt\n";
     1014   
     1015    $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\"";
     1016    #$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\"";
    9031017
    9041018    # fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png
     
    9071021    return ($command,$thumbnailfile);
    9081022}
     1023
     1024
    9091025
    9101026
     
    9471063    }
    9481064
     1065}
     1066
     1067
     1068sub parse_shot_dir
     1069{
     1070    my ($self) = shift(@_);
     1071   
     1072    my $outhandle = $self->{'outhandle'};
     1073    my $output_dir = $self->{'cached_dir'};
     1074   
     1075    my $ivideo_root  = $self->{'cached_file_root'};
     1076   
     1077    my $frames_output_dir = &util::filename_cat($output_dir,"frames");
     1078   
     1079    my @jpeg_frames = ();
     1080   
     1081    if (opendir(FDIRIN, $frames_output_dir)) {
     1082    @jpeg_frames = grep { $_ =~ /_\d+\.jpg$/ } readdir(FDIRIN);
     1083    closedir(FDIRIN);
     1084    }
     1085    else {
     1086    print STDERR "VideoConverter:: Failed to open directory $frames_output_dir:\n$!\n";
     1087    return 0;
     1088    }
     1089   
     1090    $self->{'keyframe_timeline'} = {};
     1091   
     1092    my $vfps = $self->{'video-fps'};
     1093   
     1094    my $keyframe_index = 1;
     1095   
     1096    foreach my $f (@jpeg_frames) {
     1097    my ($hh,$mm,$ss) = ($f =~ m/_(\d{2})_(\d{2})_(\d{2})_\d+\.jpg$/);
     1098    my $frame_num = (3600*$hh + 60*$mm + $ss) * $vfps;
     1099   
     1100    my $time_msec = (3600*$hh + 60*$mm + $ss) * 1000;
     1101   
     1102    my $timeline_rec = { 'name'=> "Keyframe $keyframe_index",
     1103                 'keyframeindex' => $keyframe_index,
     1104                 'timestamp' => $time_msec,
     1105                 'thumb' => $f,
     1106                 'keyframenum' => $keyframe_index };
     1107   
     1108    $self->{'keyframe_timeline'}->{$keyframe_index}=$timeline_rec;
     1109   
     1110    $keyframe_index++;
     1111    }
     1112   
     1113    my $cue_filename = &util::filename_cat($output_dir,"on_cue.xml");
     1114   
     1115    $self->open_on_cue($cue_filename);
     1116
     1117    $self->output_distributed_keyframes($self->{'keyframe_timeline'},$self->{'ffkeyframe_num_shots'});
     1118
     1119    $self->close_on_cue();
     1120   
     1121    return 1;
    9491122}
    9501123
     
    11611334    my $flashheight = $video_height + 22;
    11621335
    1163     if ($self->{'extract_keyframes'}) {
     1336    if ($self->{'create_keyframes'} eq "true") {
    11641337    $flashheight += 100;
    11651338    }
     
    12021375    $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $identify_vals->{'height'});
    12031376    $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $identify_vals->{'durationDisplay'});
     1377    $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDurationMs", $identify_vals->{'duration'});
    12041378    $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $identify_vals->{'fps'});
    12051379    $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $identify_vals->{'vcodec'});
     
    12221396    }
    12231397   
    1224     #add the metadata for the resulting file that should be open inside the flash video player
     1398    #add the metadata for the resulting file that should be open inside the replayme video player
    12251399    $doc_obj->add_utf8_metadata ($section, "streamablevideo", $streamable_url_safe);
    12261400    $doc_obj->associate_file($ifilename,$ifile,"application/octet-stream",$section);
     
    12291403    my $flashheight = $video_height + 22;
    12301404
    1231     if ($self->{'extract_keyframes'}) {
     1405    if ($self->{'create_keyframes'} eq "true") {
    12321406    $flashheight += 100;
    12331407    }
     
    13281502    my $flashheight = $video_height + 22;
    13291503
    1330     if ($self->{'extract_keyframes'}) {
     1504    if ($self->{'create_keyframes'} eq "true") {
    13311505    $flashheight += 100;
    13321506    }
Note: See TracChangeset for help on using the changeset viewer.