Index: /gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoConverter.pm
===================================================================
--- /gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoConverter.pm	(revision 24187)
+++ /gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoConverter.pm	(revision 24188)
@@ -113,14 +113,66 @@
 	'deft' => "200k",
 	'reqd' => "no" },
-      { 'name' => "extract_keyframes",
+	
+      { 'name' => "create_keyframes",
 	'desc' => "{VideoPlugin.extractkeyframes}",
-	'type' => "flag",
-	'deft' => "0",
-	'reqd' => "no" },
-      { 'name' => "keep_keyframes",
+	'type' => "enum",
+	'list' => [{'name' => "true", 'desc' => "{common.true}"},
+			{'name' => "false", 'desc' => "{common.false}"}],
+	'deft' => "false",
+	'reqd' => "no" },
+	   { 'name' => "keyframes_algorithm",
+	'desc' => "{VideoPlugin.keyframesAlgorithm}",
+	'type' => "enum",
+	'list' => [{'name' => "mtn", 'desc' => "{keyframesAlgorithm.mtn}"},
+		{'name' => "ffkeyframe", 'desc' => "{keyframesAlgorithm.ffkeyframe}"}],
+	'deft' => "mtn",
+	'reqd' => "no" },
+	
+      { 'name' => "ffkeyframe_num_shots",
 	'desc' => "{VideoPlugin.keep_keyframes}",
 	'type' => "string",
 	'deft' => "all",
 	'reqd' => "no" },
+	
+	 { 'name' => "mtn_skip_intro",
+	'desc' => "{VideoPlugin.mtnSkipIntro}",
+	'type' => "int",
+	'deft' => "0",
+	'reqd' => "no" },
+	 { 'name' => "mtn_skip_end",
+	'desc' => "{VideoPlugin.mtnSkipEnd}",
+	'type' => "int",
+	'deft' => "0",
+	'reqd' => "no" },
+	 { 'name' => "mtn_timestep",
+	'desc' => "{VideoPlugin.mtnTimestep}",
+	'type' => "int",
+	'deft' => "120",
+	'reqd' => "no" },
+	 { 'name' => "mtn_detect_blanks",
+	'desc' => "{VideoPlugin.mtnDetectBlanks}",
+	'type' => "int",
+	'deft' => "80",
+	'range' => "0,100",
+	'reqd' => "no" },
+#	{ 'name' => "mtn_detect_sharpness",
+#	'desc' => "{VideoPlugin.mtnDetectSharpness}",
+#	'type' => "enum",
+#	[{'name' => "off", 'desc' => "{mtnDetectSharpness.off}"},
+#	{'name' => "low", 'desc' => "{mtnDetectSharpness.low}"},
+#	{'name' => "medium", 'desc' => "{mtnDetectSharpness.medium}"},
+#	{'name' => "high", 'desc' => "{mtnDetectSharpness.high}"},
+#	{'name' => "highest", 'desc' => "{mtnDetectSharpness.highest}"}],
+#	'deft' => "highest",
+#	'reqd' => "no" },	
+	
+	{ 'name' => "create_montage",
+	'desc' => "{VideoPlugin.createMontage}",
+	'type' => "enum",
+	'list' => [{'name' => "true", 'desc' => "{common.true}"},
+			{'name' => "false", 'desc' => "{common.false}"}],
+	'deft' => "false",
+	'reqd' => "no" },
+	
       { 'name' => "streamingsize",
 	'desc' => "{VideoPlugin.streamingsize}",
@@ -405,4 +457,10 @@
     }
 
+	
+	my $identify_vals = { "vtype" => $vtype, "width" => $width, "height" => $height, "duration" => $duration, "filesize" => -s $video, "vcodec" => $vcodec,
+	"fps" => $fps, "acodec" => $atype, "afreq" => $afreq, "achan" => $achan, "arate" => $arate };
+
+	return $identify_vals;
+	
     # Return the specs
     return ($vtype, $width, $height, $duration, -s $video,
@@ -426,6 +484,7 @@
 	    my $full_v = &util::filename_cat($media_base_dir,$v);
 
-	    my ($vtype, $width, $height, $duration, $vsize,
-			$vcodec ,$fps ,$atype ,$afreq ,$achan ,$arate) = identify($full_v,$outhandle,0);
+	    my $identify_hash = identifyMI($full_v,$outhandle,0);
+		
+		my $duration = $identify_hash->{'duration'};
 
 	    my ($vob_num) = ($v =~ m/^VTS_\d\d_(\d)\.VOB$/);
@@ -507,5 +566,5 @@
 
 
-sub keyframe_cmd
+sub ffKeyframe_cmd
 {
     my $self = shift (@_);
@@ -538,4 +597,51 @@
     return ($ffmpeg_cmd,$oflash_filename);
 }
+
+
+sub mtnKeyframe_cmd
+{
+    my $self = shift (@_);
+    my ($ivideo_filename) = @_;
+
+    my $video_ext_dir = &util::filename_cat($ENV{'GSDLHOME'},"ext","video");
+
+    my $output_dir = $self->{'cached_dir'};
+    my $ivideo_root = $self->{'cached_file_root'};
+
+    my $frames_output_dir = &util::filename_cat($output_dir,"frames");
+
+	my $main_opts = "-z -P -I -O \"$frames_output_dir\"";
+	 
+	my $mtn_skip_intro_secs   = $self->{'mtn_skip_intro'};
+	my $mtn_skip_end_secs     = $self->{'mtn_skip_end'};
+	my $mtn_timestep_secs     = $self->{'mtn_timestep'};
+	my $mtn_detect_blank_perc = $self->{'mtn_detect_blanks'};
+	
+	my $mtn_detect_blank = $mtn_detect_blank_perc/100.0;
+	
+	my $keyframe_height;
+	if ($self->{'create_screenview'} eq "true") {
+		$keyframe_height = $self->{'screenviewsize'};
+	}
+	else {
+		# assume thumbnail size
+		$keyframe_height = $self->{'thumbnailsize'};
+	}
+		
+	$main_opts .= " -B $mtn_skip_intro_secs";
+	$main_opts .= " -E $mtn_skip_end_secs";
+	$main_opts .= " -s $mtn_timestep_secs";
+	$main_opts .= " -b $mtn_detect_blank";
+	$main_opts .= " -h $keyframe_height";
+	
+    my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
+ 
+    my $mtn_cmd = "mtn  $main_opts \"$ivideo_filename_gsdlenv\"";
+
+    my $output_s_filename = &util::filename_cat($frames_output_dir,$ivideo_root."_s.jpg");
+
+    return ($mtn_cmd,$output_s_filename);
+}
+
 
 sub get_ovideo_file
@@ -871,5 +977,5 @@
 {
     my $self = shift (@_);
-    my ($ivideo_filename,$thumbnailfile,$thumbnailwidth,$thumbnailheight) = @_;
+    my ($ivideo_filename,$thumbnailfile,$thumbnailwidth,$thumbnailheight,$video_duration) = @_;
 
     my $output_dir = $self->{'cached_dir'};
@@ -893,6 +999,5 @@
     }
     else {
-	# extract_keyframe has either not been switched on, or else had
-	# a problem when running
+	# create_keyframe is either false, or else had a problem when running
 	# => extract a from 
 	# my $frame_rate = 1.0 / 60.0;
@@ -900,5 +1005,14 @@
 	my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
 
-	$command = "ffmpeg -i \"$ivideo_filename_gsdlenv\"  -ss 4.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -deinterlace -y \"$thumbnailfile_gsdlenv\"";
+	 # If ever reused, then needs to change to newer hashmap method
+	 #my ($vtype, $width, $height, $duration, $vsize,
+		#	$vcodec ,$fps ,$atype ,$afreq ,$achan ,$arate) = identify($ivideo_filename_gsdlenv,$outhandle,0);
+	
+	#print STDERR "***** grabbing keyframe as 50% of $video_duration\n";
+	my $ss_opt = ($video_duration / 1000.0) * 0.35;
+	#print STDERR "*** ssopt = $ss_opt\n";
+	
+	$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\"";
+	#$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\"";
 
 	# fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png
@@ -907,4 +1021,6 @@
     return ($command,$thumbnailfile);
 }
+
+
 
 
@@ -947,4 +1063,61 @@
     }
 
+}
+
+
+sub parse_shot_dir
+{
+    my ($self) = shift(@_);
+    
+    my $outhandle = $self->{'outhandle'};
+    my $output_dir = $self->{'cached_dir'};
+    
+    my $ivideo_root  = $self->{'cached_file_root'};
+    
+    my $frames_output_dir = &util::filename_cat($output_dir,"frames");
+    
+    my @jpeg_frames = ();
+    
+    if (opendir(FDIRIN, $frames_output_dir)) {
+	@jpeg_frames = grep { $_ =~ /_\d+\.jpg$/ } readdir(FDIRIN);
+	closedir(FDIRIN);
+    }
+    else {
+	print STDERR "VideoConverter:: Failed to open directory $frames_output_dir:\n$!\n";
+	return 0;
+    }
+    
+    $self->{'keyframe_timeline'} = {};
+    
+    my $vfps = $self->{'video-fps'};
+    
+    my $keyframe_index = 1;
+    
+    foreach my $f (@jpeg_frames) {
+	my ($hh,$mm,$ss) = ($f =~ m/_(\d{2})_(\d{2})_(\d{2})_\d+\.jpg$/);
+	my $frame_num = (3600*$hh + 60*$mm + $ss) * $vfps;
+	
+	my $time_msec = (3600*$hh + 60*$mm + $ss) * 1000;
+	
+	my $timeline_rec = { 'name'=> "Keyframe $keyframe_index",
+			     'keyframeindex' => $keyframe_index,
+			     'timestamp' => $time_msec,
+			     'thumb' => $f,
+			     'keyframenum' => $keyframe_index };
+	
+	$self->{'keyframe_timeline'}->{$keyframe_index}=$timeline_rec;
+	
+	$keyframe_index++;
+    }
+	
+    my $cue_filename = &util::filename_cat($output_dir,"on_cue.xml");
+    
+    $self->open_on_cue($cue_filename);
+
+    $self->output_distributed_keyframes($self->{'keyframe_timeline'},$self->{'ffkeyframe_num_shots'});
+
+    $self->close_on_cue();
+	
+    return 1;
 }
 
