Image::ExifToolは画像だけでなく、動画に関しても、メタデータが取れます。
動画の場合は、例えば、下記のように取得できます。
$VAR1 = {
'AudioSampleRate' => '44100',
'SelectionTime' => '0 s',
'OpColor' => '0 0 0',
'TrackVersion (1)' => 0,
'TrackVolume (1)' => '100.00%',
'SourceImageHeight' => 360,
'MIMEType' => 'video/mp4',
'FileType' => 'MP4',
'AudioBitsPerSample' => 16,
'MediaHeaderVersion (1)' => 0,
'TrackLayer (1)' => 0,
'TrackCreateDate (1)' => '0000:00:00 00:00:00',
'ExifToolVersion' => '8.00',
'MediaModifyDate' => '0000:00:00 00:00:00',
'Directory' => '/var/www/html/master/src/city/01',
'Version' => 0,
'ImageHeight' => 360,
'PreferredRate' => '1',
'TrackID (1)' => 2,
'TrackVolume' => '0.00%',
'CompatibleBrands' => 'isom, iso2, avc1, mp41',
'PreferredVolume' => '100.00%',
'BitDepth' => 24,
'SelectionDuration' => '0 s',
'NextTrackID' => 3,
'MediaTimeScale (1)' => 30000,
'Duration' => '13.25 s',
'Rotation' => '0',
'HandlerDescription (1)' => 'VideoHandler',
'MajorBrand' => 'MP4 Base Media v1 [IS0 14496-12:2003]',
'PreviewDuration' => '0 s',
'TrackLayer' => 0,
'MinorVersion' => '0.2.0',
'MediaDuration' => '13.17 s',
'SourceImageWidth' => 640,
'ModifyDate' => '0000:00:00 00:00:00',
'MediaTimeScale' => 44100,
'MatrixStructure' => '1 0 0 0 1 0 0 0 1',
'ImageSize' => '640x360',
'ImageWidth' => 640,
'AudioFormat' => 'mp4a',
'HandlerType' => 'Audio Track',
'TimeScale' => 1000,
'PosterTime' => '0 s',
'CurrentTime' => '0 s',
'VideoFrameRate' => '29.97',
'MatrixStructure (1)' => '1 0 0 0 1 0 0 0 1',
'TrackDuration' => '13.25 s',
'GraphicsMode' => 'srcCopy',
'CompressorID' => 'avc1',
'FileName' => '0000000001.mp4',
'XResolution' => '72',
'HandlerType (1)' => 'Video Track',
'MatrixStructure (2)' => '1 0 0 0 1 0 0 0 1',
'MediaCreateDate (1)' => '0000:00:00 00:00:00',
'TrackModifyDate' => '0000:00:00 00:00:00',
'CreateDate' => '0000:00:00 00:00:00',
'MediaLanguageCode (1)' => 'und',
'HandlerDescription' => 'SoundHandler',
'FileModifyDate' => '2010:01:22 03:14:08+09:00',
'TrackVersion' => 0,
'MediaHeaderVersion' => 0,
'MediaLanguageCode' => 'und',
'MediaDuration (1)' => '13.25 s',
'MediaModifyDate (1)' => '0000:00:00 00:00:00',
'TrackID' => 1,
'FileSize' => '656 kB',
'Balance' => '0',
'AudioChannels' => 2,
'YResolution' => '72',
'TrackModifyDate (1)' => '0000:00:00 00:00:00',
'MediaCreateDate' => '0000:00:00 00:00:00',
'TrackDuration (1)' => '13.17 s',
'PreviewTime' => '0 s',
'TrackCreateDate' => '0000:00:00 00:00:00'
};
で、以下のように動画、静止画の大きさ(尺)をチェックする
スクリプトを作成してみました。
(閾値未満のものは0以外のステータスが返ります)
--------【Perl】--------
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Image::ExifTool;
use Log::Dispatch;
use constant WIDTH => 800;
use constant HEIGHT => 450;
use constant DURATION => 4;
my $log = Log::Dispatch->new(outputs => [[
"Screen",
min_level => 'debug',
stderr => 1,
newline => 1
]]);
my $file = $ARGV[0];
my $tool = new Image::ExifTool;
my $exif = $tool->ImageInfo($file);
if(defined $exif->{ImageHeight}) {
$log->debug("ImageHeight: " . $exif->{ImageHeight});
if($exif->{ImageHeight} < HEIGHT) {
$log->debug("Height is short");
exit 11;
}
} else {
$log->debug("Height is undefined.");
exit 1;
}
if(defined $exif->{ImageWidth}) {
$log->debug("ImageWidth: " . $exif->{ImageWidth});
if($exif->{ImageWidth} < WIDTH) {
$log->debug("Width is short");
exit 12;
}
} else {
$log->debug("Undefined Width.");
exit 2;
}
if(defined $exif->{Duration}) {
$log->debug("Duration : " . $exif->{Duration});
chop($exif->{Duration});
chop($exif->{Duration});
if($exif->{Duration} < DURATION) {
$log->debug("Duration is short");
exit 13;
}
} else {
exit 0;
}
--------
次は、PHPでコマンドの終了ステータスを取得してみよう
--------
http://www.suz-lab.com

0 コメント:
コメントを投稿