Index: gs2-extensions/video/trunk/perllib/plugins/VideoConverter.pm
===================================================================
--- gs2-extensions/video/trunk/perllib/plugins/VideoConverter.pm	(revision 21606)
+++ gs2-extensions/video/trunk/perllib/plugins/VideoConverter.pm	(revision 21824)
@@ -47,4 +47,11 @@
 	'deft' => "true",
 	'reqd' => "no" },
+	      { 'name' => "keep_original_video",
+	'desc' => "Copy the original video file in the collection as an associated file.",
+	'type' => "enum",
+	'list' => [{'name' => "true", 'desc' => "Include the original video file in the collection"},
+		   {'name' => "false", 'desc' => "Do not copy the original video file in the collection"}],
+	'deft' => "false",
+	'reqd' => "no" },
       { 'name' => "thumbnailsize",
 	'desc' => "{ImageConverter.thumbnailsize}",
@@ -75,5 +82,5 @@
 	'desc' => "{ImageConverter.screenviewsize}",
 	'type' => "int",
-	'deft' => "352",
+	'deft' => "576",
 	'range' => "1,",
 	'reqd' => "no" },
@@ -134,10 +141,10 @@
 	'desc' => "{VideoPlugin.streamingbitrate}",
 	'type' => "int",
-	'deft' => "426",
+	'deft' => "432",
 	'reqd' => "no" },
 	{ 'name' => "streamingHQAudioBitrate",
 	'desc' => "{VideoPlugin.streamingbitrate}",
 	'type' => "int",
-	'deft' => "86",
+	'deft' => "80",
 	'reqd' => "no" },
 
@@ -180,9 +187,109 @@
 #  'indentify' utility
 
-#  Here we use 'ffmpeg' for video but for consistency keep the Perl
+#  Here we use 'MediaInfo' for video but for consistency keep the Perl
 #  method name the same as before
 
