source: gsdl/trunk/perllib/cpan/Image/ExifTool/MPC.pm@ 16842

Last change on this file since 16842 was 16842, checked in by davidb, 16 years ago

ExifTool added to cpan area to support metadata extraction from files such as JPEG. Primarily targetted as Image files (hence the Image folder name decided upon by the ExifTool author) it also can handle video such as flash and audio such as Wav

File size: 4.1 KB
Line 
1#------------------------------------------------------------------------------
2# File: MPC.pm
3#
4# Description: Read Musepack audio meta information
5#
6# Revisions: 11/14/2006 - P. Harvey Created
7#
8# References: 1) http://www.musepack.net/
9#------------------------------------------------------------------------------
10
11package Image::ExifTool::MPC;
12
13use strict;
14use vars qw($VERSION);
15use Image::ExifTool qw(:DataAccess :Utils);
16use Image::ExifTool::FLAC;
17
18$VERSION = '1.00';
19
20# MPC metadata blocks
21%Image::ExifTool::MPC::Main = (
22 PROCESS_PROC => \&Image::ExifTool::FLAC::ProcessBitStream,
23 GROUPS => { 2 => 'Audio' },
24 NOTES => q{
25 Tags used in Musepack (MPC) audio files. ExifTool also extracts ID3 and APE
26 information from these files.
27 },
28 'Bit032-063' => 'TotalFrames',
29 'Bit080-081' => {
30 Name => 'SampleRate',
31 PrintConv => {
32 0 => 44100,
33 1 => 48000,
34 2 => 37800,
35 3 => 32000,
36 },
37 },
38 'Bit084-087' => {
39 Name => 'Quality',
40 PrintConv => {
41 1 => 'Unstable/Experimental',
42 5 => '0',
43 6 => '1',
44 7 => '2 (Telephone)',
45 8 => '3 (Thumb)',
46 9 => '4 (Radio)',
47 10 => '5 (Standard)',
48 11 => '6 (Xtreme)',
49 12 => '7 (Insane)',
50 13 => '8 (BrainDead)',
51 14 => '9',
52 15 => '10',
53 },
54 },
55 'Bit088-093' => 'MaxBand',
56 'Bit096-111' => 'ReplayGainTrackPeak',
57 'Bit112-127' => 'ReplayGainTrackGain',
58 'Bit128-143' => 'ReplayGainAlbumPeak',
59 'Bit144-159' => 'ReplayGainAlbumGain',
60 'Bit179' => {
61 Name => 'FastSeek',
62 PrintConv => { 0 => 'No', 1 => 'Yes' },
63 },
64 'Bit191' => {
65 Name => 'Gapless',
66 PrintConv => { 0 => 'No', 1 => 'Yes' },
67 },
68 'Bit216-223' => {
69 Name => 'EncoderVersion',
70 PrintConv => '$val =~ s/(\d)(\d)(\d)$/$1.$2.$3/; $val',
71 },
72);
73
74#------------------------------------------------------------------------------
75# Extract information from an MPC file
76# Inputs: 0) ExifTool object reference, 1) dirInfo reference
77# - Just looks for MPC trailer if FileType is already set
78# Returns: 1 on success, 0 if this wasn't a valid MPC file
79sub ProcessMPC($$)
80{
81 my ($exifTool, $dirInfo) = @_;
82
83 # must first check for leading ID3 information
84 unless ($exifTool->{DONE_ID3}) {
85 require Image::ExifTool::ID3;
86 Image::ExifTool::ID3::ProcessID3($exifTool, $dirInfo) and return 1;
87 }
88 my $raf = $$dirInfo{RAF};
89 my $buff;
90
91 # check MPC signature
92 $raf->Read($buff, 32) == 32 and $buff =~ /^MP\+(.)/s or return 0;
93 my $vers = ord($1) & 0x0f;
94 $exifTool->SetFileType();
95
96 # extract audio information (currently only from version 7 MPC files)
97 if ($vers == 0x07) {
98 SetByteOrder('II');
99 my $pos = $raf->Tell() - 32;
100 if ($exifTool->Options('Verbose')) {
101 $exifTool->VPrint(0, "MPC Header (32 bytes):\n");
102 $exifTool->VerboseDump(\$buff, DataPos => $pos);
103 }
104 my $tagTablePtr = GetTagTable('Image::ExifTool::MPC::Main');
105 my %dirInfo = ( DataPt => \$buff, DataPos => $pos );
106 $exifTool->ProcessDirectory(\%dirInfo, $tagTablePtr);
107 } else {
108 $exifTool->Warn('Audio info not currently extracted from this version MPC file');
109 }
110
111 # process APE trailer if it exists
112 require Image::ExifTool::APE;
113 Image::ExifTool::APE::ProcessAPE($exifTool, $dirInfo);
114
115 return 1;
116}
117
1181; # end
119
120__END__
121
122=head1 NAME
123
124Image::ExifTool::MPC - Read Musepack audio meta information
125
126=head1 SYNOPSIS
127
128This module is used by Image::ExifTool
129
130=head1 DESCRIPTION
131
132This module contains definitions required by Image::ExifTool to extract meta
133information from Musepack (MPC) audio files.
134
135=head1 AUTHOR
136
137Copyright 2003-2007, Phil Harvey (phil at owl.phy.queensu.ca)
138
139This library is free software; you can redistribute it and/or modify it
140under the same terms as Perl itself.
141
142=head1 REFERENCES
143
144=over 4
145
146=item L<http://www.musepack.net/>
147
148=back
149
150=head1 SEE ALSO
151
152L<Image::ExifTool::TagNames/MPC Tags>,
153L<Image::ExifTool(3pm)|Image::ExifTool>
154
155=cut
156
Note: See TracBrowser for help on using the repository browser.