Image::ExifTool ― 2006年06月22日 03時24分09秒
Image::ExifTool はExif はもちろん、それ以外の画像やムービー、音声にも対応している優れものです。
Image::ExifToolを用いたフィルタを書けば、数多くのメディアに対応できることになります。
しかし、個々のフォーマットのタグ名はバラバラで数も多いので、いろいろと整理してまとめる必要があります。その前準備として次のプログラムでテストをしています。
基本的にはコメントを要約にというように、タグとフィールドの対応づけを考えています。
それに加えて画像、ムービー、音声のそれぞれにいくつかのフィールドを拡張しようと思います。
拡張フィールドとしては、GPS情報等を考えています。単独では無理ですが、CGIと組み合わせれば、Namazuの検索結果に地図へのリンクを作ることも可能でしょう。
#!/usr/bin/perl -w
use strict;
use Image::ExifTool;
use NKF;
sub filter_image($);
sub filter_video($);
sub filter_audio($);
sub info($$);
sub usage();
print usage() if ($#ARGV == -1);
my $file = $ARGV[0];
my $info = Image::ExifTool::ImageInfo($file);
if (my $error = $info->{'Error'}) {
die "Can't parse image info: $error\n";
}
foreach my $key (sort keys %$info) {
my $val = $$info{$key};
if (ref $val eq 'SCALAR') {
my $msg;
if ($$val =~ /^Binary data/) {
$msg = $$val;
} else {
$msg = 'Binary data ' . length($$val) . ' bytes';
}
$val = "($msg)";
} elsif (ref $val eq 'ARRAY') {
$val = join(', ',@$val);
}
print "$key => ", nkf("-e", $val), "\n";
$$info{$key} = nkf("-emZ1", $val);
}
print "----------\n";
print "FileType: ", info($info, 'FileType'), "\n";
print "MIMEType: ", info($info, 'MIMEType'), "\n";
if ($$info{MIMEType} =~ m#^image/#) {
filter_image($info);
} elsif ($$info{MIMEType} =~ m#^video/#) {
filter_video($info);
} elsif ($$info{MIMEType} =~ m#^audio/#) {
filter_audio($info);
}
sub filter_image($)
{
my ($info) = @_;
print "ImageWidth: ", info($info, 'ImageWidth'), "\n";
print "ImageHeight: ", info($info, 'ImageHeight'), "\n";
print "Compression: ", info($info, 'Compression'), "\n";
}
sub filter_video($)
{
my ($info) = @_;
print "ImageWidth: ", info($info, 'ImageWidth'), "\n";
print "ImageHeight: ", info($info, 'ImageHeight'), "\n";
if ($$info{MIMEType} =~ m#/x-ms-asf$#) { # video/x-ms-asf
# subject => AlbumTitle Title
# from => AlbumArtist Author
# date => CreationDate
# summary => Description
print "Title: ", info($info, 'Title'), "\n";
print "Author: ", info($info, 'Author'), "\n";
print "CreationDate: ", info($info, 'CreationDate'), "\n";
print "AlbumTitle: ", info($info, 'AlbumTitle'), "\n";
print "AlbumArtist: ", info($info, 'AlbumArtist'), "\n";
print "PlayDuration: ", info($info, 'PlayDuration'), "\n";
print "SendDuration: ", info($info, 'SendDuration'), "\n";
print "Description: ", info($info, 'Description'), "\n";
print "Genre: ", info($info, 'Genre'), "\n";
print "TrackNumber: ", info($info, 'TrackNumber'), "\n";
} elsif ($$info{MIMEType} =~ m#/quicktime$#) { # video/quicktime
print "CreateDate: ", info($info, 'CreateDate'), "\n";
print "Duration: ", info($info, 'Duration'), "\n";
} elsif ($$info{MIMEType} =~ m#/mp4$#) { # video/mp4
print "CreateDate: ", info($info, 'CreateDate'), "\n";
}
}
sub filter_audio($)
{
my ($info) = @_;
if ($$info{MIMEType} =~ m#/mpeg$#) { # audio/mpeg
print "Title: ", info($info, 'Title'), "\n";
print "Subtitle: ", info($info, 'Subtitle'), "\n";
print "Artist: ", info($info, 'Artist'), "\n";
print "Album: ", info($info, 'Album'), "\n";
print "Year: ", info($info, 'Year'), "\n";
print "Comment: ", info($info, 'Comment'), "\n";
print "Genre: ", info($info, 'Genre'), "\n";
print "Track: ", info($info, 'Track'), "\n";
} elsif ($$info{MIMEType} =~ m#/x-wav$#) { # audio/x-wav
print "Encoding: ", info($info, 'Encoding'), "\n";
print "Title: ", info($info, 'Title'), "\n";
print "Subject: ", info($info, 'Subject'), "\n";
print "Artist: ", info($info, 'Artist'), "\n";
print "Comment: ", info($info, 'Comment'), "\n";
print "UserComment: ", info($info, 'UserComment'), "\n";
print "Genre: ", info($info, 'Genre'), "\n";
print "Keywords: ", info($info, 'Keywords'), "\n";
print "Comment: ", info($info, 'Comment'), "\n";
}
}
sub info($$)
{
my ($info, $key) = @_;
return (defined $$info{$key}) ? return $$info{$key} : '';
}
sub usage()
{
print "Usage: exiftool.pl imagefile\n";
exit 0;
}
最近のコメント