@@ -1161,5 +1334,5 @@
     my $flashheight = $video_height + 22;
 
-    if ($self->{'extract_keyframes'}) {
+    if ($self->{'create_keyframes'} eq "true") {
 	$flashheight += 100;
     }
@@ -1202,4 +1375,5 @@
 	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $identify_vals->{'height'});
 	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $identify_vals->{'durationDisplay'});
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDurationMs", $identify_vals->{'duration'});
 	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $identify_vals->{'fps'});
 	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $identify_vals->{'vcodec'});
@@ -1222,5 +1396,5 @@
 	}
 	
-	#add the metadata for the resulting file that should be open inside the flash video player
+	#add the metadata for the resulting file that should be open inside the replayme video player
 	$doc_obj->add_utf8_metadata ($section, "streamablevideo", $streamable_url_safe);
 	$doc_obj->associate_file($ifilename,$ifile,"application/octet-stream",$section);
@@ -1229,5 +1403,5 @@
     my $flashheight = $video_height + 22;
 
-    if ($self->{'extract_keyframes'}) {
+    if ($self->{'create_keyframes'} eq "true") {
 	$flashheight += 100;
     }
@@ -1328,5 +1502,5 @@
     my $flashheight = $video_height + 22;
 
-    if ($self->{'extract_keyframes'}) {
+    if ($self->{'create_keyframes'} eq "true") {
 	$flashheight += 100;
     }