+sub mediaInfo_Inform_Cmd {
+	my ($video, $parameter, $outhandle, $verbosity) = @_;
+	
+	# Use MediaInfo CLI to get the file spec according to the requested parameter
+    my $command = "mediainfo --Inform=\"$parameter\" \"$video\"";
+
+    print $outhandle "  $command\n" if ($verbosity > 2);
+    my $result = '';
+    $result = `$command 2>&1`;
+	chomp $result;
+    print $outhandle "  $result\n" if ($verbosity > 4);
+	
+	# Return the asked spec
+    return ($result);
+}
+
+# Here we use mediaInfo to get all the possible metadata in XML form that could then be parsed
+#the result will vary depending on the file type and how it was encoded
+sub mediaInfo_XML_Cmd 	{
+	my ($video, $outhandle, $verbosity) = @_;
+	
+	# Use MediaInfo CLI to get the file spec according to the requested parameter
+    my $command = "mediainfo --Output=XML \"$video\"";
+
+    print $outhandle "  $command\n" if ($verbosity > 2);
+    my $result = '';
+    $result = `$command 2>&1`;
+    print $outhandle "  $result\n" if ($verbosity > 4);
+	
+	# Return the asked spec
+    return ($result);
+}
+
+#Here we parse the video specs contained in the XML text in order to create a metadata entry for each field
+sub mediaInfo_parse_XML 	{
+	my ($xmlTxt, $outhandle, $verbosity) = @_;
+	
+	my @parts = split(/<track\s+type=\"(.*?)\">/is,$xmlTxt);
+	
+	shift @parts; # Skip preamble
+	my $metadata_table = {};
+
+	while (@parts) {
+		my $type = shift(@parts);
+		my $vals = shift(@parts);
+		my @fieldlist=();
+		while ($vals =~ s/<(.*?)>(.*?)<\/\1>//) {
+		  my $metaname = $1;
+		  my $metaval  = $2;
+		  my $fullmetaname = "mi.$type\^$metaname";
+		  $metadata_table->{$fullmetaname}= $metaval;
+		  push(@fieldlist,$fullmetaname);
+		}
+		
+		$metadata_table->{"mi.${type}Fields"}= join(",",@fieldlist);
+		
+	}
+	
+	return $metadata_table;
+
+}
 
 sub identify { 
+    my ($video, $outhandle, $verbosity) = @_;
+
+    # Use the ffmpeg command to get the file specs
+    my $command = "ffmpeg -i \"$video\"";
+
+    print $outhandle "  $command\n" if ($verbosity > 2);
+    my $result = '';
+    $result = `$command 2>&1`;
+    print $outhandle "  $result\n" if ($verbosity > 4);
+
+    # Read the type, width, and height etc.
+	# This could be done in a more efficient way by only calling the application mediainfo once and
+	# giving all the parameters then parsing the results, however on most operating system
+	# once the application is called once it is then cached for subsequent calls.
+    my $vtype =  mediaInfo_Inform_Cmd($video,"General;%Format%",$outhandle,0);
+	my $duration = mediaInfo_Inform_Cmd($video,"General;%Duration%",$outhandle,0);
+	my $durationDisplay = mediaInfo_Inform_Cmd($video,"General;%Duration/String1%",$outhandle,0);
+	my $filesize = mediaInfo_Inform_Cmd($video,"General;%FileSize/String%",$outhandle,0);
+    my $vcodec = mediaInfo_Inform_Cmd($video,"Video;%Format%",$outhandle,0);
+	my $vrate = mediaInfo_Inform_Cmd($video,"Video;%BitRate%",$outhandle,0);
+    my $width =  mediaInfo_Inform_Cmd($video,"Video;%Width%",$outhandle,0);
+    my $height = mediaInfo_Inform_Cmd($video,"Video;%Height%",$outhandle,0);
+    my $fps    = mediaInfo_Inform_Cmd($video,"Video;%FrameRate%",$outhandle,0);
+    my $atype =  mediaInfo_Inform_Cmd($video,"Audio;%Format%",$outhandle,0);
+    my $afreq =  mediaInfo_Inform_Cmd($video,"Audio;%SamplingRate/String%",$outhandle,0);
+    my $achan =  mediaInfo_Inform_Cmd($video,"Audio;%Channel(s)%",$outhandle,0);
+    my $arate =  mediaInfo_Inform_Cmd($video,"Audio;%BitRate%",$outhandle,0);
+
+	my $xmlTxt =  mediaInfo_XML_Cmd ($video,$outhandle,0);
+	
+	my $metadata_table = mediaInfo_parse_XML($xmlTxt,$outhandle,0);
+	
+    # Return the specs
+    return ($vtype,$width,$height,$duration,$durationDisplay,$filesize,
+	    $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate,$metadata_table);
+}
+
+
+sub identify2 { 
     my ($video, $outhandle, $verbosity) = @_;
 
@@ -227,4 +334,8 @@
 
 	($width,$height) = ($video_dim =~ m/(\d+)x(\d+)/);
+	
+	if ($video_fields[0] =~ m/(\d+)\s+tbr$/) {
+	    $fps = $1;
+	}
 
 #	if ($video_info =~ m/([^,]+),(?: ([^,]+),)? (\d+)x(\d+),.*?(\d+\.\d+)/)
@@ -279,6 +390,6 @@
 	    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 ($vtype, $width, $height, $duration, $durationDisplay, $vsize,
+		$vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate) = identify($full_v,$outhandle,0);
 
 	    my ($vob_num) = ($v =~ m/^VTS_\d\d_(\d)\.VOB$/);
@@ -392,4 +503,37 @@
 }
 
+sub get_ovideo_file
+{
+	my $self = shift (@_);
+	my ($stream_type) = @_;
+	
+    my $ivideo_root = $self->{'cached_file_root'};
+	my $ofile;
+	
+	if ($stream_type eq "flv")
+	{
+		$ofile = "${ivideo_root}_vstream.flv";
+	}
+	else
+	{
+		$ofile = "${ivideo_root}_vHQstream.mp4";
+	}
+	
+	return $ofile;
+}
+
+sub get_ovideo_filename
+{
+	my $self = shift (@_);
+	my ($stream_type) = @_;
+	
+	my $output_dir = $self->{'cached_dir'};
+
+	my $ofile = $self->get_ovideo_file($stream_type);
+		
+	my $ofilename = &util::filename_cat($output_dir,$ofile);
+	
+	return $ofilename;
+}
 
 sub stream_mp4_video_cmd
@@ -424,7 +568,10 @@
     my $omp4_filename_gsdlenv = $self->gsdlhome_independent($omp4_filename);
 	
-	my $pre_opts = "--decomb -t 1 -c 1";
-	my $post_opts = "-f mp4 $size -O -e x264 -b $streaming_HQ_VideoBitrate -a 1 -E faac -6 dpl2 -B $streaming_HQ_AudioBitrate -D 0.0 -x ref=2:bframes=2:me-umh -v 1";
-	
+	#my $pre_opts = "--decomb -t 1 -c 1";
+	#my $post_opts = "-f mp4 $size -O -e x264 -b $streaming_HQ_VideoBitrate -a 1 -E faac -6 dpl2 -B $streaming_HQ_AudioBitrate -D 0.0 -x ref=2:bframes=2:me-umh -v 1";
+	
+	my $pre_opts = "-t 1 -c 1";
+	my $post_opts = "-f mp4 -O $size --decomb -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";
+
 	my $handbrake_cmd = "HandbrakeCLI.exe -i \"$ivideo_filename_gsdlenv\" $pre_opts -o \"$omp4_filename_gsdlenv\" $post_opts";
 
@@ -715,5 +862,5 @@
 	my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
 
-	$command = "ffmpeg -i \"$ivideo_filename_gsdlenv\"  -ss 12.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -y \"$thumbnailfile_gsdlenv\"";
+	$command = "ffmpeg -i \"$ivideo_filename_gsdlenv\"  -ss 3.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -y \"$thumbnailfile_gsdlenv\"";
 
 	# fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png
@@ -1002,13 +1149,8 @@
     }
 
