Changeset 28655 for gs2-extensions

Show
Ignore:
Timestamp:
20.11.2013 13:01:51 (6 years ago)
Author:
jmt12
Message:

Added in some extra testing to check that the duration of the converted video is in the same ballpark as the input video - I wanted to detect an occasional issue where a 10 minute video got truncated down to a few seconds

Files:
1 modified

Legend:

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

    r27647 r28655  
    230230  print ' - Extracting metadata using MediaInfo...'; 
    231231  my $mi_metadata = $self->getMetadata($ivideo_path); 
     232  my $input_video_duration = &parseDurationAsSeconds($mi_metadata->{'General'}->{'Duration'}); 
     233  $doc_obj->add_utf8_metadata($topsection,"Duration",$mi_metadata->{'General'}->{'Duration'}); 
    232234  $doc_obj->add_utf8_metadata($topsection,"Format", 'multimedia (' . $mi_metadata->{'General'}->{'Format'} . ')'); 
    233235  if (defined $mi_metadata->{'General'}->{'File_size'}) 
     
    239241    $doc_obj->set_metadata_element($topsection, "FileSize", &FileUtils::fileSize($ivideo_path)); 
    240242  } 
    241   $doc_obj->add_utf8_metadata($topsection,"Duration",$mi_metadata->{'General'}->{'Duration'}); 
    242243  if (defined $mi_metadata->{'Video'}->{'Format_Info'} && defined $mi_metadata->{'Video'}->{'Format'}) 
    243244  { 
     
    318319    die("Fatal Error! Failed to convert video: " . $ovideo_path . "\nReason:" . $! . "\n"); 
    319320  } 
     321  # Extra check - ensure the converted video is approximately the same duration 
     322  # as the input video, given or take around 5 seconds 
     323  my $output_raw_video_duration = &getDuration($ovideo_path); 
     324  my $output_video_duration = &parseDurationAsSeconds($output_raw_video_duration); 
     325  if (abs($input_video_duration - $output_video_duration) > 5) 
     326  { 
     327    print STDERR "!Warning! Output video does not have same duration as input video.\n"; 
     328  } 
    320329  print STDERR " - conversion done!\n"; 
    321330 
     
    371380} 
    372381 
     382 
     383## @function getDuration() 
     384# 
     385sub getDuration 
     386{ 
     387  my ($video_path) = @_; 
     388  my $cmd = 'mediainfo --Inform="General;%Duration/String%" "' . $video_path . '" 2>&1'; 
     389  my $duration = `$cmd`; 
     390  return $duration; 
     391} 
     392## getDuration() ## 
     393 
     394 
     395## @function getMetadata() 
     396# 
    373397sub getMetadata 
    374398{ 
     
    400424  return $metadata; 
    401425} 
     426## getMetadata() ## 
     427 
     428 
     429## @function parseDurationAsSeconds() 
     430# 
     431sub parseDurationAsSeconds 
     432{ 
     433  my ($duration_str) = @_; 
     434  my $seconds = 0; 
     435  # h - hours 
     436  if ($duration_str =~ /(\d+)h/) 
     437  { 
     438    $seconds += $1 * 60 * 60; 
     439  } 
     440  # mn - minutes 
     441  if ($duration_str =~ /(\d+)mn/) 
     442  { 
     443    $seconds += $1 * 60; 
     444  } 
     445  # s - seconds 
     446  if ($duration_str =~ /(\d+)s/) 
     447  { 
     448    $seconds += $1; 
     449  } 
     450  # ms - milliseconds (ignore - I'll be lucky to match to the closest second) 
     451  return $seconds; 
     452} 
     453## parseDurationAsSeconds() ## 
    402454 
    4034551;