- Timestamp:
- 2010-12-07T17:08:07+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoConverter.pm
r23292 r23407 194 194 195 195 196 197 198 # Discover the characteristics of a video file. 199 200 # Equivalent step to that in ImagePlugin that uses ImageMagicks's 201 # 'indentify' utility 202 203 # Here we use 'MediaInfo' for video but for consistency keep the Perl 204 # method name the same as before 205 196 # Here we use 'MediaInfo' for video and ask for a specific specification 206 197 sub mediaInfo_Inform_Cmd { 207 198 my ($video, $parameter, $outhandle, $verbosity) = @_; … … 221 212 222 213 # Here we use mediaInfo to get all the possible metadata in XML form that could then be parsed 223 # the result will vary depending on the file type and how it was encoded214 # the result will vary depending on the file type and how it was encoded 224 215 sub mediaInfo_XML_Cmd { 225 216 my ($video, $outhandle, $verbosity) = @_; … … 237 228 } 238 229 239 #Here we parse the video specs contained in the XML text in order to create a metadata entry for each field 230 # Here we parse the video specs contained in the XML text in order to create a metadata entry for each field 231 # that mediainfo is giving back, this can vary from media file to media file. 240 232 sub mediaInfo_parse_XML { 241 233 my ($xmlTxt, $outhandle, $verbosity) = @_; … … 286 278 my ($video, $outhandle, $verbosity) = @_; 287 279 288 # Use the ffmpegcommand to get the file specs289 my $command = " ffmpeg -i\"$video\"";280 # Use the MediaInfo command to get the file specs 281 my $command = "MediaInfo \"$video\""; 290 282 291 283 print $outhandle " $command\n" if ($verbosity > 2); … … 294 286 print $outhandle " $result\n" if ($verbosity > 4); 295 287 296 # Read the type, width, and height etc. 297 # This could be done in a more efficient way by only calling the application mediainfo once and 298 # giving all the parameters then parsing the results, however on most operating system 299 # once the application is called once it is then cached for subsequent calls. 300 my $vtype = mediaInfo_Inform_Cmd($video,"General;%Format%",$outhandle,0); 301 my $duration = mediaInfo_Inform_Cmd($video,"General;%Duration%",$outhandle,0); 302 my $durationDisplay = mediaInfo_Inform_Cmd($video,"General;%Duration/String1%",$outhandle,0); 303 my $filesize = mediaInfo_Inform_Cmd($video,"General;%FileSize/String%",$outhandle,0); 304 my $vcodec = mediaInfo_Inform_Cmd($video,"Video;%Format%",$outhandle,0); 305 my $vrate = mediaInfo_Inform_Cmd($video,"Video;%BitRate%",$outhandle,0); 306 my $width = mediaInfo_Inform_Cmd($video,"Video;%Width%",$outhandle,0); 307 my $height = mediaInfo_Inform_Cmd($video,"Video;%Height%",$outhandle,0); 308 my $fps = mediaInfo_Inform_Cmd($video,"Video;%FrameRate%",$outhandle,0); 309 my $atype = mediaInfo_Inform_Cmd($video,"Audio;%Format%",$outhandle,0); 310 my $afreq = mediaInfo_Inform_Cmd($video,"Audio;%SamplingRate/String%",$outhandle,0); 311 my $achan = mediaInfo_Inform_Cmd($video,"Audio;%Channel(s)%",$outhandle,0); 312 my $arate = mediaInfo_Inform_Cmd($video,"Audio;%BitRate%",$outhandle,0); 288 # Read the type, width, and height etc. from media file 289 # This could be done in a more efficient way by only calling the application MediaInfo once and 290 # giving all the parameters inside a special macro file then parsing the results, however 291 # on most operating system when the application is called once it is then cached for subsequent calls. 292 # General info 293 my $vtype = mediaInfo_Inform_Cmd($video,"General;%Format%",$outhandle,0); #Container of the video e.g. MPEG-TS 294 my $duration = mediaInfo_Inform_Cmd($video,"General;%Duration%",$outhandle,0); #Duration of the video in ms e.g. 5545841 295 my $durationDisplay = mediaInfo_Inform_Cmd($video,"General;%Duration/String%",$outhandle,0); #Duration of the video in minutes and secs or hours and minutes e.g. 25m 12s or 2h 26m 296 my $filesize = mediaInfo_Inform_Cmd($video,"General;%FileSize%",$outhandle,0); #File size in bytes e.g. 1024 297 my $filesizeDisplay = mediaInfo_Inform_Cmd($video,"General;%FileSize/String%",$outhandle,0); #File size with measure e.g. 25.6 MiB 298 my $orateDisplay = mediaInfo_Inform_Cmd($video,"General;%OverallBitRate/String%",$outhandle,0); #General file bitrate with measure e.g. 7 538 Kbps 299 # Video info 300 my $vcodec = mediaInfo_Inform_Cmd($video,"Video;%Format%",$outhandle,0); #Codec used for the video compression e.g. AVC 301 my $vrate = mediaInfo_Inform_Cmd($video,"Video;%BitRate%",$outhandle,0); #Bitrate used for the video stream in bps e.g. 546165 302 my $width = mediaInfo_Inform_Cmd($video,"Video;%Width%",$outhandle,0); #Width of the video in pixels e.g. 1920 303 my $height = mediaInfo_Inform_Cmd($video,"Video;%Height%",$outhandle,0); #Height of the video in pixels e.g. 1080 304 my $fps = mediaInfo_Inform_Cmd($video,"Video;%FrameRate%",$outhandle,0); #Video frames per second e.g. 30 305 # Audio info 306 my $acodec = mediaInfo_Inform_Cmd($video,"Audio;%Format%",$outhandle,0); # Audio codec used for the compression e.g. AAC 307 my $afreq = mediaInfo_Inform_Cmd($video,"Audio;%SamplingRate/String%",$outhandle,0); #Sampling rate used for audio encoding e.g. 48000 308 my $achan = mediaInfo_Inform_Cmd($video,"Audio;%Channel(s)%",$outhandle,0); #Number of channels e.g. 2 309 my $arate = mediaInfo_Inform_Cmd($video,"Audio;%BitRate%",$outhandle,0); #Audio bitrate for the audio stream in bps e.g. 65436 310 my $atracks = mediaInfo_Inform_Cmd($video,"Audio;%StreamCount%",$outhandle,0); #number of audio tracks in this video file e.g. 1 311 # Subtitles info 312 my $stype = mediaInfo_Inform_Cmd($video,"Text;%Format%",$outhandle,0); # Format used for the subtitles e.g. DVB Subtitle 313 my $slang = mediaInfo_Inform_Cmd($video,"Text;%Language/String%",$outhandle,0); # Language used for the subtitles e.g. English 314 313 315 314 316 my $xmlTxt = mediaInfo_XML_Cmd ($video,$outhandle,0); … … 316 318 317 319 # Return the specs 318 return ($vtype,$width,$height,$duration,$durationDisplay,$filesize, 319 $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate,$metadata_table); 320 } 321 322 320 my $identify_vals = { "vtype" => $vtype, "width" => $width, "height" => $height, "duration" => $duration, "filesize" => $filesize, "vcodec" => $vcodec, 321 "fps" => $fps, "acodec" => $acodec, "afreq" => $afreq, "achan" => $achan, "arate" => $arate, "metadata_table" => $metadata_table, "durationDisplay" => $durationDisplay, 322 "filesizeDisplay" => $filesizeDisplay, "orateDisplay" => $orateDisplay, "vrate" => $vrate, "stype" => $stype, "slang" => $slang, "atracks" => $atracks }; 323 324 return $identify_vals; 325 } 326 327 # Here we use 'ffmpeg' for video and ask for a specific specification 328 # This is now deprecated this will be replaced by identifyMI in the future 323 329 sub identify { 324 330 my ($video, $outhandle, $verbosity) = @_; … … 420 426 my $full_v = &util::filename_cat($media_base_dir,$v); 421 427 422 my ($vtype, $width, $height, $duration, $ durationDisplay, $vsize,423 $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate) = identify($full_v,$outhandle,0);428 my ($vtype, $width, $height, $duration, $vsize, 429 $vcodec ,$fps ,$atype ,$afreq ,$achan ,$arate) = identify($full_v,$outhandle,0); 424 430 425 431 my ($vob_num) = ($v =~ m/^VTS_\d\d_(\d)\.VOB$/); … … 894 900 my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename); 895 901 896 $command = "ffmpeg -i \"$ivideo_filename_gsdlenv\" -ss 3.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight}-y \"$thumbnailfile_gsdlenv\"";902 $command = "ffmpeg -i \"$ivideo_filename_gsdlenv\" -ss 4.5 -vframes 1 -f image2 -s ${thumbnailwidth}x${thumbnailheight} -deinterlace -y \"$thumbnailfile_gsdlenv\""; 897 903 898 904 # fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png … … 1187 1193 my $outhandle = $self->{'outhandle'}; 1188 1194 1189 my ($vtype, $width, $height, $duration, $durationDisplay, $vsize,1190 $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate,$metadata_table) = identifyMI($ifilename,$outhandle,0); 1195 my $identify_vals = identifyMI($ifilename,$outhandle,0); 1196 1191 1197 #Add the most common metadata extracted by MediaInfo from the streamable video file 1192 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFormat", $vtype); 1193 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFileSize", $vsize); 1194 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingWidth", $width); 1195 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $height); 1196 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $durationDisplay); 1197 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $fps); 1198 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $vcodec); 1199 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoBitrate", $vrate); 1200 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioCodec", $atype); 1201 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioBitrate", $arate); 1202 #$doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFileBitrate", $vrate + $arate); 1198 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFormat", $identify_vals->{'vtype'}); 1199 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFileSize", $identify_vals->{'filesizeDisplay'}); 1200 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFileSizeBytes", $identify_vals->{'filesize'}); 1201 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingWidth", $identify_vals->{'width'}); 1202 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $identify_vals->{'height'}); 1203 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $identify_vals->{'durationDisplay'}); 1204 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $identify_vals->{'fps'}); 1205 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $identify_vals->{'vcodec'}); 1206 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoBitrate", $identify_vals->{'vrate'}); 1207 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioCodec", $identify_vals->{'acodec'}); 1208 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioBitrate", $identify_vals->{'arate'}); 1209 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioTracks", $identify_vals->{'atracks'}); 1210 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingOverallBitrate", $identify_vals->{'orateDisplay'}); 1211 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingSubtitleType", $identify_vals->{'stype'}); 1212 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingSubtitleLanguage", $identify_vals->{'slang'}); 1203 1213 1204 1214 my $get_max_metadata = $self->{'getMaximumMetadata'}; 1205 1215 if ($get_max_metadata eq "true"){ 1216 my $metadata_table = $identify_vals->{'metadata_table'}; 1206 1217 foreach my $metaname(keys %$metadata_table) 1207 1218 { 1208 my $metaval = $ metadata_table->{$metaname};1219 my $metaval = $identify_vals->{'metadata_table'}->{$metaname}; 1209 1220 $doc_obj->add_utf8_metadata ($section, $metaname, $metaval); 1210 1221 } … … 1281 1292 my $outhandle = $self->{'outhandle'}; 1282 1293 1283 my ($vtype, $width, $height, $duration, $durationDisplay, $vsize,1284 $vcodec,$vrate,$fps,$atype,$afreq,$achan,$arate,$metadata_table) = identifyMI($oflash_filename,$outhandle,0);1294 my $identify_vals = identifyMI($oflash_filename,$outhandle,0); 1295 1285 1296 #Add the most common metadata extracted by MediaInfo from the streamable video file 1286 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFormat", $vtype); 1287 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFileSize", $vsize); 1288 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingWidth", $width); 1289 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $height); 1290 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $durationDisplay); 1291 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $fps); 1292 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $vcodec); 1293 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoBitrate", $vrate); 1294 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioCodec", $atype); 1295 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioBitrate", $arate); 1296 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFileBitrate", $vrate + $arate); 1297 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFormat", $identify_vals->{'vtype'}); 1298 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoFileSize", $identify_vals->{'filesizeDisplay'}); 1299 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingWidth", $identify_vals->{'width'}); 1300 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingHeight", $identify_vals->{'height'}); 1301 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingDuration", $identify_vals->{'durationDisplay'}); 1302 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingFPS", $identify_vals->{'fps'}); 1303 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoCodec", $identify_vals->{'vcodec'}); 1304 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingVideoBitrate", $identify_vals->{'vrate'}); 1305 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioCodec", $identify_vals->{'acodec'}); 1306 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingAudioBitrate", $identify_vals->{'arate'}); 1307 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingOverallBitrate", $identify_vals->{'orateDisplay'}); 1308 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingSubtitleType", $identify_vals->{'stype'}); 1309 $doc_obj->add_utf8_metadata ($section, "tv.HQStreamingSubtitleLangue", $identify_vals->{'slang'}); 1297 1310 1298 1311 my $get_max_metadata = $self->{'getMaximumMetadata'}; 1299 1312 if ($get_max_metadata eq "true"){ 1313 my $metadata_table = $identify_vals->{'metadata_table'}; 1300 1314 foreach my $metaname(keys %$metadata_table) 1301 1315 { 1302 my $metaval = $ metadata_table->{$metaname};1316 my $metaval = $identify_vals->{'metadata_table'}->{$metaname}; 1303 1317 $doc_obj->add_utf8_metadata ($section, $metaname, $metaval); 1304 1318 } … … 1310 1324 $section); 1311 1325 } 1312 1313 1314 1315 1326 1316 1327 my $flashwidth = $video_width;
Note:
See TracChangeset
for help on using the changeset viewer.