-
-   ## my $streaming_bitrate = $self->{'streamingbitrate'};
-   ## my $streaming_size    = $self->{'streamingsize'};
 	my $streaming_HQ_size    = $self->{'streamingHQsize'};
 	my $streaming_HQ_VideoBitrate    = $self->{'streamingHQVideoBitrate'};
 	my $streaming_HQ_AudioBitrate    = $self->{'streamingHQAudioBitrate'};
-    
-  ##  my $streaming_quality = "high";
-    
+
     my ($stream_cmd,$oflash_filename,$oflash_file) 
 	= $self->stream_mp4_video_cmd($originalfilename || $filename,
@@ -1027,29 +1169,41 @@
     
     if (!$streamable_had_error) {
-#	my ($streamseekable_cmd,$ostreamseekable_filename) = $self->streamseekable_cmd($oflash_filename);
-	
-#	my $streamseekable_options = { @{$self->{'flvtool2_monitor'}},
-#				       'message_prefix' => "Stream Seekable",
-#				       'message' => "Reprocessing video stream to be seekable by timeline: $oflash_file" }; 
-	
-#	if ($streamable_regenerated) {
-#	    $self->run_general_cmd($streamseekable_cmd,$streamseekable_options);
-#	}
+
 	
 	my $streamable_url = $oflash_file;
 	my $streamable_url_safe = $self->url_safe($streamable_url);
 	
+	my $outhandle = $self->{'outhandle'};
+
+	my ($vtype, $width, $height, $duration, $durationDisplay, $vsize,
+		$vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate,$metadata_table) = identify($oflash_filename,$outhandle,0);
+		
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFormat", $vtype);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFileSize", $vsize);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingWidth", $width);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $height);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $durationDisplay);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $fps);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $vcodec);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoBitrate", $vrate);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioCodec", $atype);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioBitrate", $arate);
+	$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFileBitrate", $vrate + $arate);
+	
+	foreach my $metaname(keys %$metadata_table)
+	{
+		my $metaval = $metadata_table->{$metaname};
+		
+		$doc_obj->add_utf8_metadata ($section, $metaname, $metaval);
+	}
+	
 	#add the metadata for the resulting file that should be open inside the flash video player
 	$doc_obj->add_utf8_metadata ($section, "streamablevideo", $streamable_url_safe);
-	$doc_obj->associate_file($oflash_filename,"VideoStream.mp4","video/mp4",
+	$doc_obj->associate_file($oflash_filename,$oflash_file,"video/mp4",
 				 $section);
     }
 
 
-    #
-    # FlowPlayer.swf       height+22 pixels
-    # FlowPlayerBlack.swf  height+16 pixels
-    # FlowPlayerThermo.swf height+16 pixels
-    # FlowPlayerWhite.swf  height+26 pixels
+
 
     my $flashwidth = $video_width;
