Debian Codegraph @

README

raw
1 NAME
2 Audio::Scan - Fast C metadata and tag reader for all common audio file
3 formats
4
5 SYNOPSIS
6 use Audio::Scan;
7
8 my $data = Audio::Scan->scan('/path/to/file.mp3');
9
10 # Just file info
11 my $info = Audio::Scan->scan_info('/path/to/file.mp3');
12
13 # Just tags
14 my $tags = Audio::Scan->scan_tags('/path/to/file.mp3');
15
16 # Scan without reading (possibly large) artwork into memory.
17 # Instead of binary artwork data, the size of the artwork will be returned instead.
18 {
19 local $ENV{AUDIO_SCAN_NO_ARTWORK} = 1;
20 my $data = Audio::Scan->scan('/path/to/file.mp3');
21 }
22
23 # Scan a filehandle
24 open my $fh, '<', 'my.mp3';
25 my $data = Audio::Scan->scan_fh( mp3 => $fh );
26 close $fh;
27
28 # Scan and compute an audio MD5 checksum
29 my $data = Audio::Scan->scan( '/path/to/file.mp3', { md5_size => 100 * 1024 } );
30 my $md5 = $data->{info}->{audio_md5};
31
32 DESCRIPTION
33 Audio::Scan is a C-based scanner for audio file metadata and tag
34 information. It currently supports MP3, MP4, Ogg Vorbis, FLAC, ASF, WAV,
35 AIFF, Musepack, Monkey's Audio, and WavPack.
36
37 See below for specific details about each file format.
38
39 METHODS
40 scan( $path, [ \%OPTIONS ] )
41 Scans $path for both metadata and tag information. The type of scan
42 performed is determined by the file's extension. Supported extensions
43 are:
44
45 MP3: mp3, mp2
46 MP4: mp4, m4a, m4b, m4p, m4v, m4r, k3g, skm, 3gp, 3g2, mov
47 AAC (ADTS): aac
48 Ogg: ogg, oga, ogf
49 FLAC: flc, flac, fla, ogf
50 ASF: wma, wmv, asf
51 Musepack: mpc, mpp, mp+
52 Monkey's Audio: ape, apl
53 WAV: wav
54 AIFF: aiff, aif
55 WavPack: wv
56
57 This method returns a hashref containing two other hashrefs: info and
58 tags. The contents of the info and tag hashes vary depending on file
59 format, see below for details.
60
61 An optional hashref may be provided. Currently this supports one item:
62
63 md5_size => $audio_bytes_to_checksum
64
65 An MD5 will be computed of the first N audio bytes. Any tags in the file
66 are automatically skipped, so this is a useful way of determining if a
67 file's audio content is the same even if tags may have been changed. The
68 hex MD5 value is returned in the $info->{audio_md5} key. This option
69 will reduce performance, so choose a small enough size that works for
70 you, you should probably avoid using more than 64K for example.
71
72 scan_info( $path, [ \%OPTIONS ] )
73 If you only need file metadata and don't care about tags, you can use
74 this method.
75
76 scan_tags( $path, [ \%OPTIONS ] )
77 If you only need the tags and don't care about the metadata, use this
78 method.
79
80 scan_fh( $type => $fh, [ \%OPTIONS ] )
81 Scans a filehandle. $type is the type of file to scan as, i.e. "mp3" or
82 "ogg". Note that FLAC does not support reading from a filehandle.
83
84 find_frame( $path, $timestamp_in_ms )
85 Returns the byte offset to the first audio frame starting from the given
86 timestamp (in milliseconds).
87
88 MP3, Ogg, FLAC, ASF, MP4
89 The byte offset to the data packet containing this timestamp will be
90 returned. For file formats that don't provide timestamp information
91 such as MP3, the best estimate for the location of the timestamp
92 will be returned. This will be more accurate if the file has a Xing
93 header or is CBR for example.
94
95 WAV, AIFF, Musepack, Monkey's Audio, WavPack
96 Not yet supported by find_frame.
97
98 find_frame_return_info( $path, $timestamp_in_ms )
99 The header of an MP4 or OggFlac file contains various metadata that refers to the
100 structure of the audio data, making seeking more difficult to perform.
101 This method will return the usual $info hash with 2 additional keys:
102
103 seek_offset - The seek offset in bytes
104 seek_header - A rewritten MP4/OggFlac header that can be prepended to the audio data
105 found at seek_offset to construct a valid bitstream. Specifically, for MP4
106 the following boxes are rewritten: stts, stsc, stsz, stco. For FLAC, the
107 number of samples and md5 in STREAMINFO are zero'd
108
109 For example, to seek 30 seconds into a file and write out a new MP4 file
110 seeked to this point:
111
112 my $info = Audio::Scan->find_frame_return_info( $file, 30000 );
113
114 open my $f, '<', $file;
115 sysseek $f, $info->{seek_offset}, 1;
116
117 open my $fh, '>', 'seeked.m4a';
118 print $fh $info->{seek_header};
119
120 while ( sysread( $f, my $buf, 65536 ) ) {
121 print $fh $buf;
122 }
123
124 close $f;
125 close $fh;
126
127 find_frame_fh( $type => $fh, $offset )
128 Same as "find_frame", but with a filehandle.
129
130 find_frame_fh_return_info( $type => $fh, $offset )
131 Same as "find_frame_return_info", but with a filehandle.
132
133 has_flac()
134 Deprecated. Always returns 1 now that FLAC is always enabled.
135
136 is_supported( $path )
137 Returns 1 if the given path can be scanned by Audio::Scan, or 0 if not.
138
139 get_types()
140 Returns an array of strings of the file types supported by Audio::Scan.
141
142 extensions_for( $type )
143 Returns an array of strings of the file extensions that are considered
144 to be the file type *$type*.
145
146 type_for( $extension )
147 Returns file type for a given extension. Returns *undef* for unsupported
148 extensions.
149
150 MP3
151 INFO
152 The following metadata about a file may be returned:
153
154 id3_version (i.e. "ID3v2.4.0")
155 song_length_ms (duration in milliseconds)
156 layer (i.e. 3)
157 stereo
158 samples_per_frame
159 padding
160 audio_size (size of all audio frames)
161 audio_offset (byte offset to first audio frame)
162 bitrate (in bps, determined using Xing/LAME/VBRI if possible, or average in the worst case)
163 samplerate (in kHz)
164 vbr (1 if file is VBR)
165
166 If a Xing header is found:
167 xing_frames
168 xing_bytes
169 xing_quality
170
171 If a VBRI header is found:
172 vbri_delay
173 vbri_frames
174 vbri_bytes
175 vbri_quality
176
177 If a LAME header is found:
178 lame_encoder_version
179 lame_tag_revision
180 lame_vbr_method
181 lame_lowpass
182 lame_replay_gain_radio
183 lame_replay_gain_audiophile
184 lame_encoder_delay
185 lame_encoder_padding
186 lame_noise_shaping
187 lame_stereo_mode
188 lame_unwise_settings
189 lame_source_freq
190 lame_surround
191 lame_preset
192
193 TAGS
194 Raw tags are returned as found. This means older tags such as ID3v1 and
195 ID3v2.2/v2.3 are converted to ID3v2.4 tag names. Multiple instances of a
196 tag in a file will be returned as arrays. Complex tags such as APIC and
197 COMM are returned as arrays. All tag fields are converted to upper-case.
198 All text is converted to UTF-8.
199
200 Sample tag data:
201
202 tags => {
203 ALBUMARTISTSORT => "Solar Fields",
204 APIC => [ "image/jpeg", 3, "", <binary data snipped> ],
205 CATALOGNUMBER => "INRE 017",
206 COMM => ["eng", "", "Amazon.com Song ID: 202981429"],
207 "MUSICBRAINZ ALBUM ARTIST ID" => "a2af1f31-c9eb-4fff-990c-c4f547a11b75",
208 "MUSICBRAINZ ALBUM ID" => "282143c9-6191-474d-a31a-1117b8c88cc0",
209 "MUSICBRAINZ ALBUM RELEASE COUNTRY" => "FR",
210 "MUSICBRAINZ ALBUM STATUS" => "official",
211 "MUSICBRAINZ ALBUM TYPE" => "album",
212 "MUSICBRAINZ ARTIST ID" => "a2af1f31-c9eb-4fff-990c-c4f547a11b75",
213 "REPLAYGAIN_ALBUM_GAIN" => "-2.96 dB",
214 "REPLAYGAIN_ALBUM_PEAK" => "1.045736",
215 "REPLAYGAIN_TRACK_GAIN" => "+3.60 dB",
216 "REPLAYGAIN_TRACK_PEAK" => "0.892606",
217 TALB => "Leaving Home",
218 TCOM => "Magnus Birgersson",
219 TCON => "Ambient",
220 TCOP => "2005 ULTIMAE RECORDS",
221 TDRC => "2004-10",
222 TIT2 => "Home",
223 TPE1 => "Solar Fields",
224 TPE2 => "Solar Fields",
225 TPOS => "1/1",
226 TPUB => "Ultimae Records",
227 TRCK => "1/11",
228 TSOP => "Solar Fields",
229 UFID => [
230 "http://musicbrainz.org",
231 "1084278a-2254-4613-a03c-9fed7a8937ca",
232 ],
233 },
234
235 MP4
236 INFO
237 The following metadata about a file may be returned:
238
239 audio_offset (byte offset to start of mdat)
240 audio_size
241 compatible_brands
242 file_size
243 leading_mdat (if file has mdat before moov)
244 major_brand
245 minor_version
246 song_length_ms
247 timescale
248 tracks (array of tracks in the file)
249 Each track may contain:
250
251 audio_type
252 avg_bitrate
253 bits_per_sample
254 channels
255 duration
256 encoding
257 handler_name
258 handler_type
259 id
260 max_bitrate
261 samplerate
262
263 TAGS
264 Tags are returned in a hash with all keys converted to upper-case. Keys
265 starting with 0xA9 (copyright symbol) will have this character stripped
266 out. Sample tag data:
267
268 tags => {
269 AART => "Album Artist",
270 ALB => "Album",
271 ART => "Artist",
272 CMT => "Comments",
273 COVR => <binary data snipped>,
274 CPIL => 1,
275 DAY => 2009,
276 DESC => "Video Description",
277 DISK => "1/2",
278 "ENCODING PARAMS" => "vers\0\0\0\1acbf\0\0\0\2brat\0\1w\0cdcv\0\1\6\5",
279 GNRE => "Jazz",
280 GRP => "Grouping",
281 ITUNNORM => " 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000",
282 ITUNSMPB => " 00000000 00000840 000001E4 00000000000001DC 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000",
283 LYR => "Lyrics",
284 NAM => "Name",
285 PGAP => 1,
286 SOAA => "Sort Album Artist",
287 SOAL => "Sort Album",
288 SOAR => "Sort Artist",
289 SOCO => "Sort Composer",
290 SONM => "Sort Name",
291 SOSN => "Sort Show",
292 TMPO => 120,
293 TOO => "iTunes 8.1.1, QuickTime 7.6",
294 TRKN => "1/10",
295 TVEN => "Episode ID",
296 TVES => 12,
297 TVSH => "Show",
298 TVSN => 12,
299 WRT => "Composer",
300 },
301
302 AAC (ADTS)
303 INFO
304 The following metadata about a file is returned:
305
306 audio_offset
307 audio_size
308 bitrate (in bps)
309 channels
310 file_size
311 profile (Main, LC, or SSR)
312 samplerate (in kHz)
313 song_length_ms (duration in milliseconds)
314
315 OGG VORBIS
316 INFO
317 The following metadata about a file is returned:
318
319 version
320 channels
321 stereo
322 samplerate (in kHz)
323 bitrate_average (in bps)
324 bitrate_upper
325 bitrate_nominal
326 bitrate_lower
327 blocksize_0
328 blocksize_1
329 audio_offset (byte offset to audio)
330 audio_size
331 song_length_ms (duration in milliseconds)
332
333 TAGS
334 Raw Vorbis comments are returned. All comment keys are capitalized.
335
336 FLAC or OggFLAC
337 INFO
338 The following metadata about a file is returned:
339
340 channels
341 samplerate (in kHz)
342 bitrate (in bps)
343 bitrage_ogg (in bps, calculate from ogg frames)
344 file_size
345 audio_offset (byte offset to first audio frame)
346 audio_size
347 song_length_ms (duration in milliseconds)
348 bits_per_sample
349 frames
350 minimum_blocksize
351 maximum_blocksize
352 minimum_framesize
353 maximum_framesize
354 md5
355 total_samples
356
357 TAGS
358 Raw FLAC comments are returned. All comment keys are capitalized. Some
359 data returned is special:
360
361 APPLICATION
362
363 Each application block is returned in the APPLICATION tag keyed by application ID.
364
365 CUESHEET_BLOCK
366
367 The CUESHEET_BLOCK tag is an array containing each line of the cue sheet.
368
369 ALLPICTURES
370
371 Embedded pictures are returned in an ALLPICTURES array. Each picture has the following metadata:
372
373 mime_type
374 description
375 width
376 height
377 depth
378 color_index
379 image_data
380 picture_type
381
382 ASF (Windows Media Audio/Video)
383 INFO
384 The following metadata about a file may be returned. Reading the ASF
385 spec is encouraged if you want to find out more about any of these
386 values.
387
388 audio_offset (byte offset to first data packet)
389 audio_size
390 broadcast (boolean, whether the file is a live broadcast or not)
391 codec_list (array of information about codecs used in the file)
392 creation_date (UNIX timestamp when file was created)
393 data_packets
394 drm_key
395 drm_license_url
396 drm_protection_type
397 drm_data
398 file_id (unique file ID)
399 file_size
400 index_blocks
401 index_entry_interval (in milliseconds)
402 index_offsets (byte offsets for each second of audio, per stream. Useful for seeking)
403 index_specifiers (indicates which stream a given index_offset points to)
404 language_list (array of languages referenced by the file's metadata)
405 lossless (boolean)
406 max_bitrate
407 max_packet_size
408 min_packet_size
409 mutex_list (mutually exclusive stream information)
410 play_duration_ms
411 preroll
412 script_commands
413 script_types
414 seekable (boolean, whether the file is seekable or not)
415 send_duration_ms
416 song_length_ms (the actual length of the audio, in milliseconds)
417
418 STREAMS
419
420 The streams array contains metadata related to an individul stream
421 within the file. The following metadata may be returned:
422
423 DeviceConformanceTemplate
424 IsVBR
425 alt_bitrate
426 alt_buffer_fullness
427 alt_buffer_size
428 avg_bitrate (most accurate bitrate for this stream)
429 avg_bytes_per_sec (audio only)
430 bitrate
431 bits_per_sample (audio only)
432 block_alignment (audio only)
433 bpp (video only)
434 buffer_fullness
435 buffer_size
436 channels (audio only)
437 codec_id (audio only)
438 compression_id (video only)
439 encode_options
440 encrypted (boolean)
441 error_correction_type
442 flag_seekable (boolean)
443 height (video only)
444 index_type
445 language_index (offset into language_list array)
446 max_object_size
447 samplerate (in kHz) (audio only)
448 samples_per_block
449 stream_number
450 stream_type
451 super_block_align
452 time_offset
453 width (video only)
454
455 TAGS
456 Raw tags are returned. Tags that occur more than once are returned as
457 arrays. In contrast to the other formats, tag keys are NOT capitalized.
458 There is one special key:
459
460 WM/Picture
461
462 Pictures are returned as a hash with the following keys:
463
464 image_type (numeric type, same as ID3v2 APIC)
465 mime_type
466 description
467 image
468
469 WAV
470 INFO
471 The following metadata about a file may be returned.
472
473 audio_offset
474 audio_size
475 bitrate (in bps)
476 bits_per_sample
477 block_align
478 channels
479 file_size
480 format (WAV format code, 1 == PCM)
481 id3_version (if an ID3v2 tag is found)
482 samplerate (in kHz)
483 song_length_ms
484
485 TAGS
486 WAV files can contain several different types of tags. "Native" WAV tags
487 found in a LIST block may include these and others:
488
489 IARL - Archival Location
490 IART - Artist
491 ICMS - Commissioned
492 ICMT - Comment
493 ICOP - Copyright
494 ICRD - Creation Date
495 ICRP - Cropped
496 IENG - Engineer
497 IGNR - Genre
498 IKEY - Keywords
499 IMED - Medium
500 INAM - Name (Title)
501 IPRD - Product (Album)
502 ISBJ - Subject
503 ISFT - Software
504 ISRC - Source
505 ISRF - Source Form
506 TORG - Label
507 LOCA - Location
508 TVER - Version
509 TURL - URL
510 TLEN - Length
511 ITCH - Technician
512 TRCK - Track
513 ITRK - Track
514
515 ID3v2 tags can also be embedded within WAV files. These are returned
516 exactly as for MP3 files.
517
518 AIFF
519 INFO
520 The following metadata about a file may be returned.
521
522 audio_offset
523 audio_size
524 bitrate (in bps)
525 bits_per_sample
526 block_align
527 channels
528 compression_name (if AIFC)
529 compression_type (if AIFC)
530 file_size
531 id3_version (if an ID3v2 tag is found)
532 samplerate (in kHz)
533 song_length_ms
534
535 TAGS
536 ID3v2 tags can be embedded within AIFF files. These are returned exactly
537 as for MP3 files.
538
539 MONKEY'S AUDIO (APE)
540 INFO
541 The following metadata about a file may be returned.
542
543 audio_offset
544 audio_size
545 bitrate (in bps)
546 channels
547 compression
548 file_size
549 samplerate (in kHz)
550 song_length_ms
551 version
552
553 TAGS
554 APEv2 tags are returned as a hash of key/value pairs.
555
556 MUSEPACK
557 INFO
558 The following metadata about a file may be returned.
559
560 audio_offset
561 audio_size
562 bitrate (in bps)
563 channels
564 encoder
565 file_size
566 profile
567 samplerate (in kHz)
568 song_length_ms
569
570 TAGS
571 Musepack uses APEv2 tags. They are returned as a hash of key/value
572 pairs.
573
574 WAVPACK
575
576 The following metadata about a file may be returned.
577
578 audio_offset
579 audio_size
580 bitrate (in bps)
581 bits_per_sample
582 channels
583 encoder_version
584 file_size
585 hybrid (1 if file is lossy) (v4 only)
586 lossless (1 if file is lossless) (v4 only)
587 samplerate
588 song_length_ms
589 total_samples
590
591 TAGS
592 WavPack uses APEv2 tags. They are returned as a hash of key/value pairs.
593
594
595 THANKS
596 Some code from the Rockbox project was very helpful in implementing ASF
597 and MP4 seeking.
598
599 Some of the file format parsing code was derived from the mt-daapd
600 project, and adapted by Netgear. It has been heavily rewritten to fix
601 bugs and add more features.
602
603 The source to the original Netgear C scanner for SqueezeCenter is
604 located at
605 <http://svn.slimdevices.com/repos/slim/7.3/trunk/platforms/readynas/cont
606 rib/scanner>
607
608 The audio MD5 feature uses an MD5 implementation by L. Peter Deutsch,
609 <[email protected]>.
610
611 SEE ALSO
612 ASF Spec
613 <http://www.microsoft.com/windows/windowsmedia/forpros/format/asfspec.as
614 px>
615
616 MP4 Info:
617 <http://standards.iso.org/ittf/PubliclyAvailableStandards/c051533_ISO_IE
618 C_14496-12_2008.zip>
619 <http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt>
620
621 AUTHORS
622 Andy Grundman, <[email protected]>
623
624 Dan Sully, <[email protected]>
625
626 COPYRIGHT AND LICENSE
627 Copyright (C) 2010 Logitech, Inc.
628
629 This program is free software; you can redistribute it and/or modify it
630 under the terms of the GNU General Public License as published by the
631 Free Software Foundation; either version 2 of the License, or (at your
632 option) any later version.
633