Audio-Scan
view release on metacpan or search on metacpan
lib/Audio/Scan.pm view on Meta::CPAN
while ( sysread( $f, my $buf, 65536 ) ) {
print $fh $buf;
}
close $f;
close $fh;
=head2 find_frame_fh( $type => $fh, $offset )
Same as C<find_frame>, but with a filehandle.
=head2 find_frame_fh_return_info( $type => $fh, $offset )
Same as C<find_frame_return_info>, but with a filehandle.
=head2 has_flac()
Deprecated. Always returns 1 now that FLAC is always enabled.
=head2 is_supported( $path )
Returns 1 if the given path can be scanned by Audio::Scan, or 0 if not.
=head2 get_types()
Returns an array of strings of the file types supported by Audio::Scan.
=head2 extensions_for( $type )
Returns an array of strings of the file extensions that are considered to
be the file type I<$type>.
=head2 type_for( $extension )
Returns file type for a given extension. Returns I<undef> for unsupported
extensions.
=head1 SKIPPING ARTWORK
To save memory while reading tags, you can opt to skip potentially large
embedded artwork. To do this, set the environment variable AUDIO_SCAN_NO_ARTWORK:
local $ENV{AUDIO_SCAN_NO_ARTWORK} = 1;
my $tags = Audio::Scan->scan_tags($file);
This will return the length of the embedded artwork instead of the actual image data.
In some cases it will also return a byte offset to the image data, which can be used
to extract the image using more efficient means. Note that the offset is not always
returned so if you want to use this data make sure to check for offset. If offset
is not present, the only way to get the image data is to perform a normal tag scan
without the environment variable set.
One limitation that currently exists is that memory for embedded images is still
allocated for ASF and Ogg Vorbis files.
This information is returned in different ways depending on the format:
ID3 (MP3, AAC, WAV, AIFF):
$tags->{APIC}->[3]: image length
$tags->{APIC}->[4]: image offset (unless APIC would need unsynchronization)
MP4:
$tags->{COVR}: image length
$tags->{COVR_offset}: image offset (always available)
Ogg Vorbis:
$tags->{ALLPICTURES}->[0]->{image_data}: image length
Image offset is not supported with Vorbis because the data is always base64-encoded.
FLAC:
$tags->{ALLPICTURES}->[0]->{image_data}: image length
$tags->{ALLPICTURES}->[0]->{offset}: image offset (always available)
ASF:
$tags->{'WM/Picture'}->{image}: image length
$tags->{'WM/Picture'}->{offset}: image offset (always available)
APE, Musepack, WavPack, MP3 with APEv2:
$tags->{'COVER ART (FRONT)'}: image length
$tags->{'COVER ART (FRONT)_offset'}: image offset (always available)
=head1 MP3
=head2 INFO
The following metadata about a file may be returned:
id3_version (i.e. "ID3v2.4.0")
id3_was_unsynced (if a v2.2/v2.3 file needed whole-tag unsynchronization)
song_length_ms (duration in milliseconds)
layer (i.e. 3)
stereo
samples_per_frame
padding
audio_size (size of all audio frames)
audio_offset (byte offset to first audio frame)
bitrate (in bps, determined using Xing/LAME/VBRI if possible, or average in the worst case)
samplerate (in kHz)
vbr (1 if file is VBR)
dlna_profile (if file is compliant)
If a Xing header is found:
xing_frames
xing_bytes
xing_quality
If a VBRI header is found:
vbri_delay
vbri_frames
vbri_bytes
vbri_quality
If a LAME header is found:
lame_encoder_version
lame_tag_revision
lame_vbr_method
lame_lowpass
lame_replay_gain_radio
lame_replay_gain_audiophile
lame_encoder_delay
lame_encoder_padding
lame_noise_shaping
lame_stereo_mode
lame_unwise_settings
lame_source_freq
lame_surround
lame_preset
=head2 TAGS
Raw tags are returned as found. This means older tags such as ID3v1 and ID3v2.2/v2.3
are converted to ID3v2.4 tag names. Multiple instances of a tag in a file will be returned
as arrays. Complex tags such as APIC and COMM are returned as arrays. All tag fields are
converted to upper-case. All text is converted to UTF-8.
Sample tag data:
tags => {
ALBUMARTISTSORT => "Solar Fields",
APIC => [ "image/jpeg", 3, "", <binary data snipped> ],
CATALOGNUMBER => "INRE 017",
COMM => ["eng", "", "Amazon.com Song ID: 202981429"],
"MUSICBRAINZ ALBUM ARTIST ID" => "a2af1f31-c9eb-4fff-990c-c4f547a11b75",
"MUSICBRAINZ ALBUM ID" => "282143c9-6191-474d-a31a-1117b8c88cc0",
"MUSICBRAINZ ALBUM RELEASE COUNTRY" => "FR",
"MUSICBRAINZ ALBUM STATUS" => "official",
"MUSICBRAINZ ALBUM TYPE" => "album",
"MUSICBRAINZ ARTIST ID" => "a2af1f31-c9eb-4fff-990c-c4f547a11b75",
"REPLAYGAIN_ALBUM_GAIN" => "-2.96 dB",
( run in 1.921 second using v1.01-cache-2.11-cpan-39bf76dae61 )