Ignore:
Timestamp:
2010-12-07T17:08:07+13:00 (13 years ago)
Author:
max
Message:

Switched to using a hash map to transfer video level metadata between 'indentify' type call rather than an array/tuple.

Now we also deinterlace the video when extracting the thumbnail.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/video-and-audio/trunk/src/perllib/plugins/VideoConverter.pm

    r23292 r23407  
    194194
    195195
    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
    206197sub mediaInfo_Inform_Cmd {
    207198    my ($video, $parameter, $outhandle, $verbosity) = @_;
     
    221212
    222213# 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 encoded
     214# the result will vary depending on the file type and how it was encoded
    224215sub mediaInfo_XML_Cmd {
    225216    my ($video, $outhandle, $verbosity) = @_;
     
    237228}
    238229
    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.
    240232sub mediaInfo_parse_XML {
    241233    my ($xmlTxt, $outhandle, $verbosity) = @_;
     
    286278    my ($video, $outhandle, $verbosity) = @_;
    287279
    288     # Use the ffmpeg command to get the file specs
    289     my $command = "ffmpeg -i \"$video\"";
     280    # Use the MediaInfo command to get the file specs
     281    my $command = "MediaInfo \"$video\"";
    290282
    291283    print $outhandle "  $command\n" if ($verbosity > 2);
     
    294286    print $outhandle "  $result\n" if ($verbosity > 4);
    295287
    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       
    313315
    314316    my $xmlTxt =  mediaInfo_XML_Cmd ($video,$outhandle,0);
     
    316318   
    317319    # 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
    323329sub identify {
    324330    my ($video, $outhandle, $verbosity) = @_;
     
    420426        my $full_v = &util::filename_cat($media_base_dir,$v);
    421427
    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);
    424430
    425431        my ($vob_num) = ($v =~ m/^VTS_\d\d_(\d)\.VOB$/);
     
    894900    my $ivideo_filename_gsdlenv = $self->gsdlhome_independent($ivideo_filename);
    895901
    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\"";
    897903
    898904    # fmpeg -i input.dv -r 1 -f image2 -s 120x96 images%05d.png
     
    11871193    my $outhandle = $self->{'outhandle'};
    11881194
    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
    11911197    #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'});
    12031213   
    12041214    my $get_max_metadata = $self->{'getMaximumMetadata'};
    12051215    if ($get_max_metadata eq "true"){
     1216        my $metadata_table = $identify_vals->{'metadata_table'};
    12061217        foreach my $metaname(keys %$metadata_table)
    12071218        {
    1208             my $metaval = $metadata_table->{$metaname};
     1219            my $metaval = $identify_vals->{'metadata_table'}->{$metaname};
    12091220            $doc_obj->add_utf8_metadata ($section, $metaname, $metaval);
    12101221        }
     
    12811292    my $outhandle = $self->{'outhandle'};
    12821293
    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   
    12851296    #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'});
    12971310   
    12981311    my $get_max_metadata = $self->{'getMaximumMetadata'};
    12991312    if ($get_max_metadata eq "true"){
     1313        my $metadata_table = $identify_vals->{'metadata_table'};
    13001314        foreach my $metaname(keys %$metadata_table)
    13011315        {
    1302             my $metaval = $metadata_table->{$metaname};
     1316            my $metaval = $identify_vals->{'metadata_table'}->{$metaname};
    13031317            $doc_obj->add_utf8_metadata ($section, $metaname, $metaval);
    13041318        }
     
    13101324                 $section);
    13111325    }
    1312 
    1313 
    1314 
    13151326
    13161327    my $flashwidth = $video_width;
Note: See TracChangeset for help on using the changeset viewer.