Changeset 24188
- Timestamp:
- 2011-06-22T15:07:40+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoConverter.pm
r23407 r24188 113 113 'deft' => "200k", 114 114 'reqd' => "no" }, 115 { 'name' => "extract_keyframes", 115 116 { 'name' => "create_keyframes", 116 117 '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", 121 132 'desc' => "{VideoPlugin.keep_keyframes}", 122 133 'type' => "string", 123 134 'deft' => "all", 124 135 '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 125 177 { 'name' => "streamingsize", 126 178 'desc' => "{VideoPlugin.streamingsize}", … … 405 457 } 406 458 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 407 465 # Return the specs 408 466 return ($vtype, $width, $height, $duration, -s $video, … … 426 484 my $full_v = &util::filename_cat($media_base_dir,$v); 427 485 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'}; 430 489 431 490 my ($vob_num) = ($v =~ m/^VTS_\d\d_(\d)\.VOB$/); … … 507 566 508 567 509 sub keyframe_cmd568 sub ffKeyframe_cmd 510 569 { 511 570 my $self = shift (@_); … … 538 597 return ($ffmpeg_cmd,$oflash_filename); 539 598 } 599 600 601 sub 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 540 646 541 647 sub get_ovideo_file … … 871 977 { 872 978 my $self = shift (@_); 873 my ($ivideo_filename,$thumbnailfile,$thumbnailwidth,$thumbnailheight ) = @_;979 my ($ivideo_filename,$thumbnailfile,$thumbnailwidth,$thumbnailheight,$video_duration) = @_; 874 980 875 981 my $output_dir = $self->{'cached_dir'}; … … 893 999 } 894 1000 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 897 1002 # => extract a from 898 1003 # my $frame_rate = 1.0 / 60.0; … … 900 1005 my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename); 901 1006 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\""; 903 1017 904 1018 # fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png … … 907 1021 return ($command,$thumbnailfile); 908 1022 } 1023 1024 909 1025 910 1026 … … 947 1063 } 948 1064 1065 } 1066 1067 1068 sub 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; 949 1122 } 950 1123 … … 1161 1334 my $flashheight = $video_height + 22; 1162 1335 1163 if ($self->{' extract_keyframes'}) {1336 if ($self->{'create_keyframes'} eq "true") { 1164 1337 $flashheight += 100; 1165 1338 } … … 1202 1375 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $identify_vals->{'height'}); 1203 1376 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $identify_vals->{'durationDisplay'}); 1377 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDurationMs", $identify_vals->{'duration'}); 1204 1378 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $identify_vals->{'fps'}); 1205 1379 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $identify_vals->{'vcodec'}); … … 1222 1396 } 1223 1397 1224 #add the metadata for the resulting file that should be open inside the flashvideo player1398 #add the metadata for the resulting file that should be open inside the replayme video player 1225 1399 $doc_obj->add_utf8_metadata ($section, "streamablevideo", $streamable_url_safe); 1226 1400 $doc_obj->associate_file($ifilename,$ifile,"application/octet-stream",$section); … … 1229 1403 my $flashheight = $video_height + 22; 1230 1404 1231 if ($self->{' extract_keyframes'}) {1405 if ($self->{'create_keyframes'} eq "true") { 1232 1406 $flashheight += 100; 1233 1407 } … … 1328 1502 my $flashheight = $video_height + 22; 1329 1503 1330 if ($self->{' extract_keyframes'}) {1504 if ($self->{'create_keyframes'} eq "true") { 1331 1505 $flashheight += 100; 1332 1506 }
Note:
See TracChangeset
for help on using the changeset viewer.