Changeset 21824
- Timestamp:
- 2010-03-26T12:20:42+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/video/trunk/perllib/plugins/VideoConverter.pm
r21606 r21824 47 47 'deft' => "true", 48 48 'reqd' => "no" }, 49 { 'name' => "keep_original_video", 50 'desc' => "Copy the original video file in the collection as an associated file.", 51 'type' => "enum", 52 'list' => [{'name' => "true", 'desc' => "Include the original video file in the collection"}, 53 {'name' => "false", 'desc' => "Do not copy the original video file in the collection"}], 54 'deft' => "false", 55 'reqd' => "no" }, 49 56 { 'name' => "thumbnailsize", 50 57 'desc' => "{ImageConverter.thumbnailsize}", … … 75 82 'desc' => "{ImageConverter.screenviewsize}", 76 83 'type' => "int", 77 'deft' => " 352",84 'deft' => "576", 78 85 'range' => "1,", 79 86 'reqd' => "no" }, … … 134 141 'desc' => "{VideoPlugin.streamingbitrate}", 135 142 'type' => "int", 136 'deft' => "4 26",143 'deft' => "432", 137 144 'reqd' => "no" }, 138 145 { 'name' => "streamingHQAudioBitrate", 139 146 'desc' => "{VideoPlugin.streamingbitrate}", 140 147 'type' => "int", 141 'deft' => "8 6",148 'deft' => "80", 142 149 'reqd' => "no" }, 143 150 … … 180 187 # 'indentify' utility 181 188 182 # Here we use ' ffmpeg' for video but for consistency keep the Perl189 # Here we use 'MediaInfo' for video but for consistency keep the Perl 183 190 # method name the same as before 184 191 192 sub mediaInfo_Inform_Cmd { 193 my ($video, $parameter, $outhandle, $verbosity) = @_; 194 195 # Use MediaInfo CLI to get the file spec according to the requested parameter 196 my $command = "mediainfo --Inform=\"$parameter\" \"$video\""; 197 198 print $outhandle " $command\n" if ($verbosity > 2); 199 my $result = ''; 200 $result = `$command 2>&1`; 201 chomp $result; 202 print $outhandle " $result\n" if ($verbosity > 4); 203 204 # Return the asked spec 205 return ($result); 206 } 207 208 # Here we use mediaInfo to get all the possible metadata in XML form that could then be parsed 209 #the result will vary depending on the file type and how it was encoded 210 sub mediaInfo_XML_Cmd { 211 my ($video, $outhandle, $verbosity) = @_; 212 213 # Use MediaInfo CLI to get the file spec according to the requested parameter 214 my $command = "mediainfo --Output=XML \"$video\""; 215 216 print $outhandle " $command\n" if ($verbosity > 2); 217 my $result = ''; 218 $result = `$command 2>&1`; 219 print $outhandle " $result\n" if ($verbosity > 4); 220 221 # Return the asked spec 222 return ($result); 223 } 224 225 #Here we parse the video specs contained in the XML text in order to create a metadata entry for each field 226 sub mediaInfo_parse_XML { 227 my ($xmlTxt, $outhandle, $verbosity) = @_; 228 229 my @parts = split(/<track\s+type=\"(.*?)\">/is,$xmlTxt); 230 231 shift @parts; # Skip preamble 232 my $metadata_table = {}; 233 234 while (@parts) { 235 my $type = shift(@parts); 236 my $vals = shift(@parts); 237 my @fieldlist=(); 238 while ($vals =~ s/<(.*?)>(.*?)<\/\1>//) { 239 my $metaname = $1; 240 my $metaval = $2; 241 my $fullmetaname = "mi.$type\^$metaname"; 242 $metadata_table->{$fullmetaname}= $metaval; 243 push(@fieldlist,$fullmetaname); 244 } 245 246 $metadata_table->{"mi.${type}Fields"}= join(",",@fieldlist); 247 248 } 249 250 return $metadata_table; 251 252 } 185 253 186 254 sub identify { 255 my ($video, $outhandle, $verbosity) = @_; 256 257 # Use the ffmpeg command to get the file specs 258 my $command = "ffmpeg -i \"$video\""; 259 260 print $outhandle " $command\n" if ($verbosity > 2); 261 my $result = ''; 262 $result = `$command 2>&1`; 263 print $outhandle " $result\n" if ($verbosity > 4); 264 265 # Read the type, width, and height etc. 266 # This could be done in a more efficient way by only calling the application mediainfo once and 267 # giving all the parameters then parsing the results, however on most operating system 268 # once the application is called once it is then cached for subsequent calls. 269 my $vtype = mediaInfo_Inform_Cmd($video,"General;%Format%",$outhandle,0); 270 my $duration = mediaInfo_Inform_Cmd($video,"General;%Duration%",$outhandle,0); 271 my $durationDisplay = mediaInfo_Inform_Cmd($video,"General;%Duration/String1%",$outhandle,0); 272 my $filesize = mediaInfo_Inform_Cmd($video,"General;%FileSize/String%",$outhandle,0); 273 my $vcodec = mediaInfo_Inform_Cmd($video,"Video;%Format%",$outhandle,0); 274 my $vrate = mediaInfo_Inform_Cmd($video,"Video;%BitRate%",$outhandle,0); 275 my $width = mediaInfo_Inform_Cmd($video,"Video;%Width%",$outhandle,0); 276 my $height = mediaInfo_Inform_Cmd($video,"Video;%Height%",$outhandle,0); 277 my $fps = mediaInfo_Inform_Cmd($video,"Video;%FrameRate%",$outhandle,0); 278 my $atype = mediaInfo_Inform_Cmd($video,"Audio;%Format%",$outhandle,0); 279 my $afreq = mediaInfo_Inform_Cmd($video,"Audio;%SamplingRate/String%",$outhandle,0); 280 my $achan = mediaInfo_Inform_Cmd($video,"Audio;%Channel(s)%",$outhandle,0); 281 my $arate = mediaInfo_Inform_Cmd($video,"Audio;%BitRate%",$outhandle,0); 282 283 my $xmlTxt = mediaInfo_XML_Cmd ($video,$outhandle,0); 284 285 my $metadata_table = mediaInfo_parse_XML($xmlTxt,$outhandle,0); 286 287 # Return the specs 288 return ($vtype,$width,$height,$duration,$durationDisplay,$filesize, 289 $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate,$metadata_table); 290 } 291 292 293 sub identify2 { 187 294 my ($video, $outhandle, $verbosity) = @_; 188 295 … … 227 334 228 335 ($width,$height) = ($video_dim =~ m/(\d+)x(\d+)/); 336 337 if ($video_fields[0] =~ m/(\d+)\s+tbr$/) { 338 $fps = $1; 339 } 229 340 230 341 # if ($video_info =~ m/([^,]+),(?: ([^,]+),)? (\d+)x(\d+),.*?(\d+\.\d+)/) … … 279 390 my $full_v = &util::filename_cat($media_base_dir,$v); 280 391 281 my ($vtype, $width, $height, $duration, $ vsize,282 $vcodec,$ fps,$atype,$afreq,$achan,$arate) = identify($full_v,$outhandle,0);392 my ($vtype, $width, $height, $duration, $durationDisplay, $vsize, 393 $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate) = identify($full_v,$outhandle,0); 283 394 284 395 my ($vob_num) = ($v =~ m/^VTS_\d\d_(\d)\.VOB$/); … … 392 503 } 393 504 505 sub get_ovideo_file 506 { 507 my $self = shift (@_); 508 my ($stream_type) = @_; 509 510 my $ivideo_root = $self->{'cached_file_root'}; 511 my $ofile; 512 513 if ($stream_type eq "flv") 514 { 515 $ofile = "${ivideo_root}_vstream.flv"; 516 } 517 else 518 { 519 $ofile = "${ivideo_root}_vHQstream.mp4"; 520 } 521 522 return $ofile; 523 } 524 525 sub get_ovideo_filename 526 { 527 my $self = shift (@_); 528 my ($stream_type) = @_; 529 530 my $output_dir = $self->{'cached_dir'}; 531 532 my $ofile = $self->get_ovideo_file($stream_type); 533 534 my $ofilename = &util::filename_cat($output_dir,$ofile); 535 536 return $ofilename; 537 } 394 538 395 539 sub stream_mp4_video_cmd … … 424 568 my $omp4_filename_gsdlenv = $self->gsdlhome_independent($omp4_filename); 425 569 426 my $pre_opts = "--decomb -t 1 -c 1"; 427 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"; 428 570 #my $pre_opts = "--decomb -t 1 -c 1"; 571 #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"; 572 573 my $pre_opts = "-t 1 -c 1"; 574 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"; 575 429 576 my $handbrake_cmd = "HandbrakeCLI.exe -i \"$ivideo_filename_gsdlenv\" $pre_opts -o \"$omp4_filename_gsdlenv\" $post_opts"; 430 577 … … 715 862 my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename); 716 863 717 $command = "ffmpeg -i \"$ivideo_filename_gsdlenv\" -ss 12.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -y \"$thumbnailfile_gsdlenv\"";864 $command = "ffmpeg -i \"$ivideo_filename_gsdlenv\" -ss 3.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -y \"$thumbnailfile_gsdlenv\""; 718 865 719 866 # fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png … … 1002 1149 } 1003 1150 1004 1005 ## my $streaming_bitrate = $self->{'streamingbitrate'};1006 ## my $streaming_size = $self->{'streamingsize'};1007 1151 my $streaming_HQ_size = $self->{'streamingHQsize'}; 1008 1152 my $streaming_HQ_VideoBitrate = $self->{'streamingHQVideoBitrate'}; 1009 1153 my $streaming_HQ_AudioBitrate = $self->{'streamingHQAudioBitrate'}; 1010 1011 ## my $streaming_quality = "high"; 1012 1154 1013 1155 my ($stream_cmd,$oflash_filename,$oflash_file) 1014 1156 = $self->stream_mp4_video_cmd($originalfilename || $filename, … … 1027 1169 1028 1170 if (!$streamable_had_error) { 1029 # my ($streamseekable_cmd,$ostreamseekable_filename) = $self->streamseekable_cmd($oflash_filename); 1030 1031 # my $streamseekable_options = { @{$self->{'flvtool2_monitor'}}, 1032 # 'message_prefix' => "Stream Seekable", 1033 # 'message' => "Reprocessing video stream to be seekable by timeline: $oflash_file" }; 1034 1035 # if ($streamable_regenerated) { 1036 # $self->run_general_cmd($streamseekable_cmd,$streamseekable_options); 1037 # } 1171 1038 1172 1039 1173 my $streamable_url = $oflash_file; 1040 1174 my $streamable_url_safe = $self->url_safe($streamable_url); 1041 1175 1176 my $outhandle = $self->{'outhandle'}; 1177 1178 my ($vtype, $width, $height, $duration, $durationDisplay, $vsize, 1179 $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate,$metadata_table) = identify($oflash_filename,$outhandle,0); 1180 1181 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFormat", $vtype); 1182 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFileSize", $vsize); 1183 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingWidth", $width); 1184 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $height); 1185 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $durationDisplay); 1186 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $fps); 1187 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $vcodec); 1188 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoBitrate", $vrate); 1189 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioCodec", $atype); 1190 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioBitrate", $arate); 1191 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFileBitrate", $vrate + $arate); 1192 1193 foreach my $metaname(keys %$metadata_table) 1194 { 1195 my $metaval = $metadata_table->{$metaname}; 1196 1197 $doc_obj->add_utf8_metadata ($section, $metaname, $metaval); 1198 } 1199 1042 1200 #add the metadata for the resulting file that should be open inside the flash video player 1043 1201 $doc_obj->add_utf8_metadata ($section, "streamablevideo", $streamable_url_safe); 1044 $doc_obj->associate_file($oflash_filename, "VideoStream.mp4","video/mp4",1202 $doc_obj->associate_file($oflash_filename,$oflash_file,"video/mp4", 1045 1203 $section); 1046 1204 } 1047 1205 1048 1206 1049 # 1050 # FlowPlayer.swf height+22 pixels 1051 # FlowPlayerBlack.swf height+16 pixels 1052 # FlowPlayerThermo.swf height+16 pixels 1053 # FlowPlayerWhite.swf height+26 pixels 1207 1054 1208 1055 1209 my $flashwidth = $video_width;
Note:
See TracChangeset
for help on using the changeset viewer.