Changeset 28655 for gs2-extensions
- Timestamp:
- 2013-11-20T13:01:51+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/video-and-audio/trunk/src/perllib/plugins/SimpleVideoPlugin.pm
r27647 r28655 230 230 print ' - Extracting metadata using MediaInfo...'; 231 231 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'}); 232 234 $doc_obj->add_utf8_metadata($topsection,"Format", 'multimedia (' . $mi_metadata->{'General'}->{'Format'} . ')'); 233 235 if (defined $mi_metadata->{'General'}->{'File_size'}) … … 239 241 $doc_obj->set_metadata_element($topsection, "FileSize", &FileUtils::fileSize($ivideo_path)); 240 242 } 241 $doc_obj->add_utf8_metadata($topsection,"Duration",$mi_metadata->{'General'}->{'Duration'});242 243 if (defined $mi_metadata->{'Video'}->{'Format_Info'} && defined $mi_metadata->{'Video'}->{'Format'}) 243 244 { … … 318 319 die("Fatal Error! Failed to convert video: " . $ovideo_path . "\nReason:" . $! . "\n"); 319 320 } 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 } 320 329 print STDERR " - conversion done!\n"; 321 330 … … 371 380 } 372 381 382 383 ## @function getDuration() 384 # 385 sub 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 # 373 397 sub getMetadata 374 398 { … … 400 424 return $metadata; 401 425 } 426 ## getMetadata() ## 427 428 429 ## @function parseDurationAsSeconds() 430 # 431 sub 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() ## 402 454 403 455 1;
Note:
See TracChangeset
for help on using the changeset viewer.