NAME
File::Headerinfo - a general purpose extractor of header information from media files. Can handle most image, video and audio file types.
SYNOPSIS
use File::Headerinfo;
my $headerdata = File::Headerinfo->read('/path/to/file.ext');
or
my $reader = File::Headerinfo->new;
my %filedata = map { $_ => $reader->read($_) } @files;
DESCRIPTION
File::Headerinfo is little more than a collection of wrappers around existing modules like MP3::Info and Image::Size. It gathers them all behind a simple, friendly interface and offers an easy way to get header information from almost any kind of media file.
The main Headerinfo modules is a very simple factory class: the real work is done by a set of dedicated subclasses each able to read a different sort of file. A dispatch table in the factory class maps each file suffix onto the subclass that can read that kind of file.
In normal use that minor complexity is hidden from view: all you have to do is pass a file to the read() method and it will do the right thing.
METHODS
read( '/path/to/file.ext')
Examines the file we have been supplied with, creates an object of the appropriate class and tells it to examine the file.
Loading of the subclasses is deferred until it's necessary, as some of them use quite chunky modules to do the file-reading work for them.
You can force a file to be treated as a particular type by supplying the appropriate three or four letter file suffix as a second parameter:
my %fileinfo = File::Headerinfo('/path/to/file', 'mpeg');
new()
A very simple constructor that is rarely called directly. It is inherited by all the specific-format subclasses, so you could do this:
my $reader = File::Headerinfo::SWF->new('/path/to/file.swf');
$reader->parse_file;
my %report = $reader->report;
but needn't bother, since the same thing is achieved by writing:
my %report = File::Headerinfo->read('/path/to/file.swf');
path()
Gets or sets the full path to the file we're trying to examine.
subclass()
Identifies the subclass (or other class) that is meant to read files of the type supplied.
_suffix()
Not a method: just a useful helper. Returns the file suffix, with no dot. Useful if we have no other way of identifying the file type.
parse_file()
Each format-specific subclass has its own way of parsing the media file. This is just a placeholder.
media_classes()
Returns a hashref that maps media types onto class names. The types can come from stored information or from the suffix of the file.
default_media_class()
returns the class name we'll try to use if we can't think of anything else.
fields()
Defines the list of parameters that will be provided by each subclass, which is currently: height, width, duration, filetype, fps, filesize, freq, datarate, vcodec, metadata.
This list is used by AUTOLOAD to create get and set methods, and by report to build its hash of discovered values. It can be overridden by the format-specific subclass if it needs to be extended, but no harm will come from having unused fields here.
allowed_field()
Returns true if the supplied value is in the list of allowed fields.
report()
Returns a hashref containing all the available file information. This method is usually called by read() to return everything at once.
COPYRIGHT
Copyright 2004 William Ross (wross@cpan.org)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.