PowerPress Podcasting plugin by Blubrry - Version 6.0

Version Description

  • Released on 12/19/2014
  • You must have WordPress 3.6 or newer and PHP 5.2 or newer for PowerPress 6.0.
  • NEW FEATURE: Playlist player, utilizes WordPress built-in playlist specifically for podcasting. Learn more
  • NEW FEATURE: Subscribe links, adds subscribe on iTunes and via RSS links below the player and links.
  • NEW FEATURE: Subscribe page template and [powerpress_subscribe] page shortcode added. Create a "Subscribe to podcast" page for your podcast.
  • NEW FEATURE: Subscribe to podcast widget, adds subscribe on iTunes and via RSS links to side bar, with optional link to subscribe to podcast page.
  • NEW FEATURE: Podcasting SEO settings. Includes options to customize podcast feed titles, AudioObjects, VideoObjects, and highlight key iTunes fields.
  • NEW FEATURE: Migrate to Blubrry Podcast Hosting in 3 easy steps added.
  • iTunes image requirements updated, 1400x1400 minimum size is now "required" and 2048x2048 is now the maximum size for iTunes artwork.
  • iTunes category and subcategory selection updated for latest iTunes category selection rules.
  • Enhnaced iTunes Summary is back! The feature actually never left, but for the past few years links were not formatted in the iOS app. Now that they are, we now recommend the feature.
  • Fixed bug where Feed Maximizer option only worked when Podcast Channels was enabled (Thanks Daniel Lewis for bringing to our attention!)
  • Fixed bug where player and links would not appear if Yoast's WordPress SEO plugin option "Add Open Graph meta data" was enabled.
  • iTunes keywords feature has been removed, feature was deprecated last year by Apple. The iTunes keywords field will appear for previous episodes that used the feature.
  • Added support for Opus audio with content type audio/ogg. (Thanks thebugcast for the heads up!)
  • Files with 'ogg' file extension are now treated as audio/ogg, unless the following define is added to your wp-config.php: define('POWERPRESS_OGG_VIDEO', true); (Thanks thebugcast for pointing out the default!)
  • Updated the Find and Replace episode URLs tool to use native WordPress MySQL query functions.
  • Changed the logic for HEAD requests for HTTP authentication. Default WordPress behavior is to exit all HEAD requests. (Thanks thebugcast!)
  • Changed all content types to either use the site default or use UTF8 (applies to play in new window and 401 Unauthorized HTML pages).
  • Added new powerpress_premium_content_authorized filter for premium plugins to override the default behavior which uses roles and capabilities.
  • Updated the getid3 library to latest version, PowerPress now includes ogg duration detection support for "Speex" or "vorbis".
  • We are no longer detecting if the sample rate is optimal, we're no longer worried about Flash playback.
  • Removed Flow Player, Simple Flash, AudioPlay and Flash Mp3 Maxi players. These flash players are no longer supported.
  • New MediaElement.js Audio player max width setting added. Player will now display full with otherwise. Player is now responsive, the width will shrink or stretch for the screen.
  • Improved MediaElement.js Video player width and height settings. Player will now display full width, or as styled by the theme's CSS if width and height are blank. Player is now responsive, the width will shrink or stretch for the screen, the height can be set with a blank width to allow for the player to fit different screens.
  • We are now warning users not to use Flash based players in the player selection screens.
  • Added option to set stats redirect at the channel/post type level. Requires a define CHANNEL_STATS_REDIRECT and/or POST_TYPE_STATS_REDIRECT in the wp-config.php file.
  • FeedBurner feed URL when set will be used in the new subscribe page and subscribe sidebar widget (Thanks Daniel Lewis for bringing to our attention)
  • Playlist Player no longer includes the play time when it is zero. (Thanks Daniel Lewis for bringing to our attention)
  • Program Titles with double quotes in the general settings was not escaped correctly, it is now fixed. (Thanks Robin for bringing to our attention)
  • Edit value fields now use the esc_attr() wordpress function rather than the htmlspecialchars() native PHP function.
  • Added powerpress_admin_capabilities filter for premium capabilities. (Thanks Blair Williams for the suggestion)
  • Made subscribe sidebar and subscribe embed button icons Retina screen compatible
  • Re-added the blubrry folder icon for blubrry podcast hosting customers.
  • Tweaked wording and updated documentation for SEO settings (Thanks Daniel Lewis for the feedback!)
  • Tweaked updated documentation for the PowerPress Playlist (Thanks Daniel Lewis for asking questions, it helped us better document the features)
  • Fixed subscribe links always displaying (thanks Thiago Miro for pointing out the bug)
  • Fixed upload itunes image and poster image episode functions to use selected image size when "Link URL" is blank (Thanks Daniel Lewis for bringing to our attention)
  • Added a learn more link to the SEO page.
  • Added code for the new Subscribe embed so the subscribe embed CSS is only loaded when the shortcode is used in a page.
  • Added the wp-video and wp-video-shortcode classes to the MEJS video player so latest CSS styling in WordPress is again applied 100% of the time to the MEJS player packaged in PowerPress.
  • Playlist player will now use the iTunes episode image if one is set for each episode. Program level image is used if no image is set.
  • Playlist player taxonomy podcasting now accepts the term_taxonomy_id, making it more efficient.
  • Moved the Shortcodes into their own section in Media Appearance settings, they are now included in Podcast Channels, Category Podcasting, Post Type podcasting and Taxonomy podcasting with the appropriate attributes set for convenience.
  • Brazilian Portuguese translation for v6.0+ by Leo Lopes from Radiofobia.

=

Download this release

Release Info

Developer amandato
Plugin Icon 128x128 PowerPress Podcasting plugin by Blubrry
Version 6.0
Comparing to
See all releases

Code changes from version 5.0.10 to 6.0

Files changed (51) hide show
  1. 3rdparty/maxi_player/generator.js +0 -147
  2. audioplay.swf +0 -0
  3. buttons/classic/pausedown.png +0 -0
  4. buttons/classic/pauseover.png +0 -0
  5. buttons/classic/pauseup.png +0 -0
  6. buttons/classic/playdown.png +0 -0
  7. buttons/classic/playover.png +0 -0
  8. buttons/classic/playup.png +0 -0
  9. buttons/classic/stopdown.png +0 -0
  10. buttons/classic/stopover.png +0 -0
  11. buttons/classic/stopup.png +0 -0
  12. buttons/classic_small/pausedown.png +0 -0
  13. buttons/classic_small/pauseover.png +0 -0
  14. buttons/classic_small/pauseup.png +0 -0
  15. buttons/classic_small/playdown.png +0 -0
  16. buttons/classic_small/playover.png +0 -0
  17. buttons/classic_small/playup.png +0 -0
  18. buttons/classic_small/stopdown.png +0 -0
  19. buttons/classic_small/stopover.png +0 -0
  20. buttons/classic_small/stopup.png +0 -0
  21. buttons/negative/pausedown.png +0 -0
  22. buttons/negative/pauseover.png +0 -0
  23. buttons/negative/pauseup.png +0 -0
  24. buttons/negative/playdown.png +0 -0
  25. buttons/negative/playover.png +0 -0
  26. buttons/negative/playup.png +0 -0
  27. buttons/negative/stopdown.png +0 -0
  28. buttons/negative/stopover.png +0 -0
  29. buttons/negative/stopup.png +0 -0
  30. buttons/negative_small/pausedown.png +0 -0
  31. buttons/negative_small/pauseover.png +0 -0
  32. buttons/negative_small/pauseup.png +0 -0
  33. buttons/negative_small/playdown.png +0 -0
  34. buttons/negative_small/playover.png +0 -0
  35. buttons/negative_small/playup.png +0 -0
  36. buttons/negative_small/stopdown.png +0 -0
  37. buttons/negative_small/stopover.png +0 -0
  38. buttons/negative_small/stopup.png +0 -0
  39. class.powerpress-subscribe-widget.php +256 -0
  40. css/admin.css +18 -10
  41. css/dashboard.css +23 -1
  42. css/subscribe.css +171 -0
  43. getid3/getid3.lib.php +1379 -1317
  44. getid3/getid3.php +1809 -1766
  45. getid3/module.audio-video.quicktime.php +2246 -2134
  46. getid3/module.audio-video.riff.php +2586 -2409
  47. getid3/module.audio.aac.php +513 -515
  48. getid3/module.audio.flac.php +443 -0
  49. getid3/module.audio.mp3.php +2012 -2011
  50. getid3/module.audio.ogg.php +756 -0
  51. getid3/module.tag.apetag.php +57 -372
3rdparty/maxi_player/generator.js DELETED
@@ -1,147 +0,0 @@
1
- var generator = new Object();
2
- generator.params = new Object();
3
- generator.updateParam = function(name, value)
4
- {
5
- //var element = document.getElementById(id);
6
- switch (this.params[name].type) {
7
- case "url":
8
- case "text":
9
- case "color":
10
- this.params[name].value = value;
11
- break;
12
- case "int":
13
- this.params[name].value = Number(value);
14
- break;
15
- case "bool":
16
- this.params[name].value = value; // (value == "on")?1:0;
17
- break;
18
- }
19
- }
20
-
21
- generator.addParam = function(id, name, type, defaultValue)
22
- {
23
- var element = document.getElementById(id);
24
- this.params[name] = new Object();
25
- this.params[name].type = type;
26
- this.params[name].defaultValue = defaultValue;
27
- this.params[name].element = element;
28
- switch (type) {
29
- case "url":
30
- case "text":
31
- this.params[name].value = element.value;
32
- element.onchange = delegate(this.params[name], function()
33
- {
34
- this.value = this.element.value;
35
- generator.updatePlayer();
36
- });
37
- break;
38
- case "color":
39
- this.params[name].value = element.value.replace(/#/, '');
40
- element.onchange = delegate(this.params[name], function()
41
- {
42
- this.value = this.element.value;
43
- generator.updatePlayer();
44
- });
45
- break;
46
- break;
47
- case "int":
48
- this.params[name].value = Number(element.value);
49
- element.onchange = delegate(this.params[name], function()
50
- {
51
- this.value = Number(this.element.value);
52
- generator.updatePlayer();
53
- });
54
- break;
55
- case "bool":
56
- this.params[name].value = element.value; // (element.value == "on")?1:0;
57
- element.onchange = delegate(this.params[name], function()
58
- {
59
- this.value = this.element.value; // (this.element.value == "on")?1:0;
60
- generator.updatePlayer();
61
- });
62
- break;
63
- }
64
- };
65
- generator.updatePlayer = function()
66
- {
67
- var out = '<object type="application/x-shockwave-flash" data="'+this.player+'" width="'+this.params.width.value+'" height="'+this.params.height.value+'">'+"\n";
68
- out += ' <param name="movie" value="'+this.player+'" />'+"\n";
69
- if (this.params.bgcolor) {
70
- out += ' <param name="bgcolor" value="#'+this.params.bgcolor.value.replace(/#/, '')+'" />'+"\n";
71
- }
72
- out += ' <param name="FlashVars" value="';
73
-
74
- var separator = '';
75
- for (var i in this.params) {
76
- if (this.params[i].value != this.params[i].defaultValue && this.params[i].value != '' ) {
77
- if (this.params[i].type == "url") {
78
- out += separator + i + '=' + escape(this.params[i].value);
79
- }
80
- else if(this.params[i].type == "color") {
81
- out += separator + i + '=' + this.params[i].value.replace(/#/, '');
82
- }
83
- else {
84
- out += separator + i + '=' + escapeHTML(this.params[i].value);
85
- }
86
- separator = '&amp;';
87
- }
88
- }
89
-
90
- out += '" />'+"\n";
91
- out += '</object>';
92
-
93
- var player = document.getElementById("player_preview");
94
- player.innerHTML = out;
95
- };
96
-
97
- var params = new Object();
98
-
99
- /* =============== UTILS =============== */
100
- var delegate = function(pTarget, pFunction)
101
- {
102
- var f = function(){
103
- arguments.callee.func.apply(arguments.callee.target, arguments);
104
- };
105
- f.target = pTarget;
106
- f.func = pFunction;
107
- return f;
108
- }
109
- var escapeHTML = function(str) {
110
- str = String(str);
111
- str = str.replace(/&/gi, '');
112
-
113
- var div = document.createElement("div");
114
- var text = document.createTextNode('');
115
- div.appendChild(text);
116
- text.data = str;
117
-
118
- var result = div.innerHTML;
119
- result = result.replace(/"/gi, '&quot;');
120
-
121
- return result;
122
- }
123
- var findPosX = function (obj)
124
- {
125
- var curleft = 0;
126
- do {
127
- curleft += obj.offsetLeft || 0;
128
- obj = obj.offsetParent;
129
- } while (obj);
130
- return curleft;
131
- };
132
- var findPosY = function (obj)
133
- {
134
- var curtop = 0;
135
- do {
136
- curtop += obj.offsetTop || 0;
137
- obj = obj.offsetParent;
138
- } while (obj);
139
- return curtop;
140
- };
141
- var twoChar = function (str)
142
- {
143
- if (str.length == 1) {
144
- return "0" + str;
145
- }
146
- return str;
147
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
audioplay.swf DELETED
Binary file
buttons/classic/pausedown.png DELETED
Binary file
buttons/classic/pauseover.png DELETED
Binary file
buttons/classic/pauseup.png DELETED
Binary file
buttons/classic/playdown.png DELETED
Binary file
buttons/classic/playover.png DELETED
Binary file
buttons/classic/playup.png DELETED
Binary file
buttons/classic/stopdown.png DELETED
Binary file
buttons/classic/stopover.png DELETED
Binary file
buttons/classic/stopup.png DELETED
Binary file
buttons/classic_small/pausedown.png DELETED
Binary file
buttons/classic_small/pauseover.png DELETED
Binary file
buttons/classic_small/pauseup.png DELETED
Binary file
buttons/classic_small/playdown.png DELETED
Binary file
buttons/classic_small/playover.png DELETED
Binary file
buttons/classic_small/playup.png DELETED
Binary file
buttons/classic_small/stopdown.png DELETED
Binary file
buttons/classic_small/stopover.png DELETED
Binary file
buttons/classic_small/stopup.png DELETED
Binary file
buttons/negative/pausedown.png DELETED
Binary file
buttons/negative/pauseover.png DELETED
Binary file
buttons/negative/pauseup.png DELETED
Binary file
buttons/negative/playdown.png DELETED
Binary file
buttons/negative/playover.png DELETED
Binary file
buttons/negative/playup.png DELETED
Binary file
buttons/negative/stopdown.png DELETED
Binary file
buttons/negative/stopover.png DELETED
Binary file
buttons/negative/stopup.png DELETED
Binary file
buttons/negative_small/pausedown.png DELETED
Binary file
buttons/negative_small/pauseover.png DELETED
Binary file
buttons/negative_small/pauseup.png DELETED
Binary file
buttons/negative_small/playdown.png DELETED
Binary file
buttons/negative_small/playover.png DELETED
Binary file
buttons/negative_small/playup.png DELETED
Binary file
buttons/negative_small/stopdown.png DELETED
Binary file
buttons/negative_small/stopover.png DELETED
Binary file
buttons/negative_small/stopup.png DELETED
Binary file
class.powerpress-subscribe-widget.php ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package PowerPressSubscribe_Widget
4
+ */
5
+ class PowerPressSubscribe_Widget extends WP_Widget {
6
+
7
+ function __construct() {
8
+ load_plugin_textdomain( 'powerpress' );
9
+
10
+ parent::__construct(
11
+ 'powerpress_subscribe',
12
+ __( 'Subscribe to Podcast' , 'powerpress'),
13
+ array( 'description' => __( 'Display subscribe to podcast links.' , 'powerpress') )
14
+ );
15
+
16
+ if ( is_active_widget( false, false, $this->id_base ) ) {
17
+ add_action( 'wp_head', array( $this, 'css' ) );
18
+ }
19
+ }
20
+
21
+ function css() {
22
+ ?>
23
+
24
+ <style type="text/css">
25
+
26
+ /*
27
+ PowerPress subscribe sidebar widget
28
+ */
29
+ .widget-area .widget_powerpress_subscribe h2,
30
+ .widget-area .widget_powerpress_subscribe h3,
31
+ .widget-area .widget_powerpress_subscribe h4,
32
+ .widget_powerpress_subscribe h2,
33
+ .widget_powerpress_subscribe h3,
34
+ .widget_powerpress_subscribe h4 {
35
+ margin-bottom: 0;
36
+ padding-bottom: 0;
37
+ }
38
+
39
+ .pp-ssb-widget {
40
+ width: 100%;
41
+ margin: 0 auto;
42
+ font-family: Sans-serif;
43
+ color: #FFFFFF;
44
+ }
45
+ body .pp-ssb-widget a.pp-ssb-btn {
46
+ width: 100% !important;
47
+ height: 48px;
48
+ padding: 0;
49
+ color: #FFFFFF;
50
+ display: inline-block;
51
+ margin: 10px 0 10px 0;
52
+ text-decoration: none;
53
+ text-align:left;
54
+ vertical-align: middle;
55
+ line-height: 48px;
56
+ font-size: 90% !important;
57
+ font-weight: bold !important;
58
+ overflow: hidden;
59
+ border-radius: 1px;
60
+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
61
+ }
62
+
63
+ body .sidebar .widget .pp-ssb-widget a:link,
64
+ body .sidebar .widget .pp-ssb-widget a:visited,
65
+ body .sidebar .widget .pp-ssb-widget a:active,
66
+ body .sidebar .widget .pp-ssb-widget a:hover,
67
+ body .pp-ssb-widget a.pp-ssb-btn:link,
68
+ body .pp-ssb-widget a.pp-ssb-btn:visited,
69
+ body .pp-ssb-widget a.pp-ssb-btn:active,
70
+ body .pp-ssb-widget a.pp-ssb-btn:hover {
71
+ text-decoration: none !important;
72
+ color: #FFFFFF;
73
+ }
74
+ .pp-ssb-widget-dark a,
75
+ .pp-ssb-widget-modern a {
76
+ background-color: #222222;
77
+ }
78
+ .pp-ssb-widget-modern a.pp-ssb-itunes {
79
+ background-color: #732BBE;
80
+ }
81
+ .pp-ssb-widget-modern a.pp-ssb-email {
82
+ background-color: #337EC9;
83
+ }
84
+ .pp-ssb-widget-modern a.pp-ssb-rss {
85
+ background-color: #FF8800;
86
+ }
87
+ .pp-ssb-ic {
88
+ width: 48px;
89
+ height: 48px;
90
+ border: 0;
91
+ display: inline-block;
92
+ vertical-align: middle;
93
+ margin-right: 2px;
94
+ background-image: url(<?php echo powerpress_get_root_url(); ?>/images/spriteStandard.png);
95
+ background-repeat: no-repeat;
96
+ background-size: 294px;
97
+ }
98
+ .pp-ssb-itunes .pp-ssb-ic {
99
+ background-position: -49px 0;
100
+ }
101
+ .pp-ssb-rss .pp-ssb-ic {
102
+ background-position: 0 -49px;
103
+ }
104
+ .pp-ssb-email .pp-ssb-ic {
105
+ background-position: -196px -49px;
106
+ }
107
+ .pp-ssb-more .pp-ssb-ic {
108
+ background-position: -49px -49px;
109
+ }
110
+ /* Retina-specific stuff here */
111
+ @media only screen and (-webkit-min-device-pixel-ratio: 2.0),
112
+ only screen and (min--moz-device-pixel-ratio: 2.0),
113
+ only screen and (-o-min-device-pixel-ratio: 200/100),
114
+ only screen and (min-device-pixel-ratio: 2.0) {
115
+ .pp-sub-ic {
116
+ background-image: url(<?php echo powerpress_get_root_url(); ?>/images/spriteRetina.png);
117
+ }
118
+ }
119
+ </style>
120
+ <?php
121
+ }
122
+
123
+ function form( $instance ) {
124
+ if ( empty($instance['title']) ) {
125
+ $instance['title'] = __( 'Subscribe to Podcast' , 'powerpress');
126
+ }
127
+ if ( empty($instance['subscribe_type']) ) {
128
+ $instance['subscribe_type'] = '';
129
+ }
130
+ if ( empty($instance['subscribe_post_type']) ) {
131
+ $instance['subscribe_post_type'] = '';
132
+ }
133
+ if ( empty($instance['subscribe_feed_slug']) ) {
134
+ $instance['subscribe_feed_slug'] = '';
135
+ }
136
+ if ( empty($instance['subscribe_category_id']) ) {
137
+ $instance['subscribe_category_id'] = '';
138
+ }
139
+
140
+
141
+ ?>
142
+ <p>
143
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:' , 'powerpress'); ?></label>
144
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
145
+ </p>
146
+ <p>
147
+ <label for="<?php echo $this->get_field_id('subscribe_type'); ?>"><?php _e( 'Select Podcast Type:', 'powerpress' ); ?></label>
148
+ <select class="widefat" id="<?php echo $this->get_field_id('subscribe_type'); ?>" name="<?php echo $this->get_field_name('subscribe_type'); ?>">
149
+ <?php
150
+ $types = array(''=>__('Default Podcast','powerpress'), 'channel'=>__('Podcast Channel','powerpress'), 'category'=>__('Category Podcasting','powerpress') ); //, 'post_type'=>__('Post Type Podcasting','powerpress'), 'ttid'=>__('Taxonomy Podcasting','powerpress'));
151
+ while( list($type, $label) = each($types) ) {
152
+ echo '<option value="' . $type . '"'
153
+ . selected( $instance['subscribe_type'], $type, false )
154
+ . '>' . $label . "</option>\n";
155
+ }
156
+ ?>
157
+ </select>
158
+ </p>
159
+ <?php
160
+ /*
161
+ ?>
162
+ <p id="<?php echo $this->get_field_id('subscribe_post_type_section'); ?>">
163
+ <label for="<?php echo $this->get_field_id('subscribe_post_type'); ?>"><?php _e( 'Select Post Type:', 'powerpress' ); ?></label>
164
+ <select class="widefat" id="<?php echo $this->get_field_id('subscribe_post_type'); ?>" name="<?php echo $this->get_field_name('subscribe_post_type'); ?>">
165
+ <option value=""><?php echo __('Select Post Type', 'powerpress'); ?></option>
166
+ <?php
167
+ $post_types = powerpress_admin_get_post_types(false);
168
+ while( list($index, $label) = each($post_types) ) {
169
+ echo '<option value="' . $label . '"'
170
+ . selected( $instance['subscribe_post_type'], $label, false )
171
+ . '>' . $label . "</option>\n";
172
+ }
173
+ ?>
174
+ </select>
175
+ </p>
176
+ <?php */ ?>
177
+
178
+ <p id="<?php echo $this->get_field_id('subscribe_feed_slug_section'); ?>">
179
+ <label for="<?php echo $this->get_field_id( 'subscribe_feed_slug' ); ?>"><?php esc_html_e( 'Feed Slug:' , 'powerpress'); ?></label>
180
+ <input class="widefat" id="<?php echo $this->get_field_id( 'subscribe_feed_slug' ); ?>" name="<?php echo $this->get_field_name( 'subscribe_feed_slug' ); ?>" type="text" value="<?php echo esc_attr( $instance['subscribe_feed_slug'] ); ?>" />
181
+ </p>
182
+
183
+ <p id="<?php echo $this->get_field_id('subscribe_category_id_section'); ?>">
184
+ <label for="<?php echo $this->get_field_id( 'subscribe_category_id' ); ?>"><?php esc_html_e( 'Category ID:' , 'powerpress'); ?></label>
185
+ <input class="widefat" id="<?php echo $this->get_field_id( 'subscribe_category_id' ); ?>" name="<?php echo $this->get_field_name( 'subscribe_category_id' ); ?>" type="text" value="<?php echo esc_attr( $instance['subscribe_category_id'] ); ?>" />
186
+ </p>
187
+
188
+ <?php
189
+ }
190
+
191
+ function update( $new_instance, $old_instance ) {
192
+ $instance['title'] = strip_tags( $new_instance['title'] );
193
+ $instance['subscribe_type'] = strip_tags( $new_instance['subscribe_type'] ); // general, channel, category, post_type, ttid
194
+ $instance['subscribe_post_type'] = strip_tags( $new_instance['subscribe_post_type'] );; // eg sermons
195
+ $instance['subscribe_feed_slug'] = strip_tags( $new_instance['subscribe_feed_slug'] );; // e.g. podcast
196
+ $instance['subscribe_category_id'] = strip_tags( $new_instance['subscribe_category_id'] );; // e.g. 456
197
+ //$instance['subscribe_term_taxonomy_id'] = strip_tags( $new_instance['subscribe_term_taxonomy_id'] );; // e.g. 345
198
+ return $instance;
199
+ }
200
+
201
+ function widget( $args, $instance ) {
202
+
203
+ $ExtraData = array('type'=>'general', 'feed'=>'', 'taxonomy_term_id'=>'', 'cat_id'=>'', 'post_type'=>'');
204
+ if( !empty($instance['subscribe_type']) )
205
+ $ExtraData['type'] = $instance['subscribe_type'];
206
+
207
+ switch( $instance['subscribe_type'] )
208
+ {
209
+ case 'post_type': {
210
+ if( empty($instance['subscribe_post_type']) )
211
+ return;
212
+ $ExtraData['post_type'] = $instance['subscribe_post_type'];
213
+ };
214
+ case 'channel': {
215
+ if( empty($instance['subscribe_feed_slug']) )
216
+ return;
217
+ $ExtraData['feed'] = $instance['subscribe_feed_slug'];
218
+ }; break;
219
+ case 'ttid': {
220
+ if( empty($instance['subscribe_term_taxonomy_id']) || !is_numeric($instance['subscribe_term_taxonomy_id']) )
221
+ return;
222
+ $ExtraData['taxonomy_term_id'] = $instance['subscribe_term_taxonomy_id'];
223
+ }; break;
224
+ case 'category': {
225
+ if( empty($instance['subscribe_category_id']) || !is_numeric($instance['subscribe_category_id']) )
226
+ return;
227
+ $ExtraData['cat_id'] = $instance['subscribe_category_id'];
228
+ }; break;
229
+ default: {
230
+ // Doesn't matter, we'r using the default podcast channel
231
+
232
+ };
233
+ }
234
+
235
+ $Settings = powerpresssubscribe_get_settings( $ExtraData );
236
+ if( empty($Settings) )
237
+ return;
238
+
239
+ echo $args['before_widget'];
240
+ if ( ! empty( $instance['title'] ) ) {
241
+ echo $args['before_title'];
242
+ echo esc_html( $instance['title'] );
243
+ echo $args['after_title'];
244
+ }
245
+
246
+ echo powerpress_do_subscribe_sidebar_widget( $Settings );
247
+ echo $args['after_widget'];
248
+ return;
249
+ }
250
+ }
251
+
252
+ function powerpress_subscribe_register_widget() {
253
+ register_widget( 'PowerPressSubscribe_Widget' );
254
+ }
255
+
256
+ add_action( 'widgets_init', 'powerpress_subscribe_register_widget' );
css/admin.css CHANGED
@@ -2,28 +2,29 @@
2
  .powerpress-notice,
3
  div.powerpress-notice,
4
  .wrap div.powerpress-notice {
5
- margin-top: 20px;
6
- margin-bottom: 10px;
7
  line-height: 29px;
8
  font-size: 12px;
9
  border-width: 1px;
10
  border-style: solid;
11
  font-weight: bold;
 
12
  }
13
  .powerpress-error,
14
  div.powerpress-error,
15
  .wrap div.powerpress-error {
16
- margin-top: 10px;
17
- margin-bottom: 10px;
18
  line-height: 29px;
19
  font-size: 12px;
20
  border-width: 1px;
21
  border-style: solid;
22
  font-weight: bold;
23
- margin-top: 20px;
24
  }
25
  #powerpress_settings {
26
- background-image:url(http://images.blubrry.com/powerpress/blubrry_logo5.png);
27
  background-repeat: no-repeat;
28
  background-position: bottom right;
29
  }
@@ -243,11 +244,21 @@ padding-bottom: 15px;
243
  left: 0;
244
  position: absolute;
245
  }
 
 
 
 
246
  #powerpress_steps p {
247
  font-size: 20px;
248
  margin: 20px 4px;
249
  color: #CCCCCC;
250
- line-height:120%
 
 
 
 
 
 
251
  }
252
  #powerpress_steps a {
253
  color: #CCCCCC;
@@ -260,7 +271,6 @@ padding-bottom: 15px;
260
 
261
  #powerpress_steps .active-step h3 {
262
  color: #337EC9;
263
-
264
  }
265
  #powerpress_steps .active-step p,
266
  #powerpress_steps .active-step a {
@@ -376,5 +386,3 @@ padding-bottom: 15px;
376
  margin-right: 10px;
377
  }
378
  }
379
-
380
-
2
  .powerpress-notice,
3
  div.powerpress-notice,
4
  .wrap div.powerpress-notice {
5
+ margin: 20px 0 10px;
6
+ padding: 0 5px;
7
  line-height: 29px;
8
  font-size: 12px;
9
  border-width: 1px;
10
  border-style: solid;
11
  font-weight: bold;
12
+ /* background-color: #FFFFE0; /* yellow */
13
  }
14
  .powerpress-error,
15
  div.powerpress-error,
16
  .wrap div.powerpress-error {
17
+ margin: 20px 5px 10px;
18
+ padding: 0 10px;
19
  line-height: 29px;
20
  font-size: 12px;
21
  border-width: 1px;
22
  border-style: solid;
23
  font-weight: bold;
24
+ /* background-color: #ffebe8; /* red */
25
  }
26
  #powerpress_settings {
27
+ background-image:url(//images.blubrry.com/powerpress/blubrry_logo5.png);
28
  background-repeat: no-repeat;
29
  background-position: bottom right;
30
  }
244
  left: 0;
245
  position: absolute;
246
  }
247
+ #powerpress_single_step h3 {
248
+ color: #337EC9;
249
+ font-size: 24px;
250
+ }
251
  #powerpress_steps p {
252
  font-size: 20px;
253
  margin: 20px 4px;
254
  color: #CCCCCC;
255
+ line-height:120%;
256
+ }
257
+ #powerpress_steps p.normal {
258
+ font-size: 14px;
259
+ margin: 8px 0 8px 8px;
260
+ color: #CCCCCC;
261
+ line-height: normal;
262
  }
263
  #powerpress_steps a {
264
  color: #CCCCCC;
271
 
272
  #powerpress_steps .active-step h3 {
273
  color: #337EC9;
 
274
  }
275
  #powerpress_steps .active-step p,
276
  #powerpress_steps .active-step a {
386
  margin-right: 10px;
387
  }
388
  }
 
 
css/dashboard.css CHANGED
@@ -42,4 +42,26 @@
42
  #powerpress_dashboard_notice_3 a.browse-happy-link,
43
  #powerpress_dashboard_notice_3 a.update-browser-link {
44
  text-shadow: #d29a04 0 1px 0;
45
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  #powerpress_dashboard_notice_3 a.browse-happy-link,
43
  #powerpress_dashboard_notice_3 a.update-browser-link {
44
  text-shadow: #d29a04 0 1px 0;
45
+ }
46
+
47
+ /*
48
+ .powerpressadmin-mejs-video {
49
+ width: auto;
50
+ }
51
+ .powerpressadmin-mejs-video .powerpress_player {
52
+ position: relative;
53
+ width: 100%;
54
+ height: 0;
55
+ padding-bottom: 56.2%;
56
+ }
57
+
58
+ .powerpressadmin-mejs-video .powerpress_player .wp-video,
59
+ .powerpressadmin-mejs-video .powerpress_player .mejs-container,
60
+ .powerpressadmin-mejs-video .powerpress_player video {
61
+ position: absolute;
62
+ top: 0;
63
+ left: 0;
64
+ width: 100% !important;
65
+ height: 100% !important;
66
+ }
67
+ */
css/subscribe.css ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* subscribe.css PowerPress subscribe widget */
2
+
3
+ .pp-sub-widget {
4
+ width: 100%;
5
+ max-width: 800px;
6
+ margin: 10px auto;
7
+ border: 3px solid #787878;
8
+ font-family: Sans-serif;
9
+ background-color: #FFFFFF;
10
+ }
11
+ .pp-sub-widget .pp-sub-bx {
12
+ -webkit-column-count: 2;
13
+ -moz-column-count: 2;
14
+ column-count: 2;
15
+ -webkit-column-gap: 20px;
16
+ -moz-column-gap: 20px;
17
+ column-gap: 20px;
18
+ width: auto;
19
+ height: auto;
20
+ margin: 0 10px -10px 10px;
21
+ }
22
+
23
+ .pp-sub-widget div.pp-sub-h {
24
+ margin: 10px 10px 0 10px;
25
+ font-size: 90%;
26
+ font-weight: bold;
27
+ color: #666666;
28
+ }
29
+ .pp-sub-widget h2.pp-sub-t {
30
+ margin: 10px 10px 0 10px !important;
31
+ padding: 0 !important;
32
+ font-size: 200% !important;
33
+ color: #222222 !important;
34
+ }
35
+
36
+ .pp-sub-widget a.pp-sub-btn {
37
+ width: 100%;
38
+ height: 48px;
39
+ padding: 0px 0px 0px 0px;
40
+ color: #FFFFFF;
41
+ display: inline-block;
42
+ margin: 10px 0 10px 0;
43
+ text-decoration: none;
44
+ text-align:left;
45
+ vertical-align: middle;
46
+ line-height: 48px;
47
+ font-size: 90% !important;
48
+ font-weight: bold !important;
49
+ overflow: hidden;
50
+ border-radius: 1px;
51
+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
52
+ }
53
+
54
+ .pp-sub-widget .pp-sub-btn-l {
55
+
56
+ }
57
+ body .entry-content .pp-sub-widget a:link,
58
+ body .entry-content .pp-sub-widget a:visited,
59
+ body .entry-content .pp-sub-widget a:active,
60
+ body .entry-content .pp-sub-widget a:hover,
61
+ body .pp-sub-widget a:link,
62
+ body .pp-sub-widget a:visited,
63
+ body .pp-sub-widget a:active,
64
+ body .pp-sub-widget a:hover {
65
+ text-decoration: none !important;
66
+ color: #FFFFFF !important;
67
+ }
68
+
69
+ .pp-sub-widget img.pp-sub-l {
70
+ width: 100% !important;
71
+ height: auto !important;
72
+ max-width: 300px;
73
+ padding: 0;
74
+ margin: 10px 0;
75
+
76
+ box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
77
+ }
78
+ .pp-sub-widget .pp-sub-btns {
79
+ width: 100% !important;
80
+ margin: 0;
81
+ padding: 0;
82
+ display: inline-block;
83
+ }
84
+ .pp-sub-widget .pp-sub-m {
85
+ clear: both;
86
+ margin: 10px;
87
+ }
88
+ .pp-sub-widget p.pp-sub-m-p {
89
+ margin: 0;
90
+ font-size: 90%;
91
+ color: #222222;
92
+ }
93
+ .pp-sub-widget .pp-sub-m-i {
94
+ width: 80%;
95
+ color: #333333;
96
+ font-size: 85%;
97
+ border: 1px solid #999999;
98
+ padding: 5px;
99
+ }
100
+ @media screen and (max-width: 400px) {
101
+ .pp-sub-widget .pp-sub-bx {
102
+ -webkit-column-count: 1;
103
+ -moz-column-count: 1;
104
+ column-count: 1;
105
+ -webkit-column-gap: 0;
106
+ -moz-column-gap: 0;
107
+ column-gap: 0;
108
+ }
109
+ .pp-sub-widget .pp-sub-t {
110
+ font-size: 150%;
111
+ }
112
+ }
113
+ .pp-sub-widget-dark a,
114
+ .pp-sub-widget-modern a {
115
+ background-color: #222222;
116
+ }
117
+ .pp-sub-widget-modern a.pp-sub-itunes {
118
+ background-color: #732BBE;
119
+ }
120
+ .pp-sub-widget-modern a.pp-sub-pr,
121
+ .pp-sub-widget-modern a.pp-sub-email {
122
+ background-color: #337EC9;
123
+ }
124
+ .pp-sub-widget-modern a.pp-sub-bp,
125
+ .pp-sub-widget-modern a.pp-sub-rss {
126
+ background-color: #FF8800;
127
+ }
128
+
129
+ .pp-sub-widget-modern div.pp-sub-h,
130
+ .pp-sub-widget-modern p.pp-sub-m-p {
131
+ color: #337EC9;
132
+ }
133
+
134
+ .pp-sub-widget .pp-sub-ic {
135
+ width: 48px;
136
+ height: 48px;
137
+ border: 0;
138
+ display: inline-block;
139
+ vertical-align: middle;
140
+ margin-right: 2px;
141
+ }
142
+ .pp-sub-ic {
143
+ background-image: url(../images/spriteStandard.png);
144
+ background-repeat: no-repeat;
145
+ background-size: 294px;
146
+ }
147
+ .pp-sub-itunes .pp-sub-ic {
148
+ background-position: -49px 0;
149
+ }
150
+ .pp-sub-rss .pp-sub-ic {
151
+ background-position: 0 -49px;
152
+ }
153
+ .pp-sub-email .pp-sub-ic {
154
+ background-position: -196px -49px;
155
+ }
156
+ .pp-sub-pr .pp-sub-ic {
157
+ background-position: -196px 0;
158
+ }
159
+ .pp-sub-bp .pp-sub-ic {
160
+ background-position: -147px 0;
161
+ }
162
+
163
+ /* Retina-specific stuff here */
164
+ @media only screen and (-webkit-min-device-pixel-ratio: 2.0),
165
+ only screen and (min--moz-device-pixel-ratio: 2.0),
166
+ only screen and (-o-min-device-pixel-ratio: 200/100),
167
+ only screen and (min-device-pixel-ratio: 2.0) {
168
+ .pp-sub-ic {
169
+ background-image: url(../images/spriteRetina.png);
170
+ }
171
+ }
getid3/getid3.lib.php CHANGED
@@ -1,1317 +1,1379 @@
1
- <?php
2
- /////////////////////////////////////////////////////////////////
3
- /// getID3() by James Heinrich <info@getid3.org> //
4
- // available at http://getid3.sourceforge.net //
5
- // or http://www.getid3.org //
6
- /////////////////////////////////////////////////////////////////
7
- // //
8
- // getid3.lib.php - part of getID3() //
9
- // See readme.txt for more details //
10
- // ///
11
- /////////////////////////////////////////////////////////////////
12
-
13
-
14
- class getid3_lib
15
- {
16
-
17
- static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8') {
18
- $returnstring = '';
19
- for ($i = 0; $i < strlen($string); $i++) {
20
- if ($hex) {
21
- $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT);
22
- } else {
23
- $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string{$i}) ? $string{$i} : '�');
24
- }
25
- if ($spaces) {
26
- $returnstring .= ' ';
27
- }
28
- }
29
- if (!empty($htmlencoding)) {
30
- if ($htmlencoding === true) {
31
- $htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean
32
- }
33
- $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding);
34
- }
35
- return $returnstring;
36
- }
37
-
38
- static function trunc($floatnumber) {
39
- // truncates a floating-point number at the decimal point
40
- // returns int (if possible, otherwise float)
41
- if ($floatnumber >= 1) {
42
- $truncatednumber = floor($floatnumber);
43
- } elseif ($floatnumber <= -1) {
44
- $truncatednumber = ceil($floatnumber);
45
- } else {
46
- $truncatednumber = 0;
47
- }
48
- if (getid3_lib::intValueSupported($truncatednumber)) {
49
- $truncatednumber = (int) $truncatednumber;
50
- }
51
- return $truncatednumber;
52
- }
53
-
54
-
55
- static function safe_inc(&$variable, $increment=1) {
56
- if (isset($variable)) {
57
- $variable += $increment;
58
- } else {
59
- $variable = $increment;
60
- }
61
- return true;
62
- }
63
-
64
- static function CastAsInt($floatnum) {
65
- // convert to float if not already
66
- $floatnum = (float) $floatnum;
67
-
68
- // convert a float to type int, only if possible
69
- if (getid3_lib::trunc($floatnum) == $floatnum) {
70
- // it's not floating point
71
- if (getid3_lib::intValueSupported($floatnum)) {
72
- // it's within int range
73
- $floatnum = (int) $floatnum;
74
- }
75
- }
76
- return $floatnum;
77
- }
78
-
79
- public static function intValueSupported($num) {
80
- // check if integers are 64-bit
81
- static $hasINT64 = null;
82
- if ($hasINT64 === null) { // 10x faster than is_null()
83
- $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1
84
- if (!$hasINT64 && !defined('PHP_INT_MIN')) {
85
- define('PHP_INT_MIN', ~PHP_INT_MAX);
86
- }
87
- }
88
- // if integers are 64-bit - no other check required
89
- if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
90
- return true;
91
- }
92
- return false;
93
- }
94
-
95
- static function DecimalizeFraction($fraction) {
96
- list($numerator, $denominator) = explode('/', $fraction);
97
- return $numerator / ($denominator ? $denominator : 1);
98
- }
99
-
100
-
101
- static function DecimalBinary2Float($binarynumerator) {
102
- $numerator = getid3_lib::Bin2Dec($binarynumerator);
103
- $denominator = getid3_lib::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator)));
104
- return ($numerator / $denominator);
105
- }
106
-
107
-
108
- static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) {
109
- // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
110
- if (strpos($binarypointnumber, '.') === false) {
111
- $binarypointnumber = '0.'.$binarypointnumber;
112
- } elseif ($binarypointnumber{0} == '.') {
113
- $binarypointnumber = '0'.$binarypointnumber;
114
- }
115
- $exponent = 0;
116
- while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.')) {
117
- if (substr($binarypointnumber, 1, 1) == '.') {
118
- $exponent--;
119
- $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3);
120
- } else {
121
- $pointpos = strpos($binarypointnumber, '.');
122
- $exponent += ($pointpos - 1);
123
- $binarypointnumber = str_replace('.', '', $binarypointnumber);
124
- $binarypointnumber = $binarypointnumber{0}.'.'.substr($binarypointnumber, 1);
125
- }
126
- }
127
- $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT);
128
- return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent);
129
- }
130
-
131
-
132
- static function Float2BinaryDecimal($floatvalue) {
133
- // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
134
- $maxbits = 128; // to how many bits of precision should the calculations be taken?
135
- $intpart = getid3_lib::trunc($floatvalue);
136
- $floatpart = abs($floatvalue - $intpart);
137
- $pointbitstring = '';
138
- while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) {
139
- $floatpart *= 2;
140
- $pointbitstring .= (string) getid3_lib::trunc($floatpart);
141
- $floatpart -= getid3_lib::trunc($floatpart);
142
- }
143
- $binarypointnumber = decbin($intpart).'.'.$pointbitstring;
144
- return $binarypointnumber;
145
- }
146
-
147
-
148
- static function Float2String($floatvalue, $bits) {
149
- // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
150
- switch ($bits) {
151
- case 32:
152
- $exponentbits = 8;
153
- $fractionbits = 23;
154
- break;
155
-
156
- case 64:
157
- $exponentbits = 11;
158
- $fractionbits = 52;
159
- break;
160
-
161
- default:
162
- return false;
163
- break;
164
- }
165
- if ($floatvalue >= 0) {
166
- $signbit = '0';
167
- } else {
168
- $signbit = '1';
169
- }
170
- $normalizedbinary = getid3_lib::NormalizeBinaryPoint(getid3_lib::Float2BinaryDecimal($floatvalue), $fractionbits);
171
- $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent
172
- $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT);
173
- $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT);
174
-
175
- return getid3_lib::BigEndian2String(getid3_lib::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false);
176
- }
177
-
178
-
179
- static function LittleEndian2Float($byteword) {
180
- return getid3_lib::BigEndian2Float(strrev($byteword));
181
- }
182
-
183
-
184
- static function BigEndian2Float($byteword) {
185
- // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
186
- // http://www.psc.edu/general/software/packages/ieee/ieee.html
187
- // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
188
-
189
- $bitword = getid3_lib::BigEndian2Bin($byteword);
190
- if (!$bitword) {
191
- return 0;
192
- }
193
- $signbit = $bitword{0};
194
-
195
- switch (strlen($byteword) * 8) {
196
- case 32:
197
- $exponentbits = 8;
198
- $fractionbits = 23;
199
- break;
200
-
201
- case 64:
202
- $exponentbits = 11;
203
- $fractionbits = 52;
204
- break;
205
-
206
- case 80:
207
- // 80-bit Apple SANE format
208
- // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
209
- $exponentstring = substr($bitword, 1, 15);
210
- $isnormalized = intval($bitword{16});
211
- $fractionstring = substr($bitword, 17, 63);
212
- $exponent = pow(2, getid3_lib::Bin2Dec($exponentstring) - 16383);
213
- $fraction = $isnormalized + getid3_lib::DecimalBinary2Float($fractionstring);
214
- $floatvalue = $exponent * $fraction;
215
- if ($signbit == '1') {
216
- $floatvalue *= -1;
217
- }
218
- return $floatvalue;
219
- break;
220
-
221
- default:
222
- return false;
223
- break;
224
- }
225
- $exponentstring = substr($bitword, 1, $exponentbits);
226
- $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
227
- $exponent = getid3_lib::Bin2Dec($exponentstring);
228
- $fraction = getid3_lib::Bin2Dec($fractionstring);
229
-
230
- if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) {
231
- // Not a Number
232
- $floatvalue = false;
233
- } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) {
234
- if ($signbit == '1') {
235
- $floatvalue = '-infinity';
236
- } else {
237
- $floatvalue = '+infinity';
238
- }
239
- } elseif (($exponent == 0) && ($fraction == 0)) {
240
- if ($signbit == '1') {
241
- $floatvalue = -0;
242
- } else {
243
- $floatvalue = 0;
244
- }
245
- $floatvalue = ($signbit ? 0 : -0);
246
- } elseif (($exponent == 0) && ($fraction != 0)) {
247
- // These are 'unnormalized' values
248
- $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fractionstring);
249
- if ($signbit == '1') {
250
- $floatvalue *= -1;
251
- }
252
- } elseif ($exponent != 0) {
253
- $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fractionstring));
254
- if ($signbit == '1') {
255
- $floatvalue *= -1;
256
- }
257
- }
258
- return (float) $floatvalue;
259
- }
260
-
261
-
262
- static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {
263
- $intvalue = 0;
264
- $bytewordlen = strlen($byteword);
265
- if ($bytewordlen == 0) {
266
- return false;
267
- }
268
- for ($i = 0; $i < $bytewordlen; $i++) {
269
- if ($synchsafe) { // disregard MSB, effectively 7-bit bytes
270
- //$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems
271
- $intvalue += (ord($byteword{$i}) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7);
272
- } else {
273
- $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
274
- }
275
- }
276
- if ($signed && !$synchsafe) {
277
- // synchsafe ints are not allowed to be signed
278
- if ($bytewordlen <= PHP_INT_SIZE) {
279
- $signMaskBit = 0x80 << (8 * ($bytewordlen - 1));
280
- if ($intvalue & $signMaskBit) {
281
- $intvalue = 0 - ($intvalue & ($signMaskBit - 1));
282
- }
283
- } else {
284
- throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in getid3_lib::BigEndian2Int()');
285
- break;
286
- }
287
- }
288
- return getid3_lib::CastAsInt($intvalue);
289
- }
290
-
291
-
292
- static function LittleEndian2Int($byteword, $signed=false) {
293
- return getid3_lib::BigEndian2Int(strrev($byteword), false, $signed);
294
- }
295
-
296
-
297
- static function BigEndian2Bin($byteword) {
298
- $binvalue = '';
299
- $bytewordlen = strlen($byteword);
300
- for ($i = 0; $i < $bytewordlen; $i++) {
301
- $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT);
302
- }
303
- return $binvalue;
304
- }
305
-
306
-
307
- static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) {
308
- if ($number < 0) {
309
- throw new Exception('ERROR: getid3_lib::BigEndian2String() does not support negative numbers');
310
- }
311
- $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
312
- $intstring = '';
313
- if ($signed) {
314
- if ($minbytes > PHP_INT_SIZE) {
315
- throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in getid3_lib::BigEndian2String()');
316
- }
317
- $number = $number & (0x80 << (8 * ($minbytes - 1)));
318
- }
319
- while ($number != 0) {
320
- $quotient = ($number / ($maskbyte + 1));
321
- $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring;
322
- $number = floor($quotient);
323
- }
324
- return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT);
325
- }
326
-
327
-
328
- static function Dec2Bin($number) {
329
- while ($number >= 256) {
330
- $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
331
- $number = floor($number / 256);
332
- }
333
- $bytes[] = $number;
334
- $binstring = '';
335
- for ($i = 0; $i < count($bytes); $i++) {
336
- $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring;
337
- }
338
- return $binstring;
339
- }
340
-
341
-
342
- static function Bin2Dec($binstring, $signed=false) {
343
- $signmult = 1;
344
- if ($signed) {
345
- if ($binstring{0} == '1') {
346
- $signmult = -1;
347
- }
348
- $binstring = substr($binstring, 1);
349
- }
350
- $decvalue = 0;
351
- for ($i = 0; $i < strlen($binstring); $i++) {
352
- $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
353
- }
354
- return getid3_lib::CastAsInt($decvalue * $signmult);
355
- }
356
-
357
-
358
- static function Bin2String($binstring) {
359
- // return 'hi' for input of '0110100001101001'
360
- $string = '';
361
- $binstringreversed = strrev($binstring);
362
- for ($i = 0; $i < strlen($binstringreversed); $i += 8) {
363
- $string = chr(getid3_lib::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string;
364
- }
365
- return $string;
366
- }
367
-
368
-
369
- static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) {
370
- $intstring = '';
371
- while ($number > 0) {
372
- if ($synchsafe) {
373
- $intstring = $intstring.chr($number & 127);
374
- $number >>= 7;
375
- } else {
376
- $intstring = $intstring.chr($number & 255);
377
- $number >>= 8;
378
- }
379
- }
380
- return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
381
- }
382
-
383
-
384
- static function array_merge_clobber($array1, $array2) {
385
- // written by kc�hireability*com
386
- // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
387
- if (!is_array($array1) || !is_array($array2)) {
388
- return false;
389
- }
390
- $newarray = $array1;
391
- foreach ($array2 as $key => $val) {
392
- if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
393
- $newarray[$key] = getid3_lib::array_merge_clobber($newarray[$key], $val);
394
- } else {
395
- $newarray[$key] = $val;
396
- }
397
- }
398
- return $newarray;
399
- }
400
-
401
-
402
- static function array_merge_noclobber($array1, $array2) {
403
- if (!is_array($array1) || !is_array($array2)) {
404
- return false;
405
- }
406
- $newarray = $array1;
407
- foreach ($array2 as $key => $val) {
408
- if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
409
- $newarray[$key] = getid3_lib::array_merge_noclobber($newarray[$key], $val);
410
- } elseif (!isset($newarray[$key])) {
411
- $newarray[$key] = $val;
412
- }
413
- }
414
- return $newarray;
415
- }
416
-
417
-
418
- static function ksort_recursive(&$theArray) {
419
- ksort($theArray);
420
- foreach ($theArray as $key => $value) {
421
- if (is_array($value)) {
422
- self::ksort_recursive($theArray[$key]);
423
- }
424
- }
425
- return true;
426
- }
427
-
428
- static function fileextension($filename, $numextensions=1) {
429
- if (strstr($filename, '.')) {
430
- $reversedfilename = strrev($filename);
431
- $offset = 0;
432
- for ($i = 0; $i < $numextensions; $i++) {
433
- $offset = strpos($reversedfilename, '.', $offset + 1);
434
- if ($offset === false) {
435
- return '';
436
- }
437
- }
438
- return strrev(substr($reversedfilename, 0, $offset));
439
- }
440
- return '';
441
- }
442
-
443
-
444
- static function PlaytimeString($seconds) {
445
- $sign = (($seconds < 0) ? '-' : '');
446
- $seconds = abs($seconds);
447
- $H = floor( $seconds / 3600);
448
- $M = floor(($seconds - (3600 * $H) ) / 60);
449
- $S = round( $seconds - (3600 * $H) - (60 * $M) );
450
- return $sign.($H ? $H.':' : '').($H ? str_pad($M, 2, '0', STR_PAD_LEFT) : intval($M)).':'.str_pad($S, 2, 0, STR_PAD_LEFT);
451
- }
452
-
453
-
454
- static function DateMac2Unix($macdate) {
455
- // Macintosh timestamp: seconds since 00:00h January 1, 1904
456
- // UNIX timestamp: seconds since 00:00h January 1, 1970
457
- return getid3_lib::CastAsInt($macdate - 2082844800);
458
- }
459
-
460
-
461
- static function FixedPoint8_8($rawdata) {
462
- return getid3_lib::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
463
- }
464
-
465
-
466
- static function FixedPoint16_16($rawdata) {
467
- return getid3_lib::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
468
- }
469
-
470
-
471
- static function FixedPoint2_30($rawdata) {
472
- $binarystring = getid3_lib::BigEndian2Bin($rawdata);
473
- return getid3_lib::Bin2Dec(substr($binarystring, 0, 2)) + (float) (getid3_lib::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30));
474
- }
475
-
476
-
477
- static function CreateDeepArray($ArrayPath, $Separator, $Value) {
478
- // assigns $Value to a nested array path:
479
- // $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt')
480
- // is the same as:
481
- // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt'))));
482
- // or
483
- // $foo['path']['to']['my'] = 'file.txt';
484
- while ($ArrayPath && ($ArrayPath{0} == $Separator)) {
485
- $ArrayPath = substr($ArrayPath, 1);
486
- }
487
- if (($pos = strpos($ArrayPath, $Separator)) !== false) {
488
- $ReturnedArray[substr($ArrayPath, 0, $pos)] = getid3_lib::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value);
489
- } else {
490
- $ReturnedArray[$ArrayPath] = $Value;
491
- }
492
- return $ReturnedArray;
493
- }
494
-
495
- static function array_max($arraydata, $returnkey=false) {
496
- $maxvalue = false;
497
- $maxkey = false;
498
- foreach ($arraydata as $key => $value) {
499
- if (!is_array($value)) {
500
- if ($value > $maxvalue) {
501
- $maxvalue = $value;
502
- $maxkey = $key;
503
- }
504
- }
505
- }
506
- return ($returnkey ? $maxkey : $maxvalue);
507
- }
508
-
509
- static function array_min($arraydata, $returnkey=false) {
510
- $minvalue = false;
511
- $minkey = false;
512
- foreach ($arraydata as $key => $value) {
513
- if (!is_array($value)) {
514
- if ($value > $minvalue) {
515
- $minvalue = $value;
516
- $minkey = $key;
517
- }
518
- }
519
- }
520
- return ($returnkey ? $minkey : $minvalue);
521
- }
522
-
523
- static function XML2array($XMLstring) {
524
- if (function_exists('simplexml_load_string')) {
525
- if (function_exists('get_object_vars')) {
526
- $XMLobject = simplexml_load_string($XMLstring);
527
- return self::SimpleXMLelement2array($XMLobject);
528
- }
529
- }
530
- return false;
531
- }
532
-
533
- static function SimpleXMLelement2array($XMLobject) {
534
- if (!is_object($XMLobject) && !is_array($XMLobject)) {
535
- return $XMLobject;
536
- }
537
- $XMLarray = (is_object($XMLobject) ? get_object_vars($XMLobject) : $XMLobject);
538
- foreach ($XMLarray as $key => $value) {
539
- $XMLarray[$key] = self::SimpleXMLelement2array($value);
540
- }
541
- return $XMLarray;
542
- }
543
-
544
-
545
- // Allan Hansen <ah�artemis*dk>
546
- // getid3_lib::md5_data() - returns md5sum for a file from startuing position to absolute end position
547
- static function hash_data($file, $offset, $end, $algorithm) {
548
- static $tempdir = '';
549
- if (!getid3_lib::intValueSupported($end)) {
550
- return false;
551
- }
552
- switch ($algorithm) {
553
- case 'md5':
554
- $hash_function = 'md5_file';
555
- $unix_call = 'md5sum';
556
- $windows_call = 'md5sum.exe';
557
- $hash_length = 32;
558
- break;
559
-
560
- case 'sha1':
561
- $hash_function = 'sha1_file';
562
- $unix_call = 'sha1sum';
563
- $windows_call = 'sha1sum.exe';
564
- $hash_length = 40;
565
- break;
566
-
567
- default:
568
- throw new Exception('Invalid algorithm ('.$algorithm.') in getid3_lib::hash_data()');
569
- break;
570
- }
571
- $size = $end - $offset;
572
- while (true) {
573
- if (GETID3_OS_ISWINDOWS) {
574
-
575
- // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data
576
- // Fall back to create-temp-file method:
577
- if ($algorithm == 'sha1') {
578
- break;
579
- }
580
-
581
- $RequiredFiles = array('cygwin1.dll', 'head.exe', 'tail.exe', $windows_call);
582
- foreach ($RequiredFiles as $required_file) {
583
- if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
584
- // helper apps not available - fall back to old method
585
- break;
586
- }
587
- }
588
- $commandline = GETID3_HELPERAPPSDIR.'head.exe -c '.$end.' "'.escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)).'" | ';
589
- $commandline .= GETID3_HELPERAPPSDIR.'tail.exe -c '.$size.' | ';
590
- $commandline .= GETID3_HELPERAPPSDIR.$windows_call;
591
-
592
- } else {
593
-
594
- $commandline = 'head -c'.$end.' '.escapeshellarg($file).' | ';
595
- $commandline .= 'tail -c'.$size.' | ';
596
- $commandline .= $unix_call;
597
-
598
- }
599
- if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
600
- //throw new Exception('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm');
601
- break;
602
- }
603
- return substr(`$commandline`, 0, $hash_length);
604
- }
605
-
606
- if (empty($tempdir)) {
607
- // yes this is ugly, feel free to suggest a better way
608
- require_once(dirname(__FILE__).'/getid3.php');
609
- $getid3_temp = new getID3();
610
- $tempdir = $getid3_temp->tempdir;
611
- unset($getid3_temp);
612
- }
613
- // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
614
- if (($data_filename = tempnam($tempdir, 'gI3')) === false) {
615
- // can't find anywhere to create a temp file, just fail
616
- return false;
617
- }
618
-
619
- // Init
620
- $result = false;
621
-
622
- // copy parts of file
623
- try {
624
- getid3_lib::CopyFileParts($file, $data_filename, $offset, $end - $offset);
625
- $result = $hash_function($data_filename);
626
- } catch (Exception $e) {
627
- throw new Exception('getid3_lib::CopyFileParts() failed in getid_lib::hash_data(): '.$e->getMessage());
628
- }
629
- unlink($data_filename);
630
- return $result;
631
- }
632
-
633
- static function CopyFileParts($filename_source, $filename_dest, $offset, $length) {
634
- if (!getid3_lib::intValueSupported($offset + $length)) {
635
- throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
636
- }
637
- if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
638
- if (($fp_dest = fopen($filename_dest, 'wb'))) {
639
- if (fseek($fp_src, $offset, SEEK_SET) == 0) {
640
- $byteslefttowrite = $length;
641
- while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
642
- $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
643
- $byteslefttowrite -= $byteswritten;
644
- }
645
- return true;
646
- } else {
647
- throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source);
648
- }
649
- fclose($fp_dest);
650
- } else {
651
- throw new Exception('failed to create file for writing '.$filename_dest);
652
- }
653
- fclose($fp_src);
654
- } else {
655
- throw new Exception('failed to open file for reading '.$filename_source);
656
- }
657
- return false;
658
- }
659
-
660
- static function iconv_fallback_int_utf8($charval) {
661
- if ($charval < 128) {
662
- // 0bbbbbbb
663
- $newcharstring = chr($charval);
664
- } elseif ($charval < 2048) {
665
- // 110bbbbb 10bbbbbb
666
- $newcharstring = chr(($charval >> 6) | 0xC0);
667
- $newcharstring .= chr(($charval & 0x3F) | 0x80);
668
- } elseif ($charval < 65536) {
669
- // 1110bbbb 10bbbbbb 10bbbbbb
670
- $newcharstring = chr(($charval >> 12) | 0xE0);
671
- $newcharstring .= chr(($charval >> 6) | 0xC0);
672
- $newcharstring .= chr(($charval & 0x3F) | 0x80);
673
- } else {
674
- // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
675
- $newcharstring = chr(($charval >> 18) | 0xF0);
676
- $newcharstring .= chr(($charval >> 12) | 0xC0);
677
- $newcharstring .= chr(($charval >> 6) | 0xC0);
678
- $newcharstring .= chr(($charval & 0x3F) | 0x80);
679
- }
680
- return $newcharstring;
681
- }
682
-
683
- // ISO-8859-1 => UTF-8
684
- static function iconv_fallback_iso88591_utf8($string, $bom=false) {
685
- if (function_exists('utf8_encode')) {
686
- return utf8_encode($string);
687
- }
688
- // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
689
- $newcharstring = '';
690
- if ($bom) {
691
- $newcharstring .= "\xEF\xBB\xBF";
692
- }
693
- for ($i = 0; $i < strlen($string); $i++) {
694
- $charval = ord($string{$i});
695
- $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
696
- }
697
- return $newcharstring;
698
- }
699
-
700
- // ISO-8859-1 => UTF-16BE
701
- static function iconv_fallback_iso88591_utf16be($string, $bom=false) {
702
- $newcharstring = '';
703
- if ($bom) {
704
- $newcharstring .= "\xFE\xFF";
705
- }
706
- for ($i = 0; $i < strlen($string); $i++) {
707
- $newcharstring .= "\x00".$string{$i};
708
- }
709
- return $newcharstring;
710
- }
711
-
712
- // ISO-8859-1 => UTF-16LE
713
- static function iconv_fallback_iso88591_utf16le($string, $bom=false) {
714
- $newcharstring = '';
715
- if ($bom) {
716
- $newcharstring .= "\xFF\xFE";
717
- }
718
- for ($i = 0; $i < strlen($string); $i++) {
719
- $newcharstring .= $string{$i}."\x00";
720
- }
721
- return $newcharstring;
722
- }
723
-
724
- // ISO-8859-1 => UTF-16LE (BOM)
725
- static function iconv_fallback_iso88591_utf16($string) {
726
- return getid3_lib::iconv_fallback_iso88591_utf16le($string, true);
727
- }
728
-
729
- // UTF-8 => ISO-8859-1
730
- static function iconv_fallback_utf8_iso88591($string) {
731
- if (function_exists('utf8_decode')) {
732
- return utf8_decode($string);
733
- }
734
- // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
735
- $newcharstring = '';
736
- $offset = 0;
737
- $stringlength = strlen($string);
738
- while ($offset < $stringlength) {
739
- if ((ord($string{$offset}) | 0x07) == 0xF7) {
740
- // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
741
- $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
742
- ((ord($string{($offset + 1)}) & 0x3F) << 12) &
743
- ((ord($string{($offset + 2)}) & 0x3F) << 6) &
744
- (ord($string{($offset + 3)}) & 0x3F);
745
- $offset += 4;
746
- } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
747
- // 1110bbbb 10bbbbbb 10bbbbbb
748
- $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
749
- ((ord($string{($offset + 1)}) & 0x3F) << 6) &
750
- (ord($string{($offset + 2)}) & 0x3F);
751
- $offset += 3;
752
- } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
753
- // 110bbbbb 10bbbbbb
754
- $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
755
- (ord($string{($offset + 1)}) & 0x3F);
756
- $offset += 2;
757
- } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
758
- // 0bbbbbbb
759
- $charval = ord($string{$offset});
760
- $offset += 1;
761
- } else {
762
- // error? throw some kind of warning here?
763
- $charval = false;
764
- $offset += 1;
765
- }
766
- if ($charval !== false) {
767
- $newcharstring .= (($charval < 256) ? chr($charval) : '?');
768
- }
769
- }
770
- return $newcharstring;
771
- }
772
-
773
- // UTF-8 => UTF-16BE
774
- static function iconv_fallback_utf8_utf16be($string, $bom=false) {
775
- $newcharstring = '';
776
- if ($bom) {
777
- $newcharstring .= "\xFE\xFF";
778
- }
779
- $offset = 0;
780
- $stringlength = strlen($string);
781
- while ($offset < $stringlength) {
782
- if ((ord($string{$offset}) | 0x07) == 0xF7) {
783
- // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
784
- $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
785
- ((ord($string{($offset + 1)}) & 0x3F) << 12) &
786
- ((ord($string{($offset + 2)}) & 0x3F) << 6) &
787
- (ord($string{($offset + 3)}) & 0x3F);
788
- $offset += 4;
789
- } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
790
- // 1110bbbb 10bbbbbb 10bbbbbb
791
- $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
792
- ((ord($string{($offset + 1)}) & 0x3F) << 6) &
793
- (ord($string{($offset + 2)}) & 0x3F);
794
- $offset += 3;
795
- } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
796
- // 110bbbbb 10bbbbbb
797
- $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
798
- (ord($string{($offset + 1)}) & 0x3F);
799
- $offset += 2;
800
- } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
801
- // 0bbbbbbb
802
- $charval = ord($string{$offset});
803
- $offset += 1;
804
- } else {
805
- // error? throw some kind of warning here?
806
- $charval = false;
807
- $offset += 1;
808
- }
809
- if ($charval !== false) {
810
- $newcharstring .= (($charval < 65536) ? getid3_lib::BigEndian2String($charval, 2) : "\x00".'?');
811
- }
812
- }
813
- return $newcharstring;
814
- }
815
-
816
- // UTF-8 => UTF-16LE
817
- static function iconv_fallback_utf8_utf16le($string, $bom=false) {
818
- $newcharstring = '';
819
- if ($bom) {
820
- $newcharstring .= "\xFF\xFE";
821
- }
822
- $offset = 0;
823
- $stringlength = strlen($string);
824
- while ($offset < $stringlength) {
825
- if ((ord($string{$offset}) | 0x07) == 0xF7) {
826
- // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
827
- $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
828
- ((ord($string{($offset + 1)}) & 0x3F) << 12) &
829
- ((ord($string{($offset + 2)}) & 0x3F) << 6) &
830
- (ord($string{($offset + 3)}) & 0x3F);
831
- $offset += 4;
832
- } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
833
- // 1110bbbb 10bbbbbb 10bbbbbb
834
- $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
835
- ((ord($string{($offset + 1)}) & 0x3F) << 6) &
836
- (ord($string{($offset + 2)}) & 0x3F);
837
- $offset += 3;
838
- } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
839
- // 110bbbbb 10bbbbbb
840
- $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
841
- (ord($string{($offset + 1)}) & 0x3F);
842
- $offset += 2;
843
- } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
844
- // 0bbbbbbb
845
- $charval = ord($string{$offset});
846
- $offset += 1;
847
- } else {
848
- // error? maybe throw some warning here?
849
- $charval = false;
850
- $offset += 1;
851
- }
852
- if ($charval !== false) {
853
- $newcharstring .= (($charval < 65536) ? getid3_lib::LittleEndian2String($charval, 2) : '?'."\x00");
854
- }
855
- }
856
- return $newcharstring;
857
- }
858
-
859
- // UTF-8 => UTF-16LE (BOM)
860
- static function iconv_fallback_utf8_utf16($string) {
861
- return getid3_lib::iconv_fallback_utf8_utf16le($string, true);
862
- }
863
-
864
- // UTF-16BE => UTF-8
865
- static function iconv_fallback_utf16be_utf8($string) {
866
- if (substr($string, 0, 2) == "\xFE\xFF") {
867
- // strip BOM
868
- $string = substr($string, 2);
869
- }
870
- $newcharstring = '';
871
- for ($i = 0; $i < strlen($string); $i += 2) {
872
- $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
873
- $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
874
- }
875
- return $newcharstring;
876
- }
877
-
878
- // UTF-16LE => UTF-8
879
- static function iconv_fallback_utf16le_utf8($string) {
880
- if (substr($string, 0, 2) == "\xFF\xFE") {
881
- // strip BOM
882
- $string = substr($string, 2);
883
- }
884
- $newcharstring = '';
885
- for ($i = 0; $i < strlen($string); $i += 2) {
886
- $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
887
- $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval);
888
- }
889
- return $newcharstring;
890
- }
891
-
892
- // UTF-16BE => ISO-8859-1
893
- static function iconv_fallback_utf16be_iso88591($string) {
894
- if (substr($string, 0, 2) == "\xFE\xFF") {
895
- // strip BOM
896
- $string = substr($string, 2);
897
- }
898
- $newcharstring = '';
899
- for ($i = 0; $i < strlen($string); $i += 2) {
900
- $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
901
- $newcharstring .= (($charval < 256) ? chr($charval) : '?');
902
- }
903
- return $newcharstring;
904
- }
905
-
906
- // UTF-16LE => ISO-8859-1
907
- static function iconv_fallback_utf16le_iso88591($string) {
908
- if (substr($string, 0, 2) == "\xFF\xFE") {
909
- // strip BOM
910
- $string = substr($string, 2);
911
- }
912
- $newcharstring = '';
913
- for ($i = 0; $i < strlen($string); $i += 2) {
914
- $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
915
- $newcharstring .= (($charval < 256) ? chr($charval) : '?');
916
- }
917
- return $newcharstring;
918
- }
919
-
920
- // UTF-16 (BOM) => ISO-8859-1
921
- static function iconv_fallback_utf16_iso88591($string) {
922
- $bom = substr($string, 0, 2);
923
- if ($bom == "\xFE\xFF") {
924
- return getid3_lib::iconv_fallback_utf16be_iso88591(substr($string, 2));
925
- } elseif ($bom == "\xFF\xFE") {
926
- return getid3_lib::iconv_fallback_utf16le_iso88591(substr($string, 2));
927
- }
928
- return $string;
929
- }
930
-
931
- // UTF-16 (BOM) => UTF-8
932
- static function iconv_fallback_utf16_utf8($string) {
933
- $bom = substr($string, 0, 2);
934
- if ($bom == "\xFE\xFF") {
935
- return getid3_lib::iconv_fallback_utf16be_utf8(substr($string, 2));
936
- } elseif ($bom == "\xFF\xFE") {
937
- return getid3_lib::iconv_fallback_utf16le_utf8(substr($string, 2));
938
- }
939
- return $string;
940
- }
941
-
942
- static function iconv_fallback($in_charset, $out_charset, $string) {
943
-
944
- if ($in_charset == $out_charset) {
945
- return $string;
946
- }
947
-
948
- // iconv() availble
949
- if (function_exists('iconv')) {
950
- if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) {
951
- switch ($out_charset) {
952
- case 'ISO-8859-1':
953
- $converted_string = rtrim($converted_string, "\x00");
954
- break;
955
- }
956
- return $converted_string;
957
- }
958
-
959
- // iconv() may sometimes fail with "illegal character in input string" error message
960
- // and return an empty string, but returning the unconverted string is more useful
961
- return $string;
962
- }
963
-
964
-
965
- // iconv() not available
966
- static $ConversionFunctionList = array();
967
- if (empty($ConversionFunctionList)) {
968
- $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8';
969
- $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16';
970
- $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be';
971
- $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le';
972
- $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591';
973
- $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16';
974
- $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be';
975
- $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le';
976
- $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591';
977
- $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8';
978
- $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591';
979
- $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8';
980
- $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591';
981
- $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8';
982
- }
983
- if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) {
984
- $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
985
- return getid3_lib::$ConversionFunction($string);
986
- }
987
- throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
988
- }
989
-
990
-
991
- static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
992
- $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
993
- $HTMLstring = '';
994
-
995
- switch ($charset) {
996
- case '1251':
997
- case '1252':
998
- case '866':
999
- case '932':
1000
- case '936':
1001
- case '950':
1002
- case 'BIG5':
1003
- case 'BIG5-HKSCS':
1004
- case 'cp1251':
1005
- case 'cp1252':
1006
- case 'cp866':
1007
- case 'EUC-JP':
1008
- case 'EUCJP':
1009
- case 'GB2312':
1010
- case 'ibm866':
1011
- case 'ISO-8859-1':
1012
- case 'ISO-8859-15':
1013
- case 'ISO8859-1':
1014
- case 'ISO8859-15':
1015
- case 'KOI8-R':
1016
- case 'koi8-ru':
1017
- case 'koi8r':
1018
- case 'Shift_JIS':
1019
- case 'SJIS':
1020
- case 'win-1251':
1021
- case 'Windows-1251':
1022
- case 'Windows-1252':
1023
- $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
1024
- break;
1025
-
1026
- case 'UTF-8':
1027
- $strlen = strlen($string);
1028
- for ($i = 0; $i < $strlen; $i++) {
1029
- $char_ord_val = ord($string{$i});
1030
- $charval = 0;
1031
- if ($char_ord_val < 0x80) {
1032
- $charval = $char_ord_val;
1033
- } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) {
1034
- $charval = (($char_ord_val & 0x07) << 18);
1035
- $charval += ((ord($string{++$i}) & 0x3F) << 12);
1036
- $charval += ((ord($string{++$i}) & 0x3F) << 6);
1037
- $charval += (ord($string{++$i}) & 0x3F);
1038
- } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) {
1039
- $charval = (($char_ord_val & 0x0F) << 12);
1040
- $charval += ((ord($string{++$i}) & 0x3F) << 6);
1041
- $charval += (ord($string{++$i}) & 0x3F);
1042
- } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) {
1043
- $charval = (($char_ord_val & 0x1F) << 6);
1044
- $charval += (ord($string{++$i}) & 0x3F);
1045
- }
1046
- if (($charval >= 32) && ($charval <= 127)) {
1047
- $HTMLstring .= htmlentities(chr($charval));
1048
- } else {
1049
- $HTMLstring .= '&#'.$charval.';';
1050
- }
1051
- }
1052
- break;
1053
-
1054
- case 'UTF-16LE':
1055
- for ($i = 0; $i < strlen($string); $i += 2) {
1056
- $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
1057
- if (($charval >= 32) && ($charval <= 127)) {
1058
- $HTMLstring .= chr($charval);
1059
- } else {
1060
- $HTMLstring .= '&#'.$charval.';';
1061
- }
1062
- }
1063
- break;
1064
-
1065
- case 'UTF-16BE':
1066
- for ($i = 0; $i < strlen($string); $i += 2) {
1067
- $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2));
1068
- if (($charval >= 32) && ($charval <= 127)) {
1069
- $HTMLstring .= chr($charval);
1070
- } else {
1071
- $HTMLstring .= '&#'.$charval.';';
1072
- }
1073
- }
1074
- break;
1075
-
1076
- default:
1077
- $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()';
1078
- break;
1079
- }
1080
- return $HTMLstring;
1081
- }
1082
-
1083
-
1084
-
1085
- static function RGADnameLookup($namecode) {
1086
- static $RGADname = array();
1087
- if (empty($RGADname)) {
1088
- $RGADname[0] = 'not set';
1089
- $RGADname[1] = 'Track Gain Adjustment';
1090
- $RGADname[2] = 'Album Gain Adjustment';
1091
- }
1092
-
1093
- return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : '');
1094
- }
1095
-
1096
-
1097
- static function RGADoriginatorLookup($originatorcode) {
1098
- static $RGADoriginator = array();
1099
- if (empty($RGADoriginator)) {
1100
- $RGADoriginator[0] = 'unspecified';
1101
- $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer';
1102
- $RGADoriginator[2] = 'set by user';
1103
- $RGADoriginator[3] = 'determined automatically';
1104
- }
1105
-
1106
- return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : '');
1107
- }
1108
-
1109
-
1110
- static function RGADadjustmentLookup($rawadjustment, $signbit) {
1111
- $adjustment = $rawadjustment / 10;
1112
- if ($signbit == 1) {
1113
- $adjustment *= -1;
1114
- }
1115
- return (float) $adjustment;
1116
- }
1117
-
1118
-
1119
- static function RGADgainString($namecode, $originatorcode, $replaygain) {
1120
- if ($replaygain < 0) {
1121
- $signbit = '1';
1122
- } else {
1123
- $signbit = '0';
1124
- }
1125
- $storedreplaygain = intval(round($replaygain * 10));
1126
- $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT);
1127
- $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT);
1128
- $gainstring .= $signbit;
1129
- $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT);
1130
-
1131
- return $gainstring;
1132
- }
1133
-
1134
- static function RGADamplitude2dB($amplitude) {
1135
- return 20 * log10($amplitude);
1136
- }
1137
-
1138
-
1139
- static function GetDataImageSize($imgData, &$imageinfo) {
1140
- static $tempdir = '';
1141
- if (empty($tempdir)) {
1142
- // yes this is ugly, feel free to suggest a better way
1143
- require_once(dirname(__FILE__).'/getid3.php');
1144
- $getid3_temp = new getID3();
1145
- $tempdir = $getid3_temp->tempdir;
1146
- unset($getid3_temp);
1147
- }
1148
- $GetDataImageSize = false;
1149
- if ($tempfilename = tempnam($tempdir, 'gI3')) {
1150
- if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) {
1151
- fwrite($tmp, $imgData);
1152
- fclose($tmp);
1153
- $GetDataImageSize = @GetImageSize($tempfilename, $imageinfo);
1154
- }
1155
- unlink($tempfilename);
1156
- }
1157
- return $GetDataImageSize;
1158
- }
1159
-
1160
- static function ImageTypesLookup($imagetypeid) {
1161
- static $ImageTypesLookup = array();
1162
- if (empty($ImageTypesLookup)) {
1163
- $ImageTypesLookup[1] = 'gif';
1164
- $ImageTypesLookup[2] = 'jpeg';
1165
- $ImageTypesLookup[3] = 'png';
1166
- $ImageTypesLookup[4] = 'swf';
1167
- $ImageTypesLookup[5] = 'psd';
1168
- $ImageTypesLookup[6] = 'bmp';
1169
- $ImageTypesLookup[7] = 'tiff (little-endian)';
1170
- $ImageTypesLookup[8] = 'tiff (big-endian)';
1171
- $ImageTypesLookup[9] = 'jpc';
1172
- $ImageTypesLookup[10] = 'jp2';
1173
- $ImageTypesLookup[11] = 'jpx';
1174
- $ImageTypesLookup[12] = 'jb2';
1175
- $ImageTypesLookup[13] = 'swc';
1176
- $ImageTypesLookup[14] = 'iff';
1177
- }
1178
- return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : '');
1179
- }
1180
-
1181
- static function CopyTagsToComments(&$ThisFileInfo) {
1182
-
1183
- // Copy all entries from ['tags'] into common ['comments']
1184
- if (!empty($ThisFileInfo['tags'])) {
1185
- foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
1186
- foreach ($tagarray as $tagname => $tagdata) {
1187
- foreach ($tagdata as $key => $value) {
1188
- if (!empty($value)) {
1189
- if (empty($ThisFileInfo['comments'][$tagname])) {
1190
-
1191
- // fall through and append value
1192
-
1193
- } elseif ($tagtype == 'id3v1') {
1194
-
1195
- $newvaluelength = strlen(trim($value));
1196
- foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
1197
- $oldvaluelength = strlen(trim($existingvalue));
1198
- if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
1199
- // new value is identical but shorter-than (or equal-length to) one already in comments - skip
1200
- break 2;
1201
- }
1202
- }
1203
-
1204
- } elseif (!is_array($value)) {
1205
-
1206
- $newvaluelength = strlen(trim($value));
1207
- foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
1208
- $oldvaluelength = strlen(trim($existingvalue));
1209
- if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
1210
- $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
1211
- break 2;
1212
- }
1213
- }
1214
-
1215
- }
1216
- if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
1217
- $value = (is_string($value) ? trim($value) : $value);
1218
- $ThisFileInfo['comments'][$tagname][] = $value;
1219
- }
1220
- }
1221
- }
1222
- }
1223
- }
1224
-
1225
- // Copy to ['comments_html']
1226
- foreach ($ThisFileInfo['comments'] as $field => $values) {
1227
- if ($field == 'picture') {
1228
- // pictures can take up a lot of space, and we don't need multiple copies of them
1229
- // let there be a single copy in [comments][picture], and not elsewhere
1230
- continue;
1231
- }
1232
- foreach ($values as $index => $value) {
1233
- if (is_array($value)) {
1234
- $ThisFileInfo['comments_html'][$field][$index] = $value;
1235
- } else {
1236
- $ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', getid3_lib::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
1237
- }
1238
- }
1239
- }
1240
- }
1241
- return true;
1242
- }
1243
-
1244
-
1245
- static function EmbeddedLookup($key, $begin, $end, $file, $name) {
1246
-
1247
- // Cached
1248
- static $cache;
1249
- if (isset($cache[$file][$name])) {
1250
- return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
1251
- }
1252
-
1253
- // Init
1254
- $keylength = strlen($key);
1255
- $line_count = $end - $begin - 7;
1256
-
1257
- // Open php file
1258
- $fp = fopen($file, 'r');
1259
-
1260
- // Discard $begin lines
1261
- for ($i = 0; $i < ($begin + 3); $i++) {
1262
- fgets($fp, 1024);
1263
- }
1264
-
1265
- // Loop thru line
1266
- while (0 < $line_count--) {
1267
-
1268
- // Read line
1269
- $line = ltrim(fgets($fp, 1024), "\t ");
1270
-
1271
- // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key
1272
- //$keycheck = substr($line, 0, $keylength);
1273
- //if ($key == $keycheck) {
1274
- // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1);
1275
- // break;
1276
- //}
1277
-
1278
- // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
1279
- //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
1280
- $explodedLine = explode("\t", $line, 2);
1281
- $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : '');
1282
- $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : '');
1283
- $cache[$file][$name][$ThisKey] = trim($ThisValue);
1284
- }
1285
-
1286
- // Close and return
1287
- fclose($fp);
1288
- return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
1289
- }
1290
-
1291
- static function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) {
1292
- global $GETID3_ERRORARRAY;
1293
-
1294
- if (file_exists($filename)) {
1295
- if (include_once($filename)) {
1296
- return true;
1297
- } else {
1298
- $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors';
1299
- }
1300
- } else {
1301
- $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing';
1302
- }
1303
- if ($DieOnFailure) {
1304
- throw new Exception($diemessage);
1305
- } else {
1306
- $GETID3_ERRORARRAY[] = $diemessage;
1307
- }
1308
- return false;
1309
- }
1310
-
1311
- public static function trimNullByte($string) {
1312
- return trim($string, "\x00");
1313
- }
1314
-
1315
- }
1316
-
1317
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // //
9
+ // getid3.lib.php - part of getID3() //
10
+ // See readme.txt for more details //
11
+ // ///
12
+ /////////////////////////////////////////////////////////////////
13
+
14
+
15
+ class getid3_lib
16
+ {
17
+
18
+ public static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8') {
19
+ $returnstring = '';
20
+ for ($i = 0; $i < strlen($string); $i++) {
21
+ if ($hex) {
22
+ $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT);
23
+ } else {
24
+ $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string{$i}) ? $string{$i} : '¤');
25
+ }
26
+ if ($spaces) {
27
+ $returnstring .= ' ';
28
+ }
29
+ }
30
+ if (!empty($htmlencoding)) {
31
+ if ($htmlencoding === true) {
32
+ $htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean
33
+ }
34
+ $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding);
35
+ }
36
+ return $returnstring;
37
+ }
38
+
39
+ public static function trunc($floatnumber) {
40
+ // truncates a floating-point number at the decimal point
41
+ // returns int (if possible, otherwise float)
42
+ if ($floatnumber >= 1) {
43
+ $truncatednumber = floor($floatnumber);
44
+ } elseif ($floatnumber <= -1) {
45
+ $truncatednumber = ceil($floatnumber);
46
+ } else {
47
+ $truncatednumber = 0;
48
+ }
49
+ if (self::intValueSupported($truncatednumber)) {
50
+ $truncatednumber = (int) $truncatednumber;
51
+ }
52
+ return $truncatednumber;
53
+ }
54
+
55
+
56
+ public static function safe_inc(&$variable, $increment=1) {
57
+ if (isset($variable)) {
58
+ $variable += $increment;
59
+ } else {
60
+ $variable = $increment;
61
+ }
62
+ return true;
63
+ }
64
+
65
+ public static function CastAsInt($floatnum) {
66
+ // convert to float if not already
67
+ $floatnum = (float) $floatnum;
68
+
69
+ // convert a float to type int, only if possible
70
+ if (self::trunc($floatnum) == $floatnum) {
71
+ // it's not floating point
72
+ if (self::intValueSupported($floatnum)) {
73
+ // it's within int range
74
+ $floatnum = (int) $floatnum;
75
+ }
76
+ }
77
+ return $floatnum;
78
+ }
79
+
80
+ public static function intValueSupported($num) {
81
+ // check if integers are 64-bit
82
+ static $hasINT64 = null;
83
+ if ($hasINT64 === null) { // 10x faster than is_null()
84
+ $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1
85
+ if (!$hasINT64 && !defined('PHP_INT_MIN')) {
86
+ define('PHP_INT_MIN', ~PHP_INT_MAX);
87
+ }
88
+ }
89
+ // if integers are 64-bit - no other check required
90
+ if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
91
+ return true;
92
+ }
93
+ return false;
94
+ }
95
+
96
+ public static function DecimalizeFraction($fraction) {
97
+ list($numerator, $denominator) = explode('/', $fraction);
98
+ return $numerator / ($denominator ? $denominator : 1);
99
+ }
100
+
101
+
102
+ public static function DecimalBinary2Float($binarynumerator) {
103
+ $numerator = self::Bin2Dec($binarynumerator);
104
+ $denominator = self::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator)));
105
+ return ($numerator / $denominator);
106
+ }
107
+
108
+
109
+ public static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) {
110
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
111
+ if (strpos($binarypointnumber, '.') === false) {
112
+ $binarypointnumber = '0.'.$binarypointnumber;
113
+ } elseif ($binarypointnumber{0} == '.') {
114
+ $binarypointnumber = '0'.$binarypointnumber;
115
+ }
116
+ $exponent = 0;
117
+ while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.')) {
118
+ if (substr($binarypointnumber, 1, 1) == '.') {
119
+ $exponent--;
120
+ $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3);
121
+ } else {
122
+ $pointpos = strpos($binarypointnumber, '.');
123
+ $exponent += ($pointpos - 1);
124
+ $binarypointnumber = str_replace('.', '', $binarypointnumber);
125
+ $binarypointnumber = $binarypointnumber{0}.'.'.substr($binarypointnumber, 1);
126
+ }
127
+ }
128
+ $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT);
129
+ return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent);
130
+ }
131
+
132
+
133
+ public static function Float2BinaryDecimal($floatvalue) {
134
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
135
+ $maxbits = 128; // to how many bits of precision should the calculations be taken?
136
+ $intpart = self::trunc($floatvalue);
137
+ $floatpart = abs($floatvalue - $intpart);
138
+ $pointbitstring = '';
139
+ while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) {
140
+ $floatpart *= 2;
141
+ $pointbitstring .= (string) self::trunc($floatpart);
142
+ $floatpart -= self::trunc($floatpart);
143
+ }
144
+ $binarypointnumber = decbin($intpart).'.'.$pointbitstring;
145
+ return $binarypointnumber;
146
+ }
147
+
148
+
149
+ public static function Float2String($floatvalue, $bits) {
150
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
151
+ switch ($bits) {
152
+ case 32:
153
+ $exponentbits = 8;
154
+ $fractionbits = 23;
155
+ break;
156
+
157
+ case 64:
158
+ $exponentbits = 11;
159
+ $fractionbits = 52;
160
+ break;
161
+
162
+ default:
163
+ return false;
164
+ break;
165
+ }
166
+ if ($floatvalue >= 0) {
167
+ $signbit = '0';
168
+ } else {
169
+ $signbit = '1';
170
+ }
171
+ $normalizedbinary = self::NormalizeBinaryPoint(self::Float2BinaryDecimal($floatvalue), $fractionbits);
172
+ $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent
173
+ $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT);
174
+ $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT);
175
+
176
+ return self::BigEndian2String(self::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false);
177
+ }
178
+
179
+
180
+ public static function LittleEndian2Float($byteword) {
181
+ return self::BigEndian2Float(strrev($byteword));
182
+ }
183
+
184
+
185
+ public static function BigEndian2Float($byteword) {
186
+ // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
187
+ // http://www.psc.edu/general/software/packages/ieee/ieee.html
188
+ // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
189
+
190
+ $bitword = self::BigEndian2Bin($byteword);
191
+ if (!$bitword) {
192
+ return 0;
193
+ }
194
+ $signbit = $bitword{0};
195
+
196
+ switch (strlen($byteword) * 8) {
197
+ case 32:
198
+ $exponentbits = 8;
199
+ $fractionbits = 23;
200
+ break;
201
+
202
+ case 64:
203
+ $exponentbits = 11;
204
+ $fractionbits = 52;
205
+ break;
206
+
207
+ case 80:
208
+ // 80-bit Apple SANE format
209
+ // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
210
+ $exponentstring = substr($bitword, 1, 15);
211
+ $isnormalized = intval($bitword{16});
212
+ $fractionstring = substr($bitword, 17, 63);
213
+ $exponent = pow(2, self::Bin2Dec($exponentstring) - 16383);
214
+ $fraction = $isnormalized + self::DecimalBinary2Float($fractionstring);
215
+ $floatvalue = $exponent * $fraction;
216
+ if ($signbit == '1') {
217
+ $floatvalue *= -1;
218
+ }
219
+ return $floatvalue;
220
+ break;
221
+
222
+ default:
223
+ return false;
224
+ break;
225
+ }
226
+ $exponentstring = substr($bitword, 1, $exponentbits);
227
+ $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
228
+ $exponent = self::Bin2Dec($exponentstring);
229
+ $fraction = self::Bin2Dec($fractionstring);
230
+
231
+ if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) {
232
+ // Not a Number
233
+ $floatvalue = false;
234
+ } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) {
235
+ if ($signbit == '1') {
236
+ $floatvalue = '-infinity';
237
+ } else {
238
+ $floatvalue = '+infinity';
239
+ }
240
+ } elseif (($exponent == 0) && ($fraction == 0)) {
241
+ if ($signbit == '1') {
242
+ $floatvalue = -0;
243
+ } else {
244
+ $floatvalue = 0;
245
+ }
246
+ $floatvalue = ($signbit ? 0 : -0);
247
+ } elseif (($exponent == 0) && ($fraction != 0)) {
248
+ // These are 'unnormalized' values
249
+ $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring);
250
+ if ($signbit == '1') {
251
+ $floatvalue *= -1;
252
+ }
253
+ } elseif ($exponent != 0) {
254
+ $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + self::DecimalBinary2Float($fractionstring));
255
+ if ($signbit == '1') {
256
+ $floatvalue *= -1;
257
+ }
258
+ }
259
+ return (float) $floatvalue;
260
+ }
261
+
262
+
263
+ public static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {
264
+ $intvalue = 0;
265
+ $bytewordlen = strlen($byteword);
266
+ if ($bytewordlen == 0) {
267
+ return false;
268
+ }
269
+ for ($i = 0; $i < $bytewordlen; $i++) {
270
+ if ($synchsafe) { // disregard MSB, effectively 7-bit bytes
271
+ //$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems
272
+ $intvalue += (ord($byteword{$i}) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7);
273
+ } else {
274
+ $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
275
+ }
276
+ }
277
+ if ($signed && !$synchsafe) {
278
+ // synchsafe ints are not allowed to be signed
279
+ if ($bytewordlen <= PHP_INT_SIZE) {
280
+ $signMaskBit = 0x80 << (8 * ($bytewordlen - 1));
281
+ if ($intvalue & $signMaskBit) {
282
+ $intvalue = 0 - ($intvalue & ($signMaskBit - 1));
283
+ }
284
+ } else {
285
+ throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()');
286
+ }
287
+ }
288
+ return self::CastAsInt($intvalue);
289
+ }
290
+
291
+
292
+ public static function LittleEndian2Int($byteword, $signed=false) {
293
+ return self::BigEndian2Int(strrev($byteword), false, $signed);
294
+ }
295
+
296
+
297
+ public static function BigEndian2Bin($byteword) {
298
+ $binvalue = '';
299
+ $bytewordlen = strlen($byteword);
300
+ for ($i = 0; $i < $bytewordlen; $i++) {
301
+ $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT);
302
+ }
303
+ return $binvalue;
304
+ }
305
+
306
+
307
+ public static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) {
308
+ if ($number < 0) {
309
+ throw new Exception('ERROR: self::BigEndian2String() does not support negative numbers');
310
+ }
311
+ $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
312
+ $intstring = '';
313
+ if ($signed) {
314
+ if ($minbytes > PHP_INT_SIZE) {
315
+ throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in self::BigEndian2String()');
316
+ }
317
+ $number = $number & (0x80 << (8 * ($minbytes - 1)));
318
+ }
319
+ while ($number != 0) {
320
+ $quotient = ($number / ($maskbyte + 1));
321
+ $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring;
322
+ $number = floor($quotient);
323
+ }
324
+ return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT);
325
+ }
326
+
327
+
328
+ public static function Dec2Bin($number) {
329
+ while ($number >= 256) {
330
+ $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
331
+ $number = floor($number / 256);
332
+ }
333
+ $bytes[] = $number;
334
+ $binstring = '';
335
+ for ($i = 0; $i < count($bytes); $i++) {
336
+ $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring;
337
+ }
338
+ return $binstring;
339
+ }
340
+
341
+
342
+ public static function Bin2Dec($binstring, $signed=false) {
343
+ $signmult = 1;
344
+ if ($signed) {
345
+ if ($binstring{0} == '1') {
346
+ $signmult = -1;
347
+ }
348
+ $binstring = substr($binstring, 1);
349
+ }
350
+ $decvalue = 0;
351
+ for ($i = 0; $i < strlen($binstring); $i++) {
352
+ $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
353
+ }
354
+ return self::CastAsInt($decvalue * $signmult);
355
+ }
356
+
357
+
358
+ public static function Bin2String($binstring) {
359
+ // return 'hi' for input of '0110100001101001'
360
+ $string = '';
361
+ $binstringreversed = strrev($binstring);
362
+ for ($i = 0; $i < strlen($binstringreversed); $i += 8) {
363
+ $string = chr(self::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string;
364
+ }
365
+ return $string;
366
+ }
367
+
368
+
369
+ public static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) {
370
+ $intstring = '';
371
+ while ($number > 0) {
372
+ if ($synchsafe) {
373
+ $intstring = $intstring.chr($number & 127);
374
+ $number >>= 7;
375
+ } else {
376
+ $intstring = $intstring.chr($number & 255);
377
+ $number >>= 8;
378
+ }
379
+ }
380
+ return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
381
+ }
382
+
383
+
384
+ public static function array_merge_clobber($array1, $array2) {
385
+ // written by kcØhireability*com
386
+ // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
387
+ if (!is_array($array1) || !is_array($array2)) {
388
+ return false;
389
+ }
390
+ $newarray = $array1;
391
+ foreach ($array2 as $key => $val) {
392
+ if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
393
+ $newarray[$key] = self::array_merge_clobber($newarray[$key], $val);
394
+ } else {
395
+ $newarray[$key] = $val;
396
+ }
397
+ }
398
+ return $newarray;
399
+ }
400
+
401
+
402
+ public static function array_merge_noclobber($array1, $array2) {
403
+ if (!is_array($array1) || !is_array($array2)) {
404
+ return false;
405
+ }
406
+ $newarray = $array1;
407
+ foreach ($array2 as $key => $val) {
408
+ if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
409
+ $newarray[$key] = self::array_merge_noclobber($newarray[$key], $val);
410
+ } elseif (!isset($newarray[$key])) {
411
+ $newarray[$key] = $val;
412
+ }
413
+ }
414
+ return $newarray;
415
+ }
416
+
417
+
418
+ public static function ksort_recursive(&$theArray) {
419
+ ksort($theArray);
420
+ foreach ($theArray as $key => $value) {
421
+ if (is_array($value)) {
422
+ self::ksort_recursive($theArray[$key]);
423
+ }
424
+ }
425
+ return true;
426
+ }
427
+
428
+ public static function fileextension($filename, $numextensions=1) {
429
+ if (strstr($filename, '.')) {
430
+ $reversedfilename = strrev($filename);
431
+ $offset = 0;
432
+ for ($i = 0; $i < $numextensions; $i++) {
433
+ $offset = strpos($reversedfilename, '.', $offset + 1);
434
+ if ($offset === false) {
435
+ return '';
436
+ }
437
+ }
438
+ return strrev(substr($reversedfilename, 0, $offset));
439
+ }
440
+ return '';
441
+ }
442
+
443
+
444
+ public static function PlaytimeString($seconds) {
445
+ $sign = (($seconds < 0) ? '-' : '');
446
+ $seconds = round(abs($seconds));
447
+ $H = (int) floor( $seconds / 3600);
448
+ $M = (int) floor(($seconds - (3600 * $H) ) / 60);
449
+ $S = (int) round( $seconds - (3600 * $H) - (60 * $M) );
450
+ return $sign.($H ? $H.':' : '').($H ? str_pad($M, 2, '0', STR_PAD_LEFT) : intval($M)).':'.str_pad($S, 2, 0, STR_PAD_LEFT);
451
+ }
452
+
453
+
454
+ public static function DateMac2Unix($macdate) {
455
+ // Macintosh timestamp: seconds since 00:00h January 1, 1904
456
+ // UNIX timestamp: seconds since 00:00h January 1, 1970
457
+ return self::CastAsInt($macdate - 2082844800);
458
+ }
459
+
460
+
461
+ public static function FixedPoint8_8($rawdata) {
462
+ return self::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (self::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
463
+ }
464
+
465
+
466
+ public static function FixedPoint16_16($rawdata) {
467
+ return self::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (self::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
468
+ }
469
+
470
+
471
+ public static function FixedPoint2_30($rawdata) {
472
+ $binarystring = self::BigEndian2Bin($rawdata);
473
+ return self::Bin2Dec(substr($binarystring, 0, 2)) + (float) (self::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30));
474
+ }
475
+
476
+
477
+ public static function CreateDeepArray($ArrayPath, $Separator, $Value) {
478
+ // assigns $Value to a nested array path:
479
+ // $foo = self::CreateDeepArray('/path/to/my', '/', 'file.txt')
480
+ // is the same as:
481
+ // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt'))));
482
+ // or
483
+ // $foo['path']['to']['my'] = 'file.txt';
484
+ $ArrayPath = ltrim($ArrayPath, $Separator);
485
+ if (($pos = strpos($ArrayPath, $Separator)) !== false) {
486
+ $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value);
487
+ } else {
488
+ $ReturnedArray[$ArrayPath] = $Value;
489
+ }
490
+ return $ReturnedArray;
491
+ }
492
+
493
+ public static function array_max($arraydata, $returnkey=false) {
494
+ $maxvalue = false;
495
+ $maxkey = false;
496
+ foreach ($arraydata as $key => $value) {
497
+ if (!is_array($value)) {
498
+ if ($value > $maxvalue) {
499
+ $maxvalue = $value;
500
+ $maxkey = $key;
501
+ }
502
+ }
503
+ }
504
+ return ($returnkey ? $maxkey : $maxvalue);
505
+ }
506
+
507
+ public static function array_min($arraydata, $returnkey=false) {
508
+ $minvalue = false;
509
+ $minkey = false;
510
+ foreach ($arraydata as $key => $value) {
511
+ if (!is_array($value)) {
512
+ if ($value > $minvalue) {
513
+ $minvalue = $value;
514
+ $minkey = $key;
515
+ }
516
+ }
517
+ }
518
+ return ($returnkey ? $minkey : $minvalue);
519
+ }
520
+
521
+ public static function XML2array($XMLstring) {
522
+ if (function_exists('simplexml_load_string')) {
523
+ if (function_exists('get_object_vars')) {
524
+ if (function_exists('libxml_disable_entity_loader')) { // (PHP 5 >= 5.2.11)
525
+ // http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html
526
+ libxml_disable_entity_loader(true);
527
+ }
528
+ $XMLobject = simplexml_load_string($XMLstring);
529
+ return self::SimpleXMLelement2array($XMLobject);
530
+ }
531
+ }
532
+ return false;
533
+ }
534
+
535
+ public static function SimpleXMLelement2array($XMLobject) {
536
+ if (!is_object($XMLobject) && !is_array($XMLobject)) {
537
+ return $XMLobject;
538
+ }
539
+ $XMLarray = (is_object($XMLobject) ? get_object_vars($XMLobject) : $XMLobject);
540
+ foreach ($XMLarray as $key => $value) {
541
+ $XMLarray[$key] = self::SimpleXMLelement2array($value);
542
+ }
543
+ return $XMLarray;
544
+ }
545
+
546
+
547
+ // Allan Hansen <ahØartemis*dk>
548
+ // self::md5_data() - returns md5sum for a file from startuing position to absolute end position
549
+ public static function hash_data($file, $offset, $end, $algorithm) {
550
+ static $tempdir = '';
551
+ if (!self::intValueSupported($end)) {
552
+ return false;
553
+ }
554
+ switch ($algorithm) {
555
+ case 'md5':
556
+ $hash_function = 'md5_file';
557
+ $unix_call = 'md5sum';
558
+ $windows_call = 'md5sum.exe';
559
+ $hash_length = 32;
560
+ break;
561
+
562
+ case 'sha1':
563
+ $hash_function = 'sha1_file';
564
+ $unix_call = 'sha1sum';
565
+ $windows_call = 'sha1sum.exe';
566
+ $hash_length = 40;
567
+ break;
568
+
569
+ default:
570
+ throw new Exception('Invalid algorithm ('.$algorithm.') in self::hash_data()');
571
+ break;
572
+ }
573
+ $size = $end - $offset;
574
+ while (true) {
575
+ if (GETID3_OS_ISWINDOWS) {
576
+
577
+ // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data
578
+ // Fall back to create-temp-file method:
579
+ if ($algorithm == 'sha1') {
580
+ break;
581
+ }
582
+
583
+ $RequiredFiles = array('cygwin1.dll', 'head.exe', 'tail.exe', $windows_call);
584
+ foreach ($RequiredFiles as $required_file) {
585
+ if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
586
+ // helper apps not available - fall back to old method
587
+ break 2;
588
+ }
589
+ }
590
+ $commandline = GETID3_HELPERAPPSDIR.'head.exe -c '.$end.' '.escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)).' | ';
591
+ $commandline .= GETID3_HELPERAPPSDIR.'tail.exe -c '.$size.' | ';
592
+ $commandline .= GETID3_HELPERAPPSDIR.$windows_call;
593
+
594
+ } else {
595
+
596
+ $commandline = 'head -c'.$end.' '.escapeshellarg($file).' | ';
597
+ $commandline .= 'tail -c'.$size.' | ';
598
+ $commandline .= $unix_call;
599
+
600
+ }
601
+ if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
602
+ //throw new Exception('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm');
603
+ break;
604
+ }
605
+ return substr(`$commandline`, 0, $hash_length);
606
+ }
607
+
608
+ if (empty($tempdir)) {
609
+ // yes this is ugly, feel free to suggest a better way
610
+ require_once(dirname(__FILE__).'/getid3.php');
611
+ $getid3_temp = new getID3();
612
+ $tempdir = $getid3_temp->tempdir;
613
+ unset($getid3_temp);
614
+ }
615
+ // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
616
+ if (($data_filename = tempnam($tempdir, 'gI3')) === false) {
617
+ // can't find anywhere to create a temp file, just fail
618
+ return false;
619
+ }
620
+
621
+ // Init
622
+ $result = false;
623
+
624
+ // copy parts of file
625
+ try {
626
+ self::CopyFileParts($file, $data_filename, $offset, $end - $offset);
627
+ $result = $hash_function($data_filename);
628
+ } catch (Exception $e) {
629
+ throw new Exception('self::CopyFileParts() failed in getid_lib::hash_data(): '.$e->getMessage());
630
+ }
631
+ unlink($data_filename);
632
+ return $result;
633
+ }
634
+
635
+ public static function CopyFileParts($filename_source, $filename_dest, $offset, $length) {
636
+ if (!self::intValueSupported($offset + $length)) {
637
+ throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
638
+ }
639
+ if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
640
+ if (($fp_dest = fopen($filename_dest, 'wb'))) {
641
+ if (fseek($fp_src, $offset) == 0) {
642
+ $byteslefttowrite = $length;
643
+ while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
644
+ $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
645
+ $byteslefttowrite -= $byteswritten;
646
+ }
647
+ return true;
648
+ } else {
649
+ throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source);
650
+ }
651
+ fclose($fp_dest);
652
+ } else {
653
+ throw new Exception('failed to create file for writing '.$filename_dest);
654
+ }
655
+ fclose($fp_src);
656
+ } else {
657
+ throw new Exception('failed to open file for reading '.$filename_source);
658
+ }
659
+ return false;
660
+ }
661
+
662
+ public static function iconv_fallback_int_utf8($charval) {
663
+ if ($charval < 128) {
664
+ // 0bbbbbbb
665
+ $newcharstring = chr($charval);
666
+ } elseif ($charval < 2048) {
667
+ // 110bbbbb 10bbbbbb
668
+ $newcharstring = chr(($charval >> 6) | 0xC0);
669
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
670
+ } elseif ($charval < 65536) {
671
+ // 1110bbbb 10bbbbbb 10bbbbbb
672
+ $newcharstring = chr(($charval >> 12) | 0xE0);
673
+ $newcharstring .= chr(($charval >> 6) | 0xC0);
674
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
675
+ } else {
676
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
677
+ $newcharstring = chr(($charval >> 18) | 0xF0);
678
+ $newcharstring .= chr(($charval >> 12) | 0xC0);
679
+ $newcharstring .= chr(($charval >> 6) | 0xC0);
680
+ $newcharstring .= chr(($charval & 0x3F) | 0x80);
681
+ }
682
+ return $newcharstring;
683
+ }
684
+
685
+ // ISO-8859-1 => UTF-8
686
+ public static function iconv_fallback_iso88591_utf8($string, $bom=false) {
687
+ if (function_exists('utf8_encode')) {
688
+ return utf8_encode($string);
689
+ }
690
+ // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
691
+ $newcharstring = '';
692
+ if ($bom) {
693
+ $newcharstring .= "\xEF\xBB\xBF";
694
+ }
695
+ for ($i = 0; $i < strlen($string); $i++) {
696
+ $charval = ord($string{$i});
697
+ $newcharstring .= self::iconv_fallback_int_utf8($charval);
698
+ }
699
+ return $newcharstring;
700
+ }
701
+
702
+ // ISO-8859-1 => UTF-16BE
703
+ public static function iconv_fallback_iso88591_utf16be($string, $bom=false) {
704
+ $newcharstring = '';
705
+ if ($bom) {
706
+ $newcharstring .= "\xFE\xFF";
707
+ }
708
+ for ($i = 0; $i < strlen($string); $i++) {
709
+ $newcharstring .= "\x00".$string{$i};
710
+ }
711
+ return $newcharstring;
712
+ }
713
+
714
+ // ISO-8859-1 => UTF-16LE
715
+ public static function iconv_fallback_iso88591_utf16le($string, $bom=false) {
716
+ $newcharstring = '';
717
+ if ($bom) {
718
+ $newcharstring .= "\xFF\xFE";
719
+ }
720
+ for ($i = 0; $i < strlen($string); $i++) {
721
+ $newcharstring .= $string{$i}."\x00";
722
+ }
723
+ return $newcharstring;
724
+ }
725
+
726
+ // ISO-8859-1 => UTF-16LE (BOM)
727
+ public static function iconv_fallback_iso88591_utf16($string) {
728
+ return self::iconv_fallback_iso88591_utf16le($string, true);
729
+ }
730
+
731
+ // UTF-8 => ISO-8859-1
732
+ public static function iconv_fallback_utf8_iso88591($string) {
733
+ if (function_exists('utf8_decode')) {
734
+ return utf8_decode($string);
735
+ }
736
+ // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
737
+ $newcharstring = '';
738
+ $offset = 0;
739
+ $stringlength = strlen($string);
740
+ while ($offset < $stringlength) {
741
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
742
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
743
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
744
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
745
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
746
+ (ord($string{($offset + 3)}) & 0x3F);
747
+ $offset += 4;
748
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
749
+ // 1110bbbb 10bbbbbb 10bbbbbb
750
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
751
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
752
+ (ord($string{($offset + 2)}) & 0x3F);
753
+ $offset += 3;
754
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
755
+ // 110bbbbb 10bbbbbb
756
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
757
+ (ord($string{($offset + 1)}) & 0x3F);
758
+ $offset += 2;
759
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
760
+ // 0bbbbbbb
761
+ $charval = ord($string{$offset});
762
+ $offset += 1;
763
+ } else {
764
+ // error? throw some kind of warning here?
765
+ $charval = false;
766
+ $offset += 1;
767
+ }
768
+ if ($charval !== false) {
769
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
770
+ }
771
+ }
772
+ return $newcharstring;
773
+ }
774
+
775
+ // UTF-8 => UTF-16BE
776
+ public static function iconv_fallback_utf8_utf16be($string, $bom=false) {
777
+ $newcharstring = '';
778
+ if ($bom) {
779
+ $newcharstring .= "\xFE\xFF";
780
+ }
781
+ $offset = 0;
782
+ $stringlength = strlen($string);
783
+ while ($offset < $stringlength) {
784
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
785
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
786
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
787
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
788
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
789
+ (ord($string{($offset + 3)}) & 0x3F);
790
+ $offset += 4;
791
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
792
+ // 1110bbbb 10bbbbbb 10bbbbbb
793
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
794
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
795
+ (ord($string{($offset + 2)}) & 0x3F);
796
+ $offset += 3;
797
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
798
+ // 110bbbbb 10bbbbbb
799
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
800
+ (ord($string{($offset + 1)}) & 0x3F);
801
+ $offset += 2;
802
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
803
+ // 0bbbbbbb
804
+ $charval = ord($string{$offset});
805
+ $offset += 1;
806
+ } else {
807
+ // error? throw some kind of warning here?
808
+ $charval = false;
809
+ $offset += 1;
810
+ }
811
+ if ($charval !== false) {
812
+ $newcharstring .= (($charval < 65536) ? self::BigEndian2String($charval, 2) : "\x00".'?');
813
+ }
814
+ }
815
+ return $newcharstring;
816
+ }
817
+
818
+ // UTF-8 => UTF-16LE
819
+ public static function iconv_fallback_utf8_utf16le($string, $bom=false) {
820
+ $newcharstring = '';
821
+ if ($bom) {
822
+ $newcharstring .= "\xFF\xFE";
823
+ }
824
+ $offset = 0;
825
+ $stringlength = strlen($string);
826
+ while ($offset < $stringlength) {
827
+ if ((ord($string{$offset}) | 0x07) == 0xF7) {
828
+ // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
829
+ $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
830
+ ((ord($string{($offset + 1)}) & 0x3F) << 12) &
831
+ ((ord($string{($offset + 2)}) & 0x3F) << 6) &
832
+ (ord($string{($offset + 3)}) & 0x3F);
833
+ $offset += 4;
834
+ } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
835
+ // 1110bbbb 10bbbbbb 10bbbbbb
836
+ $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
837
+ ((ord($string{($offset + 1)}) & 0x3F) << 6) &
838
+ (ord($string{($offset + 2)}) & 0x3F);
839
+ $offset += 3;
840
+ } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
841
+ // 110bbbbb 10bbbbbb
842
+ $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
843
+ (ord($string{($offset + 1)}) & 0x3F);
844
+ $offset += 2;
845
+ } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
846
+ // 0bbbbbbb
847
+ $charval = ord($string{$offset});
848
+ $offset += 1;
849
+ } else {
850
+ // error? maybe throw some warning here?
851
+ $charval = false;
852
+ $offset += 1;
853
+ }
854
+ if ($charval !== false) {
855
+ $newcharstring .= (($charval < 65536) ? self::LittleEndian2String($charval, 2) : '?'."\x00");
856
+ }
857
+ }
858
+ return $newcharstring;
859
+ }
860
+
861
+ // UTF-8 => UTF-16LE (BOM)
862
+ public static function iconv_fallback_utf8_utf16($string) {
863
+ return self::iconv_fallback_utf8_utf16le($string, true);
864
+ }
865
+
866
+ // UTF-16BE => UTF-8
867
+ public static function iconv_fallback_utf16be_utf8($string) {
868
+ if (substr($string, 0, 2) == "\xFE\xFF") {
869
+ // strip BOM
870
+ $string = substr($string, 2);
871
+ }
872
+ $newcharstring = '';
873
+ for ($i = 0; $i < strlen($string); $i += 2) {
874
+ $charval = self::BigEndian2Int(substr($string, $i, 2));
875
+ $newcharstring .= self::iconv_fallback_int_utf8($charval);
876
+ }
877
+ return $newcharstring;
878
+ }
879
+
880
+ // UTF-16LE => UTF-8
881
+ public static function iconv_fallback_utf16le_utf8($string) {
882
+ if (substr($string, 0, 2) == "\xFF\xFE") {
883
+ // strip BOM
884
+ $string = substr($string, 2);
885
+ }
886
+ $newcharstring = '';
887
+ for ($i = 0; $i < strlen($string); $i += 2) {
888
+ $charval = self::LittleEndian2Int(substr($string, $i, 2));
889
+ $newcharstring .= self::iconv_fallback_int_utf8($charval);
890
+ }
891
+ return $newcharstring;
892
+ }
893
+
894
+ // UTF-16BE => ISO-8859-1
895
+ public static function iconv_fallback_utf16be_iso88591($string) {
896
+ if (substr($string, 0, 2) == "\xFE\xFF") {
897
+ // strip BOM
898
+ $string = substr($string, 2);
899
+ }
900
+ $newcharstring = '';
901
+ for ($i = 0; $i < strlen($string); $i += 2) {
902
+ $charval = self::BigEndian2Int(substr($string, $i, 2));
903
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
904
+ }
905
+ return $newcharstring;
906
+ }
907
+
908
+ // UTF-16LE => ISO-8859-1
909
+ public static function iconv_fallback_utf16le_iso88591($string) {
910
+ if (substr($string, 0, 2) == "\xFF\xFE") {
911
+ // strip BOM
912
+ $string = substr($string, 2);
913
+ }
914
+ $newcharstring = '';
915
+ for ($i = 0; $i < strlen($string); $i += 2) {
916
+ $charval = self::LittleEndian2Int(substr($string, $i, 2));
917
+ $newcharstring .= (($charval < 256) ? chr($charval) : '?');
918
+ }
919
+ return $newcharstring;
920
+ }
921
+
922
+ // UTF-16 (BOM) => ISO-8859-1
923
+ public static function iconv_fallback_utf16_iso88591($string) {
924
+ $bom = substr($string, 0, 2);
925
+ if ($bom == "\xFE\xFF") {
926
+ return self::iconv_fallback_utf16be_iso88591(substr($string, 2));
927
+ } elseif ($bom == "\xFF\xFE") {
928
+ return self::iconv_fallback_utf16le_iso88591(substr($string, 2));
929
+ }
930
+ return $string;
931
+ }
932
+
933
+ // UTF-16 (BOM) => UTF-8
934
+ public static function iconv_fallback_utf16_utf8($string) {
935
+ $bom = substr($string, 0, 2);
936
+ if ($bom == "\xFE\xFF") {
937
+ return self::iconv_fallback_utf16be_utf8(substr($string, 2));
938
+ } elseif ($bom == "\xFF\xFE") {
939
+ return self::iconv_fallback_utf16le_utf8(substr($string, 2));
940
+ }
941
+ return $string;
942
+ }
943
+
944
+ public static function iconv_fallback($in_charset, $out_charset, $string) {
945
+
946
+ if ($in_charset == $out_charset) {
947
+ return $string;
948
+ }
949
+
950
+ // iconv() availble
951
+ if (function_exists('iconv')) {
952
+ if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) {
953
+ switch ($out_charset) {
954
+ case 'ISO-8859-1':
955
+ $converted_string = rtrim($converted_string, "\x00");
956
+ break;
957
+ }
958
+ return $converted_string;
959
+ }
960
+
961
+ // iconv() may sometimes fail with "illegal character in input string" error message
962
+ // and return an empty string, but returning the unconverted string is more useful
963
+ return $string;
964
+ }
965
+
966
+
967
+ // iconv() not available
968
+ static $ConversionFunctionList = array();
969
+ if (empty($ConversionFunctionList)) {
970
+ $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8';
971
+ $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16';
972
+ $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be';
973
+ $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le';
974
+ $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591';
975
+ $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16';
976
+ $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be';
977
+ $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le';
978
+ $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591';
979
+ $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8';
980
+ $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591';
981
+ $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8';
982
+ $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591';
983
+ $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8';
984
+ }
985
+ if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) {
986
+ $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
987
+ return self::$ConversionFunction($string);
988
+ }
989
+ throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
990
+ }
991
+
992
+ public static function recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1') {
993
+ if (is_string($data)) {
994
+ return self::MultiByteCharString2HTML($data, $charset);
995
+ } elseif (is_array($data)) {
996
+ $return_data = array();
997
+ foreach ($data as $key => $value) {
998
+ $return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset);
999
+ }
1000
+ return $return_data;
1001
+ }
1002
+ // integer, float, objects, resources, etc
1003
+ return $data;
1004
+ }
1005
+
1006
+ public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
1007
+ $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
1008
+ $HTMLstring = '';
1009
+
1010
+ switch ($charset) {
1011
+ case '1251':
1012
+ case '1252':
1013
+ case '866':
1014
+ case '932':
1015
+ case '936':
1016
+ case '950':
1017
+ case 'BIG5':
1018
+ case 'BIG5-HKSCS':
1019
+ case 'cp1251':
1020
+ case 'cp1252':
1021
+ case 'cp866':
1022
+ case 'EUC-JP':
1023
+ case 'EUCJP':
1024
+ case 'GB2312':
1025
+ case 'ibm866':
1026
+ case 'ISO-8859-1':
1027
+ case 'ISO-8859-15':
1028
+ case 'ISO8859-1':
1029
+ case 'ISO8859-15':
1030
+ case 'KOI8-R':
1031
+ case 'koi8-ru':
1032
+ case 'koi8r':
1033
+ case 'Shift_JIS':
1034
+ case 'SJIS':
1035
+ case 'win-1251':
1036
+ case 'Windows-1251':
1037
+ case 'Windows-1252':
1038
+ $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
1039
+ break;
1040
+
1041
+ case 'UTF-8':
1042
+ $strlen = strlen($string);
1043
+ for ($i = 0; $i < $strlen; $i++) {
1044
+ $char_ord_val = ord($string{$i});
1045
+ $charval = 0;
1046
+ if ($char_ord_val < 0x80) {
1047
+ $charval = $char_ord_val;
1048
+ } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) {
1049
+ $charval = (($char_ord_val & 0x07) << 18);
1050
+ $charval += ((ord($string{++$i}) & 0x3F) << 12);
1051
+ $charval += ((ord($string{++$i}) & 0x3F) << 6);
1052
+ $charval += (ord($string{++$i}) & 0x3F);
1053
+ } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) {
1054
+ $charval = (($char_ord_val & 0x0F) << 12);
1055
+ $charval += ((ord($string{++$i}) & 0x3F) << 6);
1056
+ $charval += (ord($string{++$i}) & 0x3F);
1057
+ } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) {
1058
+ $charval = (($char_ord_val & 0x1F) << 6);
1059
+ $charval += (ord($string{++$i}) & 0x3F);
1060
+ }
1061
+ if (($charval >= 32) && ($charval <= 127)) {
1062
+ $HTMLstring .= htmlentities(chr($charval));
1063
+ } else {
1064
+ $HTMLstring .= '&#'.$charval.';';
1065
+ }
1066
+ }
1067
+ break;
1068
+
1069
+ case 'UTF-16LE':
1070
+ for ($i = 0; $i < strlen($string); $i += 2) {
1071
+ $charval = self::LittleEndian2Int(substr($string, $i, 2));
1072
+ if (($charval >= 32) && ($charval <= 127)) {
1073
+ $HTMLstring .= chr($charval);
1074
+ } else {
1075
+ $HTMLstring .= '&#'.$charval.';';
1076
+ }
1077
+ }
1078
+ break;
1079
+
1080
+ case 'UTF-16BE':
1081
+ for ($i = 0; $i < strlen($string); $i += 2) {
1082
+ $charval = self::BigEndian2Int(substr($string, $i, 2));
1083
+ if (($charval >= 32) && ($charval <= 127)) {
1084
+ $HTMLstring .= chr($charval);
1085
+ } else {
1086
+ $HTMLstring .= '&#'.$charval.';';
1087
+ }
1088
+ }
1089
+ break;
1090
+
1091
+ default:
1092
+ $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()';
1093
+ break;
1094
+ }
1095
+ return $HTMLstring;
1096
+ }
1097
+
1098
+
1099
+
1100
+ public static function RGADnameLookup($namecode) {
1101
+ static $RGADname = array();
1102
+ if (empty($RGADname)) {
1103
+ $RGADname[0] = 'not set';
1104
+ $RGADname[1] = 'Track Gain Adjustment';
1105
+ $RGADname[2] = 'Album Gain Adjustment';
1106
+ }
1107
+
1108
+ return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : '');
1109
+ }
1110
+
1111
+
1112
+ public static function RGADoriginatorLookup($originatorcode) {
1113
+ static $RGADoriginator = array();
1114
+ if (empty($RGADoriginator)) {
1115
+ $RGADoriginator[0] = 'unspecified';
1116
+ $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer';
1117
+ $RGADoriginator[2] = 'set by user';
1118
+ $RGADoriginator[3] = 'determined automatically';
1119
+ }
1120
+
1121
+ return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : '');
1122
+ }
1123
+
1124
+
1125
+ public static function RGADadjustmentLookup($rawadjustment, $signbit) {
1126
+ $adjustment = $rawadjustment / 10;
1127
+ if ($signbit == 1) {
1128
+ $adjustment *= -1;
1129
+ }
1130
+ return (float) $adjustment;
1131
+ }
1132
+
1133
+
1134
+ public static function RGADgainString($namecode, $originatorcode, $replaygain) {
1135
+ if ($replaygain < 0) {
1136
+ $signbit = '1';
1137
+ } else {
1138
+ $signbit = '0';
1139
+ }
1140
+ $storedreplaygain = intval(round($replaygain * 10));
1141
+ $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT);
1142
+ $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT);
1143
+ $gainstring .= $signbit;
1144
+ $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT);
1145
+
1146
+ return $gainstring;
1147
+ }
1148
+
1149
+ public static function RGADamplitude2dB($amplitude) {
1150
+ return 20 * log10($amplitude);
1151
+ }
1152
+
1153
+
1154
+ public static function GetDataImageSize($imgData, &$imageinfo=array()) {
1155
+ static $tempdir = '';
1156
+ if (empty($tempdir)) {
1157
+ // yes this is ugly, feel free to suggest a better way
1158
+ require_once(dirname(__FILE__).'/getid3.php');
1159
+ $getid3_temp = new getID3();
1160
+ $tempdir = $getid3_temp->tempdir;
1161
+ unset($getid3_temp);
1162
+ }
1163
+ $GetDataImageSize = false;
1164
+ if ($tempfilename = tempnam($tempdir, 'gI3')) {
1165
+ if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) {
1166
+ fwrite($tmp, $imgData);
1167
+ fclose($tmp);
1168
+ $GetDataImageSize = @getimagesize($tempfilename, $imageinfo);
1169
+ }
1170
+ unlink($tempfilename);
1171
+ }
1172
+ return $GetDataImageSize;
1173
+ }
1174
+
1175
+ public static function ImageExtFromMime($mime_type) {
1176
+ // temporary way, works OK for now, but should be reworked in the future
1177
+ return str_replace(array('image/', 'x-', 'jpeg'), array('', '', 'jpg'), $mime_type);
1178
+ }
1179
+
1180
+ public static function ImageTypesLookup($imagetypeid) {
1181
+ static $ImageTypesLookup = array();
1182
+ if (empty($ImageTypesLookup)) {
1183
+ $ImageTypesLookup[1] = 'gif';
1184
+ $ImageTypesLookup[2] = 'jpeg';
1185
+ $ImageTypesLookup[3] = 'png';
1186
+ $ImageTypesLookup[4] = 'swf';
1187
+ $ImageTypesLookup[5] = 'psd';
1188
+ $ImageTypesLookup[6] = 'bmp';
1189
+ $ImageTypesLookup[7] = 'tiff (little-endian)';
1190
+ $ImageTypesLookup[8] = 'tiff (big-endian)';
1191
+ $ImageTypesLookup[9] = 'jpc';
1192
+ $ImageTypesLookup[10] = 'jp2';
1193
+ $ImageTypesLookup[11] = 'jpx';
1194
+ $ImageTypesLookup[12] = 'jb2';
1195
+ $ImageTypesLookup[13] = 'swc';
1196
+ $ImageTypesLookup[14] = 'iff';
1197
+ }
1198
+ return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : '');
1199
+ }
1200
+
1201
+ public static function CopyTagsToComments(&$ThisFileInfo) {
1202
+
1203
+ // Copy all entries from ['tags'] into common ['comments']
1204
+ if (!empty($ThisFileInfo['tags'])) {
1205
+ foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
1206
+ foreach ($tagarray as $tagname => $tagdata) {
1207
+ foreach ($tagdata as $key => $value) {
1208
+ if (!empty($value)) {
1209
+ if (empty($ThisFileInfo['comments'][$tagname])) {
1210
+
1211
+ // fall through and append value
1212
+
1213
+ } elseif ($tagtype == 'id3v1') {
1214
+
1215
+ $newvaluelength = strlen(trim($value));
1216
+ foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
1217
+ $oldvaluelength = strlen(trim($existingvalue));
1218
+ if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
1219
+ // new value is identical but shorter-than (or equal-length to) one already in comments - skip
1220
+ break 2;
1221
+ }
1222
+ }
1223
+
1224
+ } elseif (!is_array($value)) {
1225
+
1226
+ $newvaluelength = strlen(trim($value));
1227
+ foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
1228
+ $oldvaluelength = strlen(trim($existingvalue));
1229
+ if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
1230
+ $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
1231
+ //break 2;
1232
+ break;
1233
+ }
1234
+ }
1235
+
1236
+ }
1237
+ if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
1238
+ $value = (is_string($value) ? trim($value) : $value);
1239
+ if (!is_numeric($key)) {
1240
+ $ThisFileInfo['comments'][$tagname][$key] = $value;
1241
+ } else {
1242
+ $ThisFileInfo['comments'][$tagname][] = $value;
1243
+ }
1244
+ }
1245
+ }
1246
+ }
1247
+ }
1248
+ }
1249
+
1250
+ // Copy to ['comments_html']
1251
+ if (!empty($ThisFileInfo['comments'])) {
1252
+ foreach ($ThisFileInfo['comments'] as $field => $values) {
1253
+ if ($field == 'picture') {
1254
+ // pictures can take up a lot of space, and we don't need multiple copies of them
1255
+ // let there be a single copy in [comments][picture], and not elsewhere
1256
+ continue;
1257
+ }
1258
+ foreach ($values as $index => $value) {
1259
+ if (is_array($value)) {
1260
+ $ThisFileInfo['comments_html'][$field][$index] = $value;
1261
+ } else {
1262
+ $ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
1263
+ }
1264
+ }
1265
+ }
1266
+ }
1267
+
1268
+ }
1269
+ return true;
1270
+ }
1271
+
1272
+
1273
+ public static function EmbeddedLookup($key, $begin, $end, $file, $name) {
1274
+
1275
+ // Cached
1276
+ static $cache;
1277
+ if (isset($cache[$file][$name])) {
1278
+ return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
1279
+ }
1280
+
1281
+ // Init
1282
+ $keylength = strlen($key);
1283
+ $line_count = $end - $begin - 7;
1284
+
1285
+ // Open php file
1286
+ $fp = fopen($file, 'r');
1287
+
1288
+ // Discard $begin lines
1289
+ for ($i = 0; $i < ($begin + 3); $i++) {
1290
+ fgets($fp, 1024);
1291
+ }
1292
+
1293
+ // Loop thru line
1294
+ while (0 < $line_count--) {
1295
+
1296
+ // Read line
1297
+ $line = ltrim(fgets($fp, 1024), "\t ");
1298
+
1299
+ // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key
1300
+ //$keycheck = substr($line, 0, $keylength);
1301
+ //if ($key == $keycheck) {
1302
+ // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1);
1303
+ // break;
1304
+ //}
1305
+
1306
+ // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
1307
+ //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
1308
+ $explodedLine = explode("\t", $line, 2);
1309
+ $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : '');
1310
+ $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : '');
1311
+ $cache[$file][$name][$ThisKey] = trim($ThisValue);
1312
+ }
1313
+
1314
+ // Close and return
1315
+ fclose($fp);
1316
+ return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
1317
+ }
1318
+
1319
+ public static function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) {
1320
+ global $GETID3_ERRORARRAY;
1321
+
1322
+ if (file_exists($filename)) {
1323
+ if (include_once($filename)) {
1324
+ return true;
1325
+ } else {
1326
+ $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors';
1327
+ }
1328
+ } else {
1329
+ $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing';
1330
+ }
1331
+ if ($DieOnFailure) {
1332
+ throw new Exception($diemessage);
1333
+ } else {
1334
+ $GETID3_ERRORARRAY[] = $diemessage;
1335
+ }
1336
+ return false;
1337
+ }
1338
+
1339
+ public static function trimNullByte($string) {
1340
+ return trim($string, "\x00");
1341
+ }
1342
+
1343
+ public static function getFileSizeSyscall($path) {
1344
+ $filesize = false;
1345
+
1346
+ if (GETID3_OS_ISWINDOWS) {
1347
+ if (class_exists('COM')) { // From PHP 5.3.15 and 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini:
1348
+ $filesystem = new COM('Scripting.FileSystemObject');
1349
+ $file = $filesystem->GetFile($path);
1350
+ $filesize = $file->Size();
1351
+ unset($filesystem, $file);
1352
+ } else {
1353
+ $commandline = 'for %I in ('.escapeshellarg($path).') do @echo %~zI';
1354
+ }
1355
+ } else {
1356
+ $commandline = 'ls -l '.escapeshellarg($path).' | awk \'{print $5}\'';
1357
+ }
1358
+ if (isset($commandline)) {
1359
+ $output = trim(`$commandline`);
1360
+ if (ctype_digit($output)) {
1361
+ $filesize = (float) $output;
1362
+ }
1363
+ }
1364
+ return $filesize;
1365
+ }
1366
+
1367
+
1368
+ /**
1369
+ * Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268)
1370
+ * @param string $path A path.
1371
+ * @param string $suffix If the name component ends in suffix this will also be cut off.
1372
+ * @return string
1373
+ */
1374
+ public static function mb_basename($path, $suffix = null) {
1375
+ $splited = preg_split('#/#', rtrim($path, '/ '));
1376
+ return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1);
1377
+ }
1378
+
1379
+ }
getid3/getid3.php CHANGED
@@ -1,1766 +1,1809 @@
1
- <?php
2
- /////////////////////////////////////////////////////////////////
3
- /// getID3() by James Heinrich <info@getid3.org> //
4
- // available at http://getid3.sourceforge.net //
5
- // or http://www.getid3.org //
6
- /////////////////////////////////////////////////////////////////
7
- // //
8
- // Please see readme.txt for more information //
9
- // ///
10
- /////////////////////////////////////////////////////////////////
11
-
12
- // START Added for PowerPress
13
- if( function_exists('get_temp_dir') ) // If wordpress function is available, lets use it
14
- {
15
- $temp_dir = get_temp_dir(); // WordPress temp folder
16
- }
17
- else
18
- { // END Added for PowerPress
19
-
20
- // attempt to define temp dir as something flexible but reliable
21
- $temp_dir = ini_get('upload_tmp_dir');
22
- if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) {
23
- $temp_dir = '';
24
- }
25
- if (!$temp_dir && function_exists('sys_get_temp_dir')) {
26
- // PHP v5.2.1+
27
- // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts
28
- $temp_dir = sys_get_temp_dir();
29
- }
30
- $temp_dir = realpath($temp_dir);
31
- $open_basedir = ini_get('open_basedir');
32
- if ($open_basedir) {
33
- // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/"
34
- $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir);
35
- $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir);
36
- if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) {
37
- $temp_dir .= DIRECTORY_SEPARATOR;
38
- }
39
- $found_valid_tempdir = false;
40
- $open_basedirs = explode(':', $open_basedir);
41
- foreach ($open_basedirs as $basedir) {
42
- if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) {
43
- $basedir .= DIRECTORY_SEPARATOR;
44
- }
45
- if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) {
46
- $found_valid_tempdir = true;
47
- break;
48
- }
49
- }
50
- if (!$found_valid_tempdir) {
51
- $temp_dir = '';
52
- }
53
- unset($open_basedirs, $found_valid_tempdir, $basedir);
54
- }
55
- if (!$temp_dir) {
56
- $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir
57
- }
58
-
59
- } // Added for PowerPress
60
-
61
-
62
- // $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system
63
- define('GETID3_TEMP_DIR', $temp_dir);
64
- unset($open_basedir, $temp_dir);
65
-
66
-
67
- // define a constant rather than looking up every time it is needed
68
- if (!defined('GETID3_OS_ISWINDOWS')) {
69
- if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
70
- define('GETID3_OS_ISWINDOWS', true);
71
- } else {
72
- define('GETID3_OS_ISWINDOWS', false);
73
- }
74
- }
75
-
76
- // Get base path of getID3() - ONCE
77
- if (!defined('GETID3_INCLUDEPATH')) {
78
- foreach (get_included_files() as $key => $val) {
79
- if (basename($val) == 'getid3.php') {
80
- define('GETID3_INCLUDEPATH', dirname($val).DIRECTORY_SEPARATOR);
81
- break;
82
- }
83
- }
84
- }
85
-
86
- // End: Defines
87
-
88
-
89
- class getID3
90
- {
91
- // public: Settings
92
- public $encoding = 'UTF-8'; // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
93
- public $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
94
-
95
- // public: Optional tag checks - disable for speed.
96
- public $option_tag_id3v1 = true; // Read and process ID3v1 tags
97
- public $option_tag_id3v2 = true; // Read and process ID3v2 tags
98
- public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags
99
- public $option_tag_apetag = true; // Read and process APE tags
100
- public $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding
101
- public $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
102
-
103
- // public: Optional tag/comment calucations
104
- public $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc
105
-
106
- // public: Optional handling of embedded attachments (e.g. images)
107
- public $option_save_attachments = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility
108
-
109
- // public: Optional calculations
110
- public $option_md5_data = false; // Get MD5 sum of data part - slow
111
- public $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG
112
- public $option_sha1_data = false; // Get SHA1 sum of data part - slow
113
- public $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX)
114
-
115
- // public: Read buffer size in bytes
116
- public $option_fread_buffer_size = 32768;
117
-
118
- // Public variables
119
- public $filename; // Filename of file being analysed.
120
- public $fp; // Filepointer to file being analysed.
121
- public $info; // Result array.
122
-
123
- // Protected variables
124
- protected $startup_error = '';
125
- protected $startup_warning = '';
126
- protected $memory_limit = 0;
127
-
128
- const VERSION = '1.9.3-20111213';
129
- const FREAD_BUFFER_SIZE = 32768;
130
- var $tempdir = GETID3_TEMP_DIR;
131
-
132
- const ATTACHMENTS_NONE = false;
133
- const ATTACHMENTS_INLINE = true;
134
-
135
- // public: constructor
136
- public function __construct() {
137
-
138
- // Check for PHP version
139
- $required_php_version = '5.0.5';
140
- if (version_compare(PHP_VERSION, $required_php_version, '<')) {
141
- $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION;
142
- return false;
143
- }
144
-
145
- // Check memory
146
- $this->memory_limit = ini_get('memory_limit');
147
- if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) {
148
- // could be stored as "16M" rather than 16777216 for example
149
- $this->memory_limit = $matches[1] * 1048576;
150
- } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
151
- // could be stored as "2G" rather than 2147483648 for example
152
- $this->memory_limit = $matches[1] * 1073741824;
153
- }
154
- if ($this->memory_limit <= 0) {
155
- // memory limits probably disabled
156
- } elseif ($this->memory_limit <= 4194304) {
157
- $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini';
158
- } elseif ($this->memory_limit <= 12582912) {
159
- $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini';
160
- }
161
-
162
- // Check safe_mode off
163
- if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
164
- $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
165
- }
166
-
167
- if (intval(ini_get('mbstring.func_overload')) > 0) {
168
- $this->warning('WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", this may break things.');
169
- }
170
-
171
- // Check for magic_quotes_runtime
172
- if (function_exists('get_magic_quotes_runtime')) {
173
- if (get_magic_quotes_runtime()) {
174
- return $this->startup_error('magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).');
175
- }
176
- }
177
-
178
- // Check for magic_quotes_gpc
179
- if (function_exists('magic_quotes_gpc')) {
180
- if (get_magic_quotes_gpc()) {
181
- return $this->startup_error('magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).');
182
- }
183
- }
184
-
185
- // Load support library
186
- if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
187
- $this->startup_error .= 'getid3.lib.php is missing or corrupt';
188
- }
189
-
190
- if ($this->option_max_2gb_check === null) {
191
- $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647);
192
- }
193
-
194
-
195
- // Needed for Windows only:
196
- // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
197
- // as well as other helper functions such as head, tail, md5sum, etc
198
- // This path cannot contain spaces, but the below code will attempt to get the
199
- // 8.3-equivalent path automatically
200
- // IMPORTANT: This path must include the trailing slash
201
- if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
202
-
203
- $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path
204
-
205
- if (!is_dir($helperappsdir)) {
206
- $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
207
- } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
208
- $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
209
- $path_so_far = array();
210
- foreach ($DirPieces as $key => $value) {
211
- if (strpos($value, ' ') !== false) {
212
- if (!empty($path_so_far)) {
213
- $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
214
- $dir_listing = `$commandline`;
215
- $lines = explode("\n", $dir_listing);
216
- foreach ($lines as $line) {
217
- $line = trim($line);
218
- if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(<DIR>|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) {
219
- list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches;
220
- if ((strtoupper($filesize) == '<DIR>') && (strtolower($filename) == strtolower($value))) {
221
- $value = $shortname;
222
- }
223
- }
224
- }
225
- } else {
226
- $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.';
227
- }
228
- }
229
- $path_so_far[] = $value;
230
- }
231
- $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far);
232
- }
233
- define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
234
- }
235
-
236
- return true;
237
- }
238
-
239
- public function version() {
240
- return self::VERSION;
241
- }
242
-
243
- public function fread_buffer_size() {
244
- return $this->option_fread_buffer_size;
245
- }
246
-
247
-
248
- // public: setOption
249
- function setOption($optArray) {
250
- if (!is_array($optArray) || empty($optArray)) {
251
- return false;
252
- }
253
- foreach ($optArray as $opt => $val) {
254
- if (isset($this->$opt) === false) {
255
- continue;
256
- }
257
- $this->$opt = $val;
258
- }
259
- return true;
260
- }
261
-
262
-
263
- public function openfile($filename, $filesize=false) {
264
- try {
265
- if (!empty($this->startup_error)) {
266
- throw new getid3_exception($this->startup_error);
267
- }
268
- if (!empty($this->startup_warning)) {
269
- $this->warning($this->startup_warning);
270
- }
271
-
272
- // init result array and set parameters
273
- $this->filename = $filename;
274
- $this->info = array();
275
- $this->info['GETID3_VERSION'] = $this->version();
276
- $this->info['php_memory_limit'] = $this->memory_limit;
277
-
278
- // remote files not supported
279
- if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
280
- throw new getid3_exception('Remote files are not supported - please copy the file locally first');
281
- }
282
-
283
- $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
284
- $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename);
285
-
286
- // open local file
287
- if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
288
- // great
289
- } else {
290
- throw new getid3_exception('Could not open "'.$filename.'" (does not exist, or is not a file)');
291
- }
292
-
293
- if( $filesize )
294
- $this->info['filesize'] = $filesize;
295
- else
296
- $this->info['filesize'] = filesize($filename);
297
- // set redundant parameters - might be needed in some include file
298
- $this->info['filename'] = basename($filename);
299
- $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
300
- $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
301
-
302
-
303
- // option_max_2gb_check
304
- if ($this->option_max_2gb_check) {
305
- // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
306
- // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
307
- // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
308
- $fseek = fseek($this->fp, 0, SEEK_END);
309
- if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) ||
310
- ($this->info['filesize'] < 0) ||
311
- (ftell($this->fp) < 0)) {
312
- $real_filesize = false;
313
- if (GETID3_OS_ISWINDOWS) {
314
- $commandline = 'dir /-C "'.str_replace('/', DIRECTORY_SEPARATOR, $filename).'"';
315
- $dir_output = `$commandline`;
316
- if (preg_match('#1 File\(s\)[ ]+([0-9]+) bytes#i', $dir_output, $matches)) {
317
- $real_filesize = (float) $matches[1];
318
- }
319
- } else {
320
- $commandline = 'ls -o -g -G --time-style=long-iso '.escapeshellarg($filename);
321
- $dir_output = `$commandline`;
322
- if (preg_match('#([0-9]+) ([0-9]{4}-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}) '.str_replace('#', '\\#', preg_quote($filename)).'$#', $dir_output, $matches)) {
323
- $real_filesize = (float) $matches[1];
324
- }
325
- }
326
- if ($real_filesize === false) {
327
- unset($this->info['filesize']);
328
- fclose($this->fp);
329
- throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.');
330
- } elseif (getid3_lib::intValueSupported($real_filesize)) {
331
- unset($this->info['filesize']);
332
- fclose($this->fp);
333
- throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org');
334
- }
335
- $this->info['filesize'] = $real_filesize;
336
- $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.');
337
- }
338
- }
339
-
340
- // set more parameters
341
- $this->info['avdataoffset'] = 0;
342
- $this->info['avdataend'] = $this->info['filesize'];
343
- $this->info['fileformat'] = ''; // filled in later
344
- $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used
345
- $this->info['video']['dataformat'] = ''; // filled in later, unset if not used
346
- $this->info['tags'] = array(); // filled in later, unset if not used
347
- $this->info['error'] = array(); // filled in later, unset if not used
348
- $this->info['warning'] = array(); // filled in later, unset if not used
349
- $this->info['comments'] = array(); // filled in later, unset if not used
350
- $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired
351
-
352
- return true;
353
-
354
- } catch (Exception $e) {
355
- $this->error($e->getMessage());
356
- }
357
- return false;
358
- }
359
-
360
- // public: analyze file
361
- function analyze($filename, $filesize=false, $orig_filename='file.mp3') { // 2nd AND 3rd PARAMTERS ADDED BY POWERPRESS
362
- try {
363
- if (!$this->openfile($filename, $filesize)) {
364
- return $this->info;
365
- }
366
-
367
- // ADDED BY POWERPRESS
368
- //if( $filesize )
369
- // $this->info['filesize'] = $filesize;
370
- // END ADDED BY POWERPRESS
371
-
372
- // Handle tags
373
- foreach (array('id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
374
- $option_tag = 'option_tag_'.$tag_name;
375
- if ($this->$option_tag) {
376
- $this->include_module('tag.'.$tag_name);
377
- try {
378
- $tag_class = 'getid3_'.$tag_name;
379
- $tag = new $tag_class($this);
380
- $tag->Analyze();
381
- }
382
- catch (getid3_exception $e) {
383
- throw $e;
384
- }
385
- }
386
- }
387
- if (isset($this->info['id3v2']['tag_offset_start'])) {
388
- $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']);
389
- }
390
- foreach (array('id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
391
- if (isset($this->info[$tag_key]['tag_offset_start'])) {
392
- $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']);
393
- }
394
- }
395
-
396
- // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier
397
- if (!$this->option_tag_id3v2) {
398
- fseek($this->fp, 0, SEEK_SET);
399
- $header = fread($this->fp, 10);
400
- if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) {
401
- $this->info['id3v2']['header'] = true;
402
- $this->info['id3v2']['majorversion'] = ord($header{3});
403
- $this->info['id3v2']['minorversion'] = ord($header{4});
404
- $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
405
- }
406
- }
407
-
408
- // read 32 kb file data
409
- fseek($this->fp, $this->info['avdataoffset'], SEEK_SET);
410
- $formattest = fread($this->fp, 32774);
411
-
412
- // determine format
413
- // MODIFIED BY POWERPRESS
414
- $determined_format = $this->GetFileFormat($formattest, $orig_filename);
415
- // MODIFIED BY POWERPRESS
416
-
417
- // unable to determine file format
418
- if (!$determined_format) {
419
- fclose($this->fp);
420
- return $this->error('unable to determine file format');
421
- }
422
-
423
- // check for illegal ID3 tags
424
- if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
425
- if ($determined_format['fail_id3'] === 'ERROR') {
426
- fclose($this->fp);
427
- return $this->error('ID3 tags not allowed on this file type.');
428
- } elseif ($determined_format['fail_id3'] === 'WARNING') {
429
- $this->warning('ID3 tags not allowed on this file type.');
430
- }
431
- }
432
-
433
- // check for illegal APE tags
434
- if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
435
- if ($determined_format['fail_ape'] === 'ERROR') {
436
- fclose($this->fp);
437
- return $this->error('APE tags not allowed on this file type.');
438
- } elseif ($determined_format['fail_ape'] === 'WARNING') {
439
- $this->warning('APE tags not allowed on this file type.');
440
- }
441
- }
442
-
443
- // set mime type
444
- $this->info['mime_type'] = $determined_format['mime_type'];
445
-
446
- // supported format signature pattern detected, but module deleted
447
- if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
448
- fclose($this->fp);
449
- return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.');
450
- }
451
-
452
- // module requires iconv support
453
- // Check encoding/iconv support
454
- if (!empty($determined_format['iconv_req']) && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
455
- $errormessage = 'iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
456
- if (GETID3_OS_ISWINDOWS) {
457
- $errormessage .= 'PHP does not have iconv() support. Please enable php_iconv.dll in php.ini, and copy iconv.dll from c:/php/dlls to c:/windows/system32';
458
- } else {
459
- $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
460
- }
461
- return $this->error($errormessage);
462
- }
463
-
464
- // include module
465
- include_once(GETID3_INCLUDEPATH.$determined_format['include']);
466
-
467
- // instantiate module class
468
- $class_name = 'getid3_'.$determined_format['module'];
469
- if (!class_exists($class_name)) {
470
- return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.');
471
- }
472
- //if (isset($determined_format['option'])) {
473
- // //$class = new $class_name($this->fp, $this->info, $determined_format['option']);
474
- //} else {
475
- //$class = new $class_name($this->fp, $this->info);
476
- $class = new $class_name($this);
477
- //}
478
-
479
- if (!empty($determined_format['set_inline_attachments'])) {
480
- $class->inline_attachments = $this->option_save_attachments;
481
- }
482
- $class->Analyze();
483
-
484
- unset($class);
485
-
486
- // close file
487
- fclose($this->fp);
488
-
489
- // process all tags - copy to 'tags' and convert charsets
490
- if ($this->option_tags_process) {
491
- $this->HandleAllTags();
492
- }
493
-
494
- // perform more calculations
495
- if ($this->option_extra_info) {
496
- $this->ChannelsBitratePlaytimeCalculations();
497
- $this->CalculateCompressionRatioVideo();
498
- $this->CalculateCompressionRatioAudio();
499
- $this->CalculateReplayGain();
500
- $this->ProcessAudioStreams();
501
- }
502
-
503
- // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
504
- if ($this->option_md5_data) {
505
- // do not cald md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too
506
- if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
507
- $this->getHashdata('md5');
508
- }
509
- }
510
-
511
- // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
512
- if ($this->option_sha1_data) {
513
- $this->getHashdata('sha1');
514
- }
515
-
516
- // remove undesired keys
517
- $this->CleanUp();
518
-
519
- } catch (Exception $e) {
520
- $this->error('Caught exception: '.$e->getMessage());
521
- }
522
-
523
- // return info array
524
- return $this->info;
525
- }
526
-
527
-
528
- // private: error handling
529
- function error($message) {
530
- $this->CleanUp();
531
- if (!isset($this->info['error'])) {
532
- $this->info['error'] = array();
533
- }
534
- $this->info['error'][] = $message;
535
- return $this->info;
536
- }
537
-
538
-
539
- // private: warning handling
540
- function warning($message) {
541
- $this->info['warning'][] = $message;
542
- return true;
543
- }
544
-
545
-
546
- // private: CleanUp
547
- function CleanUp() {
548
-
549
- // remove possible empty keys
550
- $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate');
551
- foreach ($AVpossibleEmptyKeys as $dummy => $key) {
552
- if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
553
- unset($this->info['audio'][$key]);
554
- }
555
- if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
556
- unset($this->info['video'][$key]);
557
- }
558
- }
559
-
560
- // remove empty root keys
561
- if (!empty($this->info)) {
562
- foreach ($this->info as $key => $value) {
563
- if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
564
- unset($this->info[$key]);
565
- }
566
- }
567
- }
568
-
569
- // remove meaningless entries from unknown-format files
570
- if (empty($this->info['fileformat'])) {
571
- if (isset($this->info['avdataoffset'])) {
572
- unset($this->info['avdataoffset']);
573
- }
574
- if (isset($this->info['avdataend'])) {
575
- unset($this->info['avdataend']);
576
- }
577
- }
578
-
579
- // remove possible duplicated identical entries
580
- if (!empty($this->info['error'])) {
581
- $this->info['error'] = array_values(array_unique($this->info['error']));
582
- }
583
- if (!empty($this->info['warning'])) {
584
- $this->info['warning'] = array_values(array_unique($this->info['warning']));
585
- }
586
-
587
- // remove "global variable" type keys
588
- unset($this->info['php_memory_limit']);
589
-
590
- return true;
591
- }
592
-
593
-
594
- // return array containing information about all supported formats
595
- function GetFileFormatArray() {
596
- static $format_info = array();
597
- if (empty($format_info)) {
598
- $format_info = array(
599
-
600
- // Audio formats
601
-
602
- // AC-3 - audio - Dolby AC-3 / Dolby Digital
603
- 'ac3' => array(
604
- 'pattern' => '^\x0B\x77',
605
- 'group' => 'audio',
606
- 'module' => 'ac3',
607
- 'mime_type' => 'audio/ac3',
608
- ),
609
-
610
- // AAC - audio - Advanced Audio Coding (AAC) - ADIF format
611
- 'adif' => array(
612
- 'pattern' => '^ADIF',
613
- 'group' => 'audio',
614
- 'module' => 'aac',
615
- 'mime_type' => 'application/octet-stream',
616
- 'fail_ape' => 'WARNING',
617
- ),
618
-
619
-
620
- // AA - audio - Audible Audiobook
621
- 'adts' => array(
622
- 'pattern' => '^.{4}\x57\x90\x75\x36',
623
- 'group' => 'audio',
624
- 'module' => 'aa',
625
- 'mime_type' => 'audio/audible ',
626
- ),
627
-
628
- // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
629
- 'adts' => array(
630
- 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]',
631
- 'group' => 'audio',
632
- 'module' => 'aac',
633
- 'mime_type' => 'application/octet-stream',
634
- 'fail_ape' => 'WARNING',
635
- ),
636
-
637
-
638
- // AU - audio - NeXT/Sun AUdio (AU)
639
- 'au' => array(
640
- 'pattern' => '^\.snd',
641
- 'group' => 'audio',
642
- 'module' => 'au',
643
- 'mime_type' => 'audio/basic',
644
- ),
645
-
646
- // AVR - audio - Audio Visual Research
647
- 'avr' => array(
648
- 'pattern' => '^2BIT',
649
- 'group' => 'audio',
650
- 'module' => 'avr',
651
- 'mime_type' => 'application/octet-stream',
652
- ),
653
-
654
- // BONK - audio - Bonk v0.9+
655
- 'bonk' => array(
656
- 'pattern' => '^\x00(BONK|INFO|META| ID3)',
657
- 'group' => 'audio',
658
- 'module' => 'bonk',
659
- 'mime_type' => 'audio/xmms-bonk',
660
- ),
661
-
662
- // DSS - audio - Digital Speech Standard
663
- 'dss' => array(
664
- 'pattern' => '^[\x02-\x03]dss',
665
- 'group' => 'audio',
666
- 'module' => 'dss',
667
- 'mime_type' => 'application/octet-stream',
668
- ),
669
-
670
- // DTS - audio - Dolby Theatre System
671
- 'dts' => array(
672
- 'pattern' => '^\x7F\xFE\x80\x01',
673
- 'group' => 'audio',
674
- 'module' => 'dts',
675
- 'mime_type' => 'audio/dts',
676
- ),
677
-
678
- // FLAC - audio - Free Lossless Audio Codec
679
- 'flac' => array(
680
- 'pattern' => '^fLaC',
681
- 'group' => 'audio',
682
- 'module' => 'flac',
683
- 'mime_type' => 'audio/x-flac',
684
- 'set_inline_attachments' => true,
685
- ),
686
-
687
- // LA - audio - Lossless Audio (LA)
688
- 'la' => array(
689
- 'pattern' => '^LA0[2-4]',
690
- 'group' => 'audio',
691
- 'module' => 'la',
692
- 'mime_type' => 'application/octet-stream',
693
- ),
694
-
695
- // LPAC - audio - Lossless Predictive Audio Compression (LPAC)
696
- 'lpac' => array(
697
- 'pattern' => '^LPAC',
698
- 'group' => 'audio',
699
- 'module' => 'lpac',
700
- 'mime_type' => 'application/octet-stream',
701
- ),
702
-
703
- // MIDI - audio - MIDI (Musical Instrument Digital Interface)
704
- 'midi' => array(
705
- 'pattern' => '^MThd',
706
- 'group' => 'audio',
707
- 'module' => 'midi',
708
- 'mime_type' => 'audio/midi',
709
- ),
710
-
711
- // MAC - audio - Monkey's Audio Compressor
712
- 'mac' => array(
713
- 'pattern' => '^MAC ',
714
- 'group' => 'audio',
715
- 'module' => 'monkey',
716
- 'mime_type' => 'application/octet-stream',
717
- ),
718
-
719
- // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
720
- // // MOD - audio - MODule (assorted sub-formats)
721
- // 'mod' => array(
722
- // 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
723
- // 'group' => 'audio',
724
- // 'module' => 'mod',
725
- // 'option' => 'mod',
726
- // 'mime_type' => 'audio/mod',
727
- // ),
728
-
729
- // MOD - audio - MODule (Impulse Tracker)
730
- 'it' => array(
731
- 'pattern' => '^IMPM',
732
- 'group' => 'audio',
733
- 'module' => 'mod',
734
- //'option' => 'it',
735
- 'mime_type' => 'audio/it',
736
- ),
737
-
738
- // MOD - audio - MODule (eXtended Module, various sub-formats)
739
- 'xm' => array(
740
- 'pattern' => '^Extended Module',
741
- 'group' => 'audio',
742
- 'module' => 'mod',
743
- //'option' => 'xm',
744
- 'mime_type' => 'audio/xm',
745
- ),
746
-
747
- // MOD - audio - MODule (ScreamTracker)
748
- 's3m' => array(
749
- 'pattern' => '^.{44}SCRM',
750
- 'group' => 'audio',
751
- 'module' => 'mod',
752
- //'option' => 's3m',
753
- 'mime_type' => 'audio/s3m',
754
- ),
755
-
756
- // MPC - audio - Musepack / MPEGplus
757
- 'mpc' => array(
758
- 'pattern' => '^(MPCK|MP\+|[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])',
759
- 'group' => 'audio',
760
- 'module' => 'mpc',
761
- 'mime_type' => 'audio/x-musepack',
762
- ),
763
-
764
- // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS)
765
- 'mp3' => array(
766
- 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\x0B\x10-\x1B\x20-\x2B\x30-\x3B\x40-\x4B\x50-\x5B\x60-\x6B\x70-\x7B\x80-\x8B\x90-\x9B\xA0-\xAB\xB0-\xBB\xC0-\xCB\xD0-\xDB\xE0-\xEB\xF0-\xFB]',
767
- 'group' => 'audio',
768
- 'module' => 'mp3',
769
- 'mime_type' => 'audio/mpeg',
770
- ),
771
-
772
- // OFR - audio - OptimFROG
773
- 'ofr' => array(
774
- 'pattern' => '^(\*RIFF|OFR)',
775
- 'group' => 'audio',
776
- 'module' => 'optimfrog',
777
- 'mime_type' => 'application/octet-stream',
778
- ),
779
-
780
- // RKAU - audio - RKive AUdio compressor
781
- 'rkau' => array(
782
- 'pattern' => '^RKA',
783
- 'group' => 'audio',
784
- 'module' => 'rkau',
785
- 'mime_type' => 'application/octet-stream',
786
- ),
787
-
788
- // SHN - audio - Shorten
789
- 'shn' => array(
790
- 'pattern' => '^ajkg',
791
- 'group' => 'audio',
792
- 'module' => 'shorten',
793
- 'mime_type' => 'audio/xmms-shn',
794
- 'fail_id3' => 'ERROR',
795
- 'fail_ape' => 'ERROR',
796
- ),
797
-
798
- // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org)
799
- 'tta' => array(
800
- 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)'
801
- 'group' => 'audio',
802
- 'module' => 'tta',
803
- 'mime_type' => 'application/octet-stream',
804
- ),
805
-
806
- // VOC - audio - Creative Voice (VOC)
807
- 'voc' => array(
808
- 'pattern' => '^Creative Voice File',
809
- 'group' => 'audio',
810
- 'module' => 'voc',
811
- 'mime_type' => 'audio/voc',
812
- ),
813
-
814
- // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF)
815
- 'vqf' => array(
816
- 'pattern' => '^TWIN',
817
- 'group' => 'audio',
818
- 'module' => 'vqf',
819
- 'mime_type' => 'application/octet-stream',
820
- ),
821
-
822
- // WV - audio - WavPack (v4.0+)
823
- 'wv' => array(
824
- 'pattern' => '^wvpk',
825
- 'group' => 'audio',
826
- 'module' => 'wavpack',
827
- 'mime_type' => 'application/octet-stream',
828
- ),
829
-
830
-
831
- // Audio-Video formats
832
-
833
- // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
834
- 'asf' => array(
835
- 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
836
- 'group' => 'audio-video',
837
- 'module' => 'asf',
838
- 'mime_type' => 'video/x-ms-asf',
839
- 'iconv_req' => false,
840
- ),
841
-
842
- // BINK - audio/video - Bink / Smacker
843
- 'bink' => array(
844
- 'pattern' => '^(BIK|SMK)',
845
- 'group' => 'audio-video',
846
- 'module' => 'bink',
847
- 'mime_type' => 'application/octet-stream',
848
- ),
849
-
850
- // FLV - audio/video - FLash Video
851
- 'flv' => array(
852
- 'pattern' => '^FLV\x01',
853
- 'group' => 'audio-video',
854
- 'module' => 'flv',
855
- 'mime_type' => 'video/x-flv',
856
- ),
857
-
858
- // MKAV - audio/video - Mastroka
859
- 'matroska' => array(
860
- 'pattern' => '^\x1A\x45\xDF\xA3',
861
- 'group' => 'audio-video',
862
- 'module' => 'matroska',
863
- 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska
864
- 'set_inline_attachments' => true,
865
- ),
866
-
867
- // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
868
- 'mpeg' => array(
869
- 'pattern' => '^\x00\x00\x01(\xBA|\xB3)',
870
- 'group' => 'audio-video',
871
- 'module' => 'mpeg',
872
- 'mime_type' => 'video/mpeg',
873
- ),
874
-
875
- // NSV - audio/video - Nullsoft Streaming Video (NSV)
876
- 'nsv' => array(
877
- 'pattern' => '^NSV[sf]',
878
- 'group' => 'audio-video',
879
- 'module' => 'nsv',
880
- 'mime_type' => 'application/octet-stream',
881
- ),
882
-
883
- // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*))
884
- 'ogg' => array(
885
- 'pattern' => '^OggS',
886
- 'group' => 'audio',
887
- 'module' => 'ogg',
888
- 'mime_type' => 'application/ogg',
889
- 'fail_id3' => 'WARNING',
890
- 'fail_ape' => 'WARNING',
891
- 'set_inline_attachments' => true,
892
- ),
893
-
894
- // QT - audio/video - Quicktime
895
- 'quicktime' => array(
896
- 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
897
- 'group' => 'audio-video',
898
- 'module' => 'quicktime',
899
- 'mime_type' => 'video/quicktime',
900
- ),
901
-
902
- // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF)
903
- 'riff' => array(
904
- 'pattern' => '^(RIFF|SDSS|FORM)',
905
- 'group' => 'audio-video',
906
- 'module' => 'riff',
907
- 'mime_type' => 'audio/x-wave',
908
- 'fail_ape' => 'WARNING',
909
- ),
910
-
911
- // Real - audio/video - RealAudio, RealVideo
912
- 'real' => array(
913
- 'pattern' => '^(\\.RMF|\\.ra)',
914
- 'group' => 'audio-video',
915
- 'module' => 'real',
916
- 'mime_type' => 'audio/x-realaudio',
917
- ),
918
-
919
- // SWF - audio/video - ShockWave Flash
920
- 'swf' => array(
921
- 'pattern' => '^(F|C)WS',
922
- 'group' => 'audio-video',
923
- 'module' => 'swf',
924
- 'mime_type' => 'application/x-shockwave-flash',
925
- ),
926
-
927
-
928
- // Still-Image formats
929
-
930
- // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4)
931
- 'bmp' => array(
932
- 'pattern' => '^BM',
933
- 'group' => 'graphic',
934
- 'module' => 'bmp',
935
- 'mime_type' => 'image/bmp',
936
- 'fail_id3' => 'ERROR',
937
- 'fail_ape' => 'ERROR',
938
- ),
939
-
940
- // GIF - still image - Graphics Interchange Format
941
- 'gif' => array(
942
- 'pattern' => '^GIF',
943
- 'group' => 'graphic',
944
- 'module' => 'gif',
945
- 'mime_type' => 'image/gif',
946
- 'fail_id3' => 'ERROR',
947
- 'fail_ape' => 'ERROR',
948
- ),
949
-
950
- // JPEG - still image - Joint Photographic Experts Group (JPEG)
951
- 'jpg' => array(
952
- 'pattern' => '^\xFF\xD8\xFF',
953
- 'group' => 'graphic',
954
- 'module' => 'jpg',
955
- 'mime_type' => 'image/jpeg',
956
- 'fail_id3' => 'ERROR',
957
- 'fail_ape' => 'ERROR',
958
- ),
959
-
960
- // PCD - still image - Kodak Photo CD
961
- 'pcd' => array(
962
- 'pattern' => '^.{2048}PCD_IPI\x00',
963
- 'group' => 'graphic',
964
- 'module' => 'pcd',
965
- 'mime_type' => 'image/x-photo-cd',
966
- 'fail_id3' => 'ERROR',
967
- 'fail_ape' => 'ERROR',
968
- ),
969
-
970
-
971
- // PNG - still image - Portable Network Graphics (PNG)
972
- 'png' => array(
973
- 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
974
- 'group' => 'graphic',
975
- 'module' => 'png',
976
- 'mime_type' => 'image/png',
977
- 'fail_id3' => 'ERROR',
978
- 'fail_ape' => 'ERROR',
979
- ),
980
-
981
-
982
- // SVG - still image - Scalable Vector Graphics (SVG)
983
- 'svg' => array(
984
- 'pattern' => '(<!DOCTYPE svg PUBLIC |xmlns="http:\/\/www\.w3\.org\/2000\/svg")',
985
- 'group' => 'graphic',
986
- 'module' => 'svg',
987
- 'mime_type' => 'image/svg+xml',
988
- 'fail_id3' => 'ERROR',
989
- 'fail_ape' => 'ERROR',
990
- ),
991
-
992
-
993
- // TIFF - still image - Tagged Information File Format (TIFF)
994
- 'tiff' => array(
995
- 'pattern' => '^(II\x2A\x00|MM\x00\x2A)',
996
- 'group' => 'graphic',
997
- 'module' => 'tiff',
998
- 'mime_type' => 'image/tiff',
999
- 'fail_id3' => 'ERROR',
1000
- 'fail_ape' => 'ERROR',
1001
- ),
1002
-
1003
-
1004
- // EFAX - still image - eFax (TIFF derivative)
1005
- 'bmp' => array(
1006
- 'pattern' => '^\xDC\xFE',
1007
- 'group' => 'graphic',
1008
- 'module' => 'efax',
1009
- 'mime_type' => 'image/efax',
1010
- 'fail_id3' => 'ERROR',
1011
- 'fail_ape' => 'ERROR',
1012
- ),
1013
-
1014
-
1015
- // Data formats
1016
-
1017
- // ISO - data - International Standards Organization (ISO) CD-ROM Image
1018
- 'iso' => array(
1019
- 'pattern' => '^.{32769}CD001',
1020
- 'group' => 'misc',
1021
- 'module' => 'iso',
1022
- 'mime_type' => 'application/octet-stream',
1023
- 'fail_id3' => 'ERROR',
1024
- 'fail_ape' => 'ERROR',
1025
- 'iconv_req' => false,
1026
- ),
1027
-
1028
- // RAR - data - RAR compressed data
1029
- 'rar' => array(
1030
- 'pattern' => '^Rar\!',
1031
- 'group' => 'archive',
1032
- 'module' => 'rar',
1033
- 'mime_type' => 'application/octet-stream',
1034
- 'fail_id3' => 'ERROR',
1035
- 'fail_ape' => 'ERROR',
1036
- ),
1037
-
1038
- // SZIP - audio/data - SZIP compressed data
1039
- 'szip' => array(
1040
- 'pattern' => '^SZ\x0A\x04',
1041
- 'group' => 'archive',
1042
- 'module' => 'szip',
1043
- 'mime_type' => 'application/octet-stream',
1044
- 'fail_id3' => 'ERROR',
1045
- 'fail_ape' => 'ERROR',
1046
- ),
1047
-
1048
- // TAR - data - TAR compressed data
1049
- 'tar' => array(
1050
- 'pattern' => '^.{100}[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20\x00]{12}[0-9\x20\x00]{12}',
1051
- 'group' => 'archive',
1052
- 'module' => 'tar',
1053
- 'mime_type' => 'application/x-tar',
1054
- 'fail_id3' => 'ERROR',
1055
- 'fail_ape' => 'ERROR',
1056
- ),
1057
-
1058
- // GZIP - data - GZIP compressed data
1059
- 'gz' => array(
1060
- 'pattern' => '^\x1F\x8B\x08',
1061
- 'group' => 'archive',
1062
- 'module' => 'gzip',
1063
- 'mime_type' => 'application/x-gzip',
1064
- 'fail_id3' => 'ERROR',
1065
- 'fail_ape' => 'ERROR',
1066
- ),
1067
-
1068
- // ZIP - data - ZIP compressed data
1069
- 'zip' => array(
1070
- 'pattern' => '^PK\x03\x04',
1071
- 'group' => 'archive',
1072
- 'module' => 'zip',
1073
- 'mime_type' => 'application/zip',
1074
- 'fail_id3' => 'ERROR',
1075
- 'fail_ape' => 'ERROR',
1076
- ),
1077
-
1078
-
1079
- // Misc other formats
1080
-
1081
- // PAR2 - data - Parity Volume Set Specification 2.0
1082
- 'par2' => array (
1083
- 'pattern' => '^PAR2\x00PKT',
1084
- 'group' => 'misc',
1085
- 'module' => 'par2',
1086
- 'mime_type' => 'application/octet-stream',
1087
- 'fail_id3' => 'ERROR',
1088
- 'fail_ape' => 'ERROR',
1089
- ),
1090
-
1091
- // PDF - data - Portable Document Format
1092
- 'pdf' => array(
1093
- 'pattern' => '^\x25PDF',
1094
- 'group' => 'misc',
1095
- 'module' => 'pdf',
1096
- 'mime_type' => 'application/pdf',
1097
- 'fail_id3' => 'ERROR',
1098
- 'fail_ape' => 'ERROR',
1099
- ),
1100
-
1101
- // MSOFFICE - data - ZIP compressed data
1102
- 'msoffice' => array(
1103
- 'pattern' => '^\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1', // D0CF11E == DOCFILE == Microsoft Office Document
1104
- 'group' => 'misc',
1105
- 'module' => 'msoffice',
1106
- 'mime_type' => 'application/octet-stream',
1107
- 'fail_id3' => 'ERROR',
1108
- 'fail_ape' => 'ERROR',
1109
- ),
1110
-
1111
- // CUE - data - CUEsheet (index to single-file disc images)
1112
- 'cue' => array(
1113
- 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents
1114
- 'group' => 'misc',
1115
- 'module' => 'cue',
1116
- 'mime_type' => 'application/octet-stream',
1117
- ),
1118
-
1119
- );
1120
- }
1121
-
1122
- return $format_info;
1123
- }
1124
-
1125
-
1126
-
1127
- function GetFileFormat(&$filedata, $filename='') {
1128
- // this function will determine the format of a file based on usually
1129
- // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
1130
- // and in the case of ISO CD image, 6 bytes offset 32kb from the start
1131
- // of the file).
1132
-
1133
- // Identify file format - loop through $format_info and detect with reg expr
1134
- foreach ($this->GetFileFormatArray() as $format_name => $info) {
1135
- // The /s switch on preg_match() forces preg_match() NOT to treat
1136
- // newline (0x0A) characters as special chars but do a binary match
1137
- if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {
1138
- $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
1139
- return $info;
1140
- }
1141
- }
1142
-
1143
-
1144
- if (preg_match('#\.mp[123a]$#i', $filename)) {
1145
- // Too many mp3 encoders on the market put gabage in front of mpeg files
1146
- // use assume format on these if format detection failed
1147
- $GetFileFormatArray = $this->GetFileFormatArray();
1148
- $info = $GetFileFormatArray['mp3'];
1149
- $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
1150
- return $info;
1151
- } elseif (preg_match('/\.cue$/i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
1152
- // there's not really a useful consistent "magic" at the beginning of .cue files to identify them
1153
- // so until I think of something better, just go by filename if all other format checks fail
1154
- // and verify there's at least one instance of "TRACK xx AUDIO" in the file
1155
- $GetFileFormatArray = $this->GetFileFormatArray();
1156
- $info = $GetFileFormatArray['cue'];
1157
- $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
1158
- return $info;
1159
- }
1160
-
1161
- return false;
1162
- }
1163
-
1164
-
1165
- // converts array to $encoding charset from $this->encoding
1166
- function CharConvert(&$array, $encoding) {
1167
-
1168
- // identical encoding - end here
1169
- if ($encoding == $this->encoding) {
1170
- return;
1171
- }
1172
-
1173
- // loop thru array
1174
- foreach ($array as $key => $value) {
1175
-
1176
- // go recursive
1177
- if (is_array($value)) {
1178
- $this->CharConvert($array[$key], $encoding);
1179
- }
1180
-
1181
- // convert string
1182
- elseif (is_string($value)) {
1183
- $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
1184
- }
1185
- }
1186
- }
1187
-
1188
-
1189
- function HandleAllTags() {
1190
-
1191
- // key name => array (tag name, character encoding)
1192
- static $tags;
1193
- if (empty($tags)) {
1194
- $tags = array(
1195
- 'asf' => array('asf' , 'UTF-16LE'),
1196
- 'midi' => array('midi' , 'ISO-8859-1'),
1197
- 'nsv' => array('nsv' , 'ISO-8859-1'),
1198
- 'ogg' => array('vorbiscomment' , 'UTF-8'),
1199
- 'png' => array('png' , 'UTF-8'),
1200
- 'tiff' => array('tiff' , 'ISO-8859-1'),
1201
- 'quicktime' => array('quicktime' , 'UTF-8'),
1202
- 'real' => array('real' , 'ISO-8859-1'),
1203
- 'vqf' => array('vqf' , 'ISO-8859-1'),
1204
- 'zip' => array('zip' , 'ISO-8859-1'),
1205
- 'riff' => array('riff' , 'ISO-8859-1'),
1206
- 'lyrics3' => array('lyrics3' , 'ISO-8859-1'),
1207
- 'id3v1' => array('id3v1' , $this->encoding_id3v1),
1208
- 'id3v2' => array('id3v2' , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8
1209
- 'ape' => array('ape' , 'UTF-8'),
1210
- 'cue' => array('cue' , 'ISO-8859-1'),
1211
- 'matroska' => array('matroska' , 'UTF-8'),
1212
- );
1213
- }
1214
-
1215
- // loop through comments array
1216
- foreach ($tags as $comment_name => $tagname_encoding_array) {
1217
- list($tag_name, $encoding) = $tagname_encoding_array;
1218
-
1219
- // fill in default encoding type if not already present
1220
- if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
1221
- $this->info[$comment_name]['encoding'] = $encoding;
1222
- }
1223
-
1224
- // copy comments if key name set
1225
- if (!empty($this->info[$comment_name]['comments'])) {
1226
-
1227
- foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
1228
- foreach ($valuearray as $key => $value) {
1229
- if (is_string($value)) {
1230
- $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed!
1231
- }
1232
- if ($value) {
1233
- $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
1234
- }
1235
- }
1236
- }
1237
-
1238
- if (!isset($this->info['tags'][$tag_name])) {
1239
- // comments are set but contain nothing but empty strings, so skip
1240
- continue;
1241
- }
1242
-
1243
- if ($this->option_tags_html) {
1244
- foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
1245
- foreach ($valuearray as $key => $value) {
1246
- if (is_string($value)) {
1247
- //$this->info['tags_html'][$tag_name][$tag_key][$key] = getid3_lib::MultiByteCharString2HTML($value, $encoding);
1248
- $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('&#0;', '', trim(getid3_lib::MultiByteCharString2HTML($value, $encoding)));
1249
- } else {
1250
- $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
1251
- }
1252
- }
1253
- }
1254
- }
1255
-
1256
- $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted!
1257
- }
1258
-
1259
- }
1260
-
1261
- // pictures can take up a lot of space, and we don't need multiple copies of them
1262
- // let there be a single copy in [comments][picture], and not elsewhere
1263
- if (!empty($this->info['tags'])) {
1264
- $unset_keys = array('tags', 'tags_html');
1265
- foreach ($this->info['tags'] as $tagtype => $tagarray) {
1266
- foreach ($tagarray as $tagname => $tagdata) {
1267
- if ($tagname == 'picture') {
1268
- foreach ($tagdata as $key => $tagarray) {
1269
- $this->info['comments']['picture'][] = $tagarray;
1270
- if (isset($tagarray['data']) && isset($tagarray['image_mime'])) {
1271
- if (isset($this->info['tags'][$tagtype][$tagname][$key])) {
1272
- unset($this->info['tags'][$tagtype][$tagname][$key]);
1273
- }
1274
- if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) {
1275
- unset($this->info['tags_html'][$tagtype][$tagname][$key]);
1276
- }
1277
- }
1278
- }
1279
- }
1280
- }
1281
- foreach ($unset_keys as $unset_key) {
1282
- // remove possible empty keys from (e.g. [tags][id3v2][picture])
1283
- if (empty($this->info[$unset_key][$tagtype]['picture'])) {
1284
- unset($this->info[$unset_key][$tagtype]['picture']);
1285
- }
1286
- if (empty($this->info[$unset_key][$tagtype])) {
1287
- unset($this->info[$unset_key][$tagtype]);
1288
- }
1289
- if (empty($this->info[$unset_key])) {
1290
- unset($this->info[$unset_key]);
1291
- }
1292
- }
1293
- // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture])
1294
- if (isset($this->info[$tagtype]['comments']['picture'])) {
1295
- unset($this->info[$tagtype]['comments']['picture']);
1296
- }
1297
- if (empty($this->info[$tagtype]['comments'])) {
1298
- unset($this->info[$tagtype]['comments']);
1299
- }
1300
- if (empty($this->info[$tagtype])) {
1301
- unset($this->info[$tagtype]);
1302
- }
1303
- }
1304
- }
1305
- return true;
1306
- }
1307
-
1308
-
1309
- function getHashdata($algorithm) {
1310
- switch ($algorithm) {
1311
- case 'md5':
1312
- case 'sha1':
1313
- break;
1314
-
1315
- default:
1316
- return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
1317
- break;
1318
- }
1319
-
1320
- if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) {
1321
-
1322
- // We cannot get an identical md5_data value for Ogg files where the comments
1323
- // span more than 1 Ogg page (compared to the same audio data with smaller
1324
- // comments) using the normal getID3() method of MD5'ing the data between the
1325
- // end of the comments and the end of the file (minus any trailing tags),
1326
- // because the page sequence numbers of the pages that the audio data is on
1327
- // do not match. Under normal circumstances, where comments are smaller than
1328
- // the nominal 4-8kB page size, then this is not a problem, but if there are
1329
- // very large comments, the only way around it is to strip off the comment
1330
- // tags with vorbiscomment and MD5 that file.
1331
- // This procedure must be applied to ALL Ogg files, not just the ones with
1332
- // comments larger than 1 page, because the below method simply MD5's the
1333
- // whole file with the comments stripped, not just the portion after the
1334
- // comments block (which is the standard getID3() method.
1335
-
1336
- // The above-mentioned problem of comments spanning multiple pages and changing
1337
- // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
1338
- // currently vorbiscomment only works on OggVorbis files.
1339
-
1340
- if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
1341
-
1342
- $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');
1343
- $this->info[$algorithm.'_data'] = false;
1344
-
1345
- } else {
1346
-
1347
- // Prevent user from aborting script
1348
- $old_abort = ignore_user_abort(true);
1349
-
1350
- // Create empty file
1351
- $empty = tempnam(GETID3_TEMP_DIR, 'getID3');
1352
- touch($empty);
1353
-
1354
- // Use vorbiscomment to make temp file without comments
1355
- $temp = tempnam(GETID3_TEMP_DIR, 'getID3');
1356
- $file = $this->info['filenamepath'];
1357
-
1358
- if (GETID3_OS_ISWINDOWS) {
1359
-
1360
- if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
1361
-
1362
- $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
1363
- $VorbisCommentError = `$commandline`;
1364
-
1365
- } else {
1366
-
1367
- $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
1368
-
1369
- }
1370
-
1371
- } else {
1372
-
1373
- $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
1374
- $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
1375
- $VorbisCommentError = `$commandline`;
1376
-
1377
- }
1378
-
1379
- if (!empty($VorbisCommentError)) {
1380
-
1381
- $this->info['warning'][] = 'Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError;
1382
- $this->info[$algorithm.'_data'] = false;
1383
-
1384
- } else {
1385
-
1386
- // Get hash of newly created file
1387
- switch ($algorithm) {
1388
- case 'md5':
1389
- $this->info[$algorithm.'_data'] = md5_file($temp);
1390
- break;
1391
-
1392
- case 'sha1':
1393
- $this->info[$algorithm.'_data'] = sha1_file($temp);
1394
- break;
1395
- }
1396
- }
1397
-
1398
- // Clean up
1399
- unlink($empty);
1400
- unlink($temp);
1401
-
1402
- // Reset abort setting
1403
- ignore_user_abort($old_abort);
1404
-
1405
- }
1406
-
1407
- } else {
1408
-
1409
- if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
1410
-
1411
- // get hash from part of file
1412
- $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
1413
-
1414
- } else {
1415
-
1416
- // get hash from whole file
1417
- switch ($algorithm) {
1418
- case 'md5':
1419
- $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']);
1420
- break;
1421
-
1422
- case 'sha1':
1423
- $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']);
1424
- break;
1425
- }
1426
- }
1427
-
1428
- }
1429
- return true;
1430
- }
1431
-
1432
-
1433
- function ChannelsBitratePlaytimeCalculations() {
1434
-
1435
- // set channelmode on audio
1436
- if (!empty($this->info['audio']['channelmode']) || !isset($this->info['audio']['channels'])) {
1437
- // ignore
1438
- } elseif ($this->info['audio']['channels'] == 1) {
1439
- $this->info['audio']['channelmode'] = 'mono';
1440
- } elseif ($this->info['audio']['channels'] == 2) {
1441
- $this->info['audio']['channelmode'] = 'stereo';
1442
- }
1443
-
1444
- // Calculate combined bitrate - audio + video
1445
- $CombinedBitrate = 0;
1446
- $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
1447
- $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
1448
- if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
1449
- $this->info['bitrate'] = $CombinedBitrate;
1450
- }
1451
- //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) {
1452
- // // for example, VBR MPEG video files cannot determine video bitrate:
1453
- // // should not set overall bitrate and playtime from audio bitrate only
1454
- // unset($this->info['bitrate']);
1455
- //}
1456
-
1457
- // video bitrate undetermined, but calculable
1458
- if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) {
1459
- // if video bitrate not set
1460
- if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) {
1461
- // AND if audio bitrate is set to same as overall bitrate
1462
- if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) {
1463
- // AND if playtime is set
1464
- if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) {
1465
- // AND if AV data offset start/end is known
1466
- // THEN we can calculate the video bitrate
1467
- $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']);
1468
- $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate'];
1469
- }
1470
- }
1471
- }
1472
- }
1473
-
1474
- if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) {
1475
- $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate'];
1476
- }
1477
-
1478
- if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) {
1479
- $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds'];
1480
- }
1481
- if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) {
1482
- if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) {
1483
- // audio only
1484
- $this->info['audio']['bitrate'] = $this->info['bitrate'];
1485
- } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) {
1486
- // video only
1487
- $this->info['video']['bitrate'] = $this->info['bitrate'];
1488
- }
1489
- }
1490
-
1491
- // Set playtime string
1492
- if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) {
1493
- $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']);
1494
- }
1495
- }
1496
-
1497
-
1498
- function CalculateCompressionRatioVideo() {
1499
- if (empty($this->info['video'])) {
1500
- return false;
1501
- }
1502
- if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) {
1503
- return false;
1504
- }
1505
- if (empty($this->info['video']['bits_per_sample'])) {
1506
- return false;
1507
- }
1508
-
1509
- switch ($this->info['video']['dataformat']) {
1510
- case 'bmp':
1511
- case 'gif':
1512
- case 'jpeg':
1513
- case 'jpg':
1514
- case 'png':
1515
- case 'tiff':
1516
- $FrameRate = 1;
1517
- $PlaytimeSeconds = 1;
1518
- $BitrateCompressed = $this->info['filesize'] * 8;
1519
- break;
1520
-
1521
- default:
1522
- if (!empty($this->info['video']['frame_rate'])) {
1523
- $FrameRate = $this->info['video']['frame_rate'];
1524
- } else {
1525
- return false;
1526
- }
1527
- if (!empty($this->info['playtime_seconds'])) {
1528
- $PlaytimeSeconds = $this->info['playtime_seconds'];
1529
- } else {
1530
- return false;
1531
- }
1532
- if (!empty($this->info['video']['bitrate'])) {
1533
- $BitrateCompressed = $this->info['video']['bitrate'];
1534
- } else {
1535
- return false;
1536
- }
1537
- break;
1538
- }
1539
- $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;
1540
-
1541
- $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
1542
- return true;
1543
- }
1544
-
1545
-
1546
- function CalculateCompressionRatioAudio() {
1547
- if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate'])) {
1548
- return false;
1549
- }
1550
- $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
1551
-
1552
- if (!empty($this->info['audio']['streams'])) {
1553
- foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
1554
- if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
1555
- $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
1556
- }
1557
- }
1558
- }
1559
- return true;
1560
- }
1561
-
1562
-
1563
- function CalculateReplayGain() {
1564
- if (isset($this->info['replay_gain'])) {
1565
- if (!isset($this->info['replay_gain']['reference_volume'])) {
1566
- $this->info['replay_gain']['reference_volume'] = (double) 89.0;
1567
- }
1568
- if (isset($this->info['replay_gain']['track']['adjustment'])) {
1569
- $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
1570
- }
1571
- if (isset($this->info['replay_gain']['album']['adjustment'])) {
1572
- $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
1573
- }
1574
-
1575
- if (isset($this->info['replay_gain']['track']['peak'])) {
1576
- $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
1577
- }
1578
- if (isset($this->info['replay_gain']['album']['peak'])) {
1579
- $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
1580
- }
1581
- }
1582
- return true;
1583
- }
1584
-
1585
- function ProcessAudioStreams() {
1586
- if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
1587
- if (!isset($this->info['audio']['streams'])) {
1588
- foreach ($this->info['audio'] as $key => $value) {
1589
- if ($key != 'streams') {
1590
- $this->info['audio']['streams'][0][$key] = $value;
1591
- }
1592
- }
1593
- }
1594
- }
1595
- return true;
1596
- }
1597
-
1598
- function getid3_tempnam() {
1599
- return tempnam($this->tempdir, 'gI3');
1600
- }
1601
-
1602
-
1603
- public function saveAttachment(&$ThisFileInfoIndex, $filename, $offset, $length) {
1604
- try {
1605
- if (!getid3_lib::intValueSupported($offset + $length)) {
1606
- throw new Exception('cannot extract attachment, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
1607
- }
1608
-
1609
- // do not extract at all
1610
- if ($this->option_save_attachments === getID3::ATTACHMENTS_NONE) {
1611
-
1612
- unset($ThisFileInfoIndex); // do not set any
1613
-
1614
- // extract to return array
1615
- } elseif ($this->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
1616
-
1617
- // get whole data in one pass, till it is anyway stored in memory
1618
- $ThisFileInfoIndex = file_get_contents($this->info['filenamepath'], false, null, $offset, $length);
1619
- if (($ThisFileInfoIndex === false) || (strlen($ThisFileInfoIndex) != $length)) { // verify
1620
- throw new Exception('failed to read attachment data');
1621
- }
1622
-
1623
- // assume directory path is given
1624
- } else {
1625
-
1626
- $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->option_save_attachments), DIRECTORY_SEPARATOR);
1627
- // check supplied directory
1628
- if (!is_dir($dir) || !is_writable($dir)) {
1629
- throw new Exception('getID3::saveAttachment() -- supplied path ('.$dir.') does not exist, or is not writable');
1630
- }
1631
-
1632
- // set up destination path
1633
- $dest = $dir.DIRECTORY_SEPARATOR.$filename;
1634
-
1635
- // optimize speed if read buffer size is configured to be large enough
1636
- // here stream_copy_to_stream() may also be used. need to do speed-compare tests
1637
- if ($length <= $this->fread_buffer_size()) {
1638
- $data = file_get_contents($this->info['filenamepath'], false, null, $offset, $length);
1639
- if (($data === false) || (strlen($data) != $length)) { // verify
1640
- throw new Exception('failed to read attachment data');
1641
- }
1642
- if (!file_put_contents($dest, $data)) {
1643
- throw new Exception('failed to create file '.$dest);
1644
- }
1645
- } else {
1646
- // optimization not available - copy data in loop
1647
- // here stream_copy_to_stream() shouldn't be used because it's internal read buffer may be larger than ours!
1648
- getid3_lib::CopyFileParts($this->info['filenamepath'], $dest, $offset, $length);
1649
- }
1650
- $ThisFileInfoIndex = $dest;
1651
- }
1652
-
1653
- } catch (Exception $e) {
1654
-
1655
- unset($ThisFileInfoIndex); // do not set any is case of error
1656
- $this->warning('Failed to extract attachment '.$filename.': '.$e->getMessage());
1657
- return false;
1658
-
1659
- }
1660
- return true;
1661
- }
1662
-
1663
-
1664
- public function include_module($name) {
1665
- //if (!file_exists($this->include_path.'module.'.$name.'.php')) {
1666
- if (!file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) {
1667
- throw new getid3_exception('Required module.'.$name.'.php is missing.');
1668
- }
1669
- include_once(GETID3_INCLUDEPATH.'module.'.$name.'.php');
1670
- return true;
1671
- }
1672
-
1673
- }
1674
-
1675
-
1676
- abstract class getid3_handler
1677
- {
1678
- protected $getid3; // pointer
1679
-
1680
- protected $data_string_flag = false; // analyzing filepointer or string
1681
- protected $data_string; // string to analyze
1682
- protected $data_string_position = 0; // seek position in string
1683
-
1684
-
1685
- public function __construct(getID3 $getid3) {
1686
- $this->getid3 = $getid3;
1687
- }
1688
-
1689
-
1690
- // Analyze from file pointer
1691
- abstract public function Analyze();
1692
-
1693
-
1694
- // Analyze from string instead
1695
- public function AnalyzeString(&$string) {
1696
- // Enter string mode
1697
- $this->data_string_flag = true;
1698
- $this->data_string = $string;
1699
-
1700
- // Save info
1701
- $saved_avdataoffset = $this->getid3->info['avdataoffset'];
1702
- $saved_avdataend = $this->getid3->info['avdataend'];
1703
- $saved_filesize = $this->getid3->info['filesize'];
1704
-
1705
- // Reset some info
1706
- $this->getid3->info['avdataoffset'] = 0;
1707
- $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = strlen($string);
1708
-
1709
- // Analyze
1710
- $this->Analyze();
1711
-
1712
- // Restore some info
1713
- $this->getid3->info['avdataoffset'] = $saved_avdataoffset;
1714
- $this->getid3->info['avdataend'] = $saved_avdataend;
1715
- $this->getid3->info['filesize'] = $saved_filesize;
1716
-
1717
- // Exit string mode
1718
- $this->data_string_flag = false;
1719
- }
1720
-
1721
-
1722
- protected function ftell() {
1723
- if ($this->data_string_flag) {
1724
- return $this->data_string_position;
1725
- }
1726
- return ftell($this->getid3->fp);
1727
- }
1728
-
1729
-
1730
- protected function fread($bytes) {
1731
- if ($this->data_string_flag) {
1732
- $this->data_string_position += $bytes;
1733
- return substr($this->data_string, $this->data_string_position - $bytes, $bytes);
1734
- }
1735
- return fread($this->getid3->fp, $bytes);
1736
- }
1737
-
1738
-
1739
- protected function fseek($bytes, $whence = SEEK_SET) {
1740
- if ($this->data_string_flag) {
1741
- switch ($whence) {
1742
- case SEEK_SET:
1743
- $this->data_string_position = $bytes;
1744
- return;
1745
-
1746
- case SEEK_CUR:
1747
- $this->data_string_position += $bytes;
1748
- return;
1749
-
1750
- case SEEK_END:
1751
- $this->data_string_position = strlen($this->data_string) + $bytes;
1752
- return;
1753
- }
1754
- }
1755
- return fseek($this->getid3->fp, $bytes, $whence);
1756
- }
1757
-
1758
- }
1759
-
1760
-
1761
- class getid3_exception extends Exception
1762
- {
1763
- public $message;
1764
- }
1765
-
1766
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // //
9
+ // Please see readme.txt for more information //
10
+ // ///
11
+ /////////////////////////////////////////////////////////////////
12
+
13
+ // define a constant rather than looking up every time it is needed
14
+ if (!defined('GETID3_OS_ISWINDOWS')) {
15
+ define('GETID3_OS_ISWINDOWS', (stripos(PHP_OS, 'WIN') === 0));
16
+ }
17
+ // Get base path of getID3() - ONCE
18
+ if (!defined('GETID3_INCLUDEPATH')) {
19
+ define('GETID3_INCLUDEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
20
+ }
21
+ // Workaround Bug #39923 (https://bugs.php.net/bug.php?id=39923)
22
+ if (!defined('IMG_JPG') && defined('IMAGETYPE_JPEG')) {
23
+ define('IMG_JPG', IMAGETYPE_JPEG);
24
+ }
25
+
26
+ // attempt to define temp dir as something flexible but reliable
27
+ $temp_dir = ini_get('upload_tmp_dir');
28
+ if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) {
29
+ $temp_dir = '';
30
+ }
31
+ if (!$temp_dir) {
32
+ // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts
33
+ $temp_dir = sys_get_temp_dir();
34
+ }
35
+ $temp_dir = @realpath($temp_dir); // see https://github.com/JamesHeinrich/getID3/pull/10
36
+ $open_basedir = ini_get('open_basedir');
37
+ if ($open_basedir) {
38
+ // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/"
39
+ $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir);
40
+ $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir);
41
+ if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) {
42
+ $temp_dir .= DIRECTORY_SEPARATOR;
43
+ }
44
+ $found_valid_tempdir = false;
45
+ $open_basedirs = explode(PATH_SEPARATOR, $open_basedir);
46
+ foreach ($open_basedirs as $basedir) {
47
+ if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) {
48
+ $basedir .= DIRECTORY_SEPARATOR;
49
+ }
50
+ if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) {
51
+ $found_valid_tempdir = true;
52
+ break;
53
+ }
54
+ }
55
+ if (!$found_valid_tempdir) {
56
+ $temp_dir = '';
57
+ }
58
+ unset($open_basedirs, $found_valid_tempdir, $basedir);
59
+ }
60
+ if (!$temp_dir) {
61
+ $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir
62
+ }
63
+ // $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system
64
+ if (!defined('GETID3_TEMP_DIR')) {
65
+ define('GETID3_TEMP_DIR', $temp_dir);
66
+ }
67
+ unset($open_basedir, $temp_dir);
68
+
69
+ // End: Defines
70
+
71
+
72
+ class getID3
73
+ {
74
+ // public: Settings
75
+ public $encoding = 'UTF-8'; // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
76
+ public $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
77
+
78
+ // public: Optional tag checks - disable for speed.
79
+ public $option_tag_id3v1 = true; // Read and process ID3v1 tags
80
+ public $option_tag_id3v2 = true; // Read and process ID3v2 tags
81
+ public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags
82
+ public $option_tag_apetag = true; // Read and process APE tags
83
+ public $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding
84
+ public $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
85
+
86
+ // public: Optional tag/comment calucations
87
+ public $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc
88
+
89
+ // public: Optional handling of embedded attachments (e.g. images)
90
+ public $option_save_attachments = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility
91
+
92
+ // public: Optional calculations
93
+ public $option_md5_data = false; // Get MD5 sum of data part - slow
94
+ public $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG
95
+ public $option_sha1_data = false; // Get SHA1 sum of data part - slow
96
+ public $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX)
97
+
98
+ // public: Read buffer size in bytes
99
+ public $option_fread_buffer_size = 32768;
100
+
101
+ // Public variables
102
+ public $filename; // Filename of file being analysed.
103
+ public $fp; // Filepointer to file being analysed.
104
+ public $info; // Result array.
105
+ public $tempdir = GETID3_TEMP_DIR;
106
+ public $memory_limit = 0;
107
+
108
+ // Protected variables
109
+ protected $startup_error = '';
110
+ protected $startup_warning = '';
111
+
112
+ const VERSION = '1.9.8-20140511';
113
+ const FREAD_BUFFER_SIZE = 32768;
114
+
115
+ const ATTACHMENTS_NONE = false;
116
+ const ATTACHMENTS_INLINE = true;
117
+
118
+ // public: constructor
119
+ public function __construct() {
120
+
121
+ // Check for PHP version
122
+ $required_php_version = '5.3.0';
123
+ if (version_compare(PHP_VERSION, $required_php_version, '<')) {
124
+ $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION;
125
+ return false;
126
+ }
127
+
128
+ // Check memory
129
+ $this->memory_limit = ini_get('memory_limit');
130
+ if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) {
131
+ // could be stored as "16M" rather than 16777216 for example
132
+ $this->memory_limit = $matches[1] * 1048576;
133
+ } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
134
+ // could be stored as "2G" rather than 2147483648 for example
135
+ $this->memory_limit = $matches[1] * 1073741824;
136
+ }
137
+ if ($this->memory_limit <= 0) {
138
+ // memory limits probably disabled
139
+ } elseif ($this->memory_limit <= 4194304) {
140
+ $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini';
141
+ } elseif ($this->memory_limit <= 12582912) {
142
+ $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini';
143
+ }
144
+
145
+ // Check safe_mode off
146
+ if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
147
+ $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
148
+ }
149
+
150
+ if (intval(ini_get('mbstring.func_overload')) > 0) {
151
+ $this->warning('WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", this may break things.');
152
+ }
153
+
154
+ // Check for magic_quotes_runtime
155
+ if (function_exists('get_magic_quotes_runtime')) {
156
+ if (get_magic_quotes_runtime()) {
157
+ return $this->startup_error('magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).');
158
+ }
159
+ }
160
+
161
+ // Check for magic_quotes_gpc
162
+ if (function_exists('magic_quotes_gpc')) {
163
+ if (get_magic_quotes_gpc()) {
164
+ return $this->startup_error('magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).');
165
+ }
166
+ }
167
+
168
+ // Load support library
169
+ if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
170
+ $this->startup_error .= 'getid3.lib.php is missing or corrupt';
171
+ }
172
+
173
+ if ($this->option_max_2gb_check === null) {
174
+ $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647);
175
+ }
176
+
177
+
178
+ // Needed for Windows only:
179
+ // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
180
+ // as well as other helper functions such as head, tail, md5sum, etc
181
+ // This path cannot contain spaces, but the below code will attempt to get the
182
+ // 8.3-equivalent path automatically
183
+ // IMPORTANT: This path must include the trailing slash
184
+ if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
185
+
186
+ $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path
187
+
188
+ if (!is_dir($helperappsdir)) {
189
+ $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
190
+ } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
191
+ $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
192
+ $path_so_far = array();
193
+ foreach ($DirPieces as $key => $value) {
194
+ if (strpos($value, ' ') !== false) {
195
+ if (!empty($path_so_far)) {
196
+ $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
197
+ $dir_listing = `$commandline`;
198
+ $lines = explode("\n", $dir_listing);
199
+ foreach ($lines as $line) {
200
+ $line = trim($line);
201
+ if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(<DIR>|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) {
202
+ list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches;
203
+ if ((strtoupper($filesize) == '<DIR>') && (strtolower($filename) == strtolower($value))) {
204
+ $value = $shortname;
205
+ }
206
+ }
207
+ }
208
+ } else {
209
+ $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.';
210
+ }
211
+ }
212
+ $path_so_far[] = $value;
213
+ }
214
+ $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far);
215
+ }
216
+ define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
217
+ }
218
+
219
+ return true;
220
+ }
221
+
222
+ public function version() {
223
+ return self::VERSION;
224
+ }
225
+
226
+ public function fread_buffer_size() {
227
+ return $this->option_fread_buffer_size;
228
+ }
229
+
230
+
231
+ // public: setOption
232
+ public function setOption($optArray) {
233
+ if (!is_array($optArray) || empty($optArray)) {
234
+ return false;
235
+ }
236
+ foreach ($optArray as $opt => $val) {
237
+ if (isset($this->$opt) === false) {
238
+ continue;
239
+ }
240
+ $this->$opt = $val;
241
+ }
242
+ return true;
243
+ }
244
+
245
+
246
+ public function openfile($filename, $filesize = false) { // , $filesize=false added by POWERPRESS
247
+ try {
248
+ if (!empty($this->startup_error)) {
249
+ throw new getid3_exception($this->startup_error);
250
+ }
251
+ if (!empty($this->startup_warning)) {
252
+ $this->warning($this->startup_warning);
253
+ }
254
+
255
+ // init result array and set parameters
256
+ $this->filename = $filename;
257
+ $this->info = array();
258
+ $this->info['GETID3_VERSION'] = $this->version();
259
+ $this->info['php_memory_limit'] = $this->memory_limit;
260
+
261
+ // remote files not supported
262
+ if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
263
+ throw new getid3_exception('Remote files are not supported - please copy the file locally first');
264
+ }
265
+
266
+ $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
267
+ $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename);
268
+
269
+ // open local file
270
+ //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see http://www.getid3.org/phpBB3/viewtopic.php?t=1720
271
+ if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
272
+ // great
273
+ } else {
274
+ $errormessagelist = array();
275
+ if (!is_readable($filename)) {
276
+ $errormessagelist[] = '!is_readable';
277
+ }
278
+ if (!is_file($filename)) {
279
+ $errormessagelist[] = '!is_file';
280
+ }
281
+ if (!file_exists($filename)) {
282
+ $errormessagelist[] = '!file_exists';
283
+ }
284
+ if (empty($errormessagelist)) {
285
+ $errormessagelist[] = 'fopen failed';
286
+ }
287
+ throw new getid3_exception('Could not open "'.$filename.'" ('.implode('; ', $errormessagelist).')');
288
+ }
289
+
290
+ // START ADDED BY POWERPRESS
291
+ if( $filesize )
292
+ $this->info['filesize'] = $filesize;
293
+ else // END ADDED BY POWERPRESS
294
+ $this->info['filesize'] = filesize($filename);
295
+ // set redundant parameters - might be needed in some include file
296
+ // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion
297
+ $filename = str_replace('\\', '/', $filename);
298
+ $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
299
+ $this->info['filename'] = getid3_lib::mb_basename($filename);
300
+ $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
301
+
302
+
303
+ // option_max_2gb_check
304
+ if ($this->option_max_2gb_check) {
305
+ // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
306
+ // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
307
+ // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
308
+ $fseek = fseek($this->fp, 0, SEEK_END);
309
+ if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) ||
310
+ ($this->info['filesize'] < 0) ||
311
+ (ftell($this->fp) < 0)) {
312
+ $real_filesize = getid3_lib::getFileSizeSyscall($this->info['filenamepath']);
313
+
314
+ if ($real_filesize === false) {
315
+ unset($this->info['filesize']);
316
+ fclose($this->fp);
317
+ throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.');
318
+ } elseif (getid3_lib::intValueSupported($real_filesize)) {
319
+ unset($this->info['filesize']);
320
+ fclose($this->fp);
321
+ throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org');
322
+ }
323
+ $this->info['filesize'] = $real_filesize;
324
+ $this->warning('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.');
325
+ }
326
+ }
327
+
328
+ // set more parameters
329
+ $this->info['avdataoffset'] = 0;
330
+ $this->info['avdataend'] = $this->info['filesize'];
331
+ $this->info['fileformat'] = ''; // filled in later
332
+ $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used
333
+ $this->info['video']['dataformat'] = ''; // filled in later, unset if not used
334
+ $this->info['tags'] = array(); // filled in later, unset if not used
335
+ $this->info['error'] = array(); // filled in later, unset if not used
336
+ $this->info['warning'] = array(); // filled in later, unset if not used
337
+ $this->info['comments'] = array(); // filled in later, unset if not used
338
+ $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired
339
+
340
+ return true;
341
+
342
+ } catch (Exception $e) {
343
+ $this->error($e->getMessage());
344
+ }
345
+ return false;
346
+ }
347
+
348
+ // public: analyze file
349
+ public function analyze($filename, $filesize=false, $orig_filename='file.mp3') { // 2nd AND 3rd PARAMTERS ADDED BY POWERPRESS
350
+ try {
351
+ if (!$this->openfile($filename, $filesize)) { // 2nd PARAMTER ADDED BY POWERPRESS
352
+ return $this->info;
353
+ }
354
+
355
+ // Handle tags
356
+ foreach (array('id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
357
+ $option_tag = 'option_tag_'.$tag_name;
358
+ if ($this->$option_tag) {
359
+ $this->include_module('tag.'.$tag_name);
360
+ try {
361
+ $tag_class = 'getid3_'.$tag_name;
362
+ $tag = new $tag_class($this);
363
+ $tag->Analyze();
364
+ }
365
+ catch (getid3_exception $e) {
366
+ throw $e;
367
+ }
368
+ }
369
+ }
370
+ if (isset($this->info['id3v2']['tag_offset_start'])) {
371
+ $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']);
372
+ }
373
+ foreach (array('id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
374
+ if (isset($this->info[$tag_key]['tag_offset_start'])) {
375
+ $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']);
376
+ }
377
+ }
378
+
379
+ // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier
380
+ if (!$this->option_tag_id3v2) {
381
+ fseek($this->fp, 0);
382
+ $header = fread($this->fp, 10);
383
+ if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) {
384
+ $this->info['id3v2']['header'] = true;
385
+ $this->info['id3v2']['majorversion'] = ord($header{3});
386
+ $this->info['id3v2']['minorversion'] = ord($header{4});
387
+ $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
388
+ }
389
+ }
390
+
391
+ // read 32 kb file data
392
+ fseek($this->fp, $this->info['avdataoffset']);
393
+ $formattest = fread($this->fp, 32774);
394
+
395
+ // determine format
396
+ // MODIFIED BY POWERPRESS
397
+ $determined_format = $this->GetFileFormat($formattest, $orig_filename);
398
+ // MODIFIED BY POWERPRESS
399
+
400
+ // unable to determine file format
401
+ if (!$determined_format) {
402
+ fclose($this->fp);
403
+ return $this->error('unable to determine file format');
404
+ }
405
+
406
+ // check for illegal ID3 tags
407
+ if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
408
+ if ($determined_format['fail_id3'] === 'ERROR') {
409
+ fclose($this->fp);
410
+ return $this->error('ID3 tags not allowed on this file type.');
411
+ } elseif ($determined_format['fail_id3'] === 'WARNING') {
412
+ $this->warning('ID3 tags not allowed on this file type.');
413
+ }
414
+ }
415
+
416
+ // check for illegal APE tags
417
+ if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
418
+ if ($determined_format['fail_ape'] === 'ERROR') {
419
+ fclose($this->fp);
420
+ return $this->error('APE tags not allowed on this file type.');
421
+ } elseif ($determined_format['fail_ape'] === 'WARNING') {
422
+ $this->warning('APE tags not allowed on this file type.');
423
+ }
424
+ }
425
+
426
+ // set mime type
427
+ $this->info['mime_type'] = $determined_format['mime_type'];
428
+
429
+ // supported format signature pattern detected, but module deleted
430
+ if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
431
+ fclose($this->fp);
432
+ return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.');
433
+ }
434
+
435
+ // module requires iconv support
436
+ // Check encoding/iconv support
437
+ if (!empty($determined_format['iconv_req']) && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
438
+ $errormessage = 'iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
439
+ if (GETID3_OS_ISWINDOWS) {
440
+ $errormessage .= 'PHP does not have iconv() support. Please enable php_iconv.dll in php.ini, and copy iconv.dll from c:/php/dlls to c:/windows/system32';
441
+ } else {
442
+ $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
443
+ }
444
+ return $this->error($errormessage);
445
+ }
446
+
447
+ // include module
448
+ include_once(GETID3_INCLUDEPATH.$determined_format['include']);
449
+
450
+ // instantiate module class
451
+ $class_name = 'getid3_'.$determined_format['module'];
452
+ if (!class_exists($class_name)) {
453
+ return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.');
454
+ }
455
+ $class = new $class_name($this);
456
+ $class->Analyze();
457
+ unset($class);
458
+
459
+ // close file
460
+ fclose($this->fp);
461
+
462
+ // process all tags - copy to 'tags' and convert charsets
463
+ if ($this->option_tags_process) {
464
+ $this->HandleAllTags();
465
+ }
466
+
467
+ // perform more calculations
468
+ if ($this->option_extra_info) {
469
+ $this->ChannelsBitratePlaytimeCalculations();
470
+ $this->CalculateCompressionRatioVideo();
471
+ $this->CalculateCompressionRatioAudio();
472
+ $this->CalculateReplayGain();
473
+ $this->ProcessAudioStreams();
474
+ }
475
+
476
+ // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
477
+ if ($this->option_md5_data) {
478
+ // do not calc md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too
479
+ if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
480
+ $this->getHashdata('md5');
481
+ }
482
+ }
483
+
484
+ // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
485
+ if ($this->option_sha1_data) {
486
+ $this->getHashdata('sha1');
487
+ }
488
+
489
+ // remove undesired keys
490
+ $this->CleanUp();
491
+
492
+ } catch (Exception $e) {
493
+ $this->error('Caught exception: '.$e->getMessage());
494
+ }
495
+
496
+ // return info array
497
+ return $this->info;
498
+ }
499
+
500
+
501
+ // private: error handling
502
+ public function error($message) {
503
+ $this->CleanUp();
504
+ if (!isset($this->info['error'])) {
505
+ $this->info['error'] = array();
506
+ }
507
+ $this->info['error'][] = $message;
508
+ return $this->info;
509
+ }
510
+
511
+
512
+ // private: warning handling
513
+ public function warning($message) {
514
+ $this->info['warning'][] = $message;
515
+ return true;
516
+ }
517
+
518
+
519
+ // private: CleanUp
520
+ private function CleanUp() {
521
+
522
+ // remove possible empty keys
523
+ $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate');
524
+ foreach ($AVpossibleEmptyKeys as $dummy => $key) {
525
+ if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
526
+ unset($this->info['audio'][$key]);
527
+ }
528
+ if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
529
+ unset($this->info['video'][$key]);
530
+ }
531
+ }
532
+
533
+ // remove empty root keys
534
+ if (!empty($this->info)) {
535
+ foreach ($this->info as $key => $value) {
536
+ if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
537
+ unset($this->info[$key]);
538
+ }
539
+ }
540
+ }
541
+
542
+ // remove meaningless entries from unknown-format files
543
+ if (empty($this->info['fileformat'])) {
544
+ if (isset($this->info['avdataoffset'])) {
545
+ unset($this->info['avdataoffset']);
546
+ }
547
+ if (isset($this->info['avdataend'])) {
548
+ unset($this->info['avdataend']);
549
+ }
550
+ }
551
+
552
+ // remove possible duplicated identical entries
553
+ if (!empty($this->info['error'])) {
554
+ $this->info['error'] = array_values(array_unique($this->info['error']));
555
+ }
556
+ if (!empty($this->info['warning'])) {
557
+ $this->info['warning'] = array_values(array_unique($this->info['warning']));
558
+ }
559
+
560
+ // remove "global variable" type keys
561
+ unset($this->info['php_memory_limit']);
562
+
563
+ return true;
564
+ }
565
+
566
+
567
+ // return array containing information about all supported formats
568
+ public function GetFileFormatArray() {
569
+ static $format_info = array();
570
+ if (empty($format_info)) {
571
+ $format_info = array(
572
+
573
+ // Audio formats
574
+
575
+ // AC-3 - audio - Dolby AC-3 / Dolby Digital
576
+ 'ac3' => array(
577
+ 'pattern' => '^\x0B\x77',
578
+ 'group' => 'audio',
579
+ 'module' => 'ac3',
580
+ 'mime_type' => 'audio/ac3',
581
+ ),
582
+
583
+ // AAC - audio - Advanced Audio Coding (AAC) - ADIF format
584
+ 'adif' => array(
585
+ 'pattern' => '^ADIF',
586
+ 'group' => 'audio',
587
+ 'module' => 'aac',
588
+ 'mime_type' => 'application/octet-stream',
589
+ 'fail_ape' => 'WARNING',
590
+ ),
591
+
592
+ /*
593
+ // AA - audio - Audible Audiobook
594
+ 'aa' => array(
595
+ 'pattern' => '^.{4}\x57\x90\x75\x36',
596
+ 'group' => 'audio',
597
+ 'module' => 'aa',
598
+ 'mime_type' => 'audio/audible',
599
+ ),
600
+ */
601
+ // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
602
+ 'adts' => array(
603
+ 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]',
604
+ 'group' => 'audio',
605
+ 'module' => 'aac',
606
+ 'mime_type' => 'application/octet-stream',
607
+ 'fail_ape' => 'WARNING',
608
+ ),
609
+
610
+
611
+ // AU - audio - NeXT/Sun AUdio (AU)
612
+ 'au' => array(
613
+ 'pattern' => '^\.snd',
614
+ 'group' => 'audio',
615
+ 'module' => 'au',
616
+ 'mime_type' => 'audio/basic',
617
+ ),
618
+
619
+ // AMR - audio - Adaptive Multi Rate
620
+ 'amr' => array(
621
+ 'pattern' => '^\x23\x21AMR\x0A', // #!AMR[0A]
622
+ 'group' => 'audio',
623
+ 'module' => 'amr',
624
+ 'mime_type' => 'audio/amr',
625
+ ),
626
+
627
+ // AVR - audio - Audio Visual Research
628
+ 'avr' => array(
629
+ 'pattern' => '^2BIT',
630
+ 'group' => 'audio',
631
+ 'module' => 'avr',
632
+ 'mime_type' => 'application/octet-stream',
633
+ ),
634
+
635
+ // BONK - audio - Bonk v0.9+
636
+ 'bonk' => array(
637
+ 'pattern' => '^\x00(BONK|INFO|META| ID3)',
638
+ 'group' => 'audio',
639
+ 'module' => 'bonk',
640
+ 'mime_type' => 'audio/xmms-bonk',
641
+ ),
642
+
643
+ // DSS - audio - Digital Speech Standard
644
+ 'dss' => array(
645
+ 'pattern' => '^[\x02-\x03]ds[s2]',
646
+ 'group' => 'audio',
647
+ 'module' => 'dss',
648
+ 'mime_type' => 'application/octet-stream',
649
+ ),
650
+
651
+ // DTS - audio - Dolby Theatre System
652
+ 'dts' => array(
653
+ 'pattern' => '^\x7F\xFE\x80\x01',
654
+ 'group' => 'audio',
655
+ 'module' => 'dts',
656
+ 'mime_type' => 'audio/dts',
657
+ ),
658
+
659
+ // FLAC - audio - Free Lossless Audio Codec
660
+ 'flac' => array(
661
+ 'pattern' => '^fLaC',
662
+ 'group' => 'audio',
663
+ 'module' => 'flac',
664
+ 'mime_type' => 'audio/x-flac',
665
+ ),
666
+
667
+ // LA - audio - Lossless Audio (LA)
668
+ 'la' => array(
669
+ 'pattern' => '^LA0[2-4]',
670
+ 'group' => 'audio',
671
+ 'module' => 'la',
672
+ 'mime_type' => 'application/octet-stream',
673
+ ),
674
+
675
+ // LPAC - audio - Lossless Predictive Audio Compression (LPAC)
676
+ 'lpac' => array(
677
+ 'pattern' => '^LPAC',
678
+ 'group' => 'audio',
679
+ 'module' => 'lpac',
680
+ 'mime_type' => 'application/octet-stream',
681
+ ),
682
+
683
+ // MIDI - audio - MIDI (Musical Instrument Digital Interface)
684
+ 'midi' => array(
685
+ 'pattern' => '^MThd',
686
+ 'group' => 'audio',
687
+ 'module' => 'midi',
688
+ 'mime_type' => 'audio/midi',
689
+ ),
690
+
691
+ // MAC - audio - Monkey's Audio Compressor
692
+ 'mac' => array(
693
+ 'pattern' => '^MAC ',
694
+ 'group' => 'audio',
695
+ 'module' => 'monkey',
696
+ 'mime_type' => 'application/octet-stream',
697
+ ),
698
+
699
+ // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
700
+ // // MOD - audio - MODule (assorted sub-formats)
701
+ // 'mod' => array(
702
+ // 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
703
+ // 'group' => 'audio',
704
+ // 'module' => 'mod',
705
+ // 'option' => 'mod',
706
+ // 'mime_type' => 'audio/mod',
707
+ // ),
708
+
709
+ // MOD - audio - MODule (Impulse Tracker)
710
+ 'it' => array(
711
+ 'pattern' => '^IMPM',
712
+ 'group' => 'audio',
713
+ 'module' => 'mod',
714
+ //'option' => 'it',
715
+ 'mime_type' => 'audio/it',
716
+ ),
717
+
718
+ // MOD - audio - MODule (eXtended Module, various sub-formats)
719
+ 'xm' => array(
720
+ 'pattern' => '^Extended Module',
721
+ 'group' => 'audio',
722
+ 'module' => 'mod',
723
+ //'option' => 'xm',
724
+ 'mime_type' => 'audio/xm',
725
+ ),
726
+
727
+ // MOD - audio - MODule (ScreamTracker)
728
+ 's3m' => array(
729
+ 'pattern' => '^.{44}SCRM',
730
+ 'group' => 'audio',
731
+ 'module' => 'mod',
732
+ //'option' => 's3m',
733
+ 'mime_type' => 'audio/s3m',
734
+ ),
735
+
736
+ // MPC - audio - Musepack / MPEGplus
737
+ 'mpc' => array(
738
+ 'pattern' => '^(MPCK|MP\+|[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])',
739
+ 'group' => 'audio',
740
+ 'module' => 'mpc',
741
+ 'mime_type' => 'audio/x-musepack',
742
+ ),
743
+
744
+ // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS)
745
+ 'mp3' => array(
746
+ 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\x0B\x10-\x1B\x20-\x2B\x30-\x3B\x40-\x4B\x50-\x5B\x60-\x6B\x70-\x7B\x80-\x8B\x90-\x9B\xA0-\xAB\xB0-\xBB\xC0-\xCB\xD0-\xDB\xE0-\xEB\xF0-\xFB]',
747
+ 'group' => 'audio',
748
+ 'module' => 'mp3',
749
+ 'mime_type' => 'audio/mpeg',
750
+ ),
751
+
752
+ // OFR - audio - OptimFROG
753
+ 'ofr' => array(
754
+ 'pattern' => '^(\*RIFF|OFR)',
755
+ 'group' => 'audio',
756
+ 'module' => 'optimfrog',
757
+ 'mime_type' => 'application/octet-stream',
758
+ ),
759
+
760
+ // RKAU - audio - RKive AUdio compressor
761
+ 'rkau' => array(
762
+ 'pattern' => '^RKA',
763
+ 'group' => 'audio',
764
+ 'module' => 'rkau',
765
+ 'mime_type' => 'application/octet-stream',
766
+ ),
767
+
768
+ // SHN - audio - Shorten
769
+ 'shn' => array(
770
+ 'pattern' => '^ajkg',
771
+ 'group' => 'audio',
772
+ 'module' => 'shorten',
773
+ 'mime_type' => 'audio/xmms-shn',
774
+ 'fail_id3' => 'ERROR',
775
+ 'fail_ape' => 'ERROR',
776
+ ),
777
+
778
+ // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org)
779
+ 'tta' => array(
780
+ 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)'
781
+ 'group' => 'audio',
782
+ 'module' => 'tta',
783
+ 'mime_type' => 'application/octet-stream',
784
+ ),
785
+
786
+ // VOC - audio - Creative Voice (VOC)
787
+ 'voc' => array(
788
+ 'pattern' => '^Creative Voice File',
789
+ 'group' => 'audio',
790
+ 'module' => 'voc',
791
+ 'mime_type' => 'audio/voc',
792
+ ),
793
+
794
+ // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF)
795
+ 'vqf' => array(
796
+ 'pattern' => '^TWIN',
797
+ 'group' => 'audio',
798
+ 'module' => 'vqf',
799
+ 'mime_type' => 'application/octet-stream',
800
+ ),
801
+
802
+ // WV - audio - WavPack (v4.0+)
803
+ 'wv' => array(
804
+ 'pattern' => '^wvpk',
805
+ 'group' => 'audio',
806
+ 'module' => 'wavpack',
807
+ 'mime_type' => 'application/octet-stream',
808
+ ),
809
+
810
+
811
+ // Audio-Video formats
812
+
813
+ // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
814
+ 'asf' => array(
815
+ 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
816
+ 'group' => 'audio-video',
817
+ 'module' => 'asf',
818
+ 'mime_type' => 'video/x-ms-asf',
819
+ 'iconv_req' => false,
820
+ ),
821
+
822
+ // BINK - audio/video - Bink / Smacker
823
+ 'bink' => array(
824
+ 'pattern' => '^(BIK|SMK)',
825
+ 'group' => 'audio-video',
826
+ 'module' => 'bink',
827
+ 'mime_type' => 'application/octet-stream',
828
+ ),
829
+
830
+ // FLV - audio/video - FLash Video
831
+ 'flv' => array(
832
+ 'pattern' => '^FLV\x01',
833
+ 'group' => 'audio-video',
834
+ 'module' => 'flv',
835
+ 'mime_type' => 'video/x-flv',
836
+ ),
837
+
838
+ // MKAV - audio/video - Mastroka
839
+ 'matroska' => array(
840
+ 'pattern' => '^\x1A\x45\xDF\xA3',
841
+ 'group' => 'audio-video',
842
+ 'module' => 'matroska',
843
+ 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska
844
+ ),
845
+
846
+ // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
847
+ 'mpeg' => array(
848
+ 'pattern' => '^\x00\x00\x01(\xBA|\xB3)',
849
+ 'group' => 'audio-video',
850
+ 'module' => 'mpeg',
851
+ 'mime_type' => 'video/mpeg',
852
+ ),
853
+
854
+ // NSV - audio/video - Nullsoft Streaming Video (NSV)
855
+ 'nsv' => array(
856
+ 'pattern' => '^NSV[sf]',
857
+ 'group' => 'audio-video',
858
+ 'module' => 'nsv',
859
+ 'mime_type' => 'application/octet-stream',
860
+ ),
861
+
862
+ // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*))
863
+ 'ogg' => array(
864
+ 'pattern' => '^OggS',
865
+ 'group' => 'audio',
866
+ 'module' => 'ogg',
867
+ 'mime_type' => 'application/ogg',
868
+ 'fail_id3' => 'WARNING',
869
+ 'fail_ape' => 'WARNING',
870
+ ),
871
+
872
+ // QT - audio/video - Quicktime
873
+ 'quicktime' => array(
874
+ 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
875
+ 'group' => 'audio-video',
876
+ 'module' => 'quicktime',
877
+ 'mime_type' => 'video/quicktime',
878
+ ),
879
+
880
+ // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF)
881
+ 'riff' => array(
882
+ 'pattern' => '^(RIFF|SDSS|FORM)',
883
+ 'group' => 'audio-video',
884
+ 'module' => 'riff',
885
+ 'mime_type' => 'audio/x-wave',
886
+ 'fail_ape' => 'WARNING',
887
+ ),
888
+
889
+ // Real - audio/video - RealAudio, RealVideo
890
+ 'real' => array(
891
+ 'pattern' => '^(\\.RMF|\\.ra)',
892
+ 'group' => 'audio-video',
893
+ 'module' => 'real',
894
+ 'mime_type' => 'audio/x-realaudio',
895
+ ),
896
+
897
+ // SWF - audio/video - ShockWave Flash
898
+ 'swf' => array(
899
+ 'pattern' => '^(F|C)WS',
900
+ 'group' => 'audio-video',
901
+ 'module' => 'swf',
902
+ 'mime_type' => 'application/x-shockwave-flash',
903
+ ),
904
+
905
+ // TS - audio/video - MPEG-2 Transport Stream
906
+ 'ts' => array(
907
+ 'pattern' => '^(\x47.{187}){10,}', // packets are 188 bytes long and start with 0x47 "G". Check for at least 10 packets matching this pattern
908
+ 'group' => 'audio-video',
909
+ 'module' => 'ts',
910
+ 'mime_type' => 'video/MP2T',
911
+ ),
912
+
913
+
914
+ // Still-Image formats
915
+
916
+ // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4)
917
+ 'bmp' => array(
918
+ 'pattern' => '^BM',
919
+ 'group' => 'graphic',
920
+ 'module' => 'bmp',
921
+ 'mime_type' => 'image/bmp',
922
+ 'fail_id3' => 'ERROR',
923
+ 'fail_ape' => 'ERROR',
924
+ ),
925
+
926
+ // GIF - still image - Graphics Interchange Format
927
+ 'gif' => array(
928
+ 'pattern' => '^GIF',
929
+ 'group' => 'graphic',
930
+ 'module' => 'gif',
931
+ 'mime_type' => 'image/gif',
932
+ 'fail_id3' => 'ERROR',
933
+ 'fail_ape' => 'ERROR',
934
+ ),
935
+
936
+ // JPEG - still image - Joint Photographic Experts Group (JPEG)
937
+ 'jpg' => array(
938
+ 'pattern' => '^\xFF\xD8\xFF',
939
+ 'group' => 'graphic',
940
+ 'module' => 'jpg',
941
+ 'mime_type' => 'image/jpeg',
942
+ 'fail_id3' => 'ERROR',
943
+ 'fail_ape' => 'ERROR',
944
+ ),
945
+
946
+ // PCD - still image - Kodak Photo CD
947
+ 'pcd' => array(
948
+ 'pattern' => '^.{2048}PCD_IPI\x00',
949
+ 'group' => 'graphic',
950
+ 'module' => 'pcd',
951
+ 'mime_type' => 'image/x-photo-cd',
952
+ 'fail_id3' => 'ERROR',
953
+ 'fail_ape' => 'ERROR',
954
+ ),
955
+
956
+
957
+ // PNG - still image - Portable Network Graphics (PNG)
958
+ 'png' => array(
959
+ 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
960
+ 'group' => 'graphic',
961
+ 'module' => 'png',
962
+ 'mime_type' => 'image/png',
963
+ 'fail_id3' => 'ERROR',
964
+ 'fail_ape' => 'ERROR',
965
+ ),
966
+
967
+
968
+ // SVG - still image - Scalable Vector Graphics (SVG)
969
+ 'svg' => array(
970
+ 'pattern' => '(<!DOCTYPE svg PUBLIC |xmlns="http:\/\/www\.w3\.org\/2000\/svg")',
971
+ 'group' => 'graphic',
972
+ 'module' => 'svg',
973
+ 'mime_type' => 'image/svg+xml',
974
+ 'fail_id3' => 'ERROR',
975
+ 'fail_ape' => 'ERROR',
976
+ ),
977
+
978
+
979
+ // TIFF - still image - Tagged Information File Format (TIFF)
980
+ 'tiff' => array(
981
+ 'pattern' => '^(II\x2A\x00|MM\x00\x2A)',
982
+ 'group' => 'graphic',
983
+ 'module' => 'tiff',
984
+ 'mime_type' => 'image/tiff',
985
+ 'fail_id3' => 'ERROR',
986
+ 'fail_ape' => 'ERROR',
987
+ ),
988
+
989
+
990
+ // EFAX - still image - eFax (TIFF derivative)
991
+ 'efax' => array(
992
+ 'pattern' => '^\xDC\xFE',
993
+ 'group' => 'graphic',
994
+ 'module' => 'efax',
995
+ 'mime_type' => 'image/efax',
996
+ 'fail_id3' => 'ERROR',
997
+ 'fail_ape' => 'ERROR',
998
+ ),
999
+
1000
+
1001
+ // Data formats
1002
+
1003
+ // ISO - data - International Standards Organization (ISO) CD-ROM Image
1004
+ 'iso' => array(
1005
+ 'pattern' => '^.{32769}CD001',
1006
+ 'group' => 'misc',
1007
+ 'module' => 'iso',
1008
+ 'mime_type' => 'application/octet-stream',
1009
+ 'fail_id3' => 'ERROR',
1010
+ 'fail_ape' => 'ERROR',
1011
+ 'iconv_req' => false,
1012
+ ),
1013
+
1014
+ // RAR - data - RAR compressed data
1015
+ 'rar' => array(
1016
+ 'pattern' => '^Rar\!',
1017
+ 'group' => 'archive',
1018
+ 'module' => 'rar',
1019
+ 'mime_type' => 'application/octet-stream',
1020
+ 'fail_id3' => 'ERROR',
1021
+ 'fail_ape' => 'ERROR',
1022
+ ),
1023
+
1024
+ // SZIP - audio/data - SZIP compressed data
1025
+ 'szip' => array(
1026
+ 'pattern' => '^SZ\x0A\x04',
1027
+ 'group' => 'archive',
1028
+ 'module' => 'szip',
1029
+ 'mime_type' => 'application/octet-stream',
1030
+ 'fail_id3' => 'ERROR',
1031
+ 'fail_ape' => 'ERROR',
1032
+ ),
1033
+
1034
+ // TAR - data - TAR compressed data
1035
+ 'tar' => array(
1036
+ 'pattern' => '^.{100}[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20\x00]{12}[0-9\x20\x00]{12}',
1037
+ 'group' => 'archive',
1038
+ 'module' => 'tar',
1039
+ 'mime_type' => 'application/x-tar',
1040
+ 'fail_id3' => 'ERROR',
1041
+ 'fail_ape' => 'ERROR',
1042
+ ),
1043
+
1044
+ // GZIP - data - GZIP compressed data
1045
+ 'gz' => array(
1046
+ 'pattern' => '^\x1F\x8B\x08',
1047
+ 'group' => 'archive',
1048
+ 'module' => 'gzip',
1049
+ 'mime_type' => 'application/x-gzip',
1050
+ 'fail_id3' => 'ERROR',
1051
+ 'fail_ape' => 'ERROR',
1052
+ ),
1053
+
1054
+ // ZIP - data - ZIP compressed data
1055
+ 'zip' => array(
1056
+ 'pattern' => '^PK\x03\x04',
1057
+ 'group' => 'archive',
1058
+ 'module' => 'zip',
1059
+ 'mime_type' => 'application/zip',
1060
+ 'fail_id3' => 'ERROR',
1061
+ 'fail_ape' => 'ERROR',
1062
+ ),
1063
+
1064
+
1065
+ // Misc other formats
1066
+
1067
+ // PAR2 - data - Parity Volume Set Specification 2.0
1068
+ 'par2' => array (
1069
+ 'pattern' => '^PAR2\x00PKT',
1070
+ 'group' => 'misc',
1071
+ 'module' => 'par2',
1072
+ 'mime_type' => 'application/octet-stream',
1073
+ 'fail_id3' => 'ERROR',
1074
+ 'fail_ape' => 'ERROR',
1075
+ ),
1076
+
1077
+ // PDF - data - Portable Document Format
1078
+ 'pdf' => array(
1079
+ 'pattern' => '^\x25PDF',
1080
+ 'group' => 'misc',
1081
+ 'module' => 'pdf',
1082
+ 'mime_type' => 'application/pdf',
1083
+ 'fail_id3' => 'ERROR',
1084
+ 'fail_ape' => 'ERROR',
1085
+ ),
1086
+
1087
+ // MSOFFICE - data - ZIP compressed data
1088
+ 'msoffice' => array(
1089
+ 'pattern' => '^\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1', // D0CF11E == DOCFILE == Microsoft Office Document
1090
+ 'group' => 'misc',
1091
+ 'module' => 'msoffice',
1092
+ 'mime_type' => 'application/octet-stream',
1093
+ 'fail_id3' => 'ERROR',
1094
+ 'fail_ape' => 'ERROR',
1095
+ ),
1096
+
1097
+ // CUE - data - CUEsheet (index to single-file disc images)
1098
+ 'cue' => array(
1099
+ 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents
1100
+ 'group' => 'misc',
1101
+ 'module' => 'cue',
1102
+ 'mime_type' => 'application/octet-stream',
1103
+ ),
1104
+
1105
+ );
1106
+ }
1107
+
1108
+ return $format_info;
1109
+ }
1110
+
1111
+
1112
+
1113
+ public function GetFileFormat(&$filedata, $filename='') {
1114
+ // this function will determine the format of a file based on usually
1115
+ // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
1116
+ // and in the case of ISO CD image, 6 bytes offset 32kb from the start
1117
+ // of the file).
1118
+
1119
+ // Identify file format - loop through $format_info and detect with reg expr
1120
+ foreach ($this->GetFileFormatArray() as $format_name => $info) {
1121
+ // The /s switch on preg_match() forces preg_match() NOT to treat
1122
+ // newline (0x0A) characters as special chars but do a binary match
1123
+ if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {
1124
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
1125
+ return $info;
1126
+ }
1127
+ }
1128
+
1129
+
1130
+ if (preg_match('#\.mp[123a]$#i', $filename)) {
1131
+ // Too many mp3 encoders on the market put gabage in front of mpeg files
1132
+ // use assume format on these if format detection failed
1133
+ $GetFileFormatArray = $this->GetFileFormatArray();
1134
+ $info = $GetFileFormatArray['mp3'];
1135
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
1136
+ return $info;
1137
+ } elseif (preg_match('/\.cue$/i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
1138
+ // there's not really a useful consistent "magic" at the beginning of .cue files to identify them
1139
+ // so until I think of something better, just go by filename if all other format checks fail
1140
+ // and verify there's at least one instance of "TRACK xx AUDIO" in the file
1141
+ $GetFileFormatArray = $this->GetFileFormatArray();
1142
+ $info = $GetFileFormatArray['cue'];
1143
+ $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
1144
+ return $info;
1145
+ }
1146
+
1147
+ return false;
1148
+ }
1149
+
1150
+
1151
+ // converts array to $encoding charset from $this->encoding
1152
+ public function CharConvert(&$array, $encoding) {
1153
+
1154
+ // identical encoding - end here
1155
+ if ($encoding == $this->encoding) {
1156
+ return;
1157
+ }
1158
+
1159
+ // loop thru array
1160
+ foreach ($array as $key => $value) {
1161
+
1162
+ // go recursive
1163
+ if (is_array($value)) {
1164
+ $this->CharConvert($array[$key], $encoding);
1165
+ }
1166
+
1167
+ // convert string
1168
+ elseif (is_string($value)) {
1169
+ $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
1170
+ }
1171
+ }
1172
+ }
1173
+
1174
+
1175
+ public function HandleAllTags() {
1176
+
1177
+ // key name => array (tag name, character encoding)
1178
+ static $tags;
1179
+ if (empty($tags)) {
1180
+ $tags = array(
1181
+ 'asf' => array('asf' , 'UTF-16LE'),
1182
+ 'midi' => array('midi' , 'ISO-8859-1'),
1183
+ 'nsv' => array('nsv' , 'ISO-8859-1'),
1184
+ 'ogg' => array('vorbiscomment' , 'UTF-8'),
1185
+ 'png' => array('png' , 'UTF-8'),
1186
+ 'tiff' => array('tiff' , 'ISO-8859-1'),
1187
+ 'quicktime' => array('quicktime' , 'UTF-8'),
1188
+ 'real' => array('real' , 'ISO-8859-1'),
1189
+ 'vqf' => array('vqf' , 'ISO-8859-1'),
1190
+ 'zip' => array('zip' , 'ISO-8859-1'),
1191
+ 'riff' => array('riff' , 'ISO-8859-1'),
1192
+ 'lyrics3' => array('lyrics3' , 'ISO-8859-1'),
1193
+ 'id3v1' => array('id3v1' , $this->encoding_id3v1),
1194
+ 'id3v2' => array('id3v2' , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8
1195
+ 'ape' => array('ape' , 'UTF-8'),
1196
+ 'cue' => array('cue' , 'ISO-8859-1'),
1197
+ 'matroska' => array('matroska' , 'UTF-8'),
1198
+ 'flac' => array('vorbiscomment' , 'UTF-8'),
1199
+ 'divxtag' => array('divx' , 'ISO-8859-1'),
1200
+ 'iptc' => array('iptc' , 'ISO-8859-1'),
1201
+ );
1202
+ }
1203
+
1204
+ // loop through comments array
1205
+ foreach ($tags as $comment_name => $tagname_encoding_array) {
1206
+ list($tag_name, $encoding) = $tagname_encoding_array;
1207
+
1208
+ // fill in default encoding type if not already present
1209
+ if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
1210
+ $this->info[$comment_name]['encoding'] = $encoding;
1211
+ }
1212
+
1213
+ // copy comments if key name set
1214
+ if (!empty($this->info[$comment_name]['comments'])) {
1215
+ foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
1216
+ foreach ($valuearray as $key => $value) {
1217
+ if (is_string($value)) {
1218
+ $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed!
1219
+ }
1220
+ if ($value) {
1221
+ if (!is_numeric($key)) {
1222
+ $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value;
1223
+ } else {
1224
+ $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
1225
+ }
1226
+ }
1227
+ }
1228
+ if ($tag_key == 'picture') {
1229
+ unset($this->info[$comment_name]['comments'][$tag_key]);
1230
+ }
1231
+ }
1232
+
1233
+ if (!isset($this->info['tags'][$tag_name])) {
1234
+ // comments are set but contain nothing but empty strings, so skip
1235
+ continue;
1236
+ }
1237
+
1238
+ if ($this->option_tags_html) {
1239
+ foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
1240
+ $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $encoding);
1241
+ }
1242
+ }
1243
+
1244
+ $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted!
1245
+ }
1246
+
1247
+ }
1248
+
1249
+ // pictures can take up a lot of space, and we don't need multiple copies of them
1250
+ // let there be a single copy in [comments][picture], and not elsewhere
1251
+ if (!empty($this->info['tags'])) {
1252
+ $unset_keys = array('tags', 'tags_html');
1253
+ foreach ($this->info['tags'] as $tagtype => $tagarray) {
1254
+ foreach ($tagarray as $tagname => $tagdata) {
1255
+ if ($tagname == 'picture') {
1256
+ foreach ($tagdata as $key => $tagarray) {
1257
+ $this->info['comments']['picture'][] = $tagarray;
1258
+ if (isset($tagarray['data']) && isset($tagarray['image_mime'])) {
1259
+ if (isset($this->info['tags'][$tagtype][$tagname][$key])) {
1260
+ unset($this->info['tags'][$tagtype][$tagname][$key]);
1261
+ }
1262
+ if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) {
1263
+ unset($this->info['tags_html'][$tagtype][$tagname][$key]);
1264
+ }
1265
+ }
1266
+ }
1267
+ }
1268
+ }
1269
+ foreach ($unset_keys as $unset_key) {
1270
+ // remove possible empty keys from (e.g. [tags][id3v2][picture])
1271
+ if (empty($this->info[$unset_key][$tagtype]['picture'])) {
1272
+ unset($this->info[$unset_key][$tagtype]['picture']);
1273
+ }
1274
+ if (empty($this->info[$unset_key][$tagtype])) {
1275
+ unset($this->info[$unset_key][$tagtype]);
1276
+ }
1277
+ if (empty($this->info[$unset_key])) {
1278
+ unset($this->info[$unset_key]);
1279
+ }
1280
+ }
1281
+ // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture])
1282
+ if (isset($this->info[$tagtype]['comments']['picture'])) {
1283
+ unset($this->info[$tagtype]['comments']['picture']);
1284
+ }
1285
+ if (empty($this->info[$tagtype]['comments'])) {
1286
+ unset($this->info[$tagtype]['comments']);
1287
+ }
1288
+ if (empty($this->info[$tagtype])) {
1289
+ unset($this->info[$tagtype]);
1290
+ }
1291
+ }
1292
+ }
1293
+ return true;
1294
+ }
1295
+
1296
+ public function getHashdata($algorithm) {
1297
+ switch ($algorithm) {
1298
+ case 'md5':
1299
+ case 'sha1':
1300
+ break;
1301
+
1302
+ default:
1303
+ return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
1304
+ break;
1305
+ }
1306
+
1307
+ if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) {
1308
+
1309
+ // We cannot get an identical md5_data value for Ogg files where the comments
1310
+ // span more than 1 Ogg page (compared to the same audio data with smaller
1311
+ // comments) using the normal getID3() method of MD5'ing the data between the
1312
+ // end of the comments and the end of the file (minus any trailing tags),
1313
+ // because the page sequence numbers of the pages that the audio data is on
1314
+ // do not match. Under normal circumstances, where comments are smaller than
1315
+ // the nominal 4-8kB page size, then this is not a problem, but if there are
1316
+ // very large comments, the only way around it is to strip off the comment
1317
+ // tags with vorbiscomment and MD5 that file.
1318
+ // This procedure must be applied to ALL Ogg files, not just the ones with
1319
+ // comments larger than 1 page, because the below method simply MD5's the
1320
+ // whole file with the comments stripped, not just the portion after the
1321
+ // comments block (which is the standard getID3() method.
1322
+
1323
+ // The above-mentioned problem of comments spanning multiple pages and changing
1324
+ // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
1325
+ // currently vorbiscomment only works on OggVorbis files.
1326
+
1327
+ if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
1328
+
1329
+ $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');
1330
+ $this->info[$algorithm.'_data'] = false;
1331
+
1332
+ } else {
1333
+
1334
+ // Prevent user from aborting script
1335
+ $old_abort = ignore_user_abort(true);
1336
+
1337
+ // Create empty file
1338
+ $empty = tempnam(GETID3_TEMP_DIR, 'getID3');
1339
+ touch($empty);
1340
+
1341
+ // Use vorbiscomment to make temp file without comments
1342
+ $temp = tempnam(GETID3_TEMP_DIR, 'getID3');
1343
+ $file = $this->info['filenamepath'];
1344
+
1345
+ if (GETID3_OS_ISWINDOWS) {
1346
+
1347
+ if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
1348
+
1349
+ $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
1350
+ $VorbisCommentError = `$commandline`;
1351
+
1352
+ } else {
1353
+
1354
+ $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
1355
+
1356
+ }
1357
+
1358
+ } else {
1359
+
1360
+ $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
1361
+ $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
1362
+ $VorbisCommentError = `$commandline`;
1363
+
1364
+ }
1365
+
1366
+ if (!empty($VorbisCommentError)) {
1367
+
1368
+ $this->info['warning'][] = 'Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError;
1369
+ $this->info[$algorithm.'_data'] = false;
1370
+
1371
+ } else {
1372
+
1373
+ // Get hash of newly created file
1374
+ switch ($algorithm) {
1375
+ case 'md5':
1376
+ $this->info[$algorithm.'_data'] = md5_file($temp);
1377
+ break;
1378
+
1379
+ case 'sha1':
1380
+ $this->info[$algorithm.'_data'] = sha1_file($temp);
1381
+ break;
1382
+ }
1383
+ }
1384
+
1385
+ // Clean up
1386
+ unlink($empty);
1387
+ unlink($temp);
1388
+
1389
+ // Reset abort setting
1390
+ ignore_user_abort($old_abort);
1391
+
1392
+ }
1393
+
1394
+ } else {
1395
+
1396
+ if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
1397
+
1398
+ // get hash from part of file
1399
+ $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
1400
+
1401
+ } else {
1402
+
1403
+ // get hash from whole file
1404
+ switch ($algorithm) {
1405
+ case 'md5':
1406
+ $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']);
1407
+ break;
1408
+
1409
+ case 'sha1':
1410
+ $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']);
1411
+ break;
1412
+ }
1413
+ }
1414
+
1415
+ }
1416
+ return true;
1417
+ }
1418
+
1419
+
1420
+ public function ChannelsBitratePlaytimeCalculations() {
1421
+
1422
+ // set channelmode on audio
1423
+ if (!empty($this->info['audio']['channelmode']) || !isset($this->info['audio']['channels'])) {
1424
+ // ignore
1425
+ } elseif ($this->info['audio']['channels'] == 1) {
1426
+ $this->info['audio']['channelmode'] = 'mono';
1427
+ } elseif ($this->info['audio']['channels'] == 2) {
1428
+ $this->info['audio']['channelmode'] = 'stereo';
1429
+ }
1430
+
1431
+ // Calculate combined bitrate - audio + video
1432
+ $CombinedBitrate = 0;
1433
+ $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
1434
+ $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
1435
+ if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
1436
+ $this->info['bitrate'] = $CombinedBitrate;
1437
+ }
1438
+ //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) {
1439
+ // // for example, VBR MPEG video files cannot determine video bitrate:
1440
+ // // should not set overall bitrate and playtime from audio bitrate only
1441
+ // unset($this->info['bitrate']);
1442
+ //}
1443
+
1444
+ // video bitrate undetermined, but calculable
1445
+ if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) {
1446
+ // if video bitrate not set
1447
+ if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) {
1448
+ // AND if audio bitrate is set to same as overall bitrate
1449
+ if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) {
1450
+ // AND if playtime is set
1451
+ if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) {
1452
+ // AND if AV data offset start/end is known
1453
+ // THEN we can calculate the video bitrate
1454
+ $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']);
1455
+ $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate'];
1456
+ }
1457
+ }
1458
+ }
1459
+ }
1460
+
1461
+ if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) {
1462
+ $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate'];
1463
+ }
1464
+
1465
+ if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) {
1466
+ $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds'];
1467
+ }
1468
+ if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) {
1469
+ if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) {
1470
+ // audio only
1471
+ $this->info['audio']['bitrate'] = $this->info['bitrate'];
1472
+ } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) {
1473
+ // video only
1474
+ $this->info['video']['bitrate'] = $this->info['bitrate'];
1475
+ }
1476
+ }
1477
+
1478
+ // Set playtime string
1479
+ if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) {
1480
+ $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']);
1481
+ }
1482
+ }
1483
+
1484
+
1485
+ public function CalculateCompressionRatioVideo() {
1486
+ if (empty($this->info['video'])) {
1487
+ return false;
1488
+ }
1489
+ if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) {
1490
+ return false;
1491
+ }
1492
+ if (empty($this->info['video']['bits_per_sample'])) {
1493
+ return false;
1494
+ }
1495
+
1496
+ switch ($this->info['video']['dataformat']) {
1497
+ case 'bmp':
1498
+ case 'gif':
1499
+ case 'jpeg':
1500
+ case 'jpg':
1501
+ case 'png':
1502
+ case 'tiff':
1503
+ $FrameRate = 1;
1504
+ $PlaytimeSeconds = 1;
1505
+ $BitrateCompressed = $this->info['filesize'] * 8;
1506
+ break;
1507
+
1508
+ default:
1509
+ if (!empty($this->info['video']['frame_rate'])) {
1510
+ $FrameRate = $this->info['video']['frame_rate'];
1511
+ } else {
1512
+ return false;
1513
+ }
1514
+ if (!empty($this->info['playtime_seconds'])) {
1515
+ $PlaytimeSeconds = $this->info['playtime_seconds'];
1516
+ } else {
1517
+ return false;
1518
+ }
1519
+ if (!empty($this->info['video']['bitrate'])) {
1520
+ $BitrateCompressed = $this->info['video']['bitrate'];
1521
+ } else {
1522
+ return false;
1523
+ }
1524
+ break;
1525
+ }
1526
+ $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;
1527
+
1528
+ $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
1529
+ return true;
1530
+ }
1531
+
1532
+
1533
+ public function CalculateCompressionRatioAudio() {
1534
+ if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || !is_numeric($this->info['audio']['sample_rate'])) {
1535
+ return false;
1536
+ }
1537
+ $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
1538
+
1539
+ if (!empty($this->info['audio']['streams'])) {
1540
+ foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
1541
+ if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
1542
+ $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
1543
+ }
1544
+ }
1545
+ }
1546
+ return true;
1547
+ }
1548
+
1549
+
1550
+ public function CalculateReplayGain() {
1551
+ if (isset($this->info['replay_gain'])) {
1552
+ if (!isset($this->info['replay_gain']['reference_volume'])) {
1553
+ $this->info['replay_gain']['reference_volume'] = (double) 89.0;
1554
+ }
1555
+ if (isset($this->info['replay_gain']['track']['adjustment'])) {
1556
+ $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
1557
+ }
1558
+ if (isset($this->info['replay_gain']['album']['adjustment'])) {
1559
+ $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
1560
+ }
1561
+
1562
+ if (isset($this->info['replay_gain']['track']['peak'])) {
1563
+ $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
1564
+ }
1565
+ if (isset($this->info['replay_gain']['album']['peak'])) {
1566
+ $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
1567
+ }
1568
+ }
1569
+ return true;
1570
+ }
1571
+
1572
+ public function ProcessAudioStreams() {
1573
+ if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
1574
+ if (!isset($this->info['audio']['streams'])) {
1575
+ foreach ($this->info['audio'] as $key => $value) {
1576
+ if ($key != 'streams') {
1577
+ $this->info['audio']['streams'][0][$key] = $value;
1578
+ }
1579
+ }
1580
+ }
1581
+ }
1582
+ return true;
1583
+ }
1584
+
1585
+ public function getid3_tempnam() {
1586
+ return tempnam($this->tempdir, 'gI3');
1587
+ }
1588
+
1589
+ public function include_module($name) {
1590
+ //if (!file_exists($this->include_path.'module.'.$name.'.php')) {
1591
+ if (!file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) {
1592
+ throw new getid3_exception('Required module.'.$name.'.php is missing.');
1593
+ }
1594
+ include_once(GETID3_INCLUDEPATH.'module.'.$name.'.php');
1595
+ return true;
1596
+ }
1597
+
1598
+ }
1599
+
1600
+
1601
+ abstract class getid3_handler {
1602
+
1603
+ /**
1604
+ * @var getID3
1605
+ */
1606
+ protected $getid3; // pointer
1607
+
1608
+ protected $data_string_flag = false; // analyzing filepointer or string
1609
+ protected $data_string = ''; // string to analyze
1610
+ protected $data_string_position = 0; // seek position in string
1611
+ protected $data_string_length = 0; // string length
1612
+
1613
+ private $dependency_to = null;
1614
+
1615
+
1616
+ public function __construct(getID3 $getid3, $call_module=null) {
1617
+ $this->getid3 = $getid3;
1618
+
1619
+ if ($call_module) {
1620
+ $this->dependency_to = str_replace('getid3_', '', $call_module);
1621
+ }
1622
+ }
1623
+
1624
+
1625
+ // Analyze from file pointer
1626
+ abstract public function Analyze();
1627
+
1628
+
1629
+ // Analyze from string instead
1630
+ public function AnalyzeString($string) {
1631
+ // Enter string mode
1632
+ $this->setStringMode($string);
1633
+
1634
+ // Save info
1635
+ $saved_avdataoffset = $this->getid3->info['avdataoffset'];
1636
+ $saved_avdataend = $this->getid3->info['avdataend'];
1637
+ $saved_filesize = (isset($this->getid3->info['filesize']) ? $this->getid3->info['filesize'] : null); // may be not set if called as dependency without openfile() call
1638
+
1639
+ // Reset some info
1640
+ $this->getid3->info['avdataoffset'] = 0;
1641
+ $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = $this->data_string_length;
1642
+
1643
+ // Analyze
1644
+ $this->Analyze();
1645
+
1646
+ // Restore some info
1647
+ $this->getid3->info['avdataoffset'] = $saved_avdataoffset;
1648
+ $this->getid3->info['avdataend'] = $saved_avdataend;
1649
+ $this->getid3->info['filesize'] = $saved_filesize;
1650
+
1651
+ // Exit string mode
1652
+ $this->data_string_flag = false;
1653
+ }
1654
+
1655
+ public function setStringMode($string) {
1656
+ $this->data_string_flag = true;
1657
+ $this->data_string = $string;
1658
+ $this->data_string_length = strlen($string);
1659
+ }
1660
+
1661
+ protected function ftell() {
1662
+ if ($this->data_string_flag) {
1663
+ return $this->data_string_position;
1664
+ }
1665
+ return ftell($this->getid3->fp);
1666
+ }
1667
+
1668
+ protected function fread($bytes) {
1669
+ if ($this->data_string_flag) {
1670
+ $this->data_string_position += $bytes;
1671
+ return substr($this->data_string, $this->data_string_position - $bytes, $bytes);
1672
+ }
1673
+ $pos = $this->ftell() + $bytes;
1674
+ if (!getid3_lib::intValueSupported($pos)) {
1675
+ throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10);
1676
+ }
1677
+ return fread($this->getid3->fp, $bytes);
1678
+ }
1679
+
1680
+ protected function fseek($bytes, $whence=SEEK_SET) {
1681
+ if ($this->data_string_flag) {
1682
+ switch ($whence) {
1683
+ case SEEK_SET:
1684
+ $this->data_string_position = $bytes;
1685
+ break;
1686
+
1687
+ case SEEK_CUR:
1688
+ $this->data_string_position += $bytes;
1689
+ break;
1690
+
1691
+ case SEEK_END:
1692
+ $this->data_string_position = $this->data_string_length + $bytes;
1693
+ break;
1694
+ }
1695
+ return 0;
1696
+ } else {
1697
+ $pos = $bytes;
1698
+ if ($whence == SEEK_CUR) {
1699
+ $pos = $this->ftell() + $bytes;
1700
+ } elseif ($whence == SEEK_END) {
1701
+ $pos = $this->getid3->info['filesize'] + $bytes;
1702
+ }
1703
+ if (!getid3_lib::intValueSupported($pos)) {
1704
+ throw new getid3_exception('cannot fseek('.$pos.') because beyond PHP filesystem limit', 10);
1705
+ }
1706
+ }
1707
+ return fseek($this->getid3->fp, $bytes, $whence);
1708
+ }
1709
+
1710
+ protected function feof() {
1711
+ if ($this->data_string_flag) {
1712
+ return $this->data_string_position >= $this->data_string_length;
1713
+ }
1714
+ return feof($this->getid3->fp);
1715
+ }
1716
+
1717
+ final protected function isDependencyFor($module) {
1718
+ return $this->dependency_to == $module;
1719
+ }
1720
+
1721
+ protected function error($text) {
1722
+ $this->getid3->info['error'][] = $text;
1723
+
1724
+ return false;
1725
+ }
1726
+
1727
+ protected function warning($text) {
1728
+ return $this->getid3->warning($text);
1729
+ }
1730
+
1731
+ protected function notice($text) {
1732
+ // does nothing for now
1733
+ }
1734
+
1735
+ public function saveAttachment($name, $offset, $length, $image_mime=null) {
1736
+ try {
1737
+
1738
+ // do not extract at all
1739
+ if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_NONE) {
1740
+
1741
+ $attachment = null; // do not set any
1742
+
1743
+ // extract to return array
1744
+ } elseif ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
1745
+
1746
+ $this->fseek($offset);
1747
+ $attachment = $this->fread($length); // get whole data in one pass, till it is anyway stored in memory
1748
+ if ($attachment === false || strlen($attachment) != $length) {
1749
+ throw new Exception('failed to read attachment data');
1750
+ }
1751
+
1752
+ // assume directory path is given
1753
+ } else {
1754
+
1755
+ // set up destination path
1756
+ $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR);
1757
+ if (!is_dir($dir) || !is_writable($dir)) { // check supplied directory
1758
+ throw new Exception('supplied path ('.$dir.') does not exist, or is not writable');
1759
+ }
1760
+ $dest = $dir.DIRECTORY_SEPARATOR.$name.($image_mime ? '.'.getid3_lib::ImageExtFromMime($image_mime) : '');
1761
+
1762
+ // create dest file
1763
+ if (($fp_dest = fopen($dest, 'wb')) == false) {
1764
+ throw new Exception('failed to create file '.$dest);
1765
+ }
1766
+
1767
+ // copy data
1768
+ $this->fseek($offset);
1769
+ $buffersize = ($this->data_string_flag ? $length : $this->getid3->fread_buffer_size());
1770
+ $bytesleft = $length;
1771
+ while ($bytesleft > 0) {
1772
+ if (($buffer = $this->fread(min($buffersize, $bytesleft))) === false || ($byteswritten = fwrite($fp_dest, $buffer)) === false || ($byteswritten === 0)) {
1773
+ throw new Exception($buffer === false ? 'not enough data to read' : 'failed to write to destination file, may be not enough disk space');
1774
+ }
1775
+ $bytesleft -= $byteswritten;
1776
+ }
1777
+
1778
+ fclose($fp_dest);
1779
+ $attachment = $dest;
1780
+
1781
+ }
1782
+
1783
+ } catch (Exception $e) {
1784
+
1785
+ // close and remove dest file if created
1786
+ if (isset($fp_dest) && is_resource($fp_dest)) {
1787
+ fclose($fp_dest);
1788
+ unlink($dest);
1789
+ }
1790
+
1791
+ // do not set any is case of error
1792
+ $attachment = null;
1793
+ $this->warning('Failed to extract attachment '.$name.': '.$e->getMessage());
1794
+
1795
+ }
1796
+
1797
+ // seek to the end of attachment
1798
+ $this->fseek($offset + $length);
1799
+
1800
+ return $attachment;
1801
+ }
1802
+
1803
+ }
1804
+
1805
+
1806
+ class getid3_exception extends Exception
1807
+ {
1808
+ public $message;
1809
+ }
getid3/module.audio-video.quicktime.php CHANGED
@@ -1,2134 +1,2246 @@
1
- <?php
2
- /////////////////////////////////////////////////////////////////
3
- /// getID3() by James Heinrich <info@getid3.org> //
4
- // available at http://getid3.sourceforge.net //
5
- // or http://www.getid3.org //
6
- /////////////////////////////////////////////////////////////////
7
- // See readme.txt for more details //
8
- /////////////////////////////////////////////////////////////////
9
- // //
10
- // module.audio-video.quicktime.php //
11
- // module for analyzing Quicktime and MP3-in-MP4 files //
12
- // dependencies: module.audio.mp3.php //
13
- // ///
14
- /////////////////////////////////////////////////////////////////
15
-
16
- getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
17
-
18
- class getid3_quicktime extends getid3_handler
19
- {
20
-
21
- var $ReturnAtomData = true;
22
- var $ParseAllPossibleAtoms = false;
23
-
24
- function Analyze() {
25
- $info = &$this->getid3->info;
26
-
27
- $info['fileformat'] = 'quicktime';
28
- $info['quicktime']['hinting'] = false;
29
- $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
30
-
31
- fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
32
-
33
- $offset = 0;
34
- $atomcounter = 0;
35
-
36
- while ($offset < $info['avdataend']) {
37
- if (!getid3_lib::intValueSupported($offset)) {
38
- $info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
39
- break;
40
- }
41
- fseek($this->getid3->fp, $offset, SEEK_SET);
42
- $AtomHeader = fread($this->getid3->fp, 8);
43
-
44
- $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
45
- $atomname = substr($AtomHeader, 4, 4);
46
-
47
- // 64-bit MOV patch by jlegate�ktnc*com
48
- if ($atomsize == 1) {
49
- $atomsize = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 8));
50
- }
51
-
52
- $info['quicktime'][$atomname]['name'] = $atomname;
53
- $info['quicktime'][$atomname]['size'] = $atomsize;
54
- $info['quicktime'][$atomname]['offset'] = $offset;
55
-
56
- if (($offset + $atomsize) > $info['avdataend']) {
57
- $info['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
58
- return false;
59
- }
60
-
61
- if ($atomsize == 0) {
62
- // Furthermore, for historical reasons the list of atoms is optionally
63
- // terminated by a 32-bit integer set to 0. If you are writing a program
64
- // to read user data atoms, you should allow for the terminating 0.
65
- break;
66
- }
67
- switch ($atomname) {
68
- case 'mdat': // Media DATa atom
69
- // 'mdat' contains the actual data for the audio/video
70
- if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
71
-
72
- $info['avdataoffset'] = $info['quicktime'][$atomname]['offset'] + 8;
73
- $OldAVDataEnd = $info['avdataend'];
74
- $info['avdataend'] = $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
75
-
76
- $getid3_temp = new getID3();
77
- $getid3_temp->openfile($this->getid3->filename);
78
- $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
79
- $getid3_temp->info['avdataend'] = $info['avdataend'];
80
- $getid3_mp3 = new getid3_mp3($getid3_temp);
81
- if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode(fread($this->getid3->fp, 4)))) {
82
- $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
83
- if (!empty($getid3_temp->info['warning'])) {
84
- foreach ($getid3_temp->info['warning'] as $value) {
85
- $info['warning'][] = $value;
86
- }
87
- }
88
- if (!empty($getid3_temp->info['mpeg'])) {
89
- $info['mpeg'] = $getid3_temp->info['mpeg'];
90
- if (isset($info['mpeg']['audio'])) {
91
- $info['audio']['dataformat'] = 'mp3';
92
- $info['audio']['codec'] = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
93
- $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
94
- $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
95
- $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
96
- $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
97
- $info['bitrate'] = $info['audio']['bitrate'];
98
- }
99
- }
100
- }
101
- unset($getid3_mp3, $getid3_temp);
102
- $info['avdataend'] = $OldAVDataEnd;
103
- unset($OldAVDataEnd);
104
-
105
- }
106
- break;
107
-
108
- case 'free': // FREE space atom
109
- case 'skip': // SKIP atom
110
- case 'wide': // 64-bit expansion placeholder atom
111
- // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
112
- break;
113
-
114
- default:
115
- $atomHierarchy = array();
116
- $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($this->getid3->fp, $atomsize), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
117
- break;
118
- }
119
-
120
- $offset += $atomsize;
121
- $atomcounter++;
122
- }
123
-
124
- if (!empty($info['avdataend_tmp'])) {
125
- // this value is assigned to a temp value and then erased because
126
- // otherwise any atoms beyond the 'mdat' atom would not get parsed
127
- $info['avdataend'] = $info['avdataend_tmp'];
128
- unset($info['avdataend_tmp']);
129
- }
130
-
131
- if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) {
132
- $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
133
- }
134
- if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) {
135
- $info['audio']['bitrate'] = $info['bitrate'];
136
- }
137
- if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) {
138
- foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) {
139
- $samples_per_second = $samples_count / $info['playtime_seconds'];
140
- if ($samples_per_second > 240) {
141
- // has to be audio samples
142
- } else {
143
- $info['video']['frame_rate'] = $samples_per_second;
144
- break;
145
- }
146
- }
147
- }
148
- if (($info['audio']['dataformat'] == 'mp4') && empty($info['video']['resolution_x'])) {
149
- $info['fileformat'] = 'mp4';
150
- $info['mime_type'] = 'audio/mp4';
151
- unset($info['video']['dataformat']);
152
- }
153
-
154
- if (!$this->ReturnAtomData) {
155
- unset($info['quicktime']['moov']);
156
- }
157
-
158
- if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) {
159
- $info['audio']['dataformat'] = 'quicktime';
160
- }
161
- if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) {
162
- $info['video']['dataformat'] = 'quicktime';
163
- }
164
-
165
- return true;
166
- }
167
-
168
- function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
169
- // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
170
-
171
- $info = &$this->getid3->info;
172
-
173
- $atom_parent = array_pop($atomHierarchy);
174
- array_push($atomHierarchy, $atomname);
175
- $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
176
- $atom_structure['name'] = $atomname;
177
- $atom_structure['size'] = $atomsize;
178
- $atom_structure['offset'] = $baseoffset;
179
- //echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8)).'<br>';
180
- //echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8), false).'<br><br>';
181
- switch ($atomname) {
182
- case 'moov': // MOVie container atom
183
- case 'trak': // TRAcK container atom
184
- case 'clip': // CLIPping container atom
185
- case 'matt': // track MATTe container atom
186
- case 'edts': // EDiTS container atom
187
- case 'tref': // Track REFerence container atom
188
- case 'mdia': // MeDIA container atom
189
- case 'minf': // Media INFormation container atom
190
- case 'dinf': // Data INFormation container atom
191
- case 'udta': // User DaTA container atom
192
- case 'cmov': // Compressed MOVie container atom
193
- case 'rmra': // Reference Movie Record Atom
194
- case 'rmda': // Reference Movie Descriptor Atom
195
- case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR)
196
- $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
197
- break;
198
-
199
- case 'ilst': // Item LiST container atom
200
- $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
201
-
202
- // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
203
- $allnumericnames = true;
204
- foreach ($atom_structure['subatoms'] as $subatomarray) {
205
- if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
206
- $allnumericnames = false;
207
- break;
208
- }
209
- }
210
- if ($allnumericnames) {
211
- $newData = array();
212
- foreach ($atom_structure['subatoms'] as $subatomarray) {
213
- foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
214
- unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
215
- $newData[$subatomarray['name']] = $newData_subatomarray;
216
- break;
217
- }
218
- }
219
- $atom_structure['data'] = $newData;
220
- unset($atom_structure['subatoms']);
221
- }
222
- break;
223
-
224
- case "\x00\x00\x00\x01":
225
- case "\x00\x00\x00\x02":
226
- case "\x00\x00\x00\x03":
227
- case "\x00\x00\x00\x04":
228
- case "\x00\x00\x00\x05":
229
- $atomname = getid3_lib::BigEndian2Int($atomname);
230
- $atom_structure['name'] = $atomname;
231
- $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
232
- break;
233
-
234
- case 'stbl': // Sample TaBLe container atom
235
- $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
236
- $isVideo = false;
237
- $framerate = 0;
238
- $framecount = 0;
239
- foreach ($atom_structure['subatoms'] as $key => $value_array) {
240
- if (isset($value_array['sample_description_table'])) {
241
- foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
242
- if (isset($value_array2['data_format'])) {
243
- switch ($value_array2['data_format']) {
244
- case 'avc1':
245
- case 'mp4v':
246
- // video data
247
- $isVideo = true;
248
- break;
249
- case 'mp4a':
250
- // audio data
251
- break;
252
- }
253
- }
254
- }
255
- } elseif (isset($value_array['time_to_sample_table'])) {
256
- foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
257
- if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) {
258
- $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
259
- $framecount = $value_array2['sample_count'];
260
- }
261
- }
262
- }
263
- }
264
- if ($isVideo && $framerate) {
265
- $info['quicktime']['video']['frame_rate'] = $framerate;
266
- $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate'];
267
- }
268
- if ($isVideo && $framecount) {
269
- $info['quicktime']['video']['frame_count'] = $framecount;
270
- }
271
- break;
272
-
273
-
274
- case 'aART': // Album ARTist
275
- case 'catg': // CaTeGory
276
- case 'covr': // COVeR artwork
277
- case 'cpil': // ComPILation
278
- case 'cprt': // CoPyRighT
279
- case 'desc': // DESCription
280
- case 'disk': // DISK number
281
- case 'egid': // Episode Global ID
282
- case 'gnre': // GeNRE
283
- case 'keyw': // KEYWord
284
- case 'ldes':
285
- case 'pcst': // PodCaST
286
- case 'pgap': // GAPless Playback
287
- case 'purd': // PURchase Date
288
- case 'purl': // Podcast URL
289
- case 'rati':
290
- case 'rndu':
291
- case 'rpdu':
292
- case 'rtng': // RaTiNG
293
- case 'stik':
294
- case 'tmpo': // TeMPO (BPM)
295
- case 'trkn': // TRacK Number
296
- case 'tves': // TV EpiSode
297
- case 'tvnn': // TV Network Name
298
- case 'tvsh': // TV SHow Name
299
- case 'tvsn': // TV SeasoN
300
- case 'akID': // iTunes store account type
301
- case 'apID':
302
- case 'atID':
303
- case 'cmID':
304
- case 'cnID':
305
- case 'geID':
306
- case 'plID':
307
- case 'sfID': // iTunes store country
308
- case '�alb': // ALBum
309
- case '�art': // ARTist
310
- case '�ART':
311
- case '�aut':
312
- case '�cmt': // CoMmenT
313
- case '�com': // COMposer
314
- case '�cpy':
315
- case '�day': // content created year
316
- case '�dir':
317
- case '�ed1':
318
- case '�ed2':
319
- case '�ed3':
320
- case '�ed4':
321
- case '�ed5':
322
- case '�ed6':
323
- case '�ed7':
324
- case '�ed8':
325
- case '�ed9':
326
- case '�enc':
327
- case '�fmt':
328
- case '�gen': // GENre
329
- case '�grp': // GRouPing
330
- case '�hst':
331
- case '�inf':
332
- case '�lyr': // LYRics
333
- case '�mak':
334
- case '�mod':
335
- case '�nam': // full NAMe
336
- case '�ope':
337
- case '�PRD':
338
- case '�prd':
339
- case '�prf':
340
- case '�req':
341
- case '�src':
342
- case '�swr':
343
- case '�too': // encoder
344
- case '�trk': // TRacK
345
- case '�url':
346
- case '�wrn':
347
- case '�wrt': // WRiTer
348
- case '----': // itunes specific
349
- if ($atom_parent == 'udta') {
350
- // User data atom handler
351
- $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
352
- $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
353
- $atom_structure['data'] = substr($atom_data, 4);
354
-
355
- $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
356
- if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
357
- $info['comments']['language'][] = $atom_structure['language'];
358
- }
359
- } else {
360
- // Apple item list box atom handler
361
- $atomoffset = 0;
362
- if (substr($atom_data, 2, 2) == "\x10\xB5") {
363
- // not sure what it means, but observed on iPhone4 data.
364
- // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data
365
- while ($atomoffset < strlen($atom_data)) {
366
- $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2));
367
- $boxsmalltype = substr($atom_data, $atomoffset + 2, 2);
368
- $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize);
369
- switch ($boxsmalltype) {
370
- case "\x10\xB5":
371
- $atom_structure['data'] = $boxsmalldata;
372
- break;
373
- default:
374
- $info['warning'][] = 'Unknown QuickTime smallbox type: "'.getid3_lib::PrintHexBytes($boxsmalltype).'" at offset '.$baseoffset;
375
- $atom_structure['data'] = $atom_data;
376
- break;
377
- }
378
- $atomoffset += (4 + $boxsmallsize);
379
- }
380
- } else {
381
- while ($atomoffset < strlen($atom_data)) {
382
- $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4));
383
- $boxtype = substr($atom_data, $atomoffset + 4, 4);
384
- $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8);
385
-
386
- switch ($boxtype) {
387
- case 'mean':
388
- case 'name':
389
- $atom_structure[$boxtype] = substr($boxdata, 4);
390
- break;
391
-
392
- case 'data':
393
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1));
394
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3));
395
- switch ($atom_structure['flags_raw']) {
396
- case 0: // data flag
397
- case 21: // tmpo/cpil flag
398
- switch ($atomname) {
399
- case 'cpil':
400
- case 'pcst':
401
- case 'pgap':
402
- $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
403
- break;
404
-
405
- case 'tmpo':
406
- $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2));
407
- break;
408
-
409
- case 'disk':
410
- case 'trkn':
411
- $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2));
412
- $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2));
413
- $atom_structure['data'] = empty($num) ? '' : $num;
414
- $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total;
415
- break;
416
-
417
- case 'gnre':
418
- $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
419
- $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1);
420
- break;
421
-
422
- case 'rtng':
423
- $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
424
- $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]);
425
- break;
426
-
427
- case 'stik':
428
- $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
429
- $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]);
430
- break;
431
-
432
- case 'sfID':
433
- $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
434
- $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]);
435
- break;
436
-
437
- case 'egid':
438
- case 'purl':
439
- $atom_structure['data'] = substr($boxdata, 8);
440
- break;
441
-
442
- default:
443
- $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
444
- }
445
- break;
446
-
447
- case 1: // text flag
448
- case 13: // image flag
449
- default:
450
- $atom_structure['data'] = substr($boxdata, 8);
451
- break;
452
-
453
- }
454
- break;
455
-
456
- default:
457
- $info['warning'][] = 'Unknown QuickTime box type: "'.getid3_lib::PrintHexBytes($boxtype).'" at offset '.$baseoffset;
458
- $atom_structure['data'] = $atom_data;
459
-
460
- }
461
- $atomoffset += $boxsize;
462
- }
463
- }
464
- }
465
- $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']);
466
- break;
467
-
468
-
469
- case 'play': // auto-PLAY atom
470
- $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
471
-
472
- $info['quicktime']['autoplay'] = $atom_structure['autoplay'];
473
- break;
474
-
475
-
476
- case 'WLOC': // Window LOCation atom
477
- $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
478
- $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
479
- break;
480
-
481
-
482
- case 'LOOP': // LOOPing atom
483
- case 'SelO': // play SELection Only atom
484
- case 'AllF': // play ALL Frames atom
485
- $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
486
- break;
487
-
488
-
489
- case 'name': //
490
- case 'MCPS': // Media Cleaner PRo
491
- case '@PRM': // adobe PReMiere version
492
- case '@PRQ': // adobe PRemiere Quicktime version
493
- $atom_structure['data'] = $atom_data;
494
- break;
495
-
496
-
497
- case 'cmvd': // Compressed MooV Data atom
498
- // Code by ubergeek�ubergeek*tv based on information from
499
- // http://developer.apple.com/quicktime/icefloe/dispatch012.html
500
- $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
501
-
502
- $CompressedFileData = substr($atom_data, 4);
503
- if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
504
- $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms);
505
- } else {
506
- $info['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atom_structure['offset'];
507
- }
508
- break;
509
-
510
-
511
- case 'dcom': // Data COMpression atom
512
- $atom_structure['compression_id'] = $atom_data;
513
- $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data);
514
- break;
515
-
516
-
517
- case 'rdrf': // Reference movie Data ReFerence atom
518
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
519
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
520
- $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001);
521
-
522
- $atom_structure['reference_type_name'] = substr($atom_data, 4, 4);
523
- $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
524
- switch ($atom_structure['reference_type_name']) {
525
- case 'url ':
526
- $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12));
527
- break;
528
-
529
- case 'alis':
530
- $atom_structure['file_alias'] = substr($atom_data, 12);
531
- break;
532
-
533
- case 'rsrc':
534
- $atom_structure['resource_alias'] = substr($atom_data, 12);
535
- break;
536
-
537
- default:
538
- $atom_structure['data'] = substr($atom_data, 12);
539
- break;
540
- }
541
- break;
542
-
543
-
544
- case 'rmqu': // Reference Movie QUality atom
545
- $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
546
- break;
547
-
548
-
549
- case 'rmcs': // Reference Movie Cpu Speed atom
550
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
551
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
552
- $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
553
- break;
554
-
555
-
556
- case 'rmvc': // Reference Movie Version Check atom
557
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
558
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
559
- $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4);
560
- $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
561
- $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
562
- $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
563
- break;
564
-
565
-
566
- case 'rmcd': // Reference Movie Component check atom
567
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
568
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
569
- $atom_structure['component_type'] = substr($atom_data, 4, 4);
570
- $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
571
- $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
572
- $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
573
- $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
574
- $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4));
575
- break;
576
-
577
-
578
- case 'rmdr': // Reference Movie Data Rate atom
579
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
580
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
581
- $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
582
-
583
- $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
584
- break;
585
-
586
-
587
- case 'rmla': // Reference Movie Language Atom
588
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
589
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
590
- $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
591
-
592
- $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
593
- if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
594
- $info['comments']['language'][] = $atom_structure['language'];
595
- }
596
- break;
597
-
598
-
599
- case 'rmla': // Reference Movie Language Atom
600
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
601
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
602
- $atom_structure['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
603
- break;
604
-
605
-
606
- case 'ptv ': // Print To Video - defines a movie's full screen mode
607
- // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
608
- $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
609
- $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000
610
- $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000
611
- $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1));
612
- $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1));
613
-
614
- $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
615
- $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag'];
616
-
617
- $ptv_lookup[0] = 'normal';
618
- $ptv_lookup[1] = 'double';
619
- $ptv_lookup[2] = 'half';
620
- $ptv_lookup[3] = 'full';
621
- $ptv_lookup[4] = 'current';
622
- if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
623
- $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
624
- } else {
625
- $info['warning'][] = 'unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')';
626
- }
627
- break;
628
-
629
-
630
- case 'stsd': // Sample Table Sample Description atom
631
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
632
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
633
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
634
- $stsdEntriesDataOffset = 8;
635
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
636
- $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4));
637
- $stsdEntriesDataOffset += 4;
638
- $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4);
639
- $stsdEntriesDataOffset += 4;
640
- $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6));
641
- $stsdEntriesDataOffset += 6;
642
- $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2));
643
- $stsdEntriesDataOffset += 2;
644
- $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
645
- $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
646
-
647
- $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2));
648
- $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2));
649
- $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4);
650
-
651
- switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
652
-
653
- case "\x00\x00\x00\x00":
654
- // audio atom
655
- $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2));
656
- $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2));
657
- $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2));
658
- $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2));
659
- $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4));
660
-
661
- switch ($atom_structure['sample_description_table'][$i]['data_format']) {
662
- case 'avc1':
663
- case 'mp4v':
664
- $info['fileformat'] = 'mp4';
665
- $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
666
- //$info['warning'][] = 'This version of getID3() ['.$this->getid3->version().'] does not fully support MPEG-4 audio/video streams'; // 2011-02-18: why am I warning about this again? What's not supported?
667
- break;
668
-
669
- case 'qtvr':
670
- $info['video']['dataformat'] = 'quicktimevr';
671
- break;
672
-
673
- case 'mp4a':
674
- default:
675
- $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
676
- $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
677
- $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels'];
678
- $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
679
- $info['audio']['codec'] = $info['quicktime']['audio']['codec'];
680
- $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate'];
681
- $info['audio']['channels'] = $info['quicktime']['audio']['channels'];
682
- $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth'];
683
- switch ($atom_structure['sample_description_table'][$i]['data_format']) {
684
- case 'raw ': // PCM
685
- case 'alac': // Apple Lossless Audio Codec
686
- $info['audio']['lossless'] = true;
687
- break;
688
- default:
689
- $info['audio']['lossless'] = false;
690
- break;
691
- }
692
- break;
693
- }
694
- break;
695
-
696
- default:
697
- switch ($atom_structure['sample_description_table'][$i]['data_format']) {
698
- case 'mp4s':
699
- $info['fileformat'] = 'mp4';
700
- break;
701
-
702
- default:
703
- // video atom
704
- $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4));
705
- $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4));
706
- $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2));
707
- $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2));
708
- $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4));
709
- $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
710
- $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4));
711
- $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2));
712
- $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1));
713
- $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']);
714
- $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2));
715
- $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2));
716
-
717
- $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
718
- $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
719
-
720
- if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
721
- $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
722
- $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
723
- $info['quicktime']['video']['codec'] = (($atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']);
724
- $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
725
- $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
726
-
727
- $info['video']['codec'] = $info['quicktime']['video']['codec'];
728
- $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth'];
729
- }
730
- $info['video']['lossless'] = false;
731
- $info['video']['pixel_aspect_ratio'] = (float) 1;
732
- break;
733
- }
734
- break;
735
- }
736
- switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
737
- case 'mp4a':
738
- $info['audio']['dataformat'] = 'mp4';
739
- $info['quicktime']['audio']['codec'] = 'mp4';
740
- break;
741
-
742
- case '3ivx':
743
- case '3iv1':
744
- case '3iv2':
745
- $info['video']['dataformat'] = '3ivx';
746
- break;
747
-
748
- case 'xvid':
749
- $info['video']['dataformat'] = 'xvid';
750
- break;
751
-
752
- case 'mp4v':
753
- $info['video']['dataformat'] = 'mpeg4';
754
- break;
755
-
756
- case 'divx':
757
- case 'div1':
758
- case 'div2':
759
- case 'div3':
760
- case 'div4':
761
- case 'div5':
762
- case 'div6':
763
- $info['video']['dataformat'] = 'divx';
764
- break;
765
-
766
- default:
767
- // do nothing
768
- break;
769
- }
770
- unset($atom_structure['sample_description_table'][$i]['data']);
771
- }
772
- break;
773
-
774
-
775
- case 'stts': // Sample Table Time-to-Sample atom
776
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
777
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
778
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
779
- $sttsEntriesDataOffset = 8;
780
- //$FrameRateCalculatorArray = array();
781
- $frames_count = 0;
782
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
783
- $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
784
- $sttsEntriesDataOffset += 4;
785
- $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
786
- $sttsEntriesDataOffset += 4;
787
-
788
- $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count'];
789
-
790
- // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
791
- //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
792
- // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
793
- // if ($stts_new_framerate <= 60) {
794
- // // some atoms have durations of "1" giving a very large framerate, which probably is not right
795
- // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate);
796
- // }
797
- //}
798
- //
799
- //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
800
- }
801
- $info['quicktime']['stts_framecount'][] = $frames_count;
802
- //$sttsFramesTotal = 0;
803
- //$sttsSecondsTotal = 0;
804
- //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
805
- // if (($frames_per_second > 60) || ($frames_per_second < 1)) {
806
- // // not video FPS information, probably audio information
807
- // $sttsFramesTotal = 0;
808
- // $sttsSecondsTotal = 0;
809
- // break;
810
- // }
811
- // $sttsFramesTotal += $frame_count;
812
- // $sttsSecondsTotal += $frame_count / $frames_per_second;
813
- //}
814
- //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
815
- // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) {
816
- // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
817
- // }
818
- //}
819
- break;
820
-
821
-
822
- case 'stss': // Sample Table Sync Sample (key frames) atom
823
- if ($ParseAllPossibleAtoms) {
824
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
825
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
826
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
827
- $stssEntriesDataOffset = 8;
828
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
829
- $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4));
830
- $stssEntriesDataOffset += 4;
831
- }
832
- }
833
- break;
834
-
835
-
836
- case 'stsc': // Sample Table Sample-to-Chunk atom
837
- if ($ParseAllPossibleAtoms) {
838
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
839
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
840
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
841
- $stscEntriesDataOffset = 8;
842
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
843
- $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
844
- $stscEntriesDataOffset += 4;
845
- $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
846
- $stscEntriesDataOffset += 4;
847
- $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
848
- $stscEntriesDataOffset += 4;
849
- }
850
- }
851
- break;
852
-
853
-
854
- case 'stsz': // Sample Table SiZe atom
855
- if ($ParseAllPossibleAtoms) {
856
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
857
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
858
- $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
859
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
860
- $stszEntriesDataOffset = 12;
861
- if ($atom_structure['sample_size'] == 0) {
862
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
863
- $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4));
864
- $stszEntriesDataOffset += 4;
865
- }
866
- }
867
- }
868
- break;
869
-
870
-
871
- case 'stco': // Sample Table Chunk Offset atom
872
- if ($ParseAllPossibleAtoms) {
873
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
874
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
875
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
876
- $stcoEntriesDataOffset = 8;
877
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
878
- $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4));
879
- $stcoEntriesDataOffset += 4;
880
- }
881
- }
882
- break;
883
-
884
-
885
- case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
886
- if ($ParseAllPossibleAtoms) {
887
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
888
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
889
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
890
- $stcoEntriesDataOffset = 8;
891
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
892
- $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8));
893
- $stcoEntriesDataOffset += 8;
894
- }
895
- }
896
- break;
897
-
898
-
899
- case 'dref': // Data REFerence atom
900
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
901
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
902
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
903
- $drefDataOffset = 8;
904
- for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
905
- $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4));
906
- $drefDataOffset += 4;
907
- $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4);
908
- $drefDataOffset += 4;
909
- $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1));
910
- $drefDataOffset += 1;
911
- $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000
912
- $drefDataOffset += 3;
913
- $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
914
- $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
915
-
916
- $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001);
917
- }
918
- break;
919
-
920
-
921
- case 'gmin': // base Media INformation atom
922
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
923
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
924
- $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
925
- $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
926
- $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
927
- $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
928
- $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2));
929
- $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
930
- break;
931
-
932
-
933
- case 'smhd': // Sound Media information HeaDer atom
934
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
935
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
936
- $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
937
- $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
938
- break;
939
-
940
-
941
- case 'vmhd': // Video Media information HeaDer atom
942
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
943
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
944
- $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
945
- $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
946
- $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
947
- $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
948
-
949
- $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001);
950
- break;
951
-
952
-
953
- case 'hdlr': // HanDLeR reference atom
954
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
955
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
956
- $atom_structure['component_type'] = substr($atom_data, 4, 4);
957
- $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
958
- $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
959
- $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
960
- $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
961
- $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24));
962
-
963
- if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) {
964
- $info['video']['dataformat'] = 'quicktimevr';
965
- }
966
- break;
967
-
968
-
969
- case 'mdhd': // MeDia HeaDer atom
970
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
971
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
972
- $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
973
- $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
974
- $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
975
- $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
976
- $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2));
977
- $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2));
978
-
979
- if ($atom_structure['time_scale'] == 0) {
980
- $info['error'][] = 'Corrupt Quicktime file: mdhd.time_scale == zero';
981
- return false;
982
- }
983
- $info['quicktime']['time_scale'] = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
984
-
985
- $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
986
- $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
987
- $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
988
- $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
989
- if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
990
- $info['comments']['language'][] = $atom_structure['language'];
991
- }
992
- break;
993
-
994
-
995
- case 'pnot': // Preview atom
996
- $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format"
997
- $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00
998
- $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT'
999
- $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01
1000
-
1001
- $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']);
1002
- break;
1003
-
1004
-
1005
- case 'crgn': // Clipping ReGioN atom
1006
- $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box,
1007
- $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields
1008
- $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region.
1009
- break;
1010
-
1011
-
1012
- case 'load': // track LOAD settings atom
1013
- $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
1014
- $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1015
- $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
1016
- $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1017
-
1018
- $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020);
1019
- $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100);
1020
- break;
1021
-
1022
-
1023
- case 'tmcd': // TiMe CoDe atom
1024
- case 'chap': // CHAPter list atom
1025
- case 'sync': // SYNChronization atom
1026
- case 'scpt': // tranSCriPT atom
1027
- case 'ssrc': // non-primary SouRCe atom
1028
- for ($i = 0; $i < (strlen($atom_data) % 4); $i++) {
1029
- $atom_structure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $i * 4, 4));
1030
- }
1031
- break;
1032
-
1033
-
1034
- case 'elst': // Edit LiST atom
1035
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1036
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
1037
- $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1038
- for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) {
1039
- $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4));
1040
- $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4));
1041
- $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4));
1042
- }
1043
- break;
1044
-
1045
-
1046
- case 'kmat': // compressed MATte atom
1047
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1048
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
1049
- $atom_structure['matte_data_raw'] = substr($atom_data, 4);
1050
- break;
1051
-
1052
-
1053
- case 'ctab': // Color TABle atom
1054
- $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000
1055
- $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000
1056
- $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1;
1057
- for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) {
1058
- $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2));
1059
- $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2));
1060
- $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2));
1061
- $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2));
1062
- }
1063
- break;
1064
-
1065
-
1066
- case 'mvhd': // MoVie HeaDer atom
1067
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1068
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
1069
- $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1070
- $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
1071
- $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1072
- $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
1073
- $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4));
1074
- $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2));
1075
- $atom_structure['reserved'] = substr($atom_data, 26, 10);
1076
- $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4));
1077
- $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
1078
- $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4));
1079
- $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4));
1080
- $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
1081
- $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4));
1082
- $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4));
1083
- $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
1084
- $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4));
1085
- $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4));
1086
- $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4));
1087
- $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4));
1088
- $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4));
1089
- $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4));
1090
- $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4));
1091
- $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4));
1092
-
1093
- if ($atom_structure['time_scale'] == 0) {
1094
- $info['error'][] = 'Corrupt Quicktime file: mvhd.time_scale == zero';
1095
- return false;
1096
- }
1097
- $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
1098
- $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
1099
- $info['quicktime']['time_scale'] = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
1100
- $info['quicktime']['display_scale'] = $atom_structure['matrix_a'];
1101
- $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
1102
- break;
1103
-
1104
-
1105
- case 'tkhd': // TracK HeaDer atom
1106
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1107
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
1108
- $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1109
- $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
1110
- $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1111
- $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
1112
- $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
1113
- $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8));
1114
- $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2));
1115
- $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2));
1116
- $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2));
1117
- $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2));
1118
- $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
1119
- $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4));
1120
- $atom_structure['matrix_u'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4));
1121
- $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
1122
- $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4));
1123
- $atom_structure['matrix_v'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4));
1124
- $atom_structure['matrix_x'] = getid3_lib::FixedPoint2_30(substr($atom_data, 64, 4));
1125
- $atom_structure['matrix_y'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4));
1126
- $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4));
1127
- $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4));
1128
- $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4));
1129
-
1130
- $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001);
1131
- $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002);
1132
- $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004);
1133
- $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008);
1134
- $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
1135
- $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
1136
-
1137
- if ($atom_structure['flags']['enabled'] == 1) {
1138
- if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) {
1139
- $info['video']['resolution_x'] = $atom_structure['width'];
1140
- $info['video']['resolution_y'] = $atom_structure['height'];
1141
- }
1142
- $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']);
1143
- $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']);
1144
- $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
1145
- $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
1146
- } else {
1147
- if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); }
1148
- if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); }
1149
- if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); }
1150
- }
1151
- break;
1152
-
1153
-
1154
- case 'iods': // Initial Object DeScriptor atom
1155
- // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h
1156
- // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html
1157
- $offset = 0;
1158
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1159
- $offset += 1;
1160
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3));
1161
- $offset += 3;
1162
- $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1163
- $offset += 1;
1164
- $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
1165
- //$offset already adjusted by quicktime_read_mp4_descr_length()
1166
- $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2));
1167
- $offset += 2;
1168
- $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1169
- $offset += 1;
1170
- $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1171
- $offset += 1;
1172
- $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1173
- $offset += 1;
1174
- $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1175
- $offset += 1;
1176
- $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1177
- $offset += 1;
1178
-
1179
- $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields
1180
- for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) {
1181
- $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1182
- $offset += 1;
1183
- $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
1184
- //$offset already adjusted by quicktime_read_mp4_descr_length()
1185
- $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4));
1186
- $offset += 4;
1187
- }
1188
-
1189
- $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']);
1190
- $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']);
1191
- break;
1192
-
1193
- case 'ftyp': // FileTYPe (?) atom (for MP4 it seems)
1194
- $atom_structure['signature'] = substr($atom_data, 0, 4);
1195
- $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1196
- $atom_structure['fourcc'] = substr($atom_data, 8, 4);
1197
- break;
1198
-
1199
- case 'mdat': // Media DATa atom
1200
- case 'free': // FREE space atom
1201
- case 'skip': // SKIP atom
1202
- case 'wide': // 64-bit expansion placeholder atom
1203
- // 'mdat' data is too big to deal with, contains no useful metadata
1204
- // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
1205
-
1206
- // When writing QuickTime files, it is sometimes necessary to update an atom's size.
1207
- // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
1208
- // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
1209
- // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
1210
- // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
1211
- // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
1212
- // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
1213
- break;
1214
-
1215
-
1216
- case 'nsav': // NoSAVe atom
1217
- // http://developer.apple.com/technotes/tn/tn2038.html
1218
- $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
1219
- break;
1220
-
1221
- case 'ctyp': // Controller TYPe atom (seen on QTVR)
1222
- // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
1223
- // some controller names are:
1224
- // 0x00 + 'std' for linear movie
1225
- // 'none' for no controls
1226
- $atom_structure['ctyp'] = substr($atom_data, 0, 4);
1227
- $info['quicktime']['controller'] = $atom_structure['ctyp'];
1228
- switch ($atom_structure['ctyp']) {
1229
- case 'qtvr':
1230
- $info['video']['dataformat'] = 'quicktimevr';
1231
- break;
1232
- }
1233
- break;
1234
-
1235
- case 'pano': // PANOrama track (seen on QTVR)
1236
- $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
1237
- break;
1238
-
1239
- case 'hint': // HINT track
1240
- case 'hinf': //
1241
- case 'hinv': //
1242
- case 'hnti': //
1243
- $info['quicktime']['hinting'] = true;
1244
- break;
1245
-
1246
- case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
1247
- for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) {
1248
- $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
1249
- }
1250
- break;
1251
-
1252
-
1253
- // Observed-but-not-handled atom types are just listed here to prevent warnings being generated
1254
- case 'FXTC': // Something to do with Adobe After Effects (?)
1255
- case 'PrmA':
1256
- case 'code':
1257
- case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
1258
- case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html
1259
- // tapt seems to be used to compute the video size [http://www.getid3.org/phpBB3/viewtopic.php?t=838]
1260
- // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html
1261
- // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html
1262
- case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1263
- case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1264
- case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1265
- case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1266
- //$atom_structure['data'] = $atom_data;
1267
- break;
1268
-
1269
- case '�xyz': // GPS latitude+longitude+altitude
1270
- $atom_structure['data'] = $atom_data;
1271
- if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) {
1272
- @list($all, $latitude, $longitude, $altitude) = $matches;
1273
- $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude);
1274
- $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude);
1275
- if (!empty($altitude)) {
1276
- $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude);
1277
- }
1278
- } else {
1279
- $info['warning'][] = 'QuickTime atom "�xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.';
1280
- }
1281
- break;
1282
-
1283
- case 'NCDT':
1284
- // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1285
- // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
1286
- $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms);
1287
- break;
1288
- case 'NCTH': // Nikon Camera THumbnail image
1289
- case 'NCVW': // Nikon Camera preVieW image
1290
- // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1291
- if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) {
1292
- $atom_structure['data'] = $atom_data;
1293
- $atom_structure['image_mime'] = 'image/jpeg';
1294
- $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image'));
1295
- $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']);
1296
- }
1297
- break;
1298
- case 'NCHD': // MakerNoteVersion
1299
- // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1300
- $atom_structure['data'] = $atom_data;
1301
- break;
1302
- case 'NCTG': // NikonTags
1303
- // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
1304
- $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data);
1305
- break;
1306
- case 'NCDB': // NikonTags
1307
- // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1308
- $atom_structure['data'] = $atom_data;
1309
- break;
1310
-
1311
- case "\x00\x00\x00\x00":
1312
- case 'meta': // METAdata atom
1313
- // some kind of metacontainer, may contain a big data dump such as:
1314
- // mdta keys mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst data DEApple 0 (data DE2011-05-11T17:54:04+0200 2 *data DE+52.4936+013.3897+040.247/ data DE4.3.1 data DEiPhone 4
1315
- // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
1316
-
1317
- $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1318
- $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
1319
- $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
1320
- //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
1321
- break;
1322
-
1323
- case 'data': // metaDATA atom
1324
- // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data
1325
- $atom_structure['language'] = substr($atom_data, 4 + 0, 2);
1326
- $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2));
1327
- $atom_structure['data'] = substr($atom_data, 4 + 4);
1328
- break;
1329
-
1330
- default:
1331
- $info['warning'][] = 'Unknown QuickTime atom type: "'.getid3_lib::PrintHexBytes($atomname).'" at offset '.$baseoffset;
1332
- $atom_structure['data'] = $atom_data;
1333
- break;
1334
- }
1335
- array_pop($atomHierarchy);
1336
- return $atom_structure;
1337
- }
1338
-
1339
- function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
1340
- //echo 'QuicktimeParseContainerAtom('.substr($atom_data, 4, 4).') @ '.$baseoffset.'<br><br>';
1341
- $atom_structure = false;
1342
- $subatomoffset = 0;
1343
- $subatomcounter = 0;
1344
- if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) {
1345
- return false;
1346
- }
1347
- while ($subatomoffset < strlen($atom_data)) {
1348
- $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4));
1349
- $subatomname = substr($atom_data, $subatomoffset + 4, 4);
1350
- $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8);
1351
- if ($subatomsize == 0) {
1352
- // Furthermore, for historical reasons the list of atoms is optionally
1353
- // terminated by a 32-bit integer set to 0. If you are writing a program
1354
- // to read user data atoms, you should allow for the terminating 0.
1355
- return $atom_structure;
1356
- }
1357
-
1358
- $atom_structure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms);
1359
-
1360
- $subatomoffset += $subatomsize;
1361
- $subatomcounter++;
1362
- }
1363
- return $atom_structure;
1364
- }
1365
-
1366
-
1367
- function quicktime_read_mp4_descr_length($data, &$offset) {
1368
- // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html
1369
- $num_bytes = 0;
1370
- $length = 0;
1371
- do {
1372
- $b = ord(substr($data, $offset++, 1));
1373
- $length = ($length << 7) | ($b & 0x7F);
1374
- } while (($b & 0x80) && ($num_bytes++ < 4));
1375
- return $length;
1376
- }
1377
-
1378
-
1379
- function QuicktimeLanguageLookup($languageid) {
1380
- static $QuicktimeLanguageLookup = array();
1381
- if (empty($QuicktimeLanguageLookup)) {
1382
- $QuicktimeLanguageLookup[0] = 'English';
1383
- $QuicktimeLanguageLookup[1] = 'French';
1384
- $QuicktimeLanguageLookup[2] = 'German';
1385
- $QuicktimeLanguageLookup[3] = 'Italian';
1386
- $QuicktimeLanguageLookup[4] = 'Dutch';
1387
- $QuicktimeLanguageLookup[5] = 'Swedish';
1388
- $QuicktimeLanguageLookup[6] = 'Spanish';
1389
- $QuicktimeLanguageLookup[7] = 'Danish';
1390
- $QuicktimeLanguageLookup[8] = 'Portuguese';
1391
- $QuicktimeLanguageLookup[9] = 'Norwegian';
1392
- $QuicktimeLanguageLookup[10] = 'Hebrew';
1393
- $QuicktimeLanguageLookup[11] = 'Japanese';
1394
- $QuicktimeLanguageLookup[12] = 'Arabic';
1395
- $QuicktimeLanguageLookup[13] = 'Finnish';
1396
- $QuicktimeLanguageLookup[14] = 'Greek';
1397
- $QuicktimeLanguageLookup[15] = 'Icelandic';
1398
- $QuicktimeLanguageLookup[16] = 'Maltese';
1399
- $QuicktimeLanguageLookup[17] = 'Turkish';
1400
- $QuicktimeLanguageLookup[18] = 'Croatian';
1401
- $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)';
1402
- $QuicktimeLanguageLookup[20] = 'Urdu';
1403
- $QuicktimeLanguageLookup[21] = 'Hindi';
1404
- $QuicktimeLanguageLookup[22] = 'Thai';
1405
- $QuicktimeLanguageLookup[23] = 'Korean';
1406
- $QuicktimeLanguageLookup[24] = 'Lithuanian';
1407
- $QuicktimeLanguageLookup[25] = 'Polish';
1408
- $QuicktimeLanguageLookup[26] = 'Hungarian';
1409
- $QuicktimeLanguageLookup[27] = 'Estonian';
1410
- $QuicktimeLanguageLookup[28] = 'Lettish';
1411
- $QuicktimeLanguageLookup[28] = 'Latvian';
1412
- $QuicktimeLanguageLookup[29] = 'Saamisk';
1413
- $QuicktimeLanguageLookup[29] = 'Lappish';
1414
- $QuicktimeLanguageLookup[30] = 'Faeroese';
1415
- $QuicktimeLanguageLookup[31] = 'Farsi';
1416
- $QuicktimeLanguageLookup[31] = 'Persian';
1417
- $QuicktimeLanguageLookup[32] = 'Russian';
1418
- $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)';
1419
- $QuicktimeLanguageLookup[34] = 'Flemish';
1420
- $QuicktimeLanguageLookup[35] = 'Irish';
1421
- $QuicktimeLanguageLookup[36] = 'Albanian';
1422
- $QuicktimeLanguageLookup[37] = 'Romanian';
1423
- $QuicktimeLanguageLookup[38] = 'Czech';
1424
- $QuicktimeLanguageLookup[39] = 'Slovak';
1425
- $QuicktimeLanguageLookup[40] = 'Slovenian';
1426
- $QuicktimeLanguageLookup[41] = 'Yiddish';
1427
- $QuicktimeLanguageLookup[42] = 'Serbian';
1428
- $QuicktimeLanguageLookup[43] = 'Macedonian';
1429
- $QuicktimeLanguageLookup[44] = 'Bulgarian';
1430
- $QuicktimeLanguageLookup[45] = 'Ukrainian';
1431
- $QuicktimeLanguageLookup[46] = 'Byelorussian';
1432
- $QuicktimeLanguageLookup[47] = 'Uzbek';
1433
- $QuicktimeLanguageLookup[48] = 'Kazakh';
1434
- $QuicktimeLanguageLookup[49] = 'Azerbaijani';
1435
- $QuicktimeLanguageLookup[50] = 'AzerbaijanAr';
1436
- $QuicktimeLanguageLookup[51] = 'Armenian';
1437
- $QuicktimeLanguageLookup[52] = 'Georgian';
1438
- $QuicktimeLanguageLookup[53] = 'Moldavian';
1439
- $QuicktimeLanguageLookup[54] = 'Kirghiz';
1440
- $QuicktimeLanguageLookup[55] = 'Tajiki';
1441
- $QuicktimeLanguageLookup[56] = 'Turkmen';
1442
- $QuicktimeLanguageLookup[57] = 'Mongolian';
1443
- $QuicktimeLanguageLookup[58] = 'MongolianCyr';
1444
- $QuicktimeLanguageLookup[59] = 'Pashto';
1445
- $QuicktimeLanguageLookup[60] = 'Kurdish';
1446
- $QuicktimeLanguageLookup[61] = 'Kashmiri';
1447
- $QuicktimeLanguageLookup[62] = 'Sindhi';
1448
- $QuicktimeLanguageLookup[63] = 'Tibetan';
1449
- $QuicktimeLanguageLookup[64] = 'Nepali';
1450
- $QuicktimeLanguageLookup[65] = 'Sanskrit';
1451
- $QuicktimeLanguageLookup[66] = 'Marathi';
1452
- $QuicktimeLanguageLookup[67] = 'Bengali';
1453
- $QuicktimeLanguageLookup[68] = 'Assamese';
1454
- $QuicktimeLanguageLookup[69] = 'Gujarati';
1455
- $QuicktimeLanguageLookup[70] = 'Punjabi';
1456
- $QuicktimeLanguageLookup[71] = 'Oriya';
1457
- $QuicktimeLanguageLookup[72] = 'Malayalam';
1458
- $QuicktimeLanguageLookup[73] = 'Kannada';
1459
- $QuicktimeLanguageLookup[74] = 'Tamil';
1460
- $QuicktimeLanguageLookup[75] = 'Telugu';
1461
- $QuicktimeLanguageLookup[76] = 'Sinhalese';
1462
- $QuicktimeLanguageLookup[77] = 'Burmese';
1463
- $QuicktimeLanguageLookup[78] = 'Khmer';
1464
- $QuicktimeLanguageLookup[79] = 'Lao';
1465
- $QuicktimeLanguageLookup[80] = 'Vietnamese';
1466
- $QuicktimeLanguageLookup[81] = 'Indonesian';
1467
- $QuicktimeLanguageLookup[82] = 'Tagalog';
1468
- $QuicktimeLanguageLookup[83] = 'MalayRoman';
1469
- $QuicktimeLanguageLookup[84] = 'MalayArabic';
1470
- $QuicktimeLanguageLookup[85] = 'Amharic';
1471
- $QuicktimeLanguageLookup[86] = 'Tigrinya';
1472
- $QuicktimeLanguageLookup[87] = 'Galla';
1473
- $QuicktimeLanguageLookup[87] = 'Oromo';
1474
- $QuicktimeLanguageLookup[88] = 'Somali';
1475
- $QuicktimeLanguageLookup[89] = 'Swahili';
1476
- $QuicktimeLanguageLookup[90] = 'Ruanda';
1477
- $QuicktimeLanguageLookup[91] = 'Rundi';
1478
- $QuicktimeLanguageLookup[92] = 'Chewa';
1479
- $QuicktimeLanguageLookup[93] = 'Malagasy';
1480
- $QuicktimeLanguageLookup[94] = 'Esperanto';
1481
- $QuicktimeLanguageLookup[128] = 'Welsh';
1482
- $QuicktimeLanguageLookup[129] = 'Basque';
1483
- $QuicktimeLanguageLookup[130] = 'Catalan';
1484
- $QuicktimeLanguageLookup[131] = 'Latin';
1485
- $QuicktimeLanguageLookup[132] = 'Quechua';
1486
- $QuicktimeLanguageLookup[133] = 'Guarani';
1487
- $QuicktimeLanguageLookup[134] = 'Aymara';
1488
- $QuicktimeLanguageLookup[135] = 'Tatar';
1489
- $QuicktimeLanguageLookup[136] = 'Uighur';
1490
- $QuicktimeLanguageLookup[137] = 'Dzongkha';
1491
- $QuicktimeLanguageLookup[138] = 'JavaneseRom';
1492
- }
1493
- return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid');
1494
- }
1495
-
1496
- function QuicktimeVideoCodecLookup($codecid) {
1497
- static $QuicktimeVideoCodecLookup = array();
1498
- if (empty($QuicktimeVideoCodecLookup)) {
1499
- $QuicktimeVideoCodecLookup['.SGI'] = 'SGI';
1500
- $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1';
1501
- $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2';
1502
- $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4';
1503
- $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB';
1504
- $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC';
1505
- $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG';
1506
- $QuicktimeVideoCodecLookup['b16g'] = '16Gray';
1507
- $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray';
1508
- $QuicktimeVideoCodecLookup['b48r'] = '48RGB';
1509
- $QuicktimeVideoCodecLookup['b64a'] = '64ARGB';
1510
- $QuicktimeVideoCodecLookup['base'] = 'Base';
1511
- $QuicktimeVideoCodecLookup['clou'] = 'Cloud';
1512
- $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK';
1513
- $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak';
1514
- $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG';
1515
- $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC';
1516
- $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL';
1517
- $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC';
1518
- $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL';
1519
- $QuicktimeVideoCodecLookup['fire'] = 'Fire';
1520
- $QuicktimeVideoCodecLookup['flic'] = 'FLC';
1521
- $QuicktimeVideoCodecLookup['gif '] = 'GIF';
1522
- $QuicktimeVideoCodecLookup['h261'] = 'H261';
1523
- $QuicktimeVideoCodecLookup['h263'] = 'H263';
1524
- $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4';
1525
- $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG';
1526
- $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD';
1527
- $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A';
1528
- $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B';
1529
- $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1';
1530
- $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420';
1531
- $QuicktimeVideoCodecLookup['path'] = 'Vector';
1532
- $QuicktimeVideoCodecLookup['png '] = 'PNG';
1533
- $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint';
1534
- $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX';
1535
- $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw';
1536
- $QuicktimeVideoCodecLookup['raw '] = 'RAW';
1537
- $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple';
1538
- $QuicktimeVideoCodecLookup['rpza'] = 'Video';
1539
- $QuicktimeVideoCodecLookup['smc '] = 'Graphics';
1540
- $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1';
1541
- $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3';
1542
- $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9';
1543
- $QuicktimeVideoCodecLookup['tga '] = 'Targa';
1544
- $QuicktimeVideoCodecLookup['tiff'] = 'TIFF';
1545
- $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW';
1546
- $QuicktimeVideoCodecLookup['WRLE'] = 'BMP';
1547
- $QuicktimeVideoCodecLookup['y420'] = 'YUV420';
1548
- $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo';
1549
- $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned';
1550
- $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned';
1551
- }
1552
- return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : '');
1553
- }
1554
-
1555
- function QuicktimeAudioCodecLookup($codecid) {
1556
- static $QuicktimeAudioCodecLookup = array();
1557
- if (empty($QuicktimeAudioCodecLookup)) {
1558
- $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias';
1559
- $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC';
1560
- $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1';
1561
- $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec';
1562
- $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1';
1563
- $QuicktimeAudioCodecLookup['conv'] = 'Sample Format';
1564
- $QuicktimeAudioCodecLookup['dvca'] = 'DV';
1565
- $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1';
1566
- $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer';
1567
- $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point';
1568
- $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point';
1569
- $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1';
1570
- $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer';
1571
- $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer';
1572
- $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1';
1573
- $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1';
1574
- $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1';
1575
- $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer';
1576
- $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer';
1577
- $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC';
1578
- $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM';
1579
- $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA';
1580
- $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III';
1581
- $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding';
1582
- $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice';
1583
- $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2';
1584
- $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1';
1585
- $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate';
1586
- $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate';
1587
- $QuicktimeAudioCodecLookup['raw '] = 'raw PCM';
1588
- $QuicktimeAudioCodecLookup['sour'] = 'Sound Source';
1589
- $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)';
1590
- $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II';
1591
- $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II';
1592
- $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II';
1593
- $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II';
1594
- $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)';
1595
- $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1';
1596
- }
1597
- return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : '');
1598
- }
1599
-
1600
- function QuicktimeDCOMLookup($compressionid) {
1601
- static $QuicktimeDCOMLookup = array();
1602
- if (empty($QuicktimeDCOMLookup)) {
1603
- $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate';
1604
- $QuicktimeDCOMLookup['adec'] = 'Apple Compression';
1605
- }
1606
- return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : '');
1607
- }
1608
-
1609
- function QuicktimeColorNameLookup($colordepthid) {
1610
- static $QuicktimeColorNameLookup = array();
1611
- if (empty($QuicktimeColorNameLookup)) {
1612
- $QuicktimeColorNameLookup[1] = '2-color (monochrome)';
1613
- $QuicktimeColorNameLookup[2] = '4-color';
1614
- $QuicktimeColorNameLookup[4] = '16-color';
1615
- $QuicktimeColorNameLookup[8] = '256-color';
1616
- $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)';
1617
- $QuicktimeColorNameLookup[24] = 'millions (24-bit color)';
1618
- $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)';
1619
- $QuicktimeColorNameLookup[33] = 'black & white';
1620
- $QuicktimeColorNameLookup[34] = '4-gray';
1621
- $QuicktimeColorNameLookup[36] = '16-gray';
1622
- $QuicktimeColorNameLookup[40] = '256-gray';
1623
- }
1624
- return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid');
1625
- }
1626
-
1627
- function QuicktimeSTIKLookup($stik) {
1628
- static $QuicktimeSTIKLookup = array();
1629
- if (empty($QuicktimeSTIKLookup)) {
1630
- $QuicktimeSTIKLookup[0] = 'Movie';
1631
- $QuicktimeSTIKLookup[1] = 'Normal';
1632
- $QuicktimeSTIKLookup[2] = 'Audiobook';
1633
- $QuicktimeSTIKLookup[5] = 'Whacked Bookmark';
1634
- $QuicktimeSTIKLookup[6] = 'Music Video';
1635
- $QuicktimeSTIKLookup[9] = 'Short Film';
1636
- $QuicktimeSTIKLookup[10] = 'TV Show';
1637
- $QuicktimeSTIKLookup[11] = 'Booklet';
1638
- $QuicktimeSTIKLookup[14] = 'Ringtone';
1639
- $QuicktimeSTIKLookup[21] = 'Podcast';
1640
- }
1641
- return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid');
1642
- }
1643
-
1644
- function QuicktimeIODSaudioProfileName($audio_profile_id) {
1645
- static $QuicktimeIODSaudioProfileNameLookup = array();
1646
- if (empty($QuicktimeIODSaudioProfileNameLookup)) {
1647
- $QuicktimeIODSaudioProfileNameLookup = array(
1648
- 0x00 => 'ISO Reserved (0x00)',
1649
- 0x01 => 'Main Audio Profile @ Level 1',
1650
- 0x02 => 'Main Audio Profile @ Level 2',
1651
- 0x03 => 'Main Audio Profile @ Level 3',
1652
- 0x04 => 'Main Audio Profile @ Level 4',
1653
- 0x05 => 'Scalable Audio Profile @ Level 1',
1654
- 0x06 => 'Scalable Audio Profile @ Level 2',
1655
- 0x07 => 'Scalable Audio Profile @ Level 3',
1656
- 0x08 => 'Scalable Audio Profile @ Level 4',
1657
- 0x09 => 'Speech Audio Profile @ Level 1',
1658
- 0x0A => 'Speech Audio Profile @ Level 2',
1659
- 0x0B => 'Synthetic Audio Profile @ Level 1',
1660
- 0x0C => 'Synthetic Audio Profile @ Level 2',
1661
- 0x0D => 'Synthetic Audio Profile @ Level 3',
1662
- 0x0E => 'High Quality Audio Profile @ Level 1',
1663
- 0x0F => 'High Quality Audio Profile @ Level 2',
1664
- 0x10 => 'High Quality Audio Profile @ Level 3',
1665
- 0x11 => 'High Quality Audio Profile @ Level 4',
1666
- 0x12 => 'High Quality Audio Profile @ Level 5',
1667
- 0x13 => 'High Quality Audio Profile @ Level 6',
1668
- 0x14 => 'High Quality Audio Profile @ Level 7',
1669
- 0x15 => 'High Quality Audio Profile @ Level 8',
1670
- 0x16 => 'Low Delay Audio Profile @ Level 1',
1671
- 0x17 => 'Low Delay Audio Profile @ Level 2',
1672
- 0x18 => 'Low Delay Audio Profile @ Level 3',
1673
- 0x19 => 'Low Delay Audio Profile @ Level 4',
1674
- 0x1A => 'Low Delay Audio Profile @ Level 5',
1675
- 0x1B => 'Low Delay Audio Profile @ Level 6',
1676
- 0x1C => 'Low Delay Audio Profile @ Level 7',
1677
- 0x1D => 'Low Delay Audio Profile @ Level 8',
1678
- 0x1E => 'Natural Audio Profile @ Level 1',
1679
- 0x1F => 'Natural Audio Profile @ Level 2',
1680
- 0x20 => 'Natural Audio Profile @ Level 3',
1681
- 0x21 => 'Natural Audio Profile @ Level 4',
1682
- 0x22 => 'Mobile Audio Internetworking Profile @ Level 1',
1683
- 0x23 => 'Mobile Audio Internetworking Profile @ Level 2',
1684
- 0x24 => 'Mobile Audio Internetworking Profile @ Level 3',
1685
- 0x25 => 'Mobile Audio Internetworking Profile @ Level 4',
1686
- 0x26 => 'Mobile Audio Internetworking Profile @ Level 5',
1687
- 0x27 => 'Mobile Audio Internetworking Profile @ Level 6',
1688
- 0x28 => 'AAC Profile @ Level 1',
1689
- 0x29 => 'AAC Profile @ Level 2',
1690
- 0x2A => 'AAC Profile @ Level 4',
1691
- 0x2B => 'AAC Profile @ Level 5',
1692
- 0x2C => 'High Efficiency AAC Profile @ Level 2',
1693
- 0x2D => 'High Efficiency AAC Profile @ Level 3',
1694
- 0x2E => 'High Efficiency AAC Profile @ Level 4',
1695
- 0x2F => 'High Efficiency AAC Profile @ Level 5',
1696
- 0xFE => 'Not part of MPEG-4 audio profiles',
1697
- 0xFF => 'No audio capability required',
1698
- );
1699
- }
1700
- return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private');
1701
- }
1702
-
1703
-
1704
- function QuicktimeIODSvideoProfileName($video_profile_id) {
1705
- static $QuicktimeIODSvideoProfileNameLookup = array();
1706
- if (empty($QuicktimeIODSvideoProfileNameLookup)) {
1707
- $QuicktimeIODSvideoProfileNameLookup = array(
1708
- 0x00 => 'Reserved (0x00) Profile',
1709
- 0x01 => 'Simple Profile @ Level 1',
1710
- 0x02 => 'Simple Profile @ Level 2',
1711
- 0x03 => 'Simple Profile @ Level 3',
1712
- 0x08 => 'Simple Profile @ Level 0',
1713
- 0x10 => 'Simple Scalable Profile @ Level 0',
1714
- 0x11 => 'Simple Scalable Profile @ Level 1',
1715
- 0x12 => 'Simple Scalable Profile @ Level 2',
1716
- 0x15 => 'AVC/H264 Profile',
1717
- 0x21 => 'Core Profile @ Level 1',
1718
- 0x22 => 'Core Profile @ Level 2',
1719
- 0x32 => 'Main Profile @ Level 2',
1720
- 0x33 => 'Main Profile @ Level 3',
1721
- 0x34 => 'Main Profile @ Level 4',
1722
- 0x42 => 'N-bit Profile @ Level 2',
1723
- 0x51 => 'Scalable Texture Profile @ Level 1',
1724
- 0x61 => 'Simple Face Animation Profile @ Level 1',
1725
- 0x62 => 'Simple Face Animation Profile @ Level 2',
1726
- 0x63 => 'Simple FBA Profile @ Level 1',
1727
- 0x64 => 'Simple FBA Profile @ Level 2',
1728
- 0x71 => 'Basic Animated Texture Profile @ Level 1',
1729
- 0x72 => 'Basic Animated Texture Profile @ Level 2',
1730
- 0x81 => 'Hybrid Profile @ Level 1',
1731
- 0x82 => 'Hybrid Profile @ Level 2',
1732
- 0x91 => 'Advanced Real Time Simple Profile @ Level 1',
1733
- 0x92 => 'Advanced Real Time Simple Profile @ Level 2',
1734
- 0x93 => 'Advanced Real Time Simple Profile @ Level 3',
1735
- 0x94 => 'Advanced Real Time Simple Profile @ Level 4',
1736
- 0xA1 => 'Core Scalable Profile @ Level1',
1737
- 0xA2 => 'Core Scalable Profile @ Level2',
1738
- 0xA3 => 'Core Scalable Profile @ Level3',
1739
- 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1',
1740
- 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2',
1741
- 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3',
1742
- 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4',
1743
- 0xC1 => 'Advanced Core Profile @ Level 1',
1744
- 0xC2 => 'Advanced Core Profile @ Level 2',
1745
- 0xD1 => 'Advanced Scalable Texture @ Level1',
1746
- 0xD2 => 'Advanced Scalable Texture @ Level2',
1747
- 0xE1 => 'Simple Studio Profile @ Level 1',
1748
- 0xE2 => 'Simple Studio Profile @ Level 2',
1749
- 0xE3 => 'Simple Studio Profile @ Level 3',
1750
- 0xE4 => 'Simple Studio Profile @ Level 4',
1751
- 0xE5 => 'Core Studio Profile @ Level 1',
1752
- 0xE6 => 'Core Studio Profile @ Level 2',
1753
- 0xE7 => 'Core Studio Profile @ Level 3',
1754
- 0xE8 => 'Core Studio Profile @ Level 4',
1755
- 0xF0 => 'Advanced Simple Profile @ Level 0',
1756
- 0xF1 => 'Advanced Simple Profile @ Level 1',
1757
- 0xF2 => 'Advanced Simple Profile @ Level 2',
1758
- 0xF3 => 'Advanced Simple Profile @ Level 3',
1759
- 0xF4 => 'Advanced Simple Profile @ Level 4',
1760
- 0xF5 => 'Advanced Simple Profile @ Level 5',
1761
- 0xF7 => 'Advanced Simple Profile @ Level 3b',
1762
- 0xF8 => 'Fine Granularity Scalable Profile @ Level 0',
1763
- 0xF9 => 'Fine Granularity Scalable Profile @ Level 1',
1764
- 0xFA => 'Fine Granularity Scalable Profile @ Level 2',
1765
- 0xFB => 'Fine Granularity Scalable Profile @ Level 3',
1766
- 0xFC => 'Fine Granularity Scalable Profile @ Level 4',
1767
- 0xFD => 'Fine Granularity Scalable Profile @ Level 5',
1768
- 0xFE => 'Not part of MPEG-4 Visual profiles',
1769
- 0xFF => 'No visual capability required',
1770
- );
1771
- }
1772
- return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile');
1773
- }
1774
-
1775
-
1776
- function QuicktimeContentRatingLookup($rtng) {
1777
- static $QuicktimeContentRatingLookup = array();
1778
- if (empty($QuicktimeContentRatingLookup)) {
1779
- $QuicktimeContentRatingLookup[0] = 'None';
1780
- $QuicktimeContentRatingLookup[2] = 'Clean';
1781
- $QuicktimeContentRatingLookup[4] = 'Explicit';
1782
- }
1783
- return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid');
1784
- }
1785
-
1786
- function QuicktimeStoreAccountTypeLookup($akid) {
1787
- static $QuicktimeStoreAccountTypeLookup = array();
1788
- if (empty($QuicktimeStoreAccountTypeLookup)) {
1789
- $QuicktimeStoreAccountTypeLookup[0] = 'iTunes';
1790
- $QuicktimeStoreAccountTypeLookup[1] = 'AOL';
1791
- }
1792
- return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid');
1793
- }
1794
-
1795
- function QuicktimeStoreFrontCodeLookup($sfid) {
1796
- static $QuicktimeStoreFrontCodeLookup = array();
1797
- if (empty($QuicktimeStoreFrontCodeLookup)) {
1798
- $QuicktimeStoreFrontCodeLookup[143460] = 'Australia';
1799
- $QuicktimeStoreFrontCodeLookup[143445] = 'Austria';
1800
- $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium';
1801
- $QuicktimeStoreFrontCodeLookup[143455] = 'Canada';
1802
- $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark';
1803
- $QuicktimeStoreFrontCodeLookup[143447] = 'Finland';
1804
- $QuicktimeStoreFrontCodeLookup[143442] = 'France';
1805
- $QuicktimeStoreFrontCodeLookup[143443] = 'Germany';
1806
- $QuicktimeStoreFrontCodeLookup[143448] = 'Greece';
1807
- $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland';
1808
- $QuicktimeStoreFrontCodeLookup[143450] = 'Italy';
1809
- $QuicktimeStoreFrontCodeLookup[143462] = 'Japan';
1810
- $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg';
1811
- $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands';
1812
- $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand';
1813
- $QuicktimeStoreFrontCodeLookup[143457] = 'Norway';
1814
- $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal';
1815
- $QuicktimeStoreFrontCodeLookup[143454] = 'Spain';
1816
- $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden';
1817
- $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland';
1818
- $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom';
1819
- $QuicktimeStoreFrontCodeLookup[143441] = 'United States';
1820
- }
1821
- return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid');
1822
- }
1823
-
1824
- function QuicktimeParseNikonNCTG($atom_data) {
1825
- // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
1826
- // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
1827
- // Data is stored as records of:
1828
- // * 4 bytes record type
1829
- // * 2 bytes size of data field type:
1830
- // 0x0001 = flag (size field *= 1-byte)
1831
- // 0x0002 = char (size field *= 1-byte)
1832
- // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
1833
- // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
1834
- // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
1835
- // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
1836
- // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
1837
- // * 2 bytes data size field
1838
- // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15")
1839
- // all integers are stored BigEndian
1840
-
1841
- $NCTGtagName = array(
1842
- 0x00000001 => 'Make',
1843
- 0x00000002 => 'Model',
1844
- 0x00000003 => 'Software',
1845
- 0x00000011 => 'CreateDate',
1846
- 0x00000012 => 'DateTimeOriginal',
1847
- 0x00000013 => 'FrameCount',
1848
- 0x00000016 => 'FrameRate',
1849
- 0x00000022 => 'FrameWidth',
1850
- 0x00000023 => 'FrameHeight',
1851
- 0x00000032 => 'AudioChannels',
1852
- 0x00000033 => 'AudioBitsPerSample',
1853
- 0x00000034 => 'AudioSampleRate',
1854
- 0x02000001 => 'MakerNoteVersion',
1855
- 0x02000005 => 'WhiteBalance',
1856
- 0x0200000b => 'WhiteBalanceFineTune',
1857
- 0x0200001e => 'ColorSpace',
1858
- 0x02000023 => 'PictureControlData',
1859
- 0x02000024 => 'WorldTime',
1860
- 0x02000032 => 'UnknownInfo',
1861
- 0x02000083 => 'LensType',
1862
- 0x02000084 => 'Lens',
1863
- );
1864
-
1865
- $offset = 0;
1866
- $datalength = strlen($atom_data);
1867
- $parsed = array();
1868
- while ($offset < $datalength) {
1869
- //echo getid3_lib::PrintHexBytes(substr($atom_data, $offset, 4)).'<br>';
1870
- $record_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); $offset += 4;
1871
- $data_size_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
1872
- $data_size = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
1873
- switch ($data_size_type) {
1874
- case 0x0001: // 0x0001 = flag (size field *= 1-byte)
1875
- $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1));
1876
- $offset += ($data_size * 1);
1877
- break;
1878
- case 0x0002: // 0x0002 = char (size field *= 1-byte)
1879
- $data = substr($atom_data, $offset, $data_size * 1);
1880
- $offset += ($data_size * 1);
1881
- $data = rtrim($data, "\x00");
1882
- break;
1883
- case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
1884
- $data = '';
1885
- for ($i = $data_size - 1; $i >= 0; $i--) {
1886
- $data .= substr($atom_data, $offset + ($i * 2), 2);
1887
- }
1888
- $data = getid3_lib::BigEndian2Int($data);
1889
- $offset += ($data_size * 2);
1890
- break;
1891
- case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
1892
- $data = '';
1893
- for ($i = $data_size - 1; $i >= 0; $i--) {
1894
- $data .= substr($atom_data, $offset + ($i * 4), 4);
1895
- }
1896
- $data = getid3_lib::BigEndian2Int($data);
1897
- $offset += ($data_size * 4);
1898
- break;
1899
- case 0x0005: // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
1900
- $data = array();
1901
- for ($i = 0; $i < $data_size; $i++) {
1902
- $numerator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4));
1903
- $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4));
1904
- if ($denomninator == 0) {
1905
- $data[$i] = false;
1906
- } else {
1907
- $data[$i] = (double) $numerator / $denomninator;
1908
- }
1909
- }
1910
- $offset += (8 * $data_size);
1911
- if (count($data) == 1) {
1912
- $data = $data[0];
1913
- }
1914
- break;
1915
- case 0x0007: // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
1916
- $data = substr($atom_data, $offset, $data_size * 1);
1917
- $offset += ($data_size * 1);
1918
- break;
1919
- case 0x0008: // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
1920
- $data = substr($atom_data, $offset, $data_size * 2);
1921
- $offset += ($data_size * 2);
1922
- break;
1923
- default:
1924
- echo 'QuicktimeParseNikonNCTG()::unknown $data_size_type: '.$data_size_type.'<br>';
1925
- break 2;
1926
- }
1927
-
1928
- switch ($record_type) {
1929
- case 0x00000011: // CreateDate
1930
- case 0x00000012: // DateTimeOriginal
1931
- $data = strtotime($data);
1932
- break;
1933
- case 0x0200001e: // ColorSpace
1934
- switch ($data) {
1935
- case 1:
1936
- $data = 'sRGB';
1937
- break;
1938
- case 2:
1939
- $data = 'Adobe RGB';
1940
- break;
1941
- }
1942
- break;
1943
- case 0x02000023: // PictureControlData
1944
- $PictureControlAdjust = array(0=>'default', 1=>'quick', 2=>'full');
1945
- $FilterEffect = array(0x80=>'off', 0x81=>'yellow', 0x82=>'orange', 0x83=>'red', 0x84=>'green', 0xff=>'n/a');
1946
- $ToningEffect = array(0x80=>'b&w', 0x81=>'sepia', 0x82=>'cyanotype', 0x83=>'red', 0x84=>'yellow', 0x85=>'green', 0x86=>'blue-green', 0x87=>'blue', 0x88=>'purple-blue', 0x89=>'red-purple', 0xff=>'n/a');
1947
- $data = array(
1948
- 'PictureControlVersion' => substr($data, 0, 4),
1949
- 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"),
1950
- 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"),
1951
- //'?' => substr($data, 44, 4),
1952
- 'PictureControlAdjust' => $PictureControlAdjust[ord(substr($data, 48, 1))],
1953
- 'PictureControlQuickAdjust' => ord(substr($data, 49, 1)),
1954
- 'Sharpness' => ord(substr($data, 50, 1)),
1955
- 'Contrast' => ord(substr($data, 51, 1)),
1956
- 'Brightness' => ord(substr($data, 52, 1)),
1957
- 'Saturation' => ord(substr($data, 53, 1)),
1958
- 'HueAdjustment' => ord(substr($data, 54, 1)),
1959
- 'FilterEffect' => $FilterEffect[ord(substr($data, 55, 1))],
1960
- 'ToningEffect' => $ToningEffect[ord(substr($data, 56, 1))],
1961
- 'ToningSaturation' => ord(substr($data, 57, 1)),
1962
- );
1963
- break;
1964
- case 0x02000024: // WorldTime
1965
- // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime
1966
- // timezone is stored as offset from GMT in minutes
1967
- $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2));
1968
- if ($timezone & 0x8000) {
1969
- $timezone = 0 - (0x10000 - $timezone);
1970
- }
1971
- $timezone /= 60;
1972
-
1973
- $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1));
1974
- switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) {
1975
- case 2:
1976
- $datedisplayformat = 'D/M/Y'; break;
1977
- case 1:
1978
- $datedisplayformat = 'M/D/Y'; break;
1979
- case 0:
1980
- default:
1981
- $datedisplayformat = 'Y/M/D'; break;
1982
- }
1983
-
1984
- $data = array('timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat);
1985
- break;
1986
- case 0x02000083: // LensType
1987
- $data = array(
1988
- //'_' => $data,
1989
- 'mf' => (bool) ($data & 0x01),
1990
- 'd' => (bool) ($data & 0x02),
1991
- 'g' => (bool) ($data & 0x04),
1992
- 'vr' => (bool) ($data & 0x08),
1993
- );
1994
- break;
1995
- }
1996
- $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT));
1997
- $parsed[$tag_name] = $data;
1998
- }
1999
- return $parsed;
2000
- }
2001
-
2002
-
2003
- function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') {
2004
- static $handyatomtranslatorarray = array();
2005
- if (empty($handyatomtranslatorarray)) {
2006
- $handyatomtranslatorarray['�cpy'] = 'copyright';
2007
- $handyatomtranslatorarray['�day'] = 'creation_date'; // iTunes 4.0
2008
- $handyatomtranslatorarray['�dir'] = 'director';
2009
- $handyatomtranslatorarray['�ed1'] = 'edit1';
2010
- $handyatomtranslatorarray['�ed2'] = 'edit2';
2011
- $handyatomtranslatorarray['�ed3'] = 'edit3';
2012
- $handyatomtranslatorarray['�ed4'] = 'edit4';
2013
- $handyatomtranslatorarray['�ed5'] = 'edit5';
2014
- $handyatomtranslatorarray['�ed6'] = 'edit6';
2015
- $handyatomtranslatorarray['�ed7'] = 'edit7';
2016
- $handyatomtranslatorarray['�ed8'] = 'edit8';
2017
- $handyatomtranslatorarray['�ed9'] = 'edit9';
2018
- $handyatomtranslatorarray['�fmt'] = 'format';
2019
- $handyatomtranslatorarray['�inf'] = 'information';
2020
- $handyatomtranslatorarray['�prd'] = 'producer';
2021
- $handyatomtranslatorarray['�prf'] = 'performers';
2022
- $handyatomtranslatorarray['�req'] = 'system_requirements';
2023
- $handyatomtranslatorarray['�src'] = 'source_credit';
2024
- $handyatomtranslatorarray['�wrt'] = 'writer';
2025
-
2026
- // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
2027
- $handyatomtranslatorarray['�nam'] = 'title'; // iTunes 4.0
2028
- $handyatomtranslatorarray['�cmt'] = 'comment'; // iTunes 4.0
2029
- $handyatomtranslatorarray['�wrn'] = 'warning';
2030
- $handyatomtranslatorarray['�hst'] = 'host_computer';
2031
- $handyatomtranslatorarray['�mak'] = 'make';
2032
- $handyatomtranslatorarray['�mod'] = 'model';
2033
- $handyatomtranslatorarray['�PRD'] = 'product';
2034
- $handyatomtranslatorarray['�swr'] = 'software';
2035
- $handyatomtranslatorarray['�aut'] = 'author';
2036
- $handyatomtranslatorarray['�ART'] = 'artist';
2037
- $handyatomtranslatorarray['�trk'] = 'track';
2038
- $handyatomtranslatorarray['�alb'] = 'album'; // iTunes 4.0
2039
- $handyatomtranslatorarray['�com'] = 'comment';
2040
- $handyatomtranslatorarray['�gen'] = 'genre'; // iTunes 4.0
2041
- $handyatomtranslatorarray['�ope'] = 'composer';
2042
- $handyatomtranslatorarray['�url'] = 'url';
2043
- $handyatomtranslatorarray['�enc'] = 'encoder';
2044
-
2045
- // http://atomicparsley.sourceforge.net/mpeg-4files.html
2046
- $handyatomtranslatorarray['�art'] = 'artist'; // iTunes 4.0
2047
- $handyatomtranslatorarray['aART'] = 'album_artist';
2048
- $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0
2049
- $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0
2050
- $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0
2051
- $handyatomtranslatorarray['�too'] = 'encoder'; // iTunes 4.0
2052
- $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0
2053
- $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0?
2054
- $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0
2055
- $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0
2056
- $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0
2057
- $handyatomtranslatorarray['�grp'] = 'grouping'; // iTunes 4.2
2058
- $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9
2059
- $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9
2060
- $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9
2061
- $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9
2062
- $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9
2063
- $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9
2064
- $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0
2065
- $handyatomtranslatorarray['�lyr'] = 'lyrics'; // iTunes 5.0
2066
- $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0
2067
- $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0
2068
- $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0
2069
- $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0
2070
- $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2
2071
- $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0
2072
-
2073
- // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt
2074
-
2075
-
2076
-
2077
- // boxnames:
2078
- $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB';
2079
- $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM';
2080
- $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params';
2081
- $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain';
2082
- $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak';
2083
- $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax';
2084
- $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID';
2085
- $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id';
2086
- $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id';
2087
- $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id';
2088
- $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id';
2089
- $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id';
2090
- }
2091
- $info = &$this->getid3->info;
2092
- $comment_key = '';
2093
- if ($boxname && ($boxname != $keyname) && isset($handyatomtranslatorarray[$boxname])) {
2094
- $comment_key = $handyatomtranslatorarray[$boxname];
2095
- } elseif (isset($handyatomtranslatorarray[$keyname])) {
2096
- $comment_key = $handyatomtranslatorarray[$keyname];
2097
- }
2098
- if ($comment_key) {
2099
- if ($comment_key == 'picture') {
2100
- if (!is_array($data)) {
2101
- $image_mime = '';
2102
- if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) {
2103
- $image_mime = 'image/png';
2104
- } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) {
2105
- $image_mime = 'image/jpeg';
2106
- } elseif (preg_match('#^GIF#', $data)) {
2107
- $image_mime = 'image/gif';
2108
- } elseif (preg_match('#^BM#', $data)) {
2109
- $image_mime = 'image/bmp';
2110
- }
2111
- $data = array('data'=>$data, 'image_mime'=>$image_mime);
2112
- }
2113
- }
2114
- $info['quicktime']['comments'][$comment_key][] = $data;
2115
- }
2116
- return true;
2117
- }
2118
-
2119
- function NoNullString($nullterminatedstring) {
2120
- // remove the single null terminator on null terminated strings
2121
- if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") {
2122
- return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1);
2123
- }
2124
- return $nullterminatedstring;
2125
- }
2126
-
2127
- function Pascal2String($pascalstring) {
2128
- // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string
2129
- return substr($pascalstring, 1);
2130
- }
2131
-
2132
- }
2133
-
2134
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // See readme.txt for more details //
9
+ /////////////////////////////////////////////////////////////////
10
+ // //
11
+ // module.audio-video.quicktime.php //
12
+ // module for analyzing Quicktime and MP3-in-MP4 files //
13
+ // dependencies: module.audio.mp3.php //
14
+ // dependencies: module.tag.id3v2.php //
15
+ // ///
16
+ /////////////////////////////////////////////////////////////////
17
+
18
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
19
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); // needed for ISO 639-2 language code lookup
20
+
21
+ class getid3_quicktime extends getid3_handler
22
+ {
23
+
24
+ public $ReturnAtomData = true;
25
+ public $ParseAllPossibleAtoms = false;
26
+
27
+ public function Analyze() {
28
+ $info = &$this->getid3->info;
29
+
30
+ $info['fileformat'] = 'quicktime';
31
+ $info['quicktime']['hinting'] = false;
32
+ $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present
33
+
34
+ $this->fseek($info['avdataoffset']);
35
+
36
+ $offset = 0;
37
+ $atomcounter = 0;
38
+
39
+ while ($offset < $info['avdataend']) {
40
+ if (!getid3_lib::intValueSupported($offset)) {
41
+ $info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
42
+ break;
43
+ }
44
+ $this->fseek($offset);
45
+ $AtomHeader = $this->fread(8);
46
+
47
+ $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4));
48
+ $atomname = substr($AtomHeader, 4, 4);
49
+
50
+ // 64-bit MOV patch by jlegateØktnc*com
51
+ if ($atomsize == 1) {
52
+ $atomsize = getid3_lib::BigEndian2Int($this->fread(8));
53
+ }
54
+
55
+ $info['quicktime'][$atomname]['name'] = $atomname;
56
+ $info['quicktime'][$atomname]['size'] = $atomsize;
57
+ $info['quicktime'][$atomname]['offset'] = $offset;
58
+
59
+ if (($offset + $atomsize) > $info['avdataend']) {
60
+ $info['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)';
61
+ return false;
62
+ }
63
+
64
+ if ($atomsize == 0) {
65
+ // Furthermore, for historical reasons the list of atoms is optionally
66
+ // terminated by a 32-bit integer set to 0. If you are writing a program
67
+ // to read user data atoms, you should allow for the terminating 0.
68
+ break;
69
+ }
70
+ $atomHierarchy = array();
71
+ $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, round($this->getid3->memory_limit / 2))), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
72
+
73
+ $offset += $atomsize;
74
+ $atomcounter++;
75
+ }
76
+
77
+ if (!empty($info['avdataend_tmp'])) {
78
+ // this value is assigned to a temp value and then erased because
79
+ // otherwise any atoms beyond the 'mdat' atom would not get parsed
80
+ $info['avdataend'] = $info['avdataend_tmp'];
81
+ unset($info['avdataend_tmp']);
82
+ }
83
+
84
+ if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) {
85
+ $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
86
+ }
87
+ if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) {
88
+ $info['audio']['bitrate'] = $info['bitrate'];
89
+ }
90
+ if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) {
91
+ foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) {
92
+ $samples_per_second = $samples_count / $info['playtime_seconds'];
93
+ if ($samples_per_second > 240) {
94
+ // has to be audio samples
95
+ } else {
96
+ $info['video']['frame_rate'] = $samples_per_second;
97
+ break;
98
+ }
99
+ }
100
+ }
101
+ if (($info['audio']['dataformat'] == 'mp4') && empty($info['video']['resolution_x'])) {
102
+ $info['fileformat'] = 'mp4';
103
+ $info['mime_type'] = 'audio/mp4';
104
+ unset($info['video']['dataformat']);
105
+ }
106
+
107
+ if (!$this->ReturnAtomData) {
108
+ unset($info['quicktime']['moov']);
109
+ }
110
+
111
+ if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) {
112
+ $info['audio']['dataformat'] = 'quicktime';
113
+ }
114
+ if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) {
115
+ $info['video']['dataformat'] = 'quicktime';
116
+ }
117
+
118
+ return true;
119
+ }
120
+
121
+ public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
122
+ // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
123
+
124
+ $info = &$this->getid3->info;
125
+
126
+ $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see http://www.getid3.org/phpBB3/viewtopic.php?t=1717
127
+ array_push($atomHierarchy, $atomname);
128
+ $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
129
+ $atom_structure['name'] = $atomname;
130
+ $atom_structure['size'] = $atomsize;
131
+ $atom_structure['offset'] = $baseoffset;
132
+ switch ($atomname) {
133
+ case 'moov': // MOVie container atom
134
+ case 'trak': // TRAcK container atom
135
+ case 'clip': // CLIPping container atom
136
+ case 'matt': // track MATTe container atom
137
+ case 'edts': // EDiTS container atom
138
+ case 'tref': // Track REFerence container atom
139
+ case 'mdia': // MeDIA container atom
140
+ case 'minf': // Media INFormation container atom
141
+ case 'dinf': // Data INFormation container atom
142
+ case 'udta': // User DaTA container atom
143
+ case 'cmov': // Compressed MOVie container atom
144
+ case 'rmra': // Reference Movie Record Atom
145
+ case 'rmda': // Reference Movie Descriptor Atom
146
+ case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR)
147
+ $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
148
+ break;
149
+
150
+ case 'ilst': // Item LiST container atom
151
+ if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) {
152
+ // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted
153
+ $allnumericnames = true;
154
+ foreach ($atom_structure['subatoms'] as $subatomarray) {
155
+ if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) {
156
+ $allnumericnames = false;
157
+ break;
158
+ }
159
+ }
160
+ if ($allnumericnames) {
161
+ $newData = array();
162
+ foreach ($atom_structure['subatoms'] as $subatomarray) {
163
+ foreach ($subatomarray['subatoms'] as $newData_subatomarray) {
164
+ unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']);
165
+ $newData[$subatomarray['name']] = $newData_subatomarray;
166
+ break;
167
+ }
168
+ }
169
+ $atom_structure['data'] = $newData;
170
+ unset($atom_structure['subatoms']);
171
+ }
172
+ }
173
+ break;
174
+
175
+ case "\x00\x00\x00\x01":
176
+ case "\x00\x00\x00\x02":
177
+ case "\x00\x00\x00\x03":
178
+ case "\x00\x00\x00\x04":
179
+ case "\x00\x00\x00\x05":
180
+ $atomname = getid3_lib::BigEndian2Int($atomname);
181
+ $atom_structure['name'] = $atomname;
182
+ $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
183
+ break;
184
+
185
+ case 'stbl': // Sample TaBLe container atom
186
+ $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
187
+ $isVideo = false;
188
+ $framerate = 0;
189
+ $framecount = 0;
190
+ foreach ($atom_structure['subatoms'] as $key => $value_array) {
191
+ if (isset($value_array['sample_description_table'])) {
192
+ foreach ($value_array['sample_description_table'] as $key2 => $value_array2) {
193
+ if (isset($value_array2['data_format'])) {
194
+ switch ($value_array2['data_format']) {
195
+ case 'avc1':
196
+ case 'mp4v':
197
+ // video data
198
+ $isVideo = true;
199
+ break;
200
+ case 'mp4a':
201
+ // audio data
202
+ break;
203
+ }
204
+ }
205
+ }
206
+ } elseif (isset($value_array['time_to_sample_table'])) {
207
+ foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) {
208
+ if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) {
209
+ $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3);
210
+ $framecount = $value_array2['sample_count'];
211
+ }
212
+ }
213
+ }
214
+ }
215
+ if ($isVideo && $framerate) {
216
+ $info['quicktime']['video']['frame_rate'] = $framerate;
217
+ $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate'];
218
+ }
219
+ if ($isVideo && $framecount) {
220
+ $info['quicktime']['video']['frame_count'] = $framecount;
221
+ }
222
+ break;
223
+
224
+
225
+ case 'aART': // Album ARTist
226
+ case 'catg': // CaTeGory
227
+ case 'covr': // COVeR artwork
228
+ case 'cpil': // ComPILation
229
+ case 'cprt': // CoPyRighT
230
+ case 'desc': // DESCription
231
+ case 'disk': // DISK number
232
+ case 'egid': // Episode Global ID
233
+ case 'gnre': // GeNRE
234
+ case 'keyw': // KEYWord
235
+ case 'ldes':
236
+ case 'pcst': // PodCaST
237
+ case 'pgap': // GAPless Playback
238
+ case 'purd': // PURchase Date
239
+ case 'purl': // Podcast URL
240
+ case 'rati':
241
+ case 'rndu':
242
+ case 'rpdu':
243
+ case 'rtng': // RaTiNG
244
+ case 'stik':
245
+ case 'tmpo': // TeMPO (BPM)
246
+ case 'trkn': // TRacK Number
247
+ case 'tves': // TV EpiSode
248
+ case 'tvnn': // TV Network Name
249
+ case 'tvsh': // TV SHow Name
250
+ case 'tvsn': // TV SeasoN
251
+ case 'akID': // iTunes store account type
252
+ case 'apID':
253
+ case 'atID':
254
+ case 'cmID':
255
+ case 'cnID':
256
+ case 'geID':
257
+ case 'plID':
258
+ case 'sfID': // iTunes store country
259
+ case "\xA9".'alb': // ALBum
260
+ case "\xA9".'art': // ARTist
261
+ case "\xA9".'ART':
262
+ case "\xA9".'aut':
263
+ case "\xA9".'cmt': // CoMmenT
264
+ case "\xA9".'com': // COMposer
265
+ case "\xA9".'cpy':
266
+ case "\xA9".'day': // content created year
267
+ case "\xA9".'dir':
268
+ case "\xA9".'ed1':
269
+ case "\xA9".'ed2':
270
+ case "\xA9".'ed3':
271
+ case "\xA9".'ed4':
272
+ case "\xA9".'ed5':
273
+ case "\xA9".'ed6':
274
+ case "\xA9".'ed7':
275
+ case "\xA9".'ed8':
276
+ case "\xA9".'ed9':
277
+ case "\xA9".'enc':
278
+ case "\xA9".'fmt':
279
+ case "\xA9".'gen': // GENre
280
+ case "\xA9".'grp': // GRouPing
281
+ case "\xA9".'hst':
282
+ case "\xA9".'inf':
283
+ case "\xA9".'lyr': // LYRics
284
+ case "\xA9".'mak':
285
+ case "\xA9".'mod':
286
+ case "\xA9".'nam': // full NAMe
287
+ case "\xA9".'ope':
288
+ case "\xA9".'PRD':
289
+ case "\xA9".'prd':
290
+ case "\xA9".'prf':
291
+ case "\xA9".'req':
292
+ case "\xA9".'src':
293
+ case "\xA9".'swr':
294
+ case "\xA9".'too': // encoder
295
+ case "\xA9".'trk': // TRacK
296
+ case "\xA9".'url':
297
+ case "\xA9".'wrn':
298
+ case "\xA9".'wrt': // WRiTer
299
+ case '----': // itunes specific
300
+ if ($atom_parent == 'udta') {
301
+ // User data atom handler
302
+ $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
303
+ $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
304
+ $atom_structure['data'] = substr($atom_data, 4);
305
+
306
+ $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
307
+ if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
308
+ $info['comments']['language'][] = $atom_structure['language'];
309
+ }
310
+ } else {
311
+ // Apple item list box atom handler
312
+ $atomoffset = 0;
313
+ if (substr($atom_data, 2, 2) == "\x10\xB5") {
314
+ // not sure what it means, but observed on iPhone4 data.
315
+ // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data
316
+ while ($atomoffset < strlen($atom_data)) {
317
+ $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2));
318
+ $boxsmalltype = substr($atom_data, $atomoffset + 2, 2);
319
+ $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize);
320
+ if ($boxsmallsize <= 1) {
321
+ $info['warning'][] = 'Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
322
+ $atom_structure['data'] = null;
323
+ $atomoffset = strlen($atom_data);
324
+ break;
325
+ }
326
+ switch ($boxsmalltype) {
327
+ case "\x10\xB5":
328
+ $atom_structure['data'] = $boxsmalldata;
329
+ break;
330
+ default:
331
+ $info['warning'][] = 'Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset;
332
+ $atom_structure['data'] = $atom_data;
333
+ break;
334
+ }
335
+ $atomoffset += (4 + $boxsmallsize);
336
+ }
337
+ } else {
338
+ while ($atomoffset < strlen($atom_data)) {
339
+ $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4));
340
+ $boxtype = substr($atom_data, $atomoffset + 4, 4);
341
+ $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8);
342
+ if ($boxsize <= 1) {
343
+ $info['warning'][] = 'Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset);
344
+ $atom_structure['data'] = null;
345
+ $atomoffset = strlen($atom_data);
346
+ break;
347
+ }
348
+ $atomoffset += $boxsize;
349
+
350
+ switch ($boxtype) {
351
+ case 'mean':
352
+ case 'name':
353
+ $atom_structure[$boxtype] = substr($boxdata, 4);
354
+ break;
355
+
356
+ case 'data':
357
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1));
358
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3));
359
+ switch ($atom_structure['flags_raw']) {
360
+ case 0: // data flag
361
+ case 21: // tmpo/cpil flag
362
+ switch ($atomname) {
363
+ case 'cpil':
364
+ case 'pcst':
365
+ case 'pgap':
366
+ $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
367
+ break;
368
+
369
+ case 'tmpo':
370
+ $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2));
371
+ break;
372
+
373
+ case 'disk':
374
+ case 'trkn':
375
+ $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2));
376
+ $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2));
377
+ $atom_structure['data'] = empty($num) ? '' : $num;
378
+ $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total;
379
+ break;
380
+
381
+ case 'gnre':
382
+ $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
383
+ $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1);
384
+ break;
385
+
386
+ case 'rtng':
387
+ $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
388
+ $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]);
389
+ break;
390
+
391
+ case 'stik':
392
+ $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1));
393
+ $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]);
394
+ break;
395
+
396
+ case 'sfID':
397
+ $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
398
+ $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]);
399
+ break;
400
+
401
+ case 'egid':
402
+ case 'purl':
403
+ $atom_structure['data'] = substr($boxdata, 8);
404
+ break;
405
+
406
+ default:
407
+ $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4));
408
+ }
409
+ break;
410
+
411
+ case 1: // text flag
412
+ case 13: // image flag
413
+ default:
414
+ $atom_structure['data'] = substr($boxdata, 8);
415
+ if ($atomname == 'covr') {
416
+ // not a foolproof check, but better than nothing
417
+ if (preg_match('#^\xFF\xD8\xFF#', $atom_structure['data'])) {
418
+ $atom_structure['image_mime'] = 'image/jpeg';
419
+ } elseif (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $atom_structure['data'])) {
420
+ $atom_structure['image_mime'] = 'image/png';
421
+ } elseif (preg_match('#^GIF#', $atom_structure['data'])) {
422
+ $atom_structure['image_mime'] = 'image/gif';
423
+ }
424
+ }
425
+ break;
426
+
427
+ }
428
+ break;
429
+
430
+ default:
431
+ $info['warning'][] = 'Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset;
432
+ $atom_structure['data'] = $atom_data;
433
+
434
+ }
435
+ }
436
+ }
437
+ }
438
+ $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']);
439
+ break;
440
+
441
+
442
+ case 'play': // auto-PLAY atom
443
+ $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
444
+
445
+ $info['quicktime']['autoplay'] = $atom_structure['autoplay'];
446
+ break;
447
+
448
+
449
+ case 'WLOC': // Window LOCation atom
450
+ $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
451
+ $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
452
+ break;
453
+
454
+
455
+ case 'LOOP': // LOOPing atom
456
+ case 'SelO': // play SELection Only atom
457
+ case 'AllF': // play ALL Frames atom
458
+ $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
459
+ break;
460
+
461
+
462
+ case 'name': //
463
+ case 'MCPS': // Media Cleaner PRo
464
+ case '@PRM': // adobe PReMiere version
465
+ case '@PRQ': // adobe PRemiere Quicktime version
466
+ $atom_structure['data'] = $atom_data;
467
+ break;
468
+
469
+
470
+ case 'cmvd': // Compressed MooV Data atom
471
+ // Code by ubergeekØubergeek*tv based on information from
472
+ // http://developer.apple.com/quicktime/icefloe/dispatch012.html
473
+ $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
474
+
475
+ $CompressedFileData = substr($atom_data, 4);
476
+ if ($UncompressedHeader = @gzuncompress($CompressedFileData)) {
477
+ $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms);
478
+ } else {
479
+ $info['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atom_structure['offset'];
480
+ }
481
+ break;
482
+
483
+
484
+ case 'dcom': // Data COMpression atom
485
+ $atom_structure['compression_id'] = $atom_data;
486
+ $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data);
487
+ break;
488
+
489
+
490
+ case 'rdrf': // Reference movie Data ReFerence atom
491
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
492
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
493
+ $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001);
494
+
495
+ $atom_structure['reference_type_name'] = substr($atom_data, 4, 4);
496
+ $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
497
+ switch ($atom_structure['reference_type_name']) {
498
+ case 'url ':
499
+ $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12));
500
+ break;
501
+
502
+ case 'alis':
503
+ $atom_structure['file_alias'] = substr($atom_data, 12);
504
+ break;
505
+
506
+ case 'rsrc':
507
+ $atom_structure['resource_alias'] = substr($atom_data, 12);
508
+ break;
509
+
510
+ default:
511
+ $atom_structure['data'] = substr($atom_data, 12);
512
+ break;
513
+ }
514
+ break;
515
+
516
+
517
+ case 'rmqu': // Reference Movie QUality atom
518
+ $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
519
+ break;
520
+
521
+
522
+ case 'rmcs': // Reference Movie Cpu Speed atom
523
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
524
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
525
+ $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
526
+ break;
527
+
528
+
529
+ case 'rmvc': // Reference Movie Version Check atom
530
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
531
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
532
+ $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4);
533
+ $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
534
+ $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
535
+ $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
536
+ break;
537
+
538
+
539
+ case 'rmcd': // Reference Movie Component check atom
540
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
541
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
542
+ $atom_structure['component_type'] = substr($atom_data, 4, 4);
543
+ $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
544
+ $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
545
+ $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
546
+ $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
547
+ $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4));
548
+ break;
549
+
550
+
551
+ case 'rmdr': // Reference Movie Data Rate atom
552
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
553
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
554
+ $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
555
+
556
+ $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
557
+ break;
558
+
559
+
560
+ case 'rmla': // Reference Movie Language Atom
561
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
562
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
563
+ $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
564
+
565
+ $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
566
+ if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
567
+ $info['comments']['language'][] = $atom_structure['language'];
568
+ }
569
+ break;
570
+
571
+
572
+ case 'rmla': // Reference Movie Language Atom
573
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
574
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
575
+ $atom_structure['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
576
+ break;
577
+
578
+
579
+ case 'ptv ': // Print To Video - defines a movie's full screen mode
580
+ // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
581
+ $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
582
+ $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000
583
+ $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000
584
+ $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1));
585
+ $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1));
586
+
587
+ $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
588
+ $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag'];
589
+
590
+ $ptv_lookup[0] = 'normal';
591
+ $ptv_lookup[1] = 'double';
592
+ $ptv_lookup[2] = 'half';
593
+ $ptv_lookup[3] = 'full';
594
+ $ptv_lookup[4] = 'current';
595
+ if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
596
+ $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
597
+ } else {
598
+ $info['warning'][] = 'unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')';
599
+ }
600
+ break;
601
+
602
+
603
+ case 'stsd': // Sample Table Sample Description atom
604
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
605
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
606
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
607
+ $stsdEntriesDataOffset = 8;
608
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
609
+ $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4));
610
+ $stsdEntriesDataOffset += 4;
611
+ $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4);
612
+ $stsdEntriesDataOffset += 4;
613
+ $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6));
614
+ $stsdEntriesDataOffset += 6;
615
+ $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2));
616
+ $stsdEntriesDataOffset += 2;
617
+ $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2));
618
+ $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
619
+
620
+ $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2));
621
+ $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2));
622
+ $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4);
623
+
624
+ switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
625
+
626
+ case "\x00\x00\x00\x00":
627
+ // audio tracks
628
+ $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2));
629
+ $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2));
630
+ $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2));
631
+ $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2));
632
+ $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4));
633
+
634
+ // video tracks
635
+ // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
636
+ $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4));
637
+ $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4));
638
+ $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2));
639
+ $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2));
640
+ $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
641
+ $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4));
642
+ $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4));
643
+ $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2));
644
+ $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4);
645
+ $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2));
646
+ $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2));
647
+
648
+ switch ($atom_structure['sample_description_table'][$i]['data_format']) {
649
+ case '2vuY':
650
+ case 'avc1':
651
+ case 'cvid':
652
+ case 'dvc ':
653
+ case 'dvcp':
654
+ case 'gif ':
655
+ case 'h263':
656
+ case 'jpeg':
657
+ case 'kpcd':
658
+ case 'mjpa':
659
+ case 'mjpb':
660
+ case 'mp4v':
661
+ case 'png ':
662
+ case 'raw ':
663
+ case 'rle ':
664
+ case 'rpza':
665
+ case 'smc ':
666
+ case 'SVQ1':
667
+ case 'SVQ3':
668
+ case 'tiff':
669
+ case 'v210':
670
+ case 'v216':
671
+ case 'v308':
672
+ case 'v408':
673
+ case 'v410':
674
+ case 'yuv2':
675
+ $info['fileformat'] = 'mp4';
676
+ $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
677
+ // http://www.getid3.org/phpBB3/viewtopic.php?t=1550
678
+ //if ((!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['width'])) && (empty($info['video']['resolution_x']) || empty($info['video']['resolution_y']) || (number_format($info['video']['resolution_x'], 6) != number_format(round($info['video']['resolution_x']), 6)) || (number_format($info['video']['resolution_y'], 6) != number_format(round($info['video']['resolution_y']), 6)))) { // ugly check for floating point numbers
679
+ if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) {
680
+ // assume that values stored here are more important than values stored in [tkhd] atom
681
+ $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width'];
682
+ $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height'];
683
+ $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
684
+ $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
685
+ }
686
+ break;
687
+
688
+ case 'qtvr':
689
+ $info['video']['dataformat'] = 'quicktimevr';
690
+ break;
691
+
692
+ case 'mp4a':
693
+ default:
694
+ $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
695
+ $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
696
+ $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels'];
697
+ $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
698
+ $info['audio']['codec'] = $info['quicktime']['audio']['codec'];
699
+ $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate'];
700
+ $info['audio']['channels'] = $info['quicktime']['audio']['channels'];
701
+ $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth'];
702
+ switch ($atom_structure['sample_description_table'][$i]['data_format']) {
703
+ case 'raw ': // PCM
704
+ case 'alac': // Apple Lossless Audio Codec
705
+ $info['audio']['lossless'] = true;
706
+ break;
707
+ default:
708
+ $info['audio']['lossless'] = false;
709
+ break;
710
+ }
711
+ break;
712
+ }
713
+ break;
714
+
715
+ default:
716
+ switch ($atom_structure['sample_description_table'][$i]['data_format']) {
717
+ case 'mp4s':
718
+ $info['fileformat'] = 'mp4';
719
+ break;
720
+
721
+ default:
722
+ // video atom
723
+ $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4));
724
+ $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4));
725
+ $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2));
726
+ $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2));
727
+ $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4));
728
+ $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
729
+ $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4));
730
+ $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2));
731
+ $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1));
732
+ $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']);
733
+ $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2));
734
+ $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2));
735
+
736
+ $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color');
737
+ $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
738
+
739
+ if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
740
+ $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
741
+ $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
742
+ $info['quicktime']['video']['codec'] = (($atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']);
743
+ $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
744
+ $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
745
+
746
+ $info['video']['codec'] = $info['quicktime']['video']['codec'];
747
+ $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth'];
748
+ }
749
+ $info['video']['lossless'] = false;
750
+ $info['video']['pixel_aspect_ratio'] = (float) 1;
751
+ break;
752
+ }
753
+ break;
754
+ }
755
+ switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
756
+ case 'mp4a':
757
+ $info['audio']['dataformat'] = 'mp4';
758
+ $info['quicktime']['audio']['codec'] = 'mp4';
759
+ break;
760
+
761
+ case '3ivx':
762
+ case '3iv1':
763
+ case '3iv2':
764
+ $info['video']['dataformat'] = '3ivx';
765
+ break;
766
+
767
+ case 'xvid':
768
+ $info['video']['dataformat'] = 'xvid';
769
+ break;
770
+
771
+ case 'mp4v':
772
+ $info['video']['dataformat'] = 'mpeg4';
773
+ break;
774
+
775
+ case 'divx':
776
+ case 'div1':
777
+ case 'div2':
778
+ case 'div3':
779
+ case 'div4':
780
+ case 'div5':
781
+ case 'div6':
782
+ $info['video']['dataformat'] = 'divx';
783
+ break;
784
+
785
+ default:
786
+ // do nothing
787
+ break;
788
+ }
789
+ unset($atom_structure['sample_description_table'][$i]['data']);
790
+ }
791
+ break;
792
+
793
+
794
+ case 'stts': // Sample Table Time-to-Sample atom
795
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
796
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
797
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
798
+ $sttsEntriesDataOffset = 8;
799
+ //$FrameRateCalculatorArray = array();
800
+ $frames_count = 0;
801
+
802
+ $max_stts_entries_to_scan = min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']);
803
+ if ($max_stts_entries_to_scan < $atom_structure['number_entries']) {
804
+ $info['warning'][] = 'QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($this->getid3->memory_limit / 1048576).'MB).';
805
+ }
806
+ for ($i = 0; $i < $max_stts_entries_to_scan; $i++) {
807
+ $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
808
+ $sttsEntriesDataOffset += 4;
809
+ $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));
810
+ $sttsEntriesDataOffset += 4;
811
+
812
+ $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count'];
813
+
814
+ // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM
815
+ //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) {
816
+ // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
817
+ // if ($stts_new_framerate <= 60) {
818
+ // // some atoms have durations of "1" giving a very large framerate, which probably is not right
819
+ // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate);
820
+ // }
821
+ //}
822
+ //
823
+ //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
824
+ }
825
+ $info['quicktime']['stts_framecount'][] = $frames_count;
826
+ //$sttsFramesTotal = 0;
827
+ //$sttsSecondsTotal = 0;
828
+ //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) {
829
+ // if (($frames_per_second > 60) || ($frames_per_second < 1)) {
830
+ // // not video FPS information, probably audio information
831
+ // $sttsFramesTotal = 0;
832
+ // $sttsSecondsTotal = 0;
833
+ // break;
834
+ // }
835
+ // $sttsFramesTotal += $frame_count;
836
+ // $sttsSecondsTotal += $frame_count / $frames_per_second;
837
+ //}
838
+ //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) {
839
+ // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) {
840
+ // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal;
841
+ // }
842
+ //}
843
+ break;
844
+
845
+
846
+ case 'stss': // Sample Table Sync Sample (key frames) atom
847
+ if ($ParseAllPossibleAtoms) {
848
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
849
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
850
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
851
+ $stssEntriesDataOffset = 8;
852
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
853
+ $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4));
854
+ $stssEntriesDataOffset += 4;
855
+ }
856
+ }
857
+ break;
858
+
859
+
860
+ case 'stsc': // Sample Table Sample-to-Chunk atom
861
+ if ($ParseAllPossibleAtoms) {
862
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
863
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
864
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
865
+ $stscEntriesDataOffset = 8;
866
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
867
+ $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
868
+ $stscEntriesDataOffset += 4;
869
+ $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
870
+ $stscEntriesDataOffset += 4;
871
+ $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4));
872
+ $stscEntriesDataOffset += 4;
873
+ }
874
+ }
875
+ break;
876
+
877
+
878
+ case 'stsz': // Sample Table SiZe atom
879
+ if ($ParseAllPossibleAtoms) {
880
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
881
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
882
+ $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
883
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
884
+ $stszEntriesDataOffset = 12;
885
+ if ($atom_structure['sample_size'] == 0) {
886
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
887
+ $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4));
888
+ $stszEntriesDataOffset += 4;
889
+ }
890
+ }
891
+ }
892
+ break;
893
+
894
+
895
+ case 'stco': // Sample Table Chunk Offset atom
896
+ if ($ParseAllPossibleAtoms) {
897
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
898
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
899
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
900
+ $stcoEntriesDataOffset = 8;
901
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
902
+ $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4));
903
+ $stcoEntriesDataOffset += 4;
904
+ }
905
+ }
906
+ break;
907
+
908
+
909
+ case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files)
910
+ if ($ParseAllPossibleAtoms) {
911
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
912
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
913
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
914
+ $stcoEntriesDataOffset = 8;
915
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
916
+ $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8));
917
+ $stcoEntriesDataOffset += 8;
918
+ }
919
+ }
920
+ break;
921
+
922
+
923
+ case 'dref': // Data REFerence atom
924
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
925
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
926
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
927
+ $drefDataOffset = 8;
928
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
929
+ $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4));
930
+ $drefDataOffset += 4;
931
+ $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4);
932
+ $drefDataOffset += 4;
933
+ $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1));
934
+ $drefDataOffset += 1;
935
+ $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000
936
+ $drefDataOffset += 3;
937
+ $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3));
938
+ $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
939
+
940
+ $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001);
941
+ }
942
+ break;
943
+
944
+
945
+ case 'gmin': // base Media INformation atom
946
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
947
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
948
+ $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
949
+ $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
950
+ $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
951
+ $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
952
+ $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2));
953
+ $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2));
954
+ break;
955
+
956
+
957
+ case 'smhd': // Sound Media information HeaDer atom
958
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
959
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
960
+ $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
961
+ $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
962
+ break;
963
+
964
+
965
+ case 'vmhd': // Video Media information HeaDer atom
966
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
967
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
968
+ $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
969
+ $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2));
970
+ $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2));
971
+ $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2));
972
+
973
+ $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001);
974
+ break;
975
+
976
+
977
+ case 'hdlr': // HanDLeR reference atom
978
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
979
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
980
+ $atom_structure['component_type'] = substr($atom_data, 4, 4);
981
+ $atom_structure['component_subtype'] = substr($atom_data, 8, 4);
982
+ $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4);
983
+ $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
984
+ $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
985
+ $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24));
986
+
987
+ if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) {
988
+ $info['video']['dataformat'] = 'quicktimevr';
989
+ }
990
+ break;
991
+
992
+
993
+ case 'mdhd': // MeDia HeaDer atom
994
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
995
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
996
+ $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
997
+ $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
998
+ $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
999
+ $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
1000
+ $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2));
1001
+ $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2));
1002
+
1003
+ if ($atom_structure['time_scale'] == 0) {
1004
+ $info['error'][] = 'Corrupt Quicktime file: mdhd.time_scale == zero';
1005
+ return false;
1006
+ }
1007
+ $info['quicktime']['time_scale'] = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
1008
+
1009
+ $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
1010
+ $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
1011
+ $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
1012
+ $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
1013
+ if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) {
1014
+ $info['comments']['language'][] = $atom_structure['language'];
1015
+ }
1016
+ break;
1017
+
1018
+
1019
+ case 'pnot': // Preview atom
1020
+ $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format"
1021
+ $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00
1022
+ $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT'
1023
+ $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01
1024
+
1025
+ $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']);
1026
+ break;
1027
+
1028
+
1029
+ case 'crgn': // Clipping ReGioN atom
1030
+ $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box,
1031
+ $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields
1032
+ $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region.
1033
+ break;
1034
+
1035
+
1036
+ case 'load': // track LOAD settings atom
1037
+ $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
1038
+ $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1039
+ $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
1040
+ $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1041
+
1042
+ $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020);
1043
+ $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100);
1044
+ break;
1045
+
1046
+
1047
+ case 'tmcd': // TiMe CoDe atom
1048
+ case 'chap': // CHAPter list atom
1049
+ case 'sync': // SYNChronization atom
1050
+ case 'scpt': // tranSCriPT atom
1051
+ case 'ssrc': // non-primary SouRCe atom
1052
+ for ($i = 0; $i < strlen($atom_data); $i += 4) {
1053
+ @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
1054
+ }
1055
+ break;
1056
+
1057
+
1058
+ case 'elst': // Edit LiST atom
1059
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1060
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
1061
+ $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1062
+ for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) {
1063
+ $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4));
1064
+ $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4));
1065
+ $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4));
1066
+ }
1067
+ break;
1068
+
1069
+
1070
+ case 'kmat': // compressed MATte atom
1071
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1072
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000
1073
+ $atom_structure['matte_data_raw'] = substr($atom_data, 4);
1074
+ break;
1075
+
1076
+
1077
+ case 'ctab': // Color TABle atom
1078
+ $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000
1079
+ $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000
1080
+ $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1;
1081
+ for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) {
1082
+ $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2));
1083
+ $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2));
1084
+ $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2));
1085
+ $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2));
1086
+ }
1087
+ break;
1088
+
1089
+
1090
+ case 'mvhd': // MoVie HeaDer atom
1091
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1092
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
1093
+ $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1094
+ $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
1095
+ $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1096
+ $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
1097
+ $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4));
1098
+ $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2));
1099
+ $atom_structure['reserved'] = substr($atom_data, 26, 10);
1100
+ $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4));
1101
+ $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
1102
+ $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4));
1103
+ $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4));
1104
+ $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
1105
+ $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4));
1106
+ $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4));
1107
+ $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
1108
+ $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4));
1109
+ $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4));
1110
+ $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4));
1111
+ $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4));
1112
+ $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4));
1113
+ $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4));
1114
+ $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4));
1115
+ $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4));
1116
+
1117
+ if ($atom_structure['time_scale'] == 0) {
1118
+ $info['error'][] = 'Corrupt Quicktime file: mvhd.time_scale == zero';
1119
+ return false;
1120
+ }
1121
+ $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
1122
+ $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
1123
+ $info['quicktime']['time_scale'] = (isset($info['quicktime']['time_scale']) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']);
1124
+ $info['quicktime']['display_scale'] = $atom_structure['matrix_a'];
1125
+ $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
1126
+ break;
1127
+
1128
+
1129
+ case 'tkhd': // TracK HeaDer atom
1130
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1131
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
1132
+ $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1133
+ $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4));
1134
+ $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4));
1135
+ $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4));
1136
+ $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4));
1137
+ $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8));
1138
+ $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2));
1139
+ $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2));
1140
+ $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2));
1141
+ $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2));
1142
+ // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/MovieBasics/MTEditing/K-Chapter/11MatrixFunctions.html
1143
+ // http://developer.apple.com/library/mac/#documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737
1144
+ $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4));
1145
+ $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4));
1146
+ $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4));
1147
+ $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4));
1148
+ $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4));
1149
+ $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4));
1150
+ $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4));
1151
+ $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4));
1152
+ $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4));
1153
+ $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4));
1154
+ $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4));
1155
+ $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001);
1156
+ $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002);
1157
+ $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004);
1158
+ $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008);
1159
+ $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']);
1160
+ $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']);
1161
+
1162
+ if ($atom_structure['flags']['enabled'] == 1) {
1163
+ if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) {
1164
+ $info['video']['resolution_x'] = $atom_structure['width'];
1165
+ $info['video']['resolution_y'] = $atom_structure['height'];
1166
+ }
1167
+ $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']);
1168
+ $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']);
1169
+ $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x'];
1170
+ $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y'];
1171
+ } else {
1172
+ // see: http://www.getid3.org/phpBB3/viewtopic.php?t=1295
1173
+ //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); }
1174
+ //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); }
1175
+ //if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); }
1176
+ }
1177
+ break;
1178
+
1179
+
1180
+ case 'iods': // Initial Object DeScriptor atom
1181
+ // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h
1182
+ // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html
1183
+ $offset = 0;
1184
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1185
+ $offset += 1;
1186
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3));
1187
+ $offset += 3;
1188
+ $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1189
+ $offset += 1;
1190
+ $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
1191
+ //$offset already adjusted by quicktime_read_mp4_descr_length()
1192
+ $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2));
1193
+ $offset += 2;
1194
+ $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1195
+ $offset += 1;
1196
+ $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1197
+ $offset += 1;
1198
+ $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1199
+ $offset += 1;
1200
+ $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1201
+ $offset += 1;
1202
+ $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1203
+ $offset += 1;
1204
+
1205
+ $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields
1206
+ for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) {
1207
+ $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1));
1208
+ $offset += 1;
1209
+ $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset);
1210
+ //$offset already adjusted by quicktime_read_mp4_descr_length()
1211
+ $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4));
1212
+ $offset += 4;
1213
+ }
1214
+
1215
+ $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']);
1216
+ $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']);
1217
+ break;
1218
+
1219
+ case 'ftyp': // FileTYPe (?) atom (for MP4 it seems)
1220
+ $atom_structure['signature'] = substr($atom_data, 0, 4);
1221
+ $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4));
1222
+ $atom_structure['fourcc'] = substr($atom_data, 8, 4);
1223
+ break;
1224
+
1225
+ case 'mdat': // Media DATa atom
1226
+ // 'mdat' contains the actual data for the audio/video, possibly also subtitles
1227
+
1228
+ /* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to info@getid3.org */
1229
+
1230
+ // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?)
1231
+ $mdat_offset = 0;
1232
+ while (true) {
1233
+ if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') {
1234
+ $mdat_offset += 8;
1235
+ } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') {
1236
+ $mdat_offset += 8;
1237
+ } else {
1238
+ break;
1239
+ }
1240
+ }
1241
+
1242
+ // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field
1243
+ while (($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2)))
1244
+ && ($chapter_string_length < 1000)
1245
+ && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2))
1246
+ && preg_match('#^[\x20-\xFF]+$#', substr($atom_data, $mdat_offset + 2, $chapter_string_length), $chapter_matches)) {
1247
+ $mdat_offset += (2 + $chapter_string_length);
1248
+ @$info['quicktime']['comments']['chapters'][] = $chapter_matches[0];
1249
+ }
1250
+
1251
+
1252
+
1253
+ if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
1254
+
1255
+ $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8;
1256
+ $OldAVDataEnd = $info['avdataend'];
1257
+ $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
1258
+
1259
+ $getid3_temp = new getID3();
1260
+ $getid3_temp->openfile($this->getid3->filename);
1261
+ $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
1262
+ $getid3_temp->info['avdataend'] = $info['avdataend'];
1263
+ $getid3_mp3 = new getid3_mp3($getid3_temp);
1264
+ if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) {
1265
+ $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
1266
+ if (!empty($getid3_temp->info['warning'])) {
1267
+ foreach ($getid3_temp->info['warning'] as $value) {
1268
+ $info['warning'][] = $value;
1269
+ }
1270
+ }
1271
+ if (!empty($getid3_temp->info['mpeg'])) {
1272
+ $info['mpeg'] = $getid3_temp->info['mpeg'];
1273
+ if (isset($info['mpeg']['audio'])) {
1274
+ $info['audio']['dataformat'] = 'mp3';
1275
+ $info['audio']['codec'] = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3')));
1276
+ $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1277
+ $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
1278
+ $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1279
+ $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
1280
+ $info['bitrate'] = $info['audio']['bitrate'];
1281
+ }
1282
+ }
1283
+ }
1284
+ unset($getid3_mp3, $getid3_temp);
1285
+ $info['avdataend'] = $OldAVDataEnd;
1286
+ unset($OldAVDataEnd);
1287
+
1288
+ }
1289
+
1290
+ unset($mdat_offset, $chapter_string_length, $chapter_matches);
1291
+ break;
1292
+
1293
+ case 'free': // FREE space atom
1294
+ case 'skip': // SKIP atom
1295
+ case 'wide': // 64-bit expansion placeholder atom
1296
+ // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
1297
+
1298
+ // When writing QuickTime files, it is sometimes necessary to update an atom's size.
1299
+ // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
1300
+ // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
1301
+ // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
1302
+ // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
1303
+ // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
1304
+ // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
1305
+ break;
1306
+
1307
+
1308
+ case 'nsav': // NoSAVe atom
1309
+ // http://developer.apple.com/technotes/tn/tn2038.html
1310
+ $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
1311
+ break;
1312
+
1313
+ case 'ctyp': // Controller TYPe atom (seen on QTVR)
1314
+ // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
1315
+ // some controller names are:
1316
+ // 0x00 + 'std' for linear movie
1317
+ // 'none' for no controls
1318
+ $atom_structure['ctyp'] = substr($atom_data, 0, 4);
1319
+ $info['quicktime']['controller'] = $atom_structure['ctyp'];
1320
+ switch ($atom_structure['ctyp']) {
1321
+ case 'qtvr':
1322
+ $info['video']['dataformat'] = 'quicktimevr';
1323
+ break;
1324
+ }
1325
+ break;
1326
+
1327
+ case 'pano': // PANOrama track (seen on QTVR)
1328
+ $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
1329
+ break;
1330
+
1331
+ case 'hint': // HINT track
1332
+ case 'hinf': //
1333
+ case 'hinv': //
1334
+ case 'hnti': //
1335
+ $info['quicktime']['hinting'] = true;
1336
+ break;
1337
+
1338
+ case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
1339
+ for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) {
1340
+ $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
1341
+ }
1342
+ break;
1343
+
1344
+
1345
+ // Observed-but-not-handled atom types are just listed here to prevent warnings being generated
1346
+ case 'FXTC': // Something to do with Adobe After Effects (?)
1347
+ case 'PrmA':
1348
+ case 'code':
1349
+ case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
1350
+ case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html
1351
+ // tapt seems to be used to compute the video size [http://www.getid3.org/phpBB3/viewtopic.php?t=838]
1352
+ // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html
1353
+ // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html
1354
+ case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1355
+ case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1356
+ case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1357
+ case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html
1358
+ //$atom_structure['data'] = $atom_data;
1359
+ break;
1360
+
1361
+ case "\xA9".'xyz': // GPS latitude+longitude+altitude
1362
+ $atom_structure['data'] = $atom_data;
1363
+ if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) {
1364
+ @list($all, $latitude, $longitude, $altitude) = $matches;
1365
+ $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude);
1366
+ $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude);
1367
+ if (!empty($altitude)) {
1368
+ $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude);
1369
+ }
1370
+ } else {
1371
+ $info['warning'][] = 'QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.';
1372
+ }
1373
+ break;
1374
+
1375
+ case 'NCDT':
1376
+ // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1377
+ // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
1378
+ $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms);
1379
+ break;
1380
+ case 'NCTH': // Nikon Camera THumbnail image
1381
+ case 'NCVW': // Nikon Camera preVieW image
1382
+ // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1383
+ if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) {
1384
+ $atom_structure['data'] = $atom_data;
1385
+ $atom_structure['image_mime'] = 'image/jpeg';
1386
+ $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image'));
1387
+ $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']);
1388
+ }
1389
+ break;
1390
+ case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
1391
+ $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data);
1392
+ break;
1393
+ case 'NCHD': // Nikon:MakerNoteVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1394
+ case 'NCDB': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html
1395
+ case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html
1396
+ $atom_structure['data'] = $atom_data;
1397
+ break;
1398
+
1399
+ case "\x00\x00\x00\x00":
1400
+ case 'meta': // METAdata atom
1401
+ // some kind of metacontainer, may contain a big data dump such as:
1402
+ // mdta keys mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst data DEApple 0 (data DE2011-05-11T17:54:04+0200 2 *data DE+52.4936+013.3897+040.247/ data DE4.3.1 data DEiPhone 4
1403
+ // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
1404
+
1405
+ $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
1406
+ $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
1407
+ $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
1408
+ //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms);
1409
+ break;
1410
+
1411
+ case 'data': // metaDATA atom
1412
+ // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data
1413
+ $atom_structure['language'] = substr($atom_data, 4 + 0, 2);
1414
+ $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2));
1415
+ $atom_structure['data'] = substr($atom_data, 4 + 4);
1416
+ break;
1417
+
1418
+ default:
1419
+ $info['warning'][] = 'Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).') at offset '.$baseoffset;
1420
+ $atom_structure['data'] = $atom_data;
1421
+ break;
1422
+ }
1423
+ array_pop($atomHierarchy);
1424
+ return $atom_structure;
1425
+ }
1426
+
1427
+ public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
1428
+ //echo 'QuicktimeParseContainerAtom('.substr($atom_data, 4, 4).') @ '.$baseoffset.'<br><br>';
1429
+ $atom_structure = false;
1430
+ $subatomoffset = 0;
1431
+ $subatomcounter = 0;
1432
+ if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) {
1433
+ return false;
1434
+ }
1435
+ while ($subatomoffset < strlen($atom_data)) {
1436
+ $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4));
1437
+ $subatomname = substr($atom_data, $subatomoffset + 4, 4);
1438
+ $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8);
1439
+ if ($subatomsize == 0) {
1440
+ // Furthermore, for historical reasons the list of atoms is optionally
1441
+ // terminated by a 32-bit integer set to 0. If you are writing a program
1442
+ // to read user data atoms, you should allow for the terminating 0.
1443
+ return $atom_structure;
1444
+ }
1445
+
1446
+ $atom_structure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms);
1447
+
1448
+ $subatomoffset += $subatomsize;
1449
+ $subatomcounter++;
1450
+ }
1451
+ return $atom_structure;
1452
+ }
1453
+
1454
+
1455
+ public function quicktime_read_mp4_descr_length($data, &$offset) {
1456
+ // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html
1457
+ $num_bytes = 0;
1458
+ $length = 0;
1459
+ do {
1460
+ $b = ord(substr($data, $offset++, 1));
1461
+ $length = ($length << 7) | ($b & 0x7F);
1462
+ } while (($b & 0x80) && ($num_bytes++ < 4));
1463
+ return $length;
1464
+ }
1465
+
1466
+
1467
+ public function QuicktimeLanguageLookup($languageid) {
1468
+ // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353
1469
+ static $QuicktimeLanguageLookup = array();
1470
+ if (empty($QuicktimeLanguageLookup)) {
1471
+ $QuicktimeLanguageLookup[0] = 'English';
1472
+ $QuicktimeLanguageLookup[1] = 'French';
1473
+ $QuicktimeLanguageLookup[2] = 'German';
1474
+ $QuicktimeLanguageLookup[3] = 'Italian';
1475
+ $QuicktimeLanguageLookup[4] = 'Dutch';
1476
+ $QuicktimeLanguageLookup[5] = 'Swedish';
1477
+ $QuicktimeLanguageLookup[6] = 'Spanish';
1478
+ $QuicktimeLanguageLookup[7] = 'Danish';
1479
+ $QuicktimeLanguageLookup[8] = 'Portuguese';
1480
+ $QuicktimeLanguageLookup[9] = 'Norwegian';
1481
+ $QuicktimeLanguageLookup[10] = 'Hebrew';
1482
+ $QuicktimeLanguageLookup[11] = 'Japanese';
1483
+ $QuicktimeLanguageLookup[12] = 'Arabic';
1484
+ $QuicktimeLanguageLookup[13] = 'Finnish';
1485
+ $QuicktimeLanguageLookup[14] = 'Greek';
1486
+ $QuicktimeLanguageLookup[15] = 'Icelandic';
1487
+ $QuicktimeLanguageLookup[16] = 'Maltese';
1488
+ $QuicktimeLanguageLookup[17] = 'Turkish';
1489
+ $QuicktimeLanguageLookup[18] = 'Croatian';
1490
+ $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)';
1491
+ $QuicktimeLanguageLookup[20] = 'Urdu';
1492
+ $QuicktimeLanguageLookup[21] = 'Hindi';
1493
+ $QuicktimeLanguageLookup[22] = 'Thai';
1494
+ $QuicktimeLanguageLookup[23] = 'Korean';
1495
+ $QuicktimeLanguageLookup[24] = 'Lithuanian';
1496
+ $QuicktimeLanguageLookup[25] = 'Polish';
1497
+ $QuicktimeLanguageLookup[26] = 'Hungarian';
1498
+ $QuicktimeLanguageLookup[27] = 'Estonian';
1499
+ $QuicktimeLanguageLookup[28] = 'Lettish';
1500
+ $QuicktimeLanguageLookup[28] = 'Latvian';
1501
+ $QuicktimeLanguageLookup[29] = 'Saamisk';
1502
+ $QuicktimeLanguageLookup[29] = 'Lappish';
1503
+ $QuicktimeLanguageLookup[30] = 'Faeroese';
1504
+ $QuicktimeLanguageLookup[31] = 'Farsi';
1505
+ $QuicktimeLanguageLookup[31] = 'Persian';
1506
+ $QuicktimeLanguageLookup[32] = 'Russian';
1507
+ $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)';
1508
+ $QuicktimeLanguageLookup[34] = 'Flemish';
1509
+ $QuicktimeLanguageLookup[35] = 'Irish';
1510
+ $QuicktimeLanguageLookup[36] = 'Albanian';
1511
+ $QuicktimeLanguageLookup[37] = 'Romanian';
1512
+ $QuicktimeLanguageLookup[38] = 'Czech';
1513
+ $QuicktimeLanguageLookup[39] = 'Slovak';
1514
+ $QuicktimeLanguageLookup[40] = 'Slovenian';
1515
+ $QuicktimeLanguageLookup[41] = 'Yiddish';
1516
+ $QuicktimeLanguageLookup[42] = 'Serbian';
1517
+ $QuicktimeLanguageLookup[43] = 'Macedonian';
1518
+ $QuicktimeLanguageLookup[44] = 'Bulgarian';
1519
+ $QuicktimeLanguageLookup[45] = 'Ukrainian';
1520
+ $QuicktimeLanguageLookup[46] = 'Byelorussian';
1521
+ $QuicktimeLanguageLookup[47] = 'Uzbek';
1522
+ $QuicktimeLanguageLookup[48] = 'Kazakh';
1523
+ $QuicktimeLanguageLookup[49] = 'Azerbaijani';
1524
+ $QuicktimeLanguageLookup[50] = 'AzerbaijanAr';
1525
+ $QuicktimeLanguageLookup[51] = 'Armenian';
1526
+ $QuicktimeLanguageLookup[52] = 'Georgian';
1527
+ $QuicktimeLanguageLookup[53] = 'Moldavian';
1528
+ $QuicktimeLanguageLookup[54] = 'Kirghiz';
1529
+ $QuicktimeLanguageLookup[55] = 'Tajiki';
1530
+ $QuicktimeLanguageLookup[56] = 'Turkmen';
1531
+ $QuicktimeLanguageLookup[57] = 'Mongolian';
1532
+ $QuicktimeLanguageLookup[58] = 'MongolianCyr';
1533
+ $QuicktimeLanguageLookup[59] = 'Pashto';
1534
+ $QuicktimeLanguageLookup[60] = 'Kurdish';
1535
+ $QuicktimeLanguageLookup[61] = 'Kashmiri';
1536
+ $QuicktimeLanguageLookup[62] = 'Sindhi';
1537
+ $QuicktimeLanguageLookup[63] = 'Tibetan';
1538
+ $QuicktimeLanguageLookup[64] = 'Nepali';
1539
+ $QuicktimeLanguageLookup[65] = 'Sanskrit';
1540
+ $QuicktimeLanguageLookup[66] = 'Marathi';
1541
+ $QuicktimeLanguageLookup[67] = 'Bengali';
1542
+ $QuicktimeLanguageLookup[68] = 'Assamese';
1543
+ $QuicktimeLanguageLookup[69] = 'Gujarati';
1544
+ $QuicktimeLanguageLookup[70] = 'Punjabi';
1545
+ $QuicktimeLanguageLookup[71] = 'Oriya';
1546
+ $QuicktimeLanguageLookup[72] = 'Malayalam';
1547
+ $QuicktimeLanguageLookup[73] = 'Kannada';
1548
+ $QuicktimeLanguageLookup[74] = 'Tamil';
1549
+ $QuicktimeLanguageLookup[75] = 'Telugu';
1550
+ $QuicktimeLanguageLookup[76] = 'Sinhalese';
1551
+ $QuicktimeLanguageLookup[77] = 'Burmese';
1552
+ $QuicktimeLanguageLookup[78] = 'Khmer';
1553
+ $QuicktimeLanguageLookup[79] = 'Lao';
1554
+ $QuicktimeLanguageLookup[80] = 'Vietnamese';
1555
+ $QuicktimeLanguageLookup[81] = 'Indonesian';
1556
+ $QuicktimeLanguageLookup[82] = 'Tagalog';
1557
+ $QuicktimeLanguageLookup[83] = 'MalayRoman';
1558
+ $QuicktimeLanguageLookup[84] = 'MalayArabic';
1559
+ $QuicktimeLanguageLookup[85] = 'Amharic';
1560
+ $QuicktimeLanguageLookup[86] = 'Tigrinya';
1561
+ $QuicktimeLanguageLookup[87] = 'Galla';
1562
+ $QuicktimeLanguageLookup[87] = 'Oromo';
1563
+ $QuicktimeLanguageLookup[88] = 'Somali';
1564
+ $QuicktimeLanguageLookup[89] = 'Swahili';
1565
+ $QuicktimeLanguageLookup[90] = 'Ruanda';
1566
+ $QuicktimeLanguageLookup[91] = 'Rundi';
1567
+ $QuicktimeLanguageLookup[92] = 'Chewa';
1568
+ $QuicktimeLanguageLookup[93] = 'Malagasy';
1569
+ $QuicktimeLanguageLookup[94] = 'Esperanto';
1570
+ $QuicktimeLanguageLookup[128] = 'Welsh';
1571
+ $QuicktimeLanguageLookup[129] = 'Basque';
1572
+ $QuicktimeLanguageLookup[130] = 'Catalan';
1573
+ $QuicktimeLanguageLookup[131] = 'Latin';
1574
+ $QuicktimeLanguageLookup[132] = 'Quechua';
1575
+ $QuicktimeLanguageLookup[133] = 'Guarani';
1576
+ $QuicktimeLanguageLookup[134] = 'Aymara';
1577
+ $QuicktimeLanguageLookup[135] = 'Tatar';
1578
+ $QuicktimeLanguageLookup[136] = 'Uighur';
1579
+ $QuicktimeLanguageLookup[137] = 'Dzongkha';
1580
+ $QuicktimeLanguageLookup[138] = 'JavaneseRom';
1581
+ $QuicktimeLanguageLookup[32767] = 'Unspecified';
1582
+ }
1583
+ if (($languageid > 138) && ($languageid < 32767)) {
1584
+ /*
1585
+ ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php
1586
+ Because the language codes specified by ISO 639-2/T are three characters long, they must be packed to fit into a 16-bit field.
1587
+ The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate
1588
+ these integers into the least significant 15 bits of a 16-bit integer, leaving the 16-bit integer's most significant bit set to zero.
1589
+
1590
+ One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character
1591
+ and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character,
1592
+ and add the three 16-bit values. This will result in a single 16-bit value with the three codes correctly packed into the 15 least
1593
+ significant bits and the most significant bit set to zero.
1594
+ */
1595
+ $iso_language_id = '';
1596
+ $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60);
1597
+ $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60);
1598
+ $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60);
1599
+ $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id);
1600
+ }
1601
+ return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid');
1602
+ }
1603
+
1604
+ public function QuicktimeVideoCodecLookup($codecid) {
1605
+ static $QuicktimeVideoCodecLookup = array();
1606
+ if (empty($QuicktimeVideoCodecLookup)) {
1607
+ $QuicktimeVideoCodecLookup['.SGI'] = 'SGI';
1608
+ $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1';
1609
+ $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2';
1610
+ $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4';
1611
+ $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB';
1612
+ $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC';
1613
+ $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG';
1614
+ $QuicktimeVideoCodecLookup['b16g'] = '16Gray';
1615
+ $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray';
1616
+ $QuicktimeVideoCodecLookup['b48r'] = '48RGB';
1617
+ $QuicktimeVideoCodecLookup['b64a'] = '64ARGB';
1618
+ $QuicktimeVideoCodecLookup['base'] = 'Base';
1619
+ $QuicktimeVideoCodecLookup['clou'] = 'Cloud';
1620
+ $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK';
1621
+ $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak';
1622
+ $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG';
1623
+ $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC';
1624
+ $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL';
1625
+ $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC';
1626
+ $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL';
1627
+ $QuicktimeVideoCodecLookup['fire'] = 'Fire';
1628
+ $QuicktimeVideoCodecLookup['flic'] = 'FLC';
1629
+ $QuicktimeVideoCodecLookup['gif '] = 'GIF';
1630
+ $QuicktimeVideoCodecLookup['h261'] = 'H261';
1631
+ $QuicktimeVideoCodecLookup['h263'] = 'H263';
1632
+ $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4';
1633
+ $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG';
1634
+ $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD';
1635
+ $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A';
1636
+ $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B';
1637
+ $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1';
1638
+ $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420';
1639
+ $QuicktimeVideoCodecLookup['path'] = 'Vector';
1640
+ $QuicktimeVideoCodecLookup['png '] = 'PNG';
1641
+ $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint';
1642
+ $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX';
1643
+ $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw';
1644
+ $QuicktimeVideoCodecLookup['raw '] = 'RAW';
1645
+ $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple';
1646
+ $QuicktimeVideoCodecLookup['rpza'] = 'Video';
1647
+ $QuicktimeVideoCodecLookup['smc '] = 'Graphics';
1648
+ $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1';
1649
+ $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3';
1650
+ $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9';
1651
+ $QuicktimeVideoCodecLookup['tga '] = 'Targa';
1652
+ $QuicktimeVideoCodecLookup['tiff'] = 'TIFF';
1653
+ $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW';
1654
+ $QuicktimeVideoCodecLookup['WRLE'] = 'BMP';
1655
+ $QuicktimeVideoCodecLookup['y420'] = 'YUV420';
1656
+ $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo';
1657
+ $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned';
1658
+ $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned';
1659
+ }
1660
+ return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : '');
1661
+ }
1662
+
1663
+ public function QuicktimeAudioCodecLookup($codecid) {
1664
+ static $QuicktimeAudioCodecLookup = array();
1665
+ if (empty($QuicktimeAudioCodecLookup)) {
1666
+ $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias';
1667
+ $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC';
1668
+ $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1';
1669
+ $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec';
1670
+ $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1';
1671
+ $QuicktimeAudioCodecLookup['conv'] = 'Sample Format';
1672
+ $QuicktimeAudioCodecLookup['dvca'] = 'DV';
1673
+ $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1';
1674
+ $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer';
1675
+ $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point';
1676
+ $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point';
1677
+ $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1';
1678
+ $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer';
1679
+ $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer';
1680
+ $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1';
1681
+ $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1';
1682
+ $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1';
1683
+ $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer';
1684
+ $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer';
1685
+ $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC';
1686
+ $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM';
1687
+ $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA';
1688
+ $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III';
1689
+ $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding';
1690
+ $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice';
1691
+ $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2';
1692
+ $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1';
1693
+ $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate';
1694
+ $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate';
1695
+ $QuicktimeAudioCodecLookup['raw '] = 'raw PCM';
1696
+ $QuicktimeAudioCodecLookup['sour'] = 'Sound Source';
1697
+ $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)';
1698
+ $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II';
1699
+ $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II';
1700
+ $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II';
1701
+ $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II';
1702
+ $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)';
1703
+ $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1';
1704
+ }
1705
+ return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : '');
1706
+ }
1707
+
1708
+ public function QuicktimeDCOMLookup($compressionid) {
1709
+ static $QuicktimeDCOMLookup = array();
1710
+ if (empty($QuicktimeDCOMLookup)) {
1711
+ $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate';
1712
+ $QuicktimeDCOMLookup['adec'] = 'Apple Compression';
1713
+ }
1714
+ return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : '');
1715
+ }
1716
+
1717
+ public function QuicktimeColorNameLookup($colordepthid) {
1718
+ static $QuicktimeColorNameLookup = array();
1719
+ if (empty($QuicktimeColorNameLookup)) {
1720
+ $QuicktimeColorNameLookup[1] = '2-color (monochrome)';
1721
+ $QuicktimeColorNameLookup[2] = '4-color';
1722
+ $QuicktimeColorNameLookup[4] = '16-color';
1723
+ $QuicktimeColorNameLookup[8] = '256-color';
1724
+ $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)';
1725
+ $QuicktimeColorNameLookup[24] = 'millions (24-bit color)';
1726
+ $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)';
1727
+ $QuicktimeColorNameLookup[33] = 'black & white';
1728
+ $QuicktimeColorNameLookup[34] = '4-gray';
1729
+ $QuicktimeColorNameLookup[36] = '16-gray';
1730
+ $QuicktimeColorNameLookup[40] = '256-gray';
1731
+ }
1732
+ return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid');
1733
+ }
1734
+
1735
+ public function QuicktimeSTIKLookup($stik) {
1736
+ static $QuicktimeSTIKLookup = array();
1737
+ if (empty($QuicktimeSTIKLookup)) {
1738
+ $QuicktimeSTIKLookup[0] = 'Movie';
1739
+ $QuicktimeSTIKLookup[1] = 'Normal';
1740
+ $QuicktimeSTIKLookup[2] = 'Audiobook';
1741
+ $QuicktimeSTIKLookup[5] = 'Whacked Bookmark';
1742
+ $QuicktimeSTIKLookup[6] = 'Music Video';
1743
+ $QuicktimeSTIKLookup[9] = 'Short Film';
1744
+ $QuicktimeSTIKLookup[10] = 'TV Show';
1745
+ $QuicktimeSTIKLookup[11] = 'Booklet';
1746
+ $QuicktimeSTIKLookup[14] = 'Ringtone';
1747
+ $QuicktimeSTIKLookup[21] = 'Podcast';
1748
+ }
1749
+ return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid');
1750
+ }
1751
+
1752
+ public function QuicktimeIODSaudioProfileName($audio_profile_id) {
1753
+ static $QuicktimeIODSaudioProfileNameLookup = array();
1754
+ if (empty($QuicktimeIODSaudioProfileNameLookup)) {
1755
+ $QuicktimeIODSaudioProfileNameLookup = array(
1756
+ 0x00 => 'ISO Reserved (0x00)',
1757
+ 0x01 => 'Main Audio Profile @ Level 1',
1758
+ 0x02 => 'Main Audio Profile @ Level 2',
1759
+ 0x03 => 'Main Audio Profile @ Level 3',
1760
+ 0x04 => 'Main Audio Profile @ Level 4',
1761
+ 0x05 => 'Scalable Audio Profile @ Level 1',
1762
+ 0x06 => 'Scalable Audio Profile @ Level 2',
1763
+ 0x07 => 'Scalable Audio Profile @ Level 3',
1764
+ 0x08 => 'Scalable Audio Profile @ Level 4',
1765
+ 0x09 => 'Speech Audio Profile @ Level 1',
1766
+ 0x0A => 'Speech Audio Profile @ Level 2',
1767
+ 0x0B => 'Synthetic Audio Profile @ Level 1',
1768
+ 0x0C => 'Synthetic Audio Profile @ Level 2',
1769
+ 0x0D => 'Synthetic Audio Profile @ Level 3',
1770
+ 0x0E => 'High Quality Audio Profile @ Level 1',
1771
+ 0x0F => 'High Quality Audio Profile @ Level 2',
1772
+ 0x10 => 'High Quality Audio Profile @ Level 3',
1773
+ 0x11 => 'High Quality Audio Profile @ Level 4',
1774
+ 0x12 => 'High Quality Audio Profile @ Level 5',
1775
+ 0x13 => 'High Quality Audio Profile @ Level 6',
1776
+ 0x14 => 'High Quality Audio Profile @ Level 7',
1777
+ 0x15 => 'High Quality Audio Profile @ Level 8',
1778
+ 0x16 => 'Low Delay Audio Profile @ Level 1',
1779
+ 0x17 => 'Low Delay Audio Profile @ Level 2',
1780
+ 0x18 => 'Low Delay Audio Profile @ Level 3',
1781
+ 0x19 => 'Low Delay Audio Profile @ Level 4',
1782
+ 0x1A => 'Low Delay Audio Profile @ Level 5',
1783
+ 0x1B => 'Low Delay Audio Profile @ Level 6',
1784
+ 0x1C => 'Low Delay Audio Profile @ Level 7',
1785
+ 0x1D => 'Low Delay Audio Profile @ Level 8',
1786
+ 0x1E => 'Natural Audio Profile @ Level 1',
1787
+ 0x1F => 'Natural Audio Profile @ Level 2',
1788
+ 0x20 => 'Natural Audio Profile @ Level 3',
1789
+ 0x21 => 'Natural Audio Profile @ Level 4',
1790
+ 0x22 => 'Mobile Audio Internetworking Profile @ Level 1',
1791
+ 0x23 => 'Mobile Audio Internetworking Profile @ Level 2',
1792
+ 0x24 => 'Mobile Audio Internetworking Profile @ Level 3',
1793
+ 0x25 => 'Mobile Audio Internetworking Profile @ Level 4',
1794
+ 0x26 => 'Mobile Audio Internetworking Profile @ Level 5',
1795
+ 0x27 => 'Mobile Audio Internetworking Profile @ Level 6',
1796
+ 0x28 => 'AAC Profile @ Level 1',
1797
+ 0x29 => 'AAC Profile @ Level 2',
1798
+ 0x2A => 'AAC Profile @ Level 4',
1799
+ 0x2B => 'AAC Profile @ Level 5',
1800
+ 0x2C => 'High Efficiency AAC Profile @ Level 2',
1801
+ 0x2D => 'High Efficiency AAC Profile @ Level 3',
1802
+ 0x2E => 'High Efficiency AAC Profile @ Level 4',
1803
+ 0x2F => 'High Efficiency AAC Profile @ Level 5',
1804
+ 0xFE => 'Not part of MPEG-4 audio profiles',
1805
+ 0xFF => 'No audio capability required',
1806
+ );
1807
+ }
1808
+ return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private');
1809
+ }
1810
+
1811
+
1812
+ public function QuicktimeIODSvideoProfileName($video_profile_id) {
1813
+ static $QuicktimeIODSvideoProfileNameLookup = array();
1814
+ if (empty($QuicktimeIODSvideoProfileNameLookup)) {
1815
+ $QuicktimeIODSvideoProfileNameLookup = array(
1816
+ 0x00 => 'Reserved (0x00) Profile',
1817
+ 0x01 => 'Simple Profile @ Level 1',
1818
+ 0x02 => 'Simple Profile @ Level 2',
1819
+ 0x03 => 'Simple Profile @ Level 3',
1820
+ 0x08 => 'Simple Profile @ Level 0',
1821
+ 0x10 => 'Simple Scalable Profile @ Level 0',
1822
+ 0x11 => 'Simple Scalable Profile @ Level 1',
1823
+ 0x12 => 'Simple Scalable Profile @ Level 2',
1824
+ 0x15 => 'AVC/H264 Profile',
1825
+ 0x21 => 'Core Profile @ Level 1',
1826
+ 0x22 => 'Core Profile @ Level 2',
1827
+ 0x32 => 'Main Profile @ Level 2',
1828
+ 0x33 => 'Main Profile @ Level 3',
1829
+ 0x34 => 'Main Profile @ Level 4',
1830
+ 0x42 => 'N-bit Profile @ Level 2',
1831
+ 0x51 => 'Scalable Texture Profile @ Level 1',
1832
+ 0x61 => 'Simple Face Animation Profile @ Level 1',
1833
+ 0x62 => 'Simple Face Animation Profile @ Level 2',
1834
+ 0x63 => 'Simple FBA Profile @ Level 1',
1835
+ 0x64 => 'Simple FBA Profile @ Level 2',
1836
+ 0x71 => 'Basic Animated Texture Profile @ Level 1',
1837
+ 0x72 => 'Basic Animated Texture Profile @ Level 2',
1838
+ 0x81 => 'Hybrid Profile @ Level 1',
1839
+ 0x82 => 'Hybrid Profile @ Level 2',
1840
+ 0x91 => 'Advanced Real Time Simple Profile @ Level 1',
1841
+ 0x92 => 'Advanced Real Time Simple Profile @ Level 2',
1842
+ 0x93 => 'Advanced Real Time Simple Profile @ Level 3',
1843
+ 0x94 => 'Advanced Real Time Simple Profile @ Level 4',
1844
+ 0xA1 => 'Core Scalable Profile @ Level1',
1845
+ 0xA2 => 'Core Scalable Profile @ Level2',
1846
+ 0xA3 => 'Core Scalable Profile @ Level3',
1847
+ 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1',
1848
+ 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2',
1849
+ 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3',
1850
+ 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4',
1851
+ 0xC1 => 'Advanced Core Profile @ Level 1',
1852
+ 0xC2 => 'Advanced Core Profile @ Level 2',
1853
+ 0xD1 => 'Advanced Scalable Texture @ Level1',
1854
+ 0xD2 => 'Advanced Scalable Texture @ Level2',
1855
+ 0xE1 => 'Simple Studio Profile @ Level 1',
1856
+ 0xE2 => 'Simple Studio Profile @ Level 2',
1857
+ 0xE3 => 'Simple Studio Profile @ Level 3',
1858
+ 0xE4 => 'Simple Studio Profile @ Level 4',
1859
+ 0xE5 => 'Core Studio Profile @ Level 1',
1860
+ 0xE6 => 'Core Studio Profile @ Level 2',
1861
+ 0xE7 => 'Core Studio Profile @ Level 3',
1862
+ 0xE8 => 'Core Studio Profile @ Level 4',
1863
+ 0xF0 => 'Advanced Simple Profile @ Level 0',
1864
+ 0xF1 => 'Advanced Simple Profile @ Level 1',
1865
+ 0xF2 => 'Advanced Simple Profile @ Level 2',
1866
+ 0xF3 => 'Advanced Simple Profile @ Level 3',
1867
+ 0xF4 => 'Advanced Simple Profile @ Level 4',
1868
+ 0xF5 => 'Advanced Simple Profile @ Level 5',
1869
+ 0xF7 => 'Advanced Simple Profile @ Level 3b',
1870
+ 0xF8 => 'Fine Granularity Scalable Profile @ Level 0',
1871
+ 0xF9 => 'Fine Granularity Scalable Profile @ Level 1',
1872
+ 0xFA => 'Fine Granularity Scalable Profile @ Level 2',
1873
+ 0xFB => 'Fine Granularity Scalable Profile @ Level 3',
1874
+ 0xFC => 'Fine Granularity Scalable Profile @ Level 4',
1875
+ 0xFD => 'Fine Granularity Scalable Profile @ Level 5',
1876
+ 0xFE => 'Not part of MPEG-4 Visual profiles',
1877
+ 0xFF => 'No visual capability required',
1878
+ );
1879
+ }
1880
+ return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile');
1881
+ }
1882
+
1883
+
1884
+ public function QuicktimeContentRatingLookup($rtng) {
1885
+ static $QuicktimeContentRatingLookup = array();
1886
+ if (empty($QuicktimeContentRatingLookup)) {
1887
+ $QuicktimeContentRatingLookup[0] = 'None';
1888
+ $QuicktimeContentRatingLookup[2] = 'Clean';
1889
+ $QuicktimeContentRatingLookup[4] = 'Explicit';
1890
+ }
1891
+ return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid');
1892
+ }
1893
+
1894
+ public function QuicktimeStoreAccountTypeLookup($akid) {
1895
+ static $QuicktimeStoreAccountTypeLookup = array();
1896
+ if (empty($QuicktimeStoreAccountTypeLookup)) {
1897
+ $QuicktimeStoreAccountTypeLookup[0] = 'iTunes';
1898
+ $QuicktimeStoreAccountTypeLookup[1] = 'AOL';
1899
+ }
1900
+ return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid');
1901
+ }
1902
+
1903
+ public function QuicktimeStoreFrontCodeLookup($sfid) {
1904
+ static $QuicktimeStoreFrontCodeLookup = array();
1905
+ if (empty($QuicktimeStoreFrontCodeLookup)) {
1906
+ $QuicktimeStoreFrontCodeLookup[143460] = 'Australia';
1907
+ $QuicktimeStoreFrontCodeLookup[143445] = 'Austria';
1908
+ $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium';
1909
+ $QuicktimeStoreFrontCodeLookup[143455] = 'Canada';
1910
+ $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark';
1911
+ $QuicktimeStoreFrontCodeLookup[143447] = 'Finland';
1912
+ $QuicktimeStoreFrontCodeLookup[143442] = 'France';
1913
+ $QuicktimeStoreFrontCodeLookup[143443] = 'Germany';
1914
+ $QuicktimeStoreFrontCodeLookup[143448] = 'Greece';
1915
+ $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland';
1916
+ $QuicktimeStoreFrontCodeLookup[143450] = 'Italy';
1917
+ $QuicktimeStoreFrontCodeLookup[143462] = 'Japan';
1918
+ $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg';
1919
+ $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands';
1920
+ $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand';
1921
+ $QuicktimeStoreFrontCodeLookup[143457] = 'Norway';
1922
+ $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal';
1923
+ $QuicktimeStoreFrontCodeLookup[143454] = 'Spain';
1924
+ $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden';
1925
+ $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland';
1926
+ $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom';
1927
+ $QuicktimeStoreFrontCodeLookup[143441] = 'United States';
1928
+ }
1929
+ return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid');
1930
+ }
1931
+
1932
+ public function QuicktimeParseNikonNCTG($atom_data) {
1933
+ // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
1934
+ // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100
1935
+ // Data is stored as records of:
1936
+ // * 4 bytes record type
1937
+ // * 2 bytes size of data field type:
1938
+ // 0x0001 = flag (size field *= 1-byte)
1939
+ // 0x0002 = char (size field *= 1-byte)
1940
+ // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
1941
+ // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
1942
+ // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
1943
+ // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
1944
+ // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
1945
+ // * 2 bytes data size field
1946
+ // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15")
1947
+ // all integers are stored BigEndian
1948
+
1949
+ $NCTGtagName = array(
1950
+ 0x00000001 => 'Make',
1951
+ 0x00000002 => 'Model',
1952
+ 0x00000003 => 'Software',
1953
+ 0x00000011 => 'CreateDate',
1954
+ 0x00000012 => 'DateTimeOriginal',
1955
+ 0x00000013 => 'FrameCount',
1956
+ 0x00000016 => 'FrameRate',
1957
+ 0x00000022 => 'FrameWidth',
1958
+ 0x00000023 => 'FrameHeight',
1959
+ 0x00000032 => 'AudioChannels',
1960
+ 0x00000033 => 'AudioBitsPerSample',
1961
+ 0x00000034 => 'AudioSampleRate',
1962
+ 0x02000001 => 'MakerNoteVersion',
1963
+ 0x02000005 => 'WhiteBalance',
1964
+ 0x0200000b => 'WhiteBalanceFineTune',
1965
+ 0x0200001e => 'ColorSpace',
1966
+ 0x02000023 => 'PictureControlData',
1967
+ 0x02000024 => 'WorldTime',
1968
+ 0x02000032 => 'UnknownInfo',
1969
+ 0x02000083 => 'LensType',
1970
+ 0x02000084 => 'Lens',
1971
+ );
1972
+
1973
+ $offset = 0;
1974
+ $datalength = strlen($atom_data);
1975
+ $parsed = array();
1976
+ while ($offset < $datalength) {
1977
+ //echo getid3_lib::PrintHexBytes(substr($atom_data, $offset, 4)).'<br>';
1978
+ $record_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); $offset += 4;
1979
+ $data_size_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
1980
+ $data_size = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2;
1981
+ switch ($data_size_type) {
1982
+ case 0x0001: // 0x0001 = flag (size field *= 1-byte)
1983
+ $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1));
1984
+ $offset += ($data_size * 1);
1985
+ break;
1986
+ case 0x0002: // 0x0002 = char (size field *= 1-byte)
1987
+ $data = substr($atom_data, $offset, $data_size * 1);
1988
+ $offset += ($data_size * 1);
1989
+ $data = rtrim($data, "\x00");
1990
+ break;
1991
+ case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB
1992
+ $data = '';
1993
+ for ($i = $data_size - 1; $i >= 0; $i--) {
1994
+ $data .= substr($atom_data, $offset + ($i * 2), 2);
1995
+ }
1996
+ $data = getid3_lib::BigEndian2Int($data);
1997
+ $offset += ($data_size * 2);
1998
+ break;
1999
+ case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD
2000
+ $data = '';
2001
+ for ($i = $data_size - 1; $i >= 0; $i--) {
2002
+ $data .= substr($atom_data, $offset + ($i * 4), 4);
2003
+ }
2004
+ $data = getid3_lib::BigEndian2Int($data);
2005
+ $offset += ($data_size * 4);
2006
+ break;
2007
+ case 0x0005: // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together
2008
+ $data = array();
2009
+ for ($i = 0; $i < $data_size; $i++) {
2010
+ $numerator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4));
2011
+ $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4));
2012
+ if ($denomninator == 0) {
2013
+ $data[$i] = false;
2014
+ } else {
2015
+ $data[$i] = (double) $numerator / $denomninator;
2016
+ }
2017
+ }
2018
+ $offset += (8 * $data_size);
2019
+ if (count($data) == 1) {
2020
+ $data = $data[0];
2021
+ }
2022
+ break;
2023
+ case 0x0007: // 0x0007 = bytes (size field *= 1-byte), values are stored as ??????
2024
+ $data = substr($atom_data, $offset, $data_size * 1);
2025
+ $offset += ($data_size * 1);
2026
+ break;
2027
+ case 0x0008: // 0x0008 = ????? (size field *= 2-byte), values are stored as ??????
2028
+ $data = substr($atom_data, $offset, $data_size * 2);
2029
+ $offset += ($data_size * 2);
2030
+ break;
2031
+ default:
2032
+ echo 'QuicktimeParseNikonNCTG()::unknown $data_size_type: '.$data_size_type.'<br>';
2033
+ break 2;
2034
+ }
2035
+
2036
+ switch ($record_type) {
2037
+ case 0x00000011: // CreateDate
2038
+ case 0x00000012: // DateTimeOriginal
2039
+ $data = strtotime($data);
2040
+ break;
2041
+ case 0x0200001e: // ColorSpace
2042
+ switch ($data) {
2043
+ case 1:
2044
+ $data = 'sRGB';
2045
+ break;
2046
+ case 2:
2047
+ $data = 'Adobe RGB';
2048
+ break;
2049
+ }
2050
+ break;
2051
+ case 0x02000023: // PictureControlData
2052
+ $PictureControlAdjust = array(0=>'default', 1=>'quick', 2=>'full');
2053
+ $FilterEffect = array(0x80=>'off', 0x81=>'yellow', 0x82=>'orange', 0x83=>'red', 0x84=>'green', 0xff=>'n/a');
2054
+ $ToningEffect = array(0x80=>'b&w', 0x81=>'sepia', 0x82=>'cyanotype', 0x83=>'red', 0x84=>'yellow', 0x85=>'green', 0x86=>'blue-green', 0x87=>'blue', 0x88=>'purple-blue', 0x89=>'red-purple', 0xff=>'n/a');
2055
+ $data = array(
2056
+ 'PictureControlVersion' => substr($data, 0, 4),
2057
+ 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"),
2058
+ 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"),
2059
+ //'?' => substr($data, 44, 4),
2060
+ 'PictureControlAdjust' => $PictureControlAdjust[ord(substr($data, 48, 1))],
2061
+ 'PictureControlQuickAdjust' => ord(substr($data, 49, 1)),
2062
+ 'Sharpness' => ord(substr($data, 50, 1)),
2063
+ 'Contrast' => ord(substr($data, 51, 1)),
2064
+ 'Brightness' => ord(substr($data, 52, 1)),
2065
+ 'Saturation' => ord(substr($data, 53, 1)),
2066
+ 'HueAdjustment' => ord(substr($data, 54, 1)),
2067
+ 'FilterEffect' => $FilterEffect[ord(substr($data, 55, 1))],
2068
+ 'ToningEffect' => $ToningEffect[ord(substr($data, 56, 1))],
2069
+ 'ToningSaturation' => ord(substr($data, 57, 1)),
2070
+ );
2071
+ break;
2072
+ case 0x02000024: // WorldTime
2073
+ // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime
2074
+ // timezone is stored as offset from GMT in minutes
2075
+ $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2));
2076
+ if ($timezone & 0x8000) {
2077
+ $timezone = 0 - (0x10000 - $timezone);
2078
+ }
2079
+ $timezone /= 60;
2080
+
2081
+ $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1));
2082
+ switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) {
2083
+ case 2:
2084
+ $datedisplayformat = 'D/M/Y'; break;
2085
+ case 1:
2086
+ $datedisplayformat = 'M/D/Y'; break;
2087
+ case 0:
2088
+ default:
2089
+ $datedisplayformat = 'Y/M/D'; break;
2090
+ }
2091
+
2092
+ $data = array('timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat);
2093
+ break;
2094
+ case 0x02000083: // LensType
2095
+ $data = array(
2096
+ //'_' => $data,
2097
+ 'mf' => (bool) ($data & 0x01),
2098
+ 'd' => (bool) ($data & 0x02),
2099
+ 'g' => (bool) ($data & 0x04),
2100
+ 'vr' => (bool) ($data & 0x08),
2101
+ );
2102
+ break;
2103
+ }
2104
+ $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT));
2105
+ $parsed[$tag_name] = $data;
2106
+ }
2107
+ return $parsed;
2108
+ }
2109
+
2110
+
2111
+ public function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') {
2112
+ static $handyatomtranslatorarray = array();
2113
+ if (empty($handyatomtranslatorarray)) {
2114
+ $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright';
2115
+ $handyatomtranslatorarray["\xA9".'day'] = 'creation_date'; // iTunes 4.0
2116
+ $handyatomtranslatorarray["\xA9".'dir'] = 'director';
2117
+ $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1';
2118
+ $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2';
2119
+ $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3';
2120
+ $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4';
2121
+ $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5';
2122
+ $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6';
2123
+ $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7';
2124
+ $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8';
2125
+ $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9';
2126
+ $handyatomtranslatorarray["\xA9".'fmt'] = 'format';
2127
+ $handyatomtranslatorarray["\xA9".'inf'] = 'information';
2128
+ $handyatomtranslatorarray["\xA9".'prd'] = 'producer';
2129
+ $handyatomtranslatorarray["\xA9".'prf'] = 'performers';
2130
+ $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements';
2131
+ $handyatomtranslatorarray["\xA9".'src'] = 'source_credit';
2132
+ $handyatomtranslatorarray["\xA9".'wrt'] = 'writer';
2133
+
2134
+ // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
2135
+ $handyatomtranslatorarray["\xA9".'nam'] = 'title'; // iTunes 4.0
2136
+ $handyatomtranslatorarray["\xA9".'cmt'] = 'comment'; // iTunes 4.0
2137
+ $handyatomtranslatorarray["\xA9".'wrn'] = 'warning';
2138
+ $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer';
2139
+ $handyatomtranslatorarray["\xA9".'mak'] = 'make';
2140
+ $handyatomtranslatorarray["\xA9".'mod'] = 'model';
2141
+ $handyatomtranslatorarray["\xA9".'PRD'] = 'product';
2142
+ $handyatomtranslatorarray["\xA9".'swr'] = 'software';
2143
+ $handyatomtranslatorarray["\xA9".'aut'] = 'author';
2144
+ $handyatomtranslatorarray["\xA9".'ART'] = 'artist';
2145
+ $handyatomtranslatorarray["\xA9".'trk'] = 'track';
2146
+ $handyatomtranslatorarray["\xA9".'alb'] = 'album'; // iTunes 4.0
2147
+ $handyatomtranslatorarray["\xA9".'com'] = 'comment';
2148
+ $handyatomtranslatorarray["\xA9".'gen'] = 'genre'; // iTunes 4.0
2149
+ $handyatomtranslatorarray["\xA9".'ope'] = 'composer';
2150
+ $handyatomtranslatorarray["\xA9".'url'] = 'url';
2151
+ $handyatomtranslatorarray["\xA9".'enc'] = 'encoder';
2152
+
2153
+ // http://atomicparsley.sourceforge.net/mpeg-4files.html
2154
+ $handyatomtranslatorarray["\xA9".'art'] = 'artist'; // iTunes 4.0
2155
+ $handyatomtranslatorarray['aART'] = 'album_artist';
2156
+ $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0
2157
+ $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0
2158
+ $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0
2159
+ $handyatomtranslatorarray["\xA9".'too'] = 'encoder'; // iTunes 4.0
2160
+ $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0
2161
+ $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0?
2162
+ $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0
2163
+ $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0
2164
+ $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0
2165
+ $handyatomtranslatorarray["\xA9".'grp'] = 'grouping'; // iTunes 4.2
2166
+ $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9
2167
+ $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9
2168
+ $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9
2169
+ $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9
2170
+ $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9
2171
+ $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9
2172
+ $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0
2173
+ $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics'; // iTunes 5.0
2174
+ $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0
2175
+ $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0
2176
+ $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0
2177
+ $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0
2178
+ $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2
2179
+ $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0
2180
+
2181
+ // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt
2182
+
2183
+
2184
+
2185
+ // boxnames:
2186
+ /*
2187
+ $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB';
2188
+ $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM';
2189
+ $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params';
2190
+ $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain';
2191
+ $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak';
2192
+ $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax';
2193
+ $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID';
2194
+ $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id';
2195
+ $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id';
2196
+ $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id';
2197
+ $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id';
2198
+ $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id';
2199
+
2200
+ // http://age.hobba.nl/audio/tag_frame_reference.html
2201
+ $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355
2202
+ $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355
2203
+ */
2204
+ }
2205
+ $info = &$this->getid3->info;
2206
+ $comment_key = '';
2207
+ if ($boxname && ($boxname != $keyname)) {
2208
+ $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname);
2209
+ } elseif (isset($handyatomtranslatorarray[$keyname])) {
2210
+ $comment_key = $handyatomtranslatorarray[$keyname];
2211
+ }
2212
+ if ($comment_key) {
2213
+ if ($comment_key == 'picture') {
2214
+ if (!is_array($data)) {
2215
+ $image_mime = '';
2216
+ if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) {
2217
+ $image_mime = 'image/png';
2218
+ } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) {
2219
+ $image_mime = 'image/jpeg';
2220
+ } elseif (preg_match('#^GIF#', $data)) {
2221
+ $image_mime = 'image/gif';
2222
+ } elseif (preg_match('#^BM#', $data)) {
2223
+ $image_mime = 'image/bmp';
2224
+ }
2225
+ $data = array('data'=>$data, 'image_mime'=>$image_mime);
2226
+ }
2227
+ }
2228
+ $info['quicktime']['comments'][$comment_key][] = $data;
2229
+ }
2230
+ return true;
2231
+ }
2232
+
2233
+ public function NoNullString($nullterminatedstring) {
2234
+ // remove the single null terminator on null terminated strings
2235
+ if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") {
2236
+ return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1);
2237
+ }
2238
+ return $nullterminatedstring;
2239
+ }
2240
+
2241
+ public function Pascal2String($pascalstring) {
2242
+ // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string
2243
+ return substr($pascalstring, 1);
2244
+ }
2245
+
2246
+ }
getid3/module.audio-video.riff.php CHANGED
@@ -1,2409 +1,2586 @@
1
- <?php
2
- /////////////////////////////////////////////////////////////////
3
- /// getID3() by James Heinrich <info@getid3.org> //
4
- // available at http://getid3.sourceforge.net //
5
- // or http://www.getid3.org //
6
- /////////////////////////////////////////////////////////////////
7
- // See readme.txt for more details //
8
- /////////////////////////////////////////////////////////////////
9
- // //
10
- // module.audio-video.riff.php //
11
- // module for analyzing RIFF files //
12
- // multiple formats supported by this module: //
13
- // Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX //
14
- // dependencies: module.audio.mp3.php //
15
- // module.audio.ac3.php (optional) //
16
- // module.audio.dts.php (optional) //
17
- // ///
18
- /////////////////////////////////////////////////////////////////
19
-
20
- getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
21
-
22
- class getid3_riff extends getid3_handler
23
- {
24
-
25
- function Analyze() {
26
- $info = &$this->getid3->info;
27
-
28
- // initialize these values to an empty array, otherwise they default to NULL
29
- // and you can't append array values to a NULL value
30
- $info['riff'] = array('raw'=>array());
31
-
32
- // Shortcuts
33
- $thisfile_riff = &$info['riff'];
34
- $thisfile_riff_raw = &$thisfile_riff['raw'];
35
- $thisfile_audio = &$info['audio'];
36
- $thisfile_video = &$info['video'];
37
- $thisfile_audio_dataformat = &$thisfile_audio['dataformat'];
38
- $thisfile_riff_audio = &$thisfile_riff['audio'];
39
- $thisfile_riff_video = &$thisfile_riff['video'];
40
-
41
-
42
- $Original['avdataoffset'] = $info['avdataoffset'];
43
- $Original['avdataend'] = $info['avdataend'];
44
-
45
- fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
46
- $RIFFheader = fread($this->getid3->fp, 12);
47
- $RIFFsubtype = substr($RIFFheader, 8, 4);
48
- switch (substr($RIFFheader, 0, 4)) {
49
- case 'FORM':
50
- $info['fileformat'] = 'aiff';
51
- $thisfile_riff['header_size'] = $this->EitherEndian2Int(substr($RIFFheader, 4, 4));
52
- $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($info['avdataoffset'] + 12, $info['avdataoffset'] + $thisfile_riff['header_size']);
53
- break;
54
-
55
- case 'RIFF': // AVI, WAV, etc
56
- case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
57
- case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
58
- $info['fileformat'] = 'riff';
59
- $thisfile_riff['header_size'] = $this->EitherEndian2Int(substr($RIFFheader, 4, 4));
60
- if ($RIFFsubtype == 'RMP3') {
61
- // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
62
- $RIFFsubtype = 'WAVE';
63
- }
64
- $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($info['avdataoffset'] + 12, $info['avdataoffset'] + $thisfile_riff['header_size']);
65
- if (($info['avdataend'] - $info['filesize']) == 1) {
66
- // LiteWave appears to incorrectly *not* pad actual output file
67
- // to nearest WORD boundary so may appear to be short by one
68
- // byte, in which case - skip warning
69
- $info['avdataend'] = $info['filesize'];
70
- }
71
-
72
- $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset
73
- while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) {
74
- if (!getid3_lib::intValueSupported($nextRIFFoffset + 1024)) {
75
- $info['error'][] = 'AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime is probably wrong';
76
- $info['warning'][] = '[avdataend] value may be incorrect, multiple AVIX chunks may be present';
77
- break;
78
- } else {
79
- fseek($this->getid3->fp, $nextRIFFoffset, SEEK_SET);
80
- $nextRIFFheader = fread($this->getid3->fp, 12);
81
- if ($nextRIFFoffset == ($info['avdataend'] - 1)) {
82
- if (substr($nextRIFFheader, 0, 1) == "\x00") {
83
- // RIFF padded to WORD boundary, we're actually already at the end
84
- break;
85
- }
86
- }
87
- $nextRIFFheaderID = substr($nextRIFFheader, 0, 4);
88
- $nextRIFFsize = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4));
89
- $nextRIFFtype = substr($nextRIFFheader, 8, 4);
90
- $chunkdata = array();
91
- $chunkdata['offset'] = $nextRIFFoffset + 8;
92
- $chunkdata['size'] = $nextRIFFsize;
93
- $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size'];
94
- switch ($nextRIFFheaderID) {
95
- case 'RIFF':
96
- $info['avdataend'] = $nextRIFFoffset;
97
- if (!getid3_lib::intValueSupported($info['avdataend'])) {
98
- $info['error'][] = 'AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime is probably wrong';
99
- $info['warning'][] = '[avdataend] value may be incorrect, multiple AVIX chunks may be present';
100
- }
101
- $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $chunkdata['offset'] + $chunkdata['size']);
102
-
103
- if (!isset($thisfile_riff[$nextRIFFtype])) {
104
- $thisfile_riff[$nextRIFFtype] = array();
105
- }
106
- $thisfile_riff[$nextRIFFtype][] = $chunkdata;
107
- break;
108
- case 'JUNK':
109
- // ignore
110
- $thisfile_riff[$nextRIFFheaderID][] = $chunkdata;
111
- break;
112
- default:
113
- if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) {
114
- $DIVXTAG = $nextRIFFheader.fread($this->getid3->fp, 128 - 12);
115
- if (substr($DIVXTAG, -7) == 'DIVXTAG') {
116
- // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file
117
- $info['warning'][] = 'Found wrongly-structured DIVXTAG at offset '.(ftell($this->getid3->fp) - 128 + 12).', parsing anyway';
118
- $thisfile_riff['DIVXTAG'] = $this->ParseDIVXTAG($DIVXTAG);
119
- foreach ($thisfile_riff['DIVXTAG'] as $key => $value) {
120
- if ($value && !preg_match('#_id$#', $key)) {
121
- $thisfile_riff['comments'][$key][] = $value;
122
- }
123
- }
124
- break 2;
125
- }
126
- }
127
- $info['warning'][] = 'expecting "RIFF" or "JUNK" at '.$nextRIFFoffset.', found '.getid3_lib::PrintHexBytes(substr($nextRIFFheader, 0, 4)).' - skipping rest of file';
128
- break 2;
129
- }
130
- }
131
- }
132
- if ($RIFFsubtype == 'WAVE') {
133
- $thisfile_riff_WAVE = &$thisfile_riff['WAVE'];
134
- }
135
- break;
136
-
137
- default:
138
- $info['error'][] = 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead';
139
- unset($info['fileformat']);
140
- return false;
141
- break;
142
- }
143
-
144
- $streamindex = 0;
145
- switch ($RIFFsubtype) {
146
- case 'WAVE':
147
- if (empty($thisfile_audio['bitrate_mode'])) {
148
- $thisfile_audio['bitrate_mode'] = 'cbr';
149
- }
150
- if (empty($thisfile_audio_dataformat)) {
151
- $thisfile_audio_dataformat = 'wav';
152
- }
153
-
154
- if (isset($thisfile_riff_WAVE['data'][0]['offset'])) {
155
- $info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8;
156
- $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size'];
157
- }
158
- if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) {
159
-
160
- $thisfile_riff_audio[$streamindex] = getid3_riff::RIFFparseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']);
161
- $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
162
- if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) {
163
- $info['error'][] = 'Corrupt RIFF file: bitrate_audio == zero';
164
- return false;
165
- }
166
- $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw'];
167
- unset($thisfile_riff_audio[$streamindex]['raw']);
168
- $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
169
-
170
- $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
171
- if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
172
- $info['warning'][] = 'Audio codec = '.$thisfile_audio['codec'];
173
- }
174
- $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
175
-
176
- $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
177
-
178
- $thisfile_audio['lossless'] = false;
179
- if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
180
- switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
181
-
182
- case 0x0001: // PCM
183
- $thisfile_audio['lossless'] = true;
184
- break;
185
-
186
- case 0x2000: // AC-3
187
- $thisfile_audio_dataformat = 'ac3';
188
- break;
189
-
190
- default:
191
- // do nothing
192
- break;
193
-
194
- }
195
- }
196
- $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag'];
197
- $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
198
- $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless'];
199
- $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat;
200
- }
201
-
202
- if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) {
203
-
204
- // shortcuts
205
- $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data'];
206
- $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array());
207
- $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad'];
208
- $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track'];
209
- $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album'];
210
-
211
- $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4));
212
- $thisfile_riff_raw_rgad['nRadioRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 4, 2));
213
- $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 6, 2));
214
-
215
- $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
216
- $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
217
- $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
218
- $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
219
- $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
220
- $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
221
- $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
222
- $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
223
- $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
224
- $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
225
-
226
- $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude'];
227
- if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) {
228
- $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']);
229
- $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']);
230
- $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']);
231
- }
232
- if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) {
233
- $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']);
234
- $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']);
235
- $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']);
236
- }
237
- }
238
-
239
- if (isset($thisfile_riff_WAVE['fact'][0]['data'])) {
240
- $thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4));
241
-
242
- // This should be a good way of calculating exact playtime,
243
- // but some sample files have had incorrect number of samples,
244
- // so cannot use this method
245
-
246
- // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) {
247
- // $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec'];
248
- // }
249
- }
250
- if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
251
- $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8);
252
- }
253
-
254
- if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
255
- // shortcut
256
- $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
257
-
258
- $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256));
259
- $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32));
260
- $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32));
261
- $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10);
262
- $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8);
263
- $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8));
264
- $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1));
265
- $thisfile_riff_WAVE_bext_0['reserved'] = substr($thisfile_riff_WAVE_bext_0['data'], 347, 254);
266
- $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601)));
267
- if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) {
268
- if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) {
269
- list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date;
270
- list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time;
271
- $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']);
272
- } else {
273
- $info['warning'][] = 'RIFF.WAVE.BEXT.origin_time is invalid';
274
- }
275
- } else {
276
- $info['warning'][] = 'RIFF.WAVE.BEXT.origin_date is invalid';
277
- }
278
- $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
279
- $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title'];
280
- }
281
-
282
- if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) {
283
- // shortcut
284
- $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0];
285
-
286
- $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2));
287
- $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001);
288
- if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) {
289
- $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true;
290
- $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004);
291
- $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008);
292
-
293
- $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2));
294
- }
295
- $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2));
296
- $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2));
297
- $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001);
298
- $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002);
299
- $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004);
300
- }
301
-
302
- if (isset($thisfile_riff_WAVE['cart'][0]['data'])) {
303
- // shortcut
304
- $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0];
305
-
306
- $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4);
307
- $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64));
308
- $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64));
309
- $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64));
310
- $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64));
311
- $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64));
312
- $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64));
313
- $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64));
314
- $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10));
315
- $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8));
316
- $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10));
317
- $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8));
318
- $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64));
319
- $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64));
320
- $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64));
321
- $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true);
322
- for ($i = 0; $i < 8; $i++) {
323
- $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4);
324
- $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4));
325
- }
326
- $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024));
327
- $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772)));
328
-
329
- $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist'];
330
- $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title'];
331
- }
332
-
333
- if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) {
334
- // SoundMiner metadata
335
-
336
- // shortcuts
337
- $thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0];
338
- $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data'];
339
- $SNDM_startoffset = 0;
340
- $SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size'];
341
-
342
- while ($SNDM_startoffset < $SNDM_endoffset) {
343
- $SNDM_thisTagOffset = 0;
344
- $SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4));
345
- $SNDM_thisTagOffset += 4;
346
- $SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4);
347
- $SNDM_thisTagOffset += 4;
348
- $SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
349
- $SNDM_thisTagOffset += 2;
350
- $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
351
- $SNDM_thisTagOffset += 2;
352
- $SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize);
353
- $SNDM_thisTagOffset += $SNDM_thisTagDataSize;
354
-
355
- if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) {
356
- $info['warning'][] = 'RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
357
- break;
358
- } elseif ($SNDM_thisTagSize <= 0) {
359
- $info['warning'][] = 'RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
360
- break;
361
- }
362
- $SNDM_startoffset += $SNDM_thisTagSize;
363
-
364
- $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText;
365
- if ($parsedkey = $this->RIFFwaveSNDMtagLookup($SNDM_thisTagKey)) {
366
- $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText;
367
- } else {
368
- $info['warning'][] = 'RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
369
- }
370
- }
371
-
372
- $tagmapping = array(
373
- 'tracktitle'=>'title',
374
- 'category' =>'genre',
375
- 'cdtitle' =>'album',
376
- 'tracktitle'=>'title',
377
- );
378
- foreach ($tagmapping as $fromkey => $tokey) {
379
- if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) {
380
- $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey];
381
- }
382
- }
383
- }
384
-
385
- if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) {
386
- // requires functions simplexml_load_string and get_object_vars
387
- if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) {
388
- $thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML;
389
- if (isset($parsedXML['SPEED']['MASTER_SPEED'])) {
390
- @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']);
391
- $thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000);
392
- }
393
- if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) {
394
- @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']);
395
- $thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000);
396
- }
397
- if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) {
398
- $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0'));
399
- $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE'];
400
- $h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] / 3600);
401
- $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600)) / 60);
402
- $s = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60));
403
- $f = ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate'];
404
- $thisfile_riff_WAVE['iXML'][0]['timecode_string'] = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s, $f);
405
- $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d', $h, $m, $s, round($f));
406
- }
407
- unset($parsedXML);
408
- }
409
- }
410
-
411
-
412
-
413
- if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
414
- $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
415
- $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
416
- }
417
-
418
- if (!empty($info['wavpack'])) {
419
- $thisfile_audio_dataformat = 'wavpack';
420
- $thisfile_audio['bitrate_mode'] = 'vbr';
421
- $thisfile_audio['encoder'] = 'WavPack v'.$info['wavpack']['version'];
422
-
423
- // Reset to the way it was - RIFF parsing will have messed this up
424
- $info['avdataend'] = $Original['avdataend'];
425
- $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
426
-
427
- fseek($this->getid3->fp, $info['avdataoffset'] - 44, SEEK_SET);
428
- $RIFFdata = fread($this->getid3->fp, 44);
429
- $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
430
- $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
431
-
432
- if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
433
- $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
434
- fseek($this->getid3->fp, $info['avdataend'], SEEK_SET);
435
- $RIFFdata .= fread($this->getid3->fp, $OrignalRIFFheaderSize - $OrignalRIFFdataSize);
436
- }
437
-
438
- // move the data chunk after all other chunks (if any)
439
- // so that the RIFF parser doesn't see EOF when trying
440
- // to skip over the data chunk
441
- $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
442
- $getid3_riff = new getid3_riff($this->getid3);
443
- $getid3_riff->ParseRIFFdata($RIFFdata);
444
- unset($getid3_riff);
445
- }
446
-
447
- if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
448
- switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
449
- case 0x0001: // PCM
450
- if (!empty($info['ac3'])) {
451
- // Dolby Digital WAV files masquerade as PCM-WAV, but they're not
452
- $thisfile_audio['wformattag'] = 0x2000;
453
- $thisfile_audio['codec'] = $this->RIFFwFormatTagLookup($thisfile_audio['wformattag']);
454
- $thisfile_audio['lossless'] = false;
455
- $thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
456
- $thisfile_audio['sample_rate'] = $info['ac3']['sample_rate'];
457
- }
458
- break;
459
- case 0x08AE: // ClearJump LiteWave
460
- $thisfile_audio['bitrate_mode'] = 'vbr';
461
- $thisfile_audio_dataformat = 'litewave';
462
-
463
- //typedef struct tagSLwFormat {
464
- // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags
465
- // DWORD m_dwScale; // scale factor for lossy compression
466
- // DWORD m_dwBlockSize; // number of samples in encoded blocks
467
- // WORD m_wQuality; // alias for the scale factor
468
- // WORD m_wMarkDistance; // distance between marks in bytes
469
- // WORD m_wReserved;
470
- //
471
- // //following paramters are ignored if CF_FILESRC is not set
472
- // DWORD m_dwOrgSize; // original file size in bytes
473
- // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file
474
- // DWORD m_dwRiffChunkSize; // riff chunk size in the original file
475
- //
476
- // PCMWAVEFORMAT m_OrgWf; // original wave format
477
- // }SLwFormat, *PSLwFormat;
478
-
479
- // shortcut
480
- $thisfile_riff['litewave']['raw'] = array();
481
- $thisfile_riff_litewave = &$thisfile_riff['litewave'];
482
- $thisfile_riff_litewave_raw = &$thisfile_riff_litewave['raw'];
483
-
484
- $thisfile_riff_litewave_raw['compression_method'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 18, 1));
485
- $thisfile_riff_litewave_raw['compression_flags'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 19, 1));
486
- $thisfile_riff_litewave_raw['m_dwScale'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 20, 4));
487
- $thisfile_riff_litewave_raw['m_dwBlockSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 24, 4));
488
- $thisfile_riff_litewave_raw['m_wQuality'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 28, 2));
489
- $thisfile_riff_litewave_raw['m_wMarkDistance'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 30, 2));
490
- $thisfile_riff_litewave_raw['m_wReserved'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 32, 2));
491
- $thisfile_riff_litewave_raw['m_dwOrgSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 34, 4));
492
- $thisfile_riff_litewave_raw['m_bFactExists'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 38, 2));
493
- $thisfile_riff_litewave_raw['m_dwRiffChunkSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 40, 4));
494
-
495
- //$thisfile_riff_litewave['quality_factor'] = intval(round((2000 - $thisfile_riff_litewave_raw['m_dwScale']) / 20));
496
- $thisfile_riff_litewave['quality_factor'] = $thisfile_riff_litewave_raw['m_wQuality'];
497
-
498
- $thisfile_riff_litewave['flags']['raw_source'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
499
- $thisfile_riff_litewave['flags']['vbr_blocksize'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
500
- $thisfile_riff_litewave['flags']['seekpoints'] = (bool) ($thisfile_riff_litewave_raw['compression_flags'] & 0x04);
501
-
502
- $thisfile_audio['lossless'] = (($thisfile_riff_litewave_raw['m_wQuality'] == 100) ? true : false);
503
- $thisfile_audio['encoder_options'] = '-q'.$thisfile_riff_litewave['quality_factor'];
504
- break;
505
-
506
- default:
507
- break;
508
- }
509
- }
510
- if ($info['avdataend'] > $info['filesize']) {
511
- switch (!empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') {
512
- case 'wavpack': // WavPack
513
- case 'lpac': // LPAC
514
- case 'ofr': // OptimFROG
515
- case 'ofs': // OptimFROG DualStream
516
- // lossless compressed audio formats that keep original RIFF headers - skip warning
517
- break;
518
-
519
- case 'litewave':
520
- if (($info['avdataend'] - $info['filesize']) == 1) {
521
- // LiteWave appears to incorrectly *not* pad actual output file
522
- // to nearest WORD boundary so may appear to be short by one
523
- // byte, in which case - skip warning
524
- } else {
525
- // Short by more than one byte, throw warning
526
- $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
527
- $info['avdataend'] = $info['filesize'];
528
- }
529
- break;
530
-
531
- default:
532
- if ((($info['avdataend'] - $info['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($info['filesize'] - $info['avdataoffset']) % 2) == 1)) {
533
- // output file appears to be incorrectly *not* padded to nearest WORD boundary
534
- // Output less severe warning
535
- $info['warning'][] = 'File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
536
- $info['avdataend'] = $info['filesize'];
537
- } else {
538
- // Short by more than one byte, throw warning
539
- $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
540
- $info['avdataend'] = $info['filesize'];
541
- }
542
- break;
543
- }
544
- }
545
- if (!empty($info['mpeg']['audio']['LAME']['audio_bytes'])) {
546
- if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
547
- $info['avdataend']--;
548
- $info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
549
- }
550
- }
551
- if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) {
552
- unset($thisfile_audio['bits_per_sample']);
553
- if (!empty($info['ac3']['bitrate']) && ($info['ac3']['bitrate'] != $thisfile_audio['bitrate'])) {
554
- $thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
555
- }
556
- }
557
- break;
558
-
559
- case 'AVI ':
560
- $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
561
- $thisfile_video['dataformat'] = 'avi';
562
- $info['mime_type'] = 'video/avi';
563
-
564
- if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) {
565
- $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8;
566
- if (isset($thisfile_riff['AVIX'])) {
567
- $info['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size'];
568
- } else {
569
- $info['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size'];
570
- }
571
- if ($info['avdataend'] > $info['filesize']) {
572
- $info['warning'][] = 'Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)';
573
- $info['avdataend'] = $info['filesize'];
574
- }
575
- }
576
-
577
- if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) {
578
- //$bIndexType = array(
579
- // 0x00 => 'AVI_INDEX_OF_INDEXES',
580
- // 0x01 => 'AVI_INDEX_OF_CHUNKS',
581
- // 0x80 => 'AVI_INDEX_IS_DATA',
582
- //);
583
- //$bIndexSubtype = array(
584
- // 0x01 => array(
585
- // 0x01 => 'AVI_INDEX_2FIELD',
586
- // ),
587
- //);
588
- foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) {
589
- $thisfile_riff_avi_hdrl_strl_indx_stream_data = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data'];
590
-
591
- $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = $this->EitherEndian2Int(substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 0, 2));
592
- $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = $this->EitherEndian2Int(substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 2, 1));
593
- $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = $this->EitherEndian2Int(substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 3, 1));
594
- $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = $this->EitherEndian2Int(substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 4, 4));
595
- $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 8, 4);
596
- $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = $this->EitherEndian2Int(substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 12, 4));
597
-
598
- //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']];
599
- //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']];
600
-
601
- unset($thisfile_riff_avi_hdrl_strl_indx_stream_data);
602
- }
603
- }
604
- if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
605
- $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'];
606
-
607
- // shortcut
608
- $thisfile_riff_raw['avih'] = array();
609
- $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih'];
610
-
611
- $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = $this->EitherEndian2Int(substr($avihData, 0, 4)); // frame display rate (or 0L)
612
- if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) {
613
- $info['error'][] = 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
614
- return false;
615
- }
616
- $thisfile_riff_raw_avih['dwMaxBytesPerSec'] = $this->EitherEndian2Int(substr($avihData, 4, 4)); // max. transfer rate
617
- $thisfile_riff_raw_avih['dwPaddingGranularity'] = $this->EitherEndian2Int(substr($avihData, 8, 4)); // pad to multiples of this size; normally 2K.
618
- $thisfile_riff_raw_avih['dwFlags'] = $this->EitherEndian2Int(substr($avihData, 12, 4)); // the ever-present flags
619
- $thisfile_riff_raw_avih['dwTotalFrames'] = $this->EitherEndian2Int(substr($avihData, 16, 4)); // # frames in file
620
- $thisfile_riff_raw_avih['dwInitialFrames'] = $this->EitherEndian2Int(substr($avihData, 20, 4));
621
- $thisfile_riff_raw_avih['dwStreams'] = $this->EitherEndian2Int(substr($avihData, 24, 4));
622
- $thisfile_riff_raw_avih['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($avihData, 28, 4));
623
- $thisfile_riff_raw_avih['dwWidth'] = $this->EitherEndian2Int(substr($avihData, 32, 4));
624
- $thisfile_riff_raw_avih['dwHeight'] = $this->EitherEndian2Int(substr($avihData, 36, 4));
625
- $thisfile_riff_raw_avih['dwScale'] = $this->EitherEndian2Int(substr($avihData, 40, 4));
626
- $thisfile_riff_raw_avih['dwRate'] = $this->EitherEndian2Int(substr($avihData, 44, 4));
627
- $thisfile_riff_raw_avih['dwStart'] = $this->EitherEndian2Int(substr($avihData, 48, 4));
628
- $thisfile_riff_raw_avih['dwLength'] = $this->EitherEndian2Int(substr($avihData, 52, 4));
629
-
630
- $thisfile_riff_raw_avih['flags']['hasindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000010);
631
- $thisfile_riff_raw_avih['flags']['mustuseindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000020);
632
- $thisfile_riff_raw_avih['flags']['interleaved'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000100);
633
- $thisfile_riff_raw_avih['flags']['trustcktype'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000800);
634
- $thisfile_riff_raw_avih['flags']['capturedfile'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00010000);
635
- $thisfile_riff_raw_avih['flags']['copyrighted'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00020010);
636
-
637
- // shortcut
638
- $thisfile_riff_video[$streamindex] = array();
639
- $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex];
640
-
641
- if ($thisfile_riff_raw_avih['dwWidth'] > 0) {
642
- $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth'];
643
- $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width'];
644
- }
645
- if ($thisfile_riff_raw_avih['dwHeight'] > 0) {
646
- $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight'];
647
- $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height'];
648
- }
649
- if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) {
650
- $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames'];
651
- $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames'];
652
- }
653
-
654
- $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3);
655
- $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate'];
656
- }
657
- if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
658
- if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) {
659
- for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
660
- if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
661
- $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
662
- $strhfccType = substr($strhData, 0, 4);
663
-
664
- if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
665
- $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
666
-
667
- // shortcut
668
- $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex];
669
-
670
- switch ($strhfccType) {
671
- case 'auds':
672
- $thisfile_audio['bitrate_mode'] = 'cbr';
673
- $thisfile_audio_dataformat = 'wav';
674
- if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) {
675
- $streamindex = count($thisfile_riff_audio);
676
- }
677
-
678
- $thisfile_riff_audio[$streamindex] = getid3_riff::RIFFparseWAVEFORMATex($strfData);
679
- $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
680
-
681
- // shortcut
682
- $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
683
- $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex];
684
-
685
- if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) {
686
- unset($thisfile_audio_streams_currentstream['bits_per_sample']);
687
- }
688
- $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag'];
689
- unset($thisfile_audio_streams_currentstream['raw']);
690
-
691
- // shortcut
692
- $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw'];
693
-
694
- unset($thisfile_riff_audio[$streamindex]['raw']);
695
- $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
696
-
697
- $thisfile_audio['lossless'] = false;
698
- switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) {
699
- case 0x0001: // PCM
700
- $thisfile_audio_dataformat = 'wav';
701
- $thisfile_audio['lossless'] = true;
702
- break;
703
-
704
- case 0x0050: // MPEG Layer 2 or Layer 1
705
- $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2
706
- break;
707
-
708
- case 0x0055: // MPEG Layer 3
709
- $thisfile_audio_dataformat = 'mp3';
710
- break;
711
-
712
- case 0x00FF: // AAC
713
- $thisfile_audio_dataformat = 'aac';
714
- break;
715
-
716
- case 0x0161: // Windows Media v7 / v8 / v9
717
- case 0x0162: // Windows Media Professional v9
718
- case 0x0163: // Windows Media Lossess v9
719
- $thisfile_audio_dataformat = 'wma';
720
- break;
721
-
722
- case 0x2000: // AC-3
723
- $thisfile_audio_dataformat = 'ac3';
724
- break;
725
-
726
- case 0x2001: // DTS
727
- $thisfile_audio_dataformat = 'dts';
728
- break;
729
-
730
- default:
731
- $thisfile_audio_dataformat = 'wav';
732
- break;
733
- }
734
- $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat;
735
- $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless'];
736
- $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
737
- break;
738
-
739
-
740
- case 'iavs':
741
- case 'vids':
742
- // shortcut
743
- $thisfile_riff_raw['strh'][$i] = array();
744
- $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i];
745
-
746
- $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType;
747
- $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4);
748
- $thisfile_riff_raw_strh_current['dwFlags'] = $this->EitherEndian2Int(substr($strhData, 8, 4)); // Contains AVITF_* flags
749
- $thisfile_riff_raw_strh_current['wPriority'] = $this->EitherEndian2Int(substr($strhData, 12, 2));
750
- $thisfile_riff_raw_strh_current['wLanguage'] = $this->EitherEndian2Int(substr($strhData, 14, 2));
751
- $thisfile_riff_raw_strh_current['dwInitialFrames'] = $this->EitherEndian2Int(substr($strhData, 16, 4));
752
- $thisfile_riff_raw_strh_current['dwScale'] = $this->EitherEndian2Int(substr($strhData, 20, 4));
753
- $thisfile_riff_raw_strh_current['dwRate'] = $this->EitherEndian2Int(substr($strhData, 24, 4));
754
- $thisfile_riff_raw_strh_current['dwStart'] = $this->EitherEndian2Int(substr($strhData, 28, 4));
755
- $thisfile_riff_raw_strh_current['dwLength'] = $this->EitherEndian2Int(substr($strhData, 32, 4));
756
- $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($strhData, 36, 4));
757
- $thisfile_riff_raw_strh_current['dwQuality'] = $this->EitherEndian2Int(substr($strhData, 40, 4));
758
- $thisfile_riff_raw_strh_current['dwSampleSize'] = $this->EitherEndian2Int(substr($strhData, 44, 4));
759
- $thisfile_riff_raw_strh_current['rcFrame'] = $this->EitherEndian2Int(substr($strhData, 48, 4));
760
-
761
- $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strh_current['fccHandler']);
762
- $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler'];
763
- if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
764
- $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']);
765
- $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
766
- }
767
- $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
768
- $thisfile_video['pixel_aspect_ratio'] = (float) 1;
769
- switch ($thisfile_riff_raw_strh_current['fccHandler']) {
770
- case 'HFYU': // Huffman Lossless Codec
771
- case 'IRAW': // Intel YUV Uncompressed
772
- case 'YUY2': // Uncompressed YUV 4:2:2
773
- $thisfile_video['lossless'] = true;
774
- break;
775
-
776
- default:
777
- $thisfile_video['lossless'] = false;
778
- break;
779
- }
780
-
781
- switch ($strhfccType) {
782
- case 'vids':
783
- $thisfile_riff_raw_strf_strhfccType_streamindex = getid3_riff::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($info['fileformat'] == 'riff'));
784
- //echo '<pre>'.print_r($thisfile_riff_raw_strf_strhfccType_streamindex, true).'</pre>';
785
- $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'];
786
-
787
- if ($thisfile_riff_video_current['codec'] == 'DV') {
788
- $thisfile_riff_video_current['dv_type'] = 2;
789
- }
790
- break;
791
-
792
- case 'iavs':
793
- $thisfile_riff_video_current['dv_type'] = 1;
794
- break;
795
- }
796
- break;
797
-
798
- default:
799
- $info['warning'][] = 'Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"';
800
- break;
801
-
802
- }
803
- }
804
- }
805
-
806
- if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
807
-
808
- $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
809
- if (getid3_riff::RIFFfourccLookup($thisfile_video['fourcc'])) {
810
- $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_video['fourcc']);
811
- $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
812
- }
813
-
814
- switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) {
815
- case 'HFYU': // Huffman Lossless Codec
816
- case 'IRAW': // Intel YUV Uncompressed
817
- case 'YUY2': // Uncompressed YUV 4:2:2
818
- $thisfile_video['lossless'] = true;
819
- //$thisfile_video['bits_per_sample'] = 24;
820
- break;
821
-
822
- default:
823
- $thisfile_video['lossless'] = false;
824
- //$thisfile_video['bits_per_sample'] = 24;
825
- break;
826
- }
827
-
828
- }
829
- }
830
- }
831
- }
832
- break;
833
-
834
- case 'CDDA':
835
- $thisfile_audio['bitrate_mode'] = 'cbr';
836
- $thisfile_audio_dataformat = 'cda';
837
- $thisfile_audio['lossless'] = true;
838
- unset($info['mime_type']);
839
-
840
- $info['avdataoffset'] = 44;
841
-
842
- if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) {
843
- // shortcut
844
- $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0];
845
-
846
- $thisfile_riff_CDDA_fmt_0['unknown1'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2));
847
- $thisfile_riff_CDDA_fmt_0['track_num'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2));
848
- $thisfile_riff_CDDA_fmt_0['disc_id'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4));
849
- $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4));
850
- $thisfile_riff_CDDA_fmt_0['playtime_frames'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4));
851
- $thisfile_riff_CDDA_fmt_0['unknown6'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4));
852
- $thisfile_riff_CDDA_fmt_0['unknown7'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4));
853
-
854
- $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75;
855
- $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75;
856
- $info['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num'];
857
- $info['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds'];
858
-
859
- // hardcoded data for CD-audio
860
- $thisfile_audio['sample_rate'] = 44100;
861
- $thisfile_audio['channels'] = 2;
862
- $thisfile_audio['bits_per_sample'] = 16;
863
- $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample'];
864
- $thisfile_audio['bitrate_mode'] = 'cbr';
865
- }
866
- break;
867
-
868
-
869
- case 'AIFF':
870
- case 'AIFC':
871
- $thisfile_audio['bitrate_mode'] = 'cbr';
872
- $thisfile_audio_dataformat = 'aiff';
873
- $thisfile_audio['lossless'] = true;
874
- $info['mime_type'] = 'audio/x-aiff';
875
-
876
- if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) {
877
- $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8;
878
- $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size'];
879
- if ($info['avdataend'] > $info['filesize']) {
880
- if (($info['avdataend'] == ($info['filesize'] + 1)) && (($info['filesize'] % 2) == 1)) {
881
- // structures rounded to 2-byte boundary, but dumb encoders
882
- // forget to pad end of file to make this actually work
883
- } else {
884
- $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
885
- }
886
- $info['avdataend'] = $info['filesize'];
887
- }
888
- }
889
-
890
- if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) {
891
-
892
- // shortcut
893
- $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data'];
894
-
895
- $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true);
896
- $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false);
897
- $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true);
898
- $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10));
899
-
900
- if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) {
901
- $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4);
902
- $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false);
903
- $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize);
904
- switch ($thisfile_riff_audio['codec_name']) {
905
- case 'NONE':
906
- $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
907
- $thisfile_audio['lossless'] = true;
908
- break;
909
-
910
- case '':
911
- switch ($thisfile_riff_audio['codec_fourcc']) {
912
- // http://developer.apple.com/qa/snd/snd07.html
913
- case 'sowt':
914
- $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
915
- $thisfile_audio['lossless'] = true;
916
- break;
917
-
918
- case 'twos':
919
- $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
920
- $thisfile_audio['lossless'] = true;
921
- break;
922
-
923
- default:
924
- break;
925
- }
926
- break;
927
-
928
- default:
929
- $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name'];
930
- $thisfile_audio['lossless'] = false;
931
- break;
932
- }
933
- }
934
-
935
- $thisfile_audio['channels'] = $thisfile_riff_audio['channels'];
936
- if ($thisfile_riff_audio['bits_per_sample'] > 0) {
937
- $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample'];
938
- }
939
- $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate'];
940
- if ($thisfile_audio['sample_rate'] == 0) {
941
- $info['error'][] = 'Corrupted AIFF file: sample_rate == zero';
942
- return false;
943
- }
944
- $info['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate'];
945
- }
946
-
947
- if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) {
948
- $offset = 0;
949
- $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
950
- $offset += 2;
951
- for ($i = 0; $i < $CommentCount; $i++) {
952
- $info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false);
953
- $offset += 4;
954
- $info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true);
955
- $offset += 2;
956
- $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
957
- $offset += 2;
958
- $info['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength);
959
- $offset += $CommentLength;
960
-
961
- $info['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($info['comments_raw'][$i]['timestamp']);
962
- $thisfile_riff['comments']['comment'][] = $info['comments_raw'][$i]['comment'];
963
- }
964
- }
965
-
966
- $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
967
- foreach ($CommentsChunkNames as $key => $value) {
968
- if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
969
- $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
970
- }
971
- }
972
-
973
- if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) {
974
- getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
975
- $getid3_temp = new getID3();
976
- $getid3_temp->openfile($this->getid3->filename);
977
- $getid3_id3v2 = new getid3_id3v2($getid3_temp);
978
- $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8;
979
- if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
980
- $info['id3v2'] = $getid3_temp->info['id3v2'];
981
- }
982
- unset($getid3_temp, $getid3_id3v2);
983
- }
984
- break;
985
-
986
- case '8SVX':
987
- $thisfile_audio['bitrate_mode'] = 'cbr';
988
- $thisfile_audio_dataformat = '8svx';
989
- $thisfile_audio['bits_per_sample'] = 8;
990
- $thisfile_audio['channels'] = 1; // overridden below, if need be
991
- $info['mime_type'] = 'audio/x-aiff';
992
-
993
- if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) {
994
- $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8;
995
- $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size'];
996
- if ($info['avdataend'] > $info['filesize']) {
997
- $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
998
- }
999
- }
1000
-
1001
- if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) {
1002
- // shortcut
1003
- $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0];
1004
-
1005
- $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4));
1006
- $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4));
1007
- $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4));
1008
- $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2));
1009
- $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1));
1010
- $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1));
1011
- $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4));
1012
-
1013
- $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'];
1014
-
1015
- switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) {
1016
- case 0:
1017
- $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
1018
- $thisfile_audio['lossless'] = true;
1019
- $ActualBitsPerSample = 8;
1020
- break;
1021
-
1022
- case 1:
1023
- $thisfile_audio['codec'] = 'Fibonacci-delta encoding';
1024
- $thisfile_audio['lossless'] = false;
1025
- $ActualBitsPerSample = 4;
1026
- break;
1027
-
1028
- default:
1029
- $info['warning'][] = 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"';
1030
- break;
1031
- }
1032
- }
1033
-
1034
- if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) {
1035
- $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4));
1036
- switch ($ChannelsIndex) {
1037
- case 6: // Stereo
1038
- $thisfile_audio['channels'] = 2;
1039
- break;
1040
-
1041
- case 2: // Left channel only
1042
- case 4: // Right channel only
1043
- $thisfile_audio['channels'] = 1;
1044
- break;
1045
-
1046
- default:
1047
- $info['warning'][] = 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"';
1048
- break;
1049
- }
1050
-
1051
- }
1052
-
1053
- $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
1054
- foreach ($CommentsChunkNames as $key => $value) {
1055
- if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
1056
- $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
1057
- }
1058
- }
1059
-
1060
- $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels'];
1061
- if (!empty($thisfile_audio['bitrate'])) {
1062
- $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($thisfile_audio['bitrate'] / 8);
1063
- }
1064
- break;
1065
-
1066
-
1067
- case 'CDXA':
1068
- $info['mime_type'] = 'video/mpeg';
1069
- if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) {
1070
- if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, false)) {
1071
- $getid3_temp = new getID3();
1072
- $getid3_temp->openfile($this->getid3->filename);
1073
- $getid3_mpeg = new getid3_mpeg($getid3_temp);
1074
- $getid3_mpeg->Analyze();
1075
- if (empty($getid3_temp->info['error'])) {
1076
- $info['audio'] = $getid3_temp->info['audio'];
1077
- $info['video'] = $getid3_temp->info['video'];
1078
- $info['mpeg'] = $getid3_temp->info['mpeg'];
1079
- $info['warning'] = $getid3_temp->info['warning'];
1080
- }
1081
- unset($getid3_temp, $getid3_mpeg);
1082
- }
1083
- }
1084
- break;
1085
-
1086
-
1087
- default:
1088
- $info['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$RIFFsubtype.'" instead';
1089
- unset($info['fileformat']);
1090
- break;
1091
- }
1092
-
1093
- if (isset($thisfile_riff_raw['fmt ']['wFormatTag']) && ($thisfile_riff_raw['fmt ']['wFormatTag'] == 1)) {
1094
- // http://www.mega-nerd.com/erikd/Blog/Windiots/dts.html
1095
- fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
1096
- $FirstFourBytes = fread($this->getid3->fp, 4);
1097
- if (preg_match('/^\xFF\x1F\x00\xE8/s', $FirstFourBytes)) {
1098
- // DTSWAV
1099
- $thisfile_audio_dataformat = 'dts';
1100
- } elseif (preg_match('/^\x7F\xFF\x80\x01/s', $FirstFourBytes)) {
1101
- // DTS, but this probably shouldn't happen
1102
- $thisfile_audio_dataformat = 'dts';
1103
- }
1104
- }
1105
-
1106
-
1107
- if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) {
1108
- $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4));
1109
- }
1110
- if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) {
1111
- $this->RIFFcommentsParse($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']);
1112
- }
1113
- if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) {
1114
- $this->RIFFcommentsParse($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']);
1115
- }
1116
-
1117
- if (empty($thisfile_audio['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version'])) {
1118
- $thisfile_audio['encoder'] = $info['mpeg']['audio']['LAME']['short_version'];
1119
- }
1120
-
1121
- if (!isset($info['playtime_seconds'])) {
1122
- $info['playtime_seconds'] = 0;
1123
- }
1124
- if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
1125
- // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie
1126
- $info['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
1127
- } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
1128
- $info['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
1129
- }
1130
-
1131
- if ($info['playtime_seconds'] > 0) {
1132
- if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
1133
-
1134
- if (!isset($info['bitrate'])) {
1135
- $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1136
- }
1137
-
1138
- } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) {
1139
-
1140
- if (!isset($thisfile_audio['bitrate'])) {
1141
- $thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1142
- }
1143
-
1144
- } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
1145
-
1146
- if (!isset($thisfile_video['bitrate'])) {
1147
- $thisfile_video['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1148
- }
1149
-
1150
- }
1151
- }
1152
-
1153
-
1154
- if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($info['playtime_seconds'] > 0)) {
1155
-
1156
- $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1157
- $thisfile_audio['bitrate'] = 0;
1158
- $thisfile_video['bitrate'] = $info['bitrate'];
1159
- foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) {
1160
- $thisfile_video['bitrate'] -= $audioinfoarray['bitrate'];
1161
- $thisfile_audio['bitrate'] += $audioinfoarray['bitrate'];
1162
- }
1163
- if ($thisfile_video['bitrate'] <= 0) {
1164
- unset($thisfile_video['bitrate']);
1165
- }
1166
- if ($thisfile_audio['bitrate'] <= 0) {
1167
- unset($thisfile_audio['bitrate']);
1168
- }
1169
- }
1170
-
1171
- if (isset($info['mpeg']['audio'])) {
1172
- $thisfile_audio_dataformat = 'mp'.$info['mpeg']['audio']['layer'];
1173
- $thisfile_audio['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1174
- $thisfile_audio['channels'] = $info['mpeg']['audio']['channels'];
1175
- $thisfile_audio['bitrate'] = $info['mpeg']['audio']['bitrate'];
1176
- $thisfile_audio['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
1177
- if (!empty($info['mpeg']['audio']['codec'])) {
1178
- $thisfile_audio['codec'] = $info['mpeg']['audio']['codec'].' '.$thisfile_audio['codec'];
1179
- }
1180
- if (!empty($thisfile_audio['streams'])) {
1181
- foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) {
1182
- if ($streamdata['dataformat'] == $thisfile_audio_dataformat) {
1183
- $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate'];
1184
- $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels'];
1185
- $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
1186
- $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
1187
- $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec'];
1188
- }
1189
- }
1190
- }
1191
- $getid3_mp3 = new getid3_mp3($this->getid3);
1192
- $thisfile_audio['encoder_options'] = $getid3_mp3->GuessEncoderOptions();
1193
- unset($getid3_mp3);
1194
- }
1195
-
1196
-
1197
- if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
1198
- switch ($thisfile_audio_dataformat) {
1199
- case 'ac3':
1200
- // ignore bits_per_sample
1201
- break;
1202
-
1203
- default:
1204
- $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample'];
1205
- break;
1206
- }
1207
- }
1208
-
1209
-
1210
- if (empty($thisfile_riff_raw)) {
1211
- unset($thisfile_riff['raw']);
1212
- }
1213
- if (empty($thisfile_riff_audio)) {
1214
- unset($thisfile_riff['audio']);
1215
- }
1216
- if (empty($thisfile_riff_video)) {
1217
- unset($thisfile_riff['video']);
1218
- }
1219
-
1220
- return true;
1221
- }
1222
-
1223
-
1224
- static function RIFFcommentsParse(&$RIFFinfoArray, &$CommentsTargetArray) {
1225
- $RIFFinfoKeyLookup = array(
1226
- 'IARL'=>'archivallocation',
1227
- 'IART'=>'artist',
1228
- 'ICDS'=>'costumedesigner',
1229
- 'ICMS'=>'commissionedby',
1230
- 'ICMT'=>'comment',
1231
- 'ICNT'=>'country',
1232
- 'ICOP'=>'copyright',
1233
- 'ICRD'=>'creationdate',
1234
- 'IDIM'=>'dimensions',
1235
- 'IDIT'=>'digitizationdate',
1236
- 'IDPI'=>'resolution',
1237
- 'IDST'=>'distributor',
1238
- 'IEDT'=>'editor',
1239
- 'IENG'=>'engineers',
1240
- 'IFRM'=>'accountofparts',
1241
- 'IGNR'=>'genre',
1242
- 'IKEY'=>'keywords',
1243
- 'ILGT'=>'lightness',
1244
- 'ILNG'=>'language',
1245
- 'IMED'=>'orignalmedium',
1246
- 'IMUS'=>'composer',
1247
- 'INAM'=>'title',
1248
- 'IPDS'=>'productiondesigner',
1249
- 'IPLT'=>'palette',
1250
- 'IPRD'=>'product',
1251
- 'IPRO'=>'producer',
1252
- 'IPRT'=>'part',
1253
- 'IRTD'=>'rating',
1254
- 'ISBJ'=>'subject',
1255
- 'ISFT'=>'software',
1256
- 'ISGN'=>'secondarygenre',
1257
- 'ISHP'=>'sharpness',
1258
- 'ISRC'=>'sourcesupplier',
1259
- 'ISRF'=>'digitizationsource',
1260
- 'ISTD'=>'productionstudio',
1261
- 'ISTR'=>'starring',
1262
- 'ITCH'=>'encoded_by',
1263
- 'IWEB'=>'url',
1264
- 'IWRI'=>'writer'
1265
- );
1266
- foreach ($RIFFinfoKeyLookup as $key => $value) {
1267
- if (isset($RIFFinfoArray[$key])) {
1268
- foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) {
1269
- if (trim($commentdata['data']) != '') {
1270
- if (isset($CommentsTargetArray[$value])) {
1271
- $CommentsTargetArray[$value][] = trim($commentdata['data']);
1272
- } else {
1273
- $CommentsTargetArray[$value] = array(trim($commentdata['data']));
1274
- }
1275
- }
1276
- }
1277
- }
1278
- }
1279
- return true;
1280
- }
1281
-
1282
- function ParseRIFF($startoffset, $maxoffset) {
1283
- $info = &$this->getid3->info;
1284
-
1285
- $maxoffset = min($maxoffset, $info['avdataend']);
1286
-
1287
- $RIFFchunk = false;
1288
- $FoundAllChunksWeNeed = false;
1289
-
1290
- if (($startoffset < 0) || !getid3_lib::intValueSupported($startoffset)) {
1291
- $info['warning'][] = 'Unable to ParseRIFF() at '.$startoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
1292
- return false;
1293
- }
1294
- $max_usable_offset = min(PHP_INT_MAX - 1024, $maxoffset);
1295
- if ($maxoffset > $max_usable_offset) {
1296
- $info['warning'][] = 'ParseRIFF() may return incomplete data for chunk starting at '.$startoffset.' because beyond it extends to '.$maxoffset.', which is beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
1297
- }
1298
- fseek($this->getid3->fp, $startoffset, SEEK_SET);
1299
-
1300
- while (ftell($this->getid3->fp) < $max_usable_offset) {
1301
- $chunknamesize = fread($this->getid3->fp, 8);
1302
- $chunkname = substr($chunknamesize, 0, 4);
1303
- $chunksize = $this->EitherEndian2Int(substr($chunknamesize, 4, 4));
1304
- if (strlen($chunkname) < 4) {
1305
- $info['error'][] = 'Expecting chunk name at offset '.(ftell($this->getid3->fp) - 4).' but found nothing. Aborting RIFF parsing.';
1306
- break;
1307
- }
1308
- if ($chunksize == 0) {
1309
- if ($chunkname == 'JUNK') {
1310
- // we'll allow zero-size JUNK frames
1311
- } else {
1312
- $info['warning'][] = 'Chunk size at offset '.(ftell($this->getid3->fp) - 4).' is zero. Aborting RIFF parsing.';
1313
- break;
1314
- }
1315
- }
1316
- if (($chunksize % 2) != 0) {
1317
- // all structures are packed on word boundaries
1318
- $chunksize++;
1319
- }
1320
-
1321
- switch ($chunkname) {
1322
- case 'LIST':
1323
- $listname = fread($this->getid3->fp, 4);
1324
- if (preg_match('#^(movi|rec )$#i', $listname)) {
1325
- $RIFFchunk[$listname]['offset'] = ftell($this->getid3->fp) - 4;
1326
- $RIFFchunk[$listname]['size'] = $chunksize;
1327
-
1328
- if ($FoundAllChunksWeNeed) {
1329
-
1330
- // skip over
1331
-
1332
- } else {
1333
-
1334
- $WhereWeWere = ftell($this->getid3->fp);
1335
- $AudioChunkHeader = fread($this->getid3->fp, 12);
1336
- $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2);
1337
- $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2);
1338
- $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4));
1339
-
1340
- if ($AudioChunkStreamType == 'wb') {
1341
- $FirstFourBytes = substr($AudioChunkHeader, 8, 4);
1342
- if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) {
1343
- // MP3
1344
- if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) {
1345
- $getid3_temp = new getID3();
1346
- $getid3_temp->openfile($this->getid3->filename);
1347
- $getid3_temp->info['avdataoffset'] = ftell($this->getid3->fp) - 4;
1348
- $getid3_temp->info['avdataend'] = ftell($this->getid3->fp) + $AudioChunkSize;
1349
- $getid3_mp3 = new getid3_mp3($getid3_temp);
1350
- $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
1351
- if (isset($getid3_temp->info['mpeg']['audio'])) {
1352
- $info['mpeg']['audio'] = $getid3_temp->info['mpeg']['audio'];
1353
- $info['audio'] = $getid3_temp->info['audio'];
1354
- $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
1355
- $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1356
- $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
1357
- $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1358
- $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
1359
- //$info['bitrate'] = $info['audio']['bitrate'];
1360
- }
1361
- unset($getid3_temp, $getid3_mp3);
1362
- }
1363
-
1364
- } elseif (preg_match('/^\x0B\x77/s', $FirstFourBytes)) {
1365
-
1366
- // AC3
1367
- if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1368
- $getid3_temp = new getID3();
1369
- $getid3_temp->openfile($this->getid3->filename);
1370
- $getid3_temp->info['avdataoffset'] = ftell($this->getid3->fp) - 4;
1371
- $getid3_temp->info['avdataend'] = ftell($this->getid3->fp) + $AudioChunkSize;
1372
- $getid3_ac3 = new getid3_ac3($getid3_temp);
1373
- $getid3_ac3->Analyze();
1374
- if (empty($getid3_temp->info['error'])) {
1375
- $info['audio'] = $getid3_temp->info['audio'];
1376
- $info['ac3'] = $getid3_temp->info['ac3'];
1377
- if (!empty($getid3_temp->info['warning'])) {
1378
- foreach ($getid3_temp->info['warning'] as $key => $value) {
1379
- $info['warning'][] = $value;
1380
- }
1381
- }
1382
- }
1383
- unset($getid3_temp, $getid3_ac3);
1384
- }
1385
-
1386
- }
1387
-
1388
- }
1389
-
1390
- $FoundAllChunksWeNeed = true;
1391
- fseek($this->getid3->fp, $WhereWeWere, SEEK_SET);
1392
-
1393
- }
1394
- fseek($this->getid3->fp, $chunksize - 4, SEEK_CUR);
1395
-
1396
- //} elseif (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#i', $listname)) {
1397
- //
1398
- // // data chunk, ignore
1399
- //
1400
- } else {
1401
-
1402
- if (!isset($RIFFchunk[$listname])) {
1403
- $RIFFchunk[$listname] = array();
1404
- }
1405
- $LISTchunkParent = $listname;
1406
- $LISTchunkMaxOffset = ftell($this->getid3->fp) - 4 + $chunksize;
1407
- if ($parsedChunk = $this->ParseRIFF(ftell($this->getid3->fp), ftell($this->getid3->fp) + $chunksize - 4)) {
1408
- $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk);
1409
- }
1410
-
1411
- }
1412
- break;
1413
-
1414
- default:
1415
- if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) {
1416
- $nextoffset = ftell($this->getid3->fp) + $chunksize;
1417
- if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) {
1418
- $info['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
1419
- break 2;
1420
- }
1421
- fseek($this->getid3->fp, $nextoffset, SEEK_SET);
1422
- break;
1423
- }
1424
- $thisindex = 0;
1425
- if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) {
1426
- $thisindex = count($RIFFchunk[$chunkname]);
1427
- }
1428
- $RIFFchunk[$chunkname][$thisindex]['offset'] = ftell($this->getid3->fp) - 8;
1429
- $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize;
1430
- switch ($chunkname) {
1431
- case 'data':
1432
- $info['avdataoffset'] = ftell($this->getid3->fp);
1433
- $info['avdataend'] = $info['avdataoffset'] + $chunksize;
1434
-
1435
- $RIFFdataChunkContentsTest = fread($this->getid3->fp, 36);
1436
-
1437
- if ((strlen($RIFFdataChunkContentsTest) > 0) && preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($RIFFdataChunkContentsTest, 0, 4))) {
1438
-
1439
- // Probably is MP3 data
1440
- if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($RIFFdataChunkContentsTest, 0, 4))) {
1441
- $getid3_temp = new getID3();
1442
- $getid3_temp->openfile($this->getid3->filename);
1443
- $getid3_temp->info['avdataoffset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1444
- $getid3_temp->info['avdataend'] = $RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size'];
1445
- $getid3_mp3 = new getid3_mp3($getid3_temp);
1446
- $getid3_mp3->getOnlyMPEGaudioInfo($RIFFchunk[$chunkname][$thisindex]['offset'], false);
1447
- if (empty($getid3_temp->info['error'])) {
1448
- $info['mpeg'] = $getid3_temp->info['mpeg'];
1449
- $info['audio'] = $getid3_temp->info['audio'];
1450
- }
1451
- unset($getid3_temp, $getid3_mp3);
1452
- }
1453
-
1454
- } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 0, 2) == "\x0B\x77")) {
1455
-
1456
- // This is probably AC-3 data
1457
- if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1458
- $getid3_temp = new getID3();
1459
- $getid3_temp->openfile($this->getid3->filename);
1460
- $getid3_temp->info['avdataoffset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1461
- $getid3_temp->info['avdataend'] = $RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size'];
1462
- $getid3_ac3 = new getid3_ac3($getid3_temp);
1463
- $getid3_ac3->Analyze();
1464
- if (empty($getid3_temp->info['error'])) {
1465
- $info['audio'] = $getid3_temp->info['audio'];
1466
- $info['ac3'] = $getid3_temp->info['ac3'];
1467
- $info['warning'] = $getid3_temp->info['warning'];
1468
- }
1469
- unset($getid3_temp, $getid3_ac3);
1470
- }
1471
-
1472
- } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 8, 2) == "\x77\x0B")) {
1473
-
1474
- // Dolby Digital WAV
1475
- // AC-3 content, but not encoded in same format as normal AC-3 file
1476
- // For one thing, byte order is swapped
1477
-
1478
- if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1479
-
1480
- // ok to use tmpfile here - only 56 bytes
1481
- if ($RIFFtempfilename = tempnam(GETID3_TEMP_DIR, 'id3')) {
1482
- if ($fd_temp = fopen($RIFFtempfilename, 'wb')) {
1483
- for ($i = 0; $i < 28; $i += 2) {
1484
- // swap byte order
1485
- fwrite($fd_temp, substr($RIFFdataChunkContentsTest, 8 + $i + 1, 1));
1486
- fwrite($fd_temp, substr($RIFFdataChunkContentsTest, 8 + $i + 0, 1));
1487
- }
1488
- fclose($fd_temp);
1489
-
1490
- $getid3_temp = new getID3();
1491
- $getid3_temp->openfile($RIFFtempfilename);
1492
- $getid3_temp->info['avdataend'] = 20;
1493
- $getid3_ac3 = new getid3_ac3($getid3_temp);
1494
- $getid3_ac3->Analyze();
1495
- if (empty($getid3_temp->info['error'])) {
1496
- $info['audio'] = $getid3_temp->info['audio'];
1497
- $info['ac3'] = $getid3_temp->info['ac3'];
1498
- $info['warning'] = $getid3_temp->info['warning'];
1499
- } else {
1500
- $info['error'][] = 'Error parsing Dolby Digital WAV (AC3-in-RIFF): '.implode(';', $getid3_temp->info['error']);
1501
- }
1502
- unset($getid3_ac3, $getid3_temp);
1503
- } else {
1504
- $info['error'][] = 'Error parsing Dolby Digital WAV (AC3-in-RIFF): failed to write temp file';
1505
- }
1506
- unlink($RIFFtempfilename);
1507
-
1508
- } else {
1509
- $info['error'][] = 'Error parsing Dolby Digital WAV (AC3-in-RIFF): failed to write temp file';
1510
- }
1511
-
1512
- }
1513
-
1514
- } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 0, 4) == 'wvpk')) {
1515
-
1516
- // This is WavPack data
1517
- $info['wavpack']['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1518
- $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($RIFFdataChunkContentsTest, 4, 4));
1519
- $this->RIFFparseWavPackHeader(substr($RIFFdataChunkContentsTest, 8, 28));
1520
-
1521
- } else {
1522
-
1523
- // This is some other kind of data (quite possibly just PCM)
1524
- // do nothing special, just skip it
1525
-
1526
- }
1527
- $nextoffset = $RIFFchunk[$chunkname][$thisindex]['offset'] + 8 + $chunksize;
1528
- if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) {
1529
- $info['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
1530
- break 3;
1531
- }
1532
- fseek($this->getid3->fp, $RIFFchunk[$chunkname][$thisindex]['offset'] + 8 + $chunksize, SEEK_SET);
1533
- break;
1534
-
1535
- case 'iXML':
1536
- case 'bext':
1537
- case 'cart':
1538
- case 'fmt ':
1539
- case 'strh':
1540
- case 'strf':
1541
- case 'indx':
1542
- case 'MEXT':
1543
- case 'DISP':
1544
- // always read data in
1545
- case 'JUNK':
1546
- // should be: never read data in
1547
- // but some programs write their version strings in a JUNK chunk (e.g. VirtualDub, AVIdemux, etc)
1548
- if ($chunksize < 1048576) {
1549
- if ($chunksize > 0) {
1550
- $RIFFchunk[$chunkname][$thisindex]['data'] = fread($this->getid3->fp, $chunksize);
1551
- if ($chunkname == 'JUNK') {
1552
- if (preg_match('#^([\\x20-\\x7F]+)#', $RIFFchunk[$chunkname][$thisindex]['data'], $matches)) {
1553
- // only keep text characters [chr(32)-chr(127)]
1554
- $info['riff']['comments']['junk'][] = trim($matches[1]);
1555
- }
1556
- // but if nothing there, ignore
1557
- // remove the key in either case
1558
- unset($RIFFchunk[$chunkname][$thisindex]['data']);
1559
- }
1560
- }
1561
- } else {
1562
- $info['warning'][] = 'chunk "'.$chunkname.'" at offset '.ftell($this->getid3->fp).' is unexpectedly larger than 1MB (claims to be '.number_format($chunksize).' bytes), skipping data';
1563
- $nextoffset = ftell($this->getid3->fp) + $chunksize;
1564
- if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) {
1565
- $info['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
1566
- break 3;
1567
- }
1568
- fseek($this->getid3->fp, $nextoffset, SEEK_SET);
1569
- }
1570
- break;
1571
-
1572
- default:
1573
- if (!preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname) && !empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) {
1574
- $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1575
- $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size'];
1576
- unset($RIFFchunk[$chunkname][$thisindex]['offset']);
1577
- unset($RIFFchunk[$chunkname][$thisindex]['size']);
1578
- if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) {
1579
- unset($RIFFchunk[$chunkname][$thisindex]);
1580
- }
1581
- if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) {
1582
- unset($RIFFchunk[$chunkname]);
1583
- }
1584
- $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = fread($this->getid3->fp, $chunksize);
1585
- //} elseif (in_array($chunkname, array('ID3 ')) || (($chunksize > 0) && ($chunksize < 2048))) {
1586
- } elseif (($chunksize > 0) && ($chunksize < 2048)) {
1587
- // only read data in if smaller than 2kB
1588
- $RIFFchunk[$chunkname][$thisindex]['data'] = fread($this->getid3->fp, $chunksize);
1589
- } else {
1590
- $nextoffset = ftell($this->getid3->fp) + $chunksize;
1591
- if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) {
1592
- $info['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
1593
- break 3;
1594
- }
1595
- fseek($this->getid3->fp, $nextoffset, SEEK_SET);
1596
- }
1597
- break;
1598
- }
1599
- break;
1600
-
1601
- }
1602
-
1603
- }
1604
-
1605
- return $RIFFchunk;
1606
- }
1607
-
1608
-
1609
- function ParseRIFFdata(&$RIFFdata) {
1610
- $info = &$this->getid3->info;
1611
- if ($RIFFdata) {
1612
- $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3');
1613
- $fp_temp = fopen($tempfile, 'wb');
1614
- $RIFFdataLength = strlen($RIFFdata);
1615
- $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4);
1616
- for ($i = 0; $i < 4; $i++) {
1617
- $RIFFdata{$i + 4} = $NewLengthString{$i};
1618
- }
1619
- fwrite($fp_temp, $RIFFdata);
1620
- fclose($fp_temp);
1621
-
1622
- $getid3_temp = new getID3();
1623
- $getid3_temp->openfile($tempfile);
1624
- $getid3_temp->info['filesize'] = $RIFFdataLength;
1625
- $getid3_temp->info['filenamepath'] = $info['filenamepath'];
1626
- $getid3_temp->info['tags'] = $info['tags'];
1627
- $getid3_temp->info['warning'] = $info['warning'];
1628
- $getid3_temp->info['error'] = $info['error'];
1629
- $getid3_temp->info['comments'] = $info['comments'];
1630
- $getid3_temp->info['audio'] = (isset($info['audio']) ? $info['audio'] : array());
1631
- $getid3_temp->info['video'] = (isset($info['video']) ? $info['video'] : array());
1632
- $getid3_riff = new getid3_riff($getid3_temp);
1633
- $getid3_riff->Analyze();
1634
-
1635
- $info['riff'] = $getid3_temp->info['riff'];
1636
- $info['warning'] = $getid3_temp->info['warning'];
1637
- $info['error'] = $getid3_temp->info['error'];
1638
- $info['tags'] = $getid3_temp->info['tags'];
1639
- $info['comments'] = $getid3_temp->info['comments'];
1640
- unset($getid3_riff, $getid3_temp);
1641
- unlink($tempfile);
1642
- }
1643
- return false;
1644
- }
1645
-
1646
-
1647
- public static function RIFFparseWAVEFORMATex($WaveFormatExData) {
1648
- // shortcut
1649
- $WaveFormatEx['raw'] = array();
1650
- $WaveFormatEx_raw = &$WaveFormatEx['raw'];
1651
-
1652
- $WaveFormatEx_raw['wFormatTag'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 0, 2));
1653
- $WaveFormatEx_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 2, 2));
1654
- $WaveFormatEx_raw['nSamplesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 4, 4));
1655
- $WaveFormatEx_raw['nAvgBytesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 8, 4));
1656
- $WaveFormatEx_raw['nBlockAlign'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 12, 2));
1657
- $WaveFormatEx_raw['wBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 14, 2));
1658
- if (strlen($WaveFormatExData) > 16) {
1659
- $WaveFormatEx_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 16, 2));
1660
- }
1661
-
1662
- $WaveFormatEx['codec'] = getid3_riff::RIFFwFormatTagLookup($WaveFormatEx_raw['wFormatTag']);
1663
- $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels'];
1664
- $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec'];
1665
- $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8;
1666
- $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample'];
1667
-
1668
- return $WaveFormatEx;
1669
- }
1670
-
1671
-
1672
- function RIFFparseWavPackHeader($WavPackChunkData) {
1673
- // typedef struct {
1674
- // char ckID [4];
1675
- // long ckSize;
1676
- // short version;
1677
- // short bits; // added for version 2.00
1678
- // short flags, shift; // added for version 3.00
1679
- // long total_samples, crc, crc2;
1680
- // char extension [4], extra_bc, extras [3];
1681
- // } WavpackHeader;
1682
-
1683
- // shortcut
1684
- $info = &$this->getid3->info;
1685
- $info['wavpack'] = array();
1686
- $thisfile_wavpack = &$info['wavpack'];
1687
-
1688
- $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2));
1689
- if ($thisfile_wavpack['version'] >= 2) {
1690
- $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2));
1691
- }
1692
- if ($thisfile_wavpack['version'] >= 3) {
1693
- $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2));
1694
- $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2));
1695
- $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4));
1696
- $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4));
1697
- $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4));
1698
- $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4);
1699
- $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1));
1700
- for ($i = 0; $i <= 2; $i++) {
1701
- $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1));
1702
- }
1703
-
1704
- // shortcut
1705
- $thisfile_wavpack['flags'] = array();
1706
- $thisfile_wavpack_flags = &$thisfile_wavpack['flags'];
1707
-
1708
- $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001);
1709
- $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002);
1710
- $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004);
1711
- $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008);
1712
- $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010);
1713
- $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020);
1714
- $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040);
1715
- $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080);
1716
- $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100);
1717
- $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200);
1718
- $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400);
1719
- $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800);
1720
- $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000);
1721
- $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000);
1722
- $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000);
1723
- $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000);
1724
- $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000);
1725
- $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000);
1726
- $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000);
1727
- $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000);
1728
- }
1729
-
1730
- return true;
1731
- }
1732
-
1733
- public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) {
1734
-
1735
- $functionname = ($littleEndian ? 'LittleEndian2Int' : 'BigEndian2Int');
1736
- $parsed['biSize'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 0, 4)); // number of bytes required by the BITMAPINFOHEADER structure
1737
- $parsed['biWidth'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 4, 4)); // width of the bitmap in pixels
1738
- $parsed['biHeight'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 8, 4)); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
1739
- $parsed['biPlanes'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 12, 2)); // number of color planes on the target device. In most cases this value must be set to 1
1740
- $parsed['biBitCount'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 14, 2)); // Specifies the number of bits per pixels
1741
- $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier
1742
- $parsed['biSizeImage'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 20, 4)); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
1743
- $parsed['biXPelsPerMeter'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 24, 4)); // horizontal resolution, in pixels per metre, of the target device
1744
- $parsed['biYPelsPerMeter'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 28, 4)); // vertical resolution, in pixels per metre, of the target device
1745
- $parsed['biClrUsed'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 32, 4)); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
1746
- $parsed['biClrImportant'] = getid3_lib::$functionname(substr($BITMAPINFOHEADER, 36, 4)); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
1747
-
1748
- return $parsed;
1749
- }
1750
-
1751
- static function ParseDIVXTAG($DIVXTAG) {
1752
- // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/
1753
- // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip
1754
- // 'Byte Layout: '1111111111111111
1755
- // '32 for Movie - 1 '1111111111111111
1756
- // '28 for Author - 6 '6666666666666666
1757
- // '4 for year - 2 '6666666666662222
1758
- // '3 for genre - 3 '7777777777777777
1759
- // '48 for Comments - 7 '7777777777777777
1760
- // '1 for Rating - 4 '7777777777777777
1761
- // '5 for Future Additions - 0 '333400000DIVXTAG
1762
- // '128 bytes total
1763
-
1764
- static $DIVXTAGgenre = array(
1765
- 0 => 'Action',
1766
- 1 => 'Action/Adventure',
1767
- 2 => 'Adventure',
1768
- 3 => 'Adult',
1769
- 4 => 'Anime',
1770
- 5 => 'Cartoon',
1771
- 6 => 'Claymation',
1772
- 7 => 'Comedy',
1773
- 8 => 'Commercial',
1774
- 9 => 'Documentary',
1775
- 10 => 'Drama',
1776
- 11 => 'Home Video',
1777
- 12 => 'Horror',
1778
- 13 => 'Infomercial',
1779
- 14 => 'Interactive',
1780
- 15 => 'Mystery',
1781
- 16 => 'Music Video',
1782
- 17 => 'Other',
1783
- 18 => 'Religion',
1784
- 19 => 'Sci Fi',
1785
- 20 => 'Thriller',
1786
- 21 => 'Western',
1787
- );
1788
- static $DIVXTAGrating = array(
1789
- 0=>'Unrated',
1790
- 1=>'G',
1791
- 2=>'PG',
1792
- 3=>'PG-13',
1793
- 4=>'R',
1794
- 5=>'NC-17'
1795
- );
1796
-
1797
- $parsed['title'] = trim(substr($DIVXTAG, 0, 32));
1798
- $parsed['artist'] = trim(substr($DIVXTAG, 32, 28));
1799
- $parsed['year'] = intval(trim(substr($DIVXTAG, 60, 4)));
1800
- $parsed['comment'] = trim(substr($DIVXTAG, 64, 48));
1801
- $parsed['genre_id'] = intval(trim(substr($DIVXTAG, 112, 3)));
1802
- $parsed['rating_id'] = ord(substr($DIVXTAG, 115, 1));
1803
- //$parsed['padding'] = substr($DIVXTAG, 116, 5); // 5-byte null
1804
- //$parsed['magic'] = substr($DIVXTAG, 121, 7); // "DIVXTAG"
1805
-
1806
- $parsed['genre'] = (isset($DIVXTAGgenre[$parsed['genre_id']]) ? $DIVXTAGgenre[$parsed['genre_id']] : $parsed['genre_id']);
1807
- $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']);
1808
- return $parsed;
1809
- }
1810
-
1811
- static function RIFFwaveSNDMtagLookup($tagshortname) {
1812
- $begin = __LINE__;
1813
-
1814
- /** This is not a comment!
1815
-
1816
- �kwd keywords
1817
- �BPM bpm
1818
- �trt tracktitle
1819
- �des description
1820
- �gen category
1821
- �fin featuredinstrument
1822
- �LID longid
1823
- �bex bwdescription
1824
- �pub publisher
1825
- �cdt cdtitle
1826
- �alb library
1827
- �com composer
1828
-
1829
- */
1830
-
1831
- return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm');
1832
- }
1833
-
1834
- static function RIFFwFormatTagLookup($wFormatTag) {
1835
-
1836
- $begin = __LINE__;
1837
-
1838
- /** This is not a comment!
1839
-
1840
- 0x0000 Microsoft Unknown Wave Format
1841
- 0x0001 Pulse Code Modulation (PCM)
1842
- 0x0002 Microsoft ADPCM
1843
- 0x0003 IEEE Float
1844
- 0x0004 Compaq Computer VSELP
1845
- 0x0005 IBM CVSD
1846
- 0x0006 Microsoft A-Law
1847
- 0x0007 Microsoft mu-Law
1848
- 0x0008 Microsoft DTS
1849
- 0x0010 OKI ADPCM
1850
- 0x0011 Intel DVI/IMA ADPCM
1851
- 0x0012 Videologic MediaSpace ADPCM
1852
- 0x0013 Sierra Semiconductor ADPCM
1853
- 0x0014 Antex Electronics G.723 ADPCM
1854
- 0x0015 DSP Solutions DigiSTD
1855
- 0x0016 DSP Solutions DigiFIX
1856
- 0x0017 Dialogic OKI ADPCM
1857
- 0x0018 MediaVision ADPCM
1858
- 0x0019 Hewlett-Packard CU
1859
- 0x0020 Yamaha ADPCM
1860
- 0x0021 Speech Compression Sonarc
1861
- 0x0022 DSP Group TrueSpeech
1862
- 0x0023 Echo Speech EchoSC1
1863
- 0x0024 Audiofile AF36
1864
- 0x0025 Audio Processing Technology APTX
1865
- 0x0026 AudioFile AF10
1866
- 0x0027 Prosody 1612
1867
- 0x0028 LRC
1868
- 0x0030 Dolby AC2
1869
- 0x0031 Microsoft GSM 6.10
1870
- 0x0032 MSNAudio
1871
- 0x0033 Antex Electronics ADPCME
1872
- 0x0034 Control Resources VQLPC
1873
- 0x0035 DSP Solutions DigiREAL
1874
- 0x0036 DSP Solutions DigiADPCM
1875
- 0x0037 Control Resources CR10
1876
- 0x0038 Natural MicroSystems VBXADPCM
1877
- 0x0039 Crystal Semiconductor IMA ADPCM
1878
- 0x003A EchoSC3
1879
- 0x003B Rockwell ADPCM
1880
- 0x003C Rockwell Digit LK
1881
- 0x003D Xebec
1882
- 0x0040 Antex Electronics G.721 ADPCM
1883
- 0x0041 G.728 CELP
1884
- 0x0042 MSG723
1885
- 0x0050 MPEG Layer-2 or Layer-1
1886
- 0x0052 RT24
1887
- 0x0053 PAC
1888
- 0x0055 MPEG Layer-3
1889
- 0x0059 Lucent G.723
1890
- 0x0060 Cirrus
1891
- 0x0061 ESPCM
1892
- 0x0062 Voxware
1893
- 0x0063 Canopus Atrac
1894
- 0x0064 G.726 ADPCM
1895
- 0x0065 G.722 ADPCM
1896
- 0x0066 DSAT
1897
- 0x0067 DSAT Display
1898
- 0x0069 Voxware Byte Aligned
1899
- 0x0070 Voxware AC8
1900
- 0x0071 Voxware AC10
1901
- 0x0072 Voxware AC16
1902
- 0x0073 Voxware AC20
1903
- 0x0074 Voxware MetaVoice
1904
- 0x0075 Voxware MetaSound
1905
- 0x0076 Voxware RT29HW
1906
- 0x0077 Voxware VR12
1907
- 0x0078 Voxware VR18
1908
- 0x0079 Voxware TQ40
1909
- 0x0080 Softsound
1910
- 0x0081 Voxware TQ60
1911
- 0x0082 MSRT24
1912
- 0x0083 G.729A
1913
- 0x0084 MVI MV12
1914
- 0x0085 DF G.726
1915
- 0x0086 DF GSM610
1916
- 0x0088 ISIAudio
1917
- 0x0089 Onlive
1918
- 0x0091 SBC24
1919
- 0x0092 Dolby AC3 SPDIF
1920
- 0x0093 MediaSonic G.723
1921
- 0x0094 Aculab PLC Prosody 8kbps
1922
- 0x0097 ZyXEL ADPCM
1923
- 0x0098 Philips LPCBB
1924
- 0x0099 Packed
1925
- 0x00FF AAC
1926
- 0x0100 Rhetorex ADPCM
1927
- 0x0101 IBM mu-law
1928
- 0x0102 IBM A-law
1929
- 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM)
1930
- 0x0111 Vivo G.723
1931
- 0x0112 Vivo Siren
1932
- 0x0123 Digital G.723
1933
- 0x0125 Sanyo LD ADPCM
1934
- 0x0130 Sipro Lab Telecom ACELP NET
1935
- 0x0131 Sipro Lab Telecom ACELP 4800
1936
- 0x0132 Sipro Lab Telecom ACELP 8V3
1937
- 0x0133 Sipro Lab Telecom G.729
1938
- 0x0134 Sipro Lab Telecom G.729A
1939
- 0x0135 Sipro Lab Telecom Kelvin
1940
- 0x0140 Windows Media Video V8
1941
- 0x0150 Qualcomm PureVoice
1942
- 0x0151 Qualcomm HalfRate
1943
- 0x0155 Ring Zero Systems TUB GSM
1944
- 0x0160 Microsoft Audio 1
1945
- 0x0161 Windows Media Audio V7 / V8 / V9
1946
- 0x0162 Windows Media Audio Professional V9
1947
- 0x0163 Windows Media Audio Lossless V9
1948
- 0x0200 Creative Labs ADPCM
1949
- 0x0202 Creative Labs Fastspeech8
1950
- 0x0203 Creative Labs Fastspeech10
1951
- 0x0210 UHER Informatic GmbH ADPCM
1952
- 0x0220 Quarterdeck
1953
- 0x0230 I-link Worldwide VC
1954
- 0x0240 Aureal RAW Sport
1955
- 0x0250 Interactive Products HSX
1956
- 0x0251 Interactive Products RPELP
1957
- 0x0260 Consistent Software CS2
1958
- 0x0270 Sony SCX
1959
- 0x0300 Fujitsu FM Towns Snd
1960
- 0x0400 BTV Digital
1961
- 0x0401 Intel Music Coder
1962
- 0x0450 QDesign Music
1963
- 0x0680 VME VMPCM
1964
- 0x0681 AT&T Labs TPC
1965
- 0x08AE ClearJump LiteWave
1966
- 0x1000 Olivetti GSM
1967
- 0x1001 Olivetti ADPCM
1968
- 0x1002 Olivetti CELP
1969
- 0x1003 Olivetti SBC
1970
- 0x1004 Olivetti OPR
1971
- 0x1100 Lernout & Hauspie Codec (0x1100)
1972
- 0x1101 Lernout & Hauspie CELP Codec (0x1101)
1973
- 0x1102 Lernout & Hauspie SBC Codec (0x1102)
1974
- 0x1103 Lernout & Hauspie SBC Codec (0x1103)
1975
- 0x1104 Lernout & Hauspie SBC Codec (0x1104)
1976
- 0x1400 Norris
1977
- 0x1401 AT&T ISIAudio
1978
- 0x1500 Soundspace Music Compression
1979
- 0x181C VoxWare RT24 Speech
1980
- 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com)
1981
- 0x2000 Dolby AC3
1982
- 0x2001 Dolby DTS
1983
- 0x2002 WAVE_FORMAT_14_4
1984
- 0x2003 WAVE_FORMAT_28_8
1985
- 0x2004 WAVE_FORMAT_COOK
1986
- 0x2005 WAVE_FORMAT_DNET
1987
- 0x674F Ogg Vorbis 1
1988
- 0x6750 Ogg Vorbis 2
1989
- 0x6751 Ogg Vorbis 3
1990
- 0x676F Ogg Vorbis 1+
1991
- 0x6770 Ogg Vorbis 2+
1992
- 0x6771 Ogg Vorbis 3+
1993
- 0x7A21 GSM-AMR (CBR, no SID)
1994
- 0x7A22 GSM-AMR (VBR, including SID)
1995
- 0xFFFE WAVE_FORMAT_EXTENSIBLE
1996
- 0xFFFF WAVE_FORMAT_DEVELOPMENT
1997
-
1998
- */
1999
-
2000
- return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag');
2001
-
2002
- }
2003
-
2004
-
2005
- public static function RIFFfourccLookup($fourcc) {
2006
-
2007
- $begin = __LINE__;
2008
-
2009
- /** This is not a comment!
2010
-
2011
- swot http://developer.apple.com/qa/snd/snd07.html
2012
- ____ No Codec (____)
2013
- _BIT BI_BITFIELDS (Raw RGB)
2014
- _JPG JPEG compressed
2015
- _PNG PNG compressed W3C/ISO/IEC (RFC-2083)
2016
- _RAW Full Frames (Uncompressed)
2017
- _RGB Raw RGB Bitmap
2018
- _RL4 RLE 4bpp RGB
2019
- _RL8 RLE 8bpp RGB
2020
- 3IV1 3ivx MPEG-4 v1
2021
- 3IV2 3ivx MPEG-4 v2
2022
- 3IVX 3ivx MPEG-4
2023
- AASC Autodesk Animator
2024
- ABYR Kensington ?ABYR?
2025
- AEMI Array Microsystems VideoONE MPEG1-I Capture
2026
- AFLC Autodesk Animator FLC
2027
- AFLI Autodesk Animator FLI
2028
- AMPG Array Microsystems VideoONE MPEG
2029
- ANIM Intel RDX (ANIM)
2030
- AP41 AngelPotion Definitive
2031
- ASV1 Asus Video v1
2032
- ASV2 Asus Video v2
2033
- ASVX Asus Video 2.0 (audio)
2034
- AUR2 AuraVision Aura 2 Codec - YUV 4:2:2
2035
- AURA AuraVision Aura 1 Codec - YUV 4:1:1
2036
- AVDJ Independent JPEG Group\'s codec (AVDJ)
2037
- AVRN Independent JPEG Group\'s codec (AVRN)
2038
- AYUV 4:4:4 YUV (AYUV)
2039
- AZPR Quicktime Apple Video (AZPR)
2040
- BGR Raw RGB32
2041
- BLZ0 Blizzard DivX MPEG-4
2042
- BTVC Conexant Composite Video
2043
- BINK RAD Game Tools Bink Video
2044
- BT20 Conexant Prosumer Video
2045
- BTCV Conexant Composite Video Codec
2046
- BW10 Data Translation Broadway MPEG Capture
2047
- CC12 Intel YUV12
2048
- CDVC Canopus DV
2049
- CFCC Digital Processing Systems DPS Perception
2050
- CGDI Microsoft Office 97 Camcorder Video
2051
- CHAM Winnov Caviara Champagne
2052
- CJPG Creative WebCam JPEG
2053
- CLJR Cirrus Logic YUV 4:1:1
2054
- CMYK Common Data Format in Printing (Colorgraph)
2055
- CPLA Weitek 4:2:0 YUV Planar
2056
- CRAM Microsoft Video 1 (CRAM)
2057
- cvid Radius Cinepak
2058
- CVID Radius Cinepak
2059
- CWLT Microsoft Color WLT DIB
2060
- CYUV Creative Labs YUV
2061
- CYUY ATI YUV
2062
- D261 H.261
2063
- D263 H.263
2064
- DIB Device Independent Bitmap
2065
- DIV1 FFmpeg OpenDivX
2066
- DIV2 Microsoft MPEG-4 v1/v2
2067
- DIV3 DivX ;-) MPEG-4 v3.x Low-Motion
2068
- DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion
2069
- DIV5 DivX MPEG-4 v5.x
2070
- DIV6 DivX ;-) (MS MPEG-4 v3.x)
2071
- DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo)
2072
- divx DivX MPEG-4
2073
- DMB1 Matrox Rainbow Runner hardware MJPEG
2074
- DMB2 Paradigm MJPEG
2075
- DSVD ?DSVD?
2076
- DUCK Duck TrueMotion 1.0
2077
- DPS0 DPS/Leitch Reality Motion JPEG
2078
- DPSC DPS/Leitch PAR Motion JPEG
2079
- DV25 Matrox DVCPRO codec
2080
- DV50 Matrox DVCPRO50 codec
2081
- DVC IEC 61834 and SMPTE 314M (DVC/DV Video)
2082
- DVCP IEC 61834 and SMPTE 314M (DVC/DV Video)
2083
- DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps
2084
- DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com)
2085
- DVSL IEC Standard DV compressed in SD (SDL)
2086
- DVAN ?DVAN?
2087
- DVE2 InSoft DVE-2 Videoconferencing
2088
- dvsd IEC 61834 and SMPTE 314M DVC/DV Video
2089
- DVSD IEC 61834 and SMPTE 314M DVC/DV Video
2090
- DVX1 Lucent DVX1000SP Video Decoder
2091
- DVX2 Lucent DVX2000S Video Decoder
2092
- DVX3 Lucent DVX3000S Video Decoder
2093
- DX50 DivX v5
2094
- DXT1 Microsoft DirectX Compressed Texture (DXT1)
2095
- DXT2 Microsoft DirectX Compressed Texture (DXT2)
2096
- DXT3 Microsoft DirectX Compressed Texture (DXT3)
2097
- DXT4 Microsoft DirectX Compressed Texture (DXT4)
2098
- DXT5 Microsoft DirectX Compressed Texture (DXT5)
2099
- DXTC Microsoft DirectX Compressed Texture (DXTC)
2100
- DXTn Microsoft DirectX Compressed Texture (DXTn)
2101
- EM2V Etymonix MPEG-2 I-frame (www.etymonix.com)
2102
- EKQ0 Elsa ?EKQ0?
2103
- ELK0 Elsa ?ELK0?
2104
- ESCP Eidos Escape
2105
- ETV1 eTreppid Video ETV1
2106
- ETV2 eTreppid Video ETV2
2107
- ETVC eTreppid Video ETVC
2108
- FLIC Autodesk FLI/FLC Animation
2109
- FLV1 Sorenson Spark
2110
- FLV4 On2 TrueMotion VP6
2111
- FRWT Darim Vision Forward Motion JPEG (www.darvision.com)
2112
- FRWU Darim Vision Forward Uncompressed (www.darvision.com)
2113
- FLJP D-Vision Field Encoded Motion JPEG
2114
- FPS1 FRAPS v1
2115
- FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel
2116
- FRWD SoftLab-Nsk Forward Motion JPEG
2117
- FVF1 Iterated Systems Fractal Video Frame
2118
- GLZW Motion LZW (gabest@freemail.hu)
2119
- GPEG Motion JPEG (gabest@freemail.hu)
2120
- GWLT Microsoft Greyscale WLT DIB
2121
- H260 Intel ITU H.260 Videoconferencing
2122
- H261 Intel ITU H.261 Videoconferencing
2123
- H262 Intel ITU H.262 Videoconferencing
2124
- H263 Intel ITU H.263 Videoconferencing
2125
- H264 Intel ITU H.264 Videoconferencing
2126
- H265 Intel ITU H.265 Videoconferencing
2127
- H266 Intel ITU H.266 Videoconferencing
2128
- H267 Intel ITU H.267 Videoconferencing
2129
- H268 Intel ITU H.268 Videoconferencing
2130
- H269 Intel ITU H.269 Videoconferencing
2131
- HFYU Huffman Lossless Codec
2132
- HMCR Rendition Motion Compensation Format (HMCR)
2133
- HMRR Rendition Motion Compensation Format (HMRR)
2134
- I263 FFmpeg I263 decoder
2135
- IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane")
2136
- IUYV Interlaced version of UYVY (www.leadtools.com)
2137
- IY41 Interlaced version of Y41P (www.leadtools.com)
2138
- IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
2139
- IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
2140
- IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2�2 U and V planes)
2141
- i263 Intel ITU H.263 Videoconferencing (i263)
2142
- I420 Intel Indeo 4
2143
- IAN Intel Indeo 4 (RDX)
2144
- ICLB InSoft CellB Videoconferencing
2145
- IGOR Power DVD
2146
- IJPG Intergraph JPEG
2147
- ILVC Intel Layered Video
2148
- ILVR ITU-T H.263+
2149
- IPDV I-O Data Device Giga AVI DV Codec
2150
- IR21 Intel Indeo 2.1
2151
- IRAW Intel YUV Uncompressed
2152
- IV30 Intel Indeo 3.0
2153
- IV31 Intel Indeo 3.1
2154
- IV32 Ligos Indeo 3.2
2155
- IV33 Ligos Indeo 3.3
2156
- IV34 Ligos Indeo 3.4
2157
- IV35 Ligos Indeo 3.5
2158
- IV36 Ligos Indeo 3.6
2159
- IV37 Ligos Indeo 3.7
2160
- IV38 Ligos Indeo 3.8
2161
- IV39 Ligos Indeo 3.9
2162
- IV40 Ligos Indeo Interactive 4.0
2163
- IV41 Ligos Indeo Interactive 4.1
2164
- IV42 Ligos Indeo Interactive 4.2
2165
- IV43 Ligos Indeo Interactive 4.3
2166
- IV44 Ligos Indeo Interactive 4.4
2167
- IV45 Ligos Indeo Interactive 4.5
2168
- IV46 Ligos Indeo Interactive 4.6
2169
- IV47 Ligos Indeo Interactive 4.7
2170
- IV48 Ligos Indeo Interactive 4.8
2171
- IV49 Ligos Indeo Interactive 4.9
2172
- IV50 Ligos Indeo Interactive 5.0
2173
- JBYR Kensington ?JBYR?
2174
- JPEG Still Image JPEG DIB
2175
- JPGL Pegasus Lossless Motion JPEG
2176
- KMVC Team17 Software Karl Morton\'s Video Codec
2177
- LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com)
2178
- LEAD LEAD Video Codec
2179
- Ljpg LEAD MJPEG Codec
2180
- MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de)
2181
- MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com)
2182
- MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com)
2183
- MMES Matrox MPEG-2 I-frame
2184
- MP2v Microsoft S-Mpeg 4 version 1 (MP2v)
2185
- MP42 Microsoft S-Mpeg 4 version 2 (MP42)
2186
- MP43 Microsoft S-Mpeg 4 version 3 (MP43)
2187
- MP4S Microsoft S-Mpeg 4 version 3 (MP4S)
2188
- MP4V FFmpeg MPEG-4
2189
- MPG1 FFmpeg MPEG 1/2
2190
- MPG2 FFmpeg MPEG 1/2
2191
- MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3)
2192
- MPG4 Microsoft MPEG-4
2193
- MPGI Sigma Designs MPEG
2194
- MPNG PNG images decoder
2195
- MSS1 Microsoft Windows Screen Video
2196
- MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
2197
- M261 Microsoft H.261
2198
- M263 Microsoft H.263
2199
- M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2)
2200
- m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2)
2201
- MC12 ATI Motion Compensation Format (MC12)
2202
- MCAM ATI Motion Compensation Format (MCAM)
2203
- MJ2C Morgan Multimedia Motion JPEG2000
2204
- mJPG IBM Motion JPEG w/ Huffman Tables
2205
- MJPG Microsoft Motion JPEG DIB
2206
- MP42 Microsoft MPEG-4 (low-motion)
2207
- MP43 Microsoft MPEG-4 (fast-motion)
2208
- MP4S Microsoft MPEG-4 (MP4S)
2209
- mp4s Microsoft MPEG-4 (mp4s)
2210
- MPEG Chromatic Research MPEG-1 Video I-Frame
2211
- MPG4 Microsoft MPEG-4 Video High Speed Compressor
2212
- MPGI Sigma Designs MPEG
2213
- MRCA FAST Multimedia Martin Regen Codec
2214
- MRLE Microsoft Run Length Encoding
2215
- MSVC Microsoft Video 1
2216
- MTX1 Matrox ?MTX1?
2217
- MTX2 Matrox ?MTX2?
2218
- MTX3 Matrox ?MTX3?
2219
- MTX4 Matrox ?MTX4?
2220
- MTX5 Matrox ?MTX5?
2221
- MTX6 Matrox ?MTX6?
2222
- MTX7 Matrox ?MTX7?
2223
- MTX8 Matrox ?MTX8?
2224
- MTX9 Matrox ?MTX9?
2225
- MV12 Motion Pixels Codec (old)
2226
- MWV1 Aware Motion Wavelets
2227
- nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm)
2228
- NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com)
2229
- NUV1 NuppelVideo
2230
- NTN1 Nogatech Video Compression 1
2231
- NVS0 nVidia GeForce Texture (NVS0)
2232
- NVS1 nVidia GeForce Texture (NVS1)
2233
- NVS2 nVidia GeForce Texture (NVS2)
2234
- NVS3 nVidia GeForce Texture (NVS3)
2235
- NVS4 nVidia GeForce Texture (NVS4)
2236
- NVS5 nVidia GeForce Texture (NVS5)
2237
- NVT0 nVidia GeForce Texture (NVT0)
2238
- NVT1 nVidia GeForce Texture (NVT1)
2239
- NVT2 nVidia GeForce Texture (NVT2)
2240
- NVT3 nVidia GeForce Texture (NVT3)
2241
- NVT4 nVidia GeForce Texture (NVT4)
2242
- NVT5 nVidia GeForce Texture (NVT5)
2243
- PIXL MiroXL, Pinnacle PCTV
2244
- PDVC I-O Data Device Digital Video Capture DV codec
2245
- PGVV Radius Video Vision
2246
- PHMO IBM Photomotion
2247
- PIM1 MPEG Realtime (Pinnacle Cards)
2248
- PIM2 Pegasus Imaging ?PIM2?
2249
- PIMJ Pegasus Imaging Lossless JPEG
2250
- PVEZ Horizons Technology PowerEZ
2251
- PVMM PacketVideo Corporation MPEG-4
2252
- PVW2 Pegasus Imaging Wavelet Compression
2253
- Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de)
2254
- Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de)
2255
- QPEG Q-Team QPEG 1.0
2256
- qpeq Q-Team QPEG 1.1
2257
- RGB Raw BGR32
2258
- RGBA Raw RGB w/ Alpha
2259
- RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com)
2260
- ROQV Id RoQ File Video Decoder
2261
- RPZA Quicktime Apple Video (RPZA)
2262
- RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/)
2263
- RV10 RealVideo 1.0 (aka RealVideo 5.0)
2264
- RV13 RealVideo 1.0 (RV13)
2265
- RV20 RealVideo G2
2266
- RV30 RealVideo 8
2267
- RV40 RealVideo 9
2268
- RGBT Raw RGB w/ Transparency
2269
- RLE Microsoft Run Length Encoder
2270
- RLE4 Run Length Encoded (4bpp, 16-color)
2271
- RLE8 Run Length Encoded (8bpp, 256-color)
2272
- RT21 Intel Indeo RealTime Video 2.1
2273
- rv20 RealVideo G2
2274
- rv30 RealVideo 8
2275
- RVX Intel RDX (RVX )
2276
- SMC Apple Graphics (SMC )
2277
- SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2
2278
- SPIG Radius Spigot
2279
- SVQ3 Sorenson Video 3 (Apple Quicktime 5)
2280
- s422 Tekram VideoCap C210 YUV 4:2:2
2281
- SDCC Sun Communication Digital Camera Codec
2282
- SFMC CrystalNet Surface Fitting Method
2283
- SMSC Radius SMSC
2284
- SMSD Radius SMSD
2285
- smsv WorldConnect Wavelet Video
2286
- SPIG Radius Spigot
2287
- SPLC Splash Studios ACM Audio Codec (www.splashstudios.net)
2288
- SQZ2 Microsoft VXTreme Video Codec V2
2289
- STVA ST Microelectronics CMOS Imager Data (Bayer)
2290
- STVB ST Microelectronics CMOS Imager Data (Nudged Bayer)
2291
- STVC ST Microelectronics CMOS Imager Data (Bunched)
2292
- STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format)
2293
- STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data)
2294
- SV10 Sorenson Video R1
2295
- SVQ1 Sorenson Video
2296
- T420 Toshiba YUV 4:2:0
2297
- TM2A Duck TrueMotion Archiver 2.0 (www.duck.com)
2298
- TVJP Pinnacle/Truevision Targa 2000 board (TVJP)
2299
- TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ)
2300
- TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com)
2301
- TY2C Trident Decompression Driver
2302
- TLMS TeraLogic Motion Intraframe Codec (TLMS)
2303
- TLST TeraLogic Motion Intraframe Codec (TLST)
2304
- TM20 Duck TrueMotion 2.0
2305
- TM2X Duck TrueMotion 2X
2306
- TMIC TeraLogic Motion Intraframe Codec (TMIC)
2307
- TMOT Horizons Technology TrueMotion S
2308
- tmot Horizons TrueMotion Video Compression
2309
- TR20 Duck TrueMotion RealTime 2.0
2310
- TSCC TechSmith Screen Capture Codec
2311
- TV10 Tecomac Low-Bit Rate Codec
2312
- TY2N Trident ?TY2N?
2313
- U263 UB Video H.263/H.263+/H.263++ Decoder
2314
- UMP4 UB Video MPEG 4 (www.ubvideo.com)
2315
- UYNV Nvidia UYVY packed 4:2:2
2316
- UYVP Evans & Sutherland YCbCr 4:2:2 extended precision
2317
- UCOD eMajix.com ClearVideo
2318
- ULTI IBM Ultimotion
2319
- UYVY UYVY packed 4:2:2
2320
- V261 Lucent VX2000S
2321
- VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/)
2322
- VIV1 FFmpeg H263+ decoder
2323
- VIV2 Vivo H.263
2324
- VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf)
2325
- VTLP Alaris VideoGramPiX
2326
- VYU9 ATI YUV (VYU9)
2327
- VYUY ATI YUV (VYUY)
2328
- V261 Lucent VX2000S
2329
- V422 Vitec Multimedia 24-bit YUV 4:2:2 Format
2330
- V655 Vitec Multimedia 16-bit YUV 4:2:2 Format
2331
- VCR1 ATI Video Codec 1
2332
- VCR2 ATI Video Codec 2
2333
- VCR3 ATI VCR 3.0
2334
- VCR4 ATI VCR 4.0
2335
- VCR5 ATI VCR 5.0
2336
- VCR6 ATI VCR 6.0
2337
- VCR7 ATI VCR 7.0
2338
- VCR8 ATI VCR 8.0
2339
- VCR9 ATI VCR 9.0
2340
- VDCT Vitec Multimedia Video Maker Pro DIB
2341
- VDOM VDOnet VDOWave
2342
- VDOW VDOnet VDOLive (H.263)
2343
- VDTZ Darim Vison VideoTizer YUV
2344
- VGPX Alaris VideoGramPiX
2345
- VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422
2346
- VIVO Vivo H.263 v2.00
2347
- vivo Vivo H.263
2348
- VIXL Miro/Pinnacle Video XL
2349
- VLV1 VideoLogic/PURE Digital Videologic Capture
2350
- VP30 On2 VP3.0
2351
- VP31 On2 VP3.1
2352
- VP6F On2 TrueMotion VP6
2353
- VX1K Lucent VX1000S Video Codec
2354
- VX2K Lucent VX2000S Video Codec
2355
- VXSP Lucent VX1000SP Video Codec
2356
- WBVC Winbond W9960
2357
- WHAM Microsoft Video 1 (WHAM)
2358
- WINX Winnov Software Compression
2359
- WJPG AverMedia Winbond JPEG
2360
- WMV1 Windows Media Video V7
2361
- WMV2 Windows Media Video V8
2362
- WMV3 Windows Media Video V9
2363
- WNV1 Winnov Hardware Compression
2364
- XYZP Extended PAL format XYZ palette (www.riff.org)
2365
- x263 Xirlink H.263
2366
- XLV0 NetXL Video Decoder
2367
- XMPG Xing MPEG (I-Frame only)
2368
- XVID XviD MPEG-4 (www.xvid.org)
2369
- XXAN ?XXAN?
2370
- YU92 Intel YUV (YU92)
2371
- YUNV Nvidia Uncompressed YUV 4:2:2
2372
- YUVP Extended PAL format YUV palette (www.riff.org)
2373
- Y211 YUV 2:1:1 Packed
2374
- Y411 YUV 4:1:1 Packed
2375
- Y41B Weitek YUV 4:1:1 Planar
2376
- Y41P Brooktree PC1 YUV 4:1:1 Packed
2377
- Y41T Brooktree PC1 YUV 4:1:1 with transparency
2378
- Y42B Weitek YUV 4:2:2 Planar
2379
- Y42T Brooktree UYUV 4:2:2 with transparency
2380
- Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera
2381
- Y800 Simple, single Y plane for monochrome images
2382
- Y8 Grayscale video
2383
- YC12 Intel YUV 12 codec
2384
- YUV8 Winnov Caviar YUV8
2385
- YUV9 Intel YUV9
2386
- YUY2 Uncompressed YUV 4:2:2
2387
- YUYV Canopus YUV
2388
- YV12 YVU12 Planar
2389
- YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes)
2390
- YVYU YVYU 4:2:2 Packed
2391
- ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
2392
- ZPEG Metheus Video Zipper
2393
-
2394
- */
2395
-
2396
- return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc');
2397
- }
2398
-
2399
-
2400
- function EitherEndian2Int($byteword, $signed=false) {
2401
- if ($this->getid3->info['fileformat'] == 'riff') {
2402
- return getid3_lib::LittleEndian2Int($byteword, $signed);
2403
- }
2404
- return getid3_lib::BigEndian2Int($byteword, false, $signed);
2405
- }
2406
-
2407
- }
2408
-
2409
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // See readme.txt for more details //
9
+ /////////////////////////////////////////////////////////////////
10
+ // //
11
+ // module.audio-video.riff.php //
12
+ // module for analyzing RIFF files //
13
+ // multiple formats supported by this module: //
14
+ // Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX //
15
+ // dependencies: module.audio.mp3.php //
16
+ // module.audio.ac3.php //
17
+ // module.audio.dts.php //
18
+ // ///
19
+ /////////////////////////////////////////////////////////////////
20
+
21
+ /**
22
+ * @todo Parse AC-3/DTS audio inside WAVE correctly
23
+ * @todo Rewrite RIFF parser totally
24
+ */
25
+
26
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
27
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true);
28
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, true);
29
+
30
+ class getid3_riff extends getid3_handler {
31
+
32
+ protected $container = 'riff'; // default
33
+
34
+ public function Analyze() {
35
+ $info = &$this->getid3->info;
36
+
37
+ // initialize these values to an empty array, otherwise they default to NULL
38
+ // and you can't append array values to a NULL value
39
+ $info['riff'] = array('raw'=>array());
40
+
41
+ // Shortcuts
42
+ $thisfile_riff = &$info['riff'];
43
+ $thisfile_riff_raw = &$thisfile_riff['raw'];
44
+ $thisfile_audio = &$info['audio'];
45
+ $thisfile_video = &$info['video'];
46
+ $thisfile_audio_dataformat = &$thisfile_audio['dataformat'];
47
+ $thisfile_riff_audio = &$thisfile_riff['audio'];
48
+ $thisfile_riff_video = &$thisfile_riff['video'];
49
+
50
+ $Original['avdataoffset'] = $info['avdataoffset'];
51
+ $Original['avdataend'] = $info['avdataend'];
52
+
53
+ $this->fseek($info['avdataoffset']);
54
+ $RIFFheader = $this->fread(12);
55
+ $offset = $this->ftell();
56
+ $RIFFtype = substr($RIFFheader, 0, 4);
57
+ $RIFFsize = substr($RIFFheader, 4, 4);
58
+ $RIFFsubtype = substr($RIFFheader, 8, 4);
59
+
60
+ switch ($RIFFtype) {
61
+
62
+ case 'FORM': // AIFF, AIFC
63
+ //$info['fileformat'] = 'aiff';
64
+ $this->container = 'aiff';
65
+ $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
66
+ $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
67
+ break;
68
+
69
+ case 'RIFF': // AVI, WAV, etc
70
+ case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
71
+ case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
72
+ //$info['fileformat'] = 'riff';
73
+ $this->container = 'riff';
74
+ $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
75
+ if ($RIFFsubtype == 'RMP3') {
76
+ // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
77
+ $RIFFsubtype = 'WAVE';
78
+ }
79
+ if ($RIFFsubtype != 'AMV ') {
80
+ // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
81
+ // Handled separately in ParseRIFFAMV()
82
+ $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
83
+ }
84
+ if (($info['avdataend'] - $info['filesize']) == 1) {
85
+ // LiteWave appears to incorrectly *not* pad actual output file
86
+ // to nearest WORD boundary so may appear to be short by one
87
+ // byte, in which case - skip warning
88
+ $info['avdataend'] = $info['filesize'];
89
+ }
90
+
91
+ $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset
92
+ while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) {
93
+ try {
94
+ $this->fseek($nextRIFFoffset);
95
+ } catch (getid3_exception $e) {
96
+ if ($e->getCode() == 10) {
97
+ //$this->warning('RIFF parser: '.$e->getMessage());
98
+ $this->error('AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime may be wrong');
99
+ $this->warning('[avdataend] value may be incorrect, multiple AVIX chunks may be present');
100
+ break;
101
+ } else {
102
+ throw $e;
103
+ }
104
+ }
105
+ $nextRIFFheader = $this->fread(12);
106
+ if ($nextRIFFoffset == ($info['avdataend'] - 1)) {
107
+ if (substr($nextRIFFheader, 0, 1) == "\x00") {
108
+ // RIFF padded to WORD boundary, we're actually already at the end
109
+ break;
110
+ }
111
+ }
112
+ $nextRIFFheaderID = substr($nextRIFFheader, 0, 4);
113
+ $nextRIFFsize = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4));
114
+ $nextRIFFtype = substr($nextRIFFheader, 8, 4);
115
+ $chunkdata = array();
116
+ $chunkdata['offset'] = $nextRIFFoffset + 8;
117
+ $chunkdata['size'] = $nextRIFFsize;
118
+ $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size'];
119
+
120
+ switch ($nextRIFFheaderID) {
121
+ case 'RIFF':
122
+ $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset);
123
+ if (!isset($thisfile_riff[$nextRIFFtype])) {
124
+ $thisfile_riff[$nextRIFFtype] = array();
125
+ }
126
+ $thisfile_riff[$nextRIFFtype][] = $chunkdata;
127
+ break;
128
+
129
+ case 'AMV ':
130
+ unset($info['riff']);
131
+ $info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset);
132
+ break;
133
+
134
+ case 'JUNK':
135
+ // ignore
136
+ $thisfile_riff[$nextRIFFheaderID][] = $chunkdata;
137
+ break;
138
+
139
+ case 'IDVX':
140
+ $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunkdata['size']));
141
+ break;
142
+
143
+ default:
144
+ if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) {
145
+ $DIVXTAG = $nextRIFFheader.$this->fread(128 - 12);
146
+ if (substr($DIVXTAG, -7) == 'DIVXTAG') {
147
+ // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file
148
+ $this->warning('Found wrongly-structured DIVXTAG at offset '.($this->ftell() - 128).', parsing anyway');
149
+ $info['divxtag']['comments'] = self::ParseDIVXTAG($DIVXTAG);
150
+ break 2;
151
+ }
152
+ }
153
+ $this->warning('Expecting "RIFF|JUNK|IDVX" at '.$nextRIFFoffset.', found "'.$nextRIFFheaderID.'" ('.getid3_lib::PrintHexBytes($nextRIFFheaderID).') - skipping rest of file');
154
+ break 2;
155
+
156
+ }
157
+
158
+ }
159
+ if ($RIFFsubtype == 'WAVE') {
160
+ $thisfile_riff_WAVE = &$thisfile_riff['WAVE'];
161
+ }
162
+ break;
163
+
164
+ default:
165
+ $this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead');
166
+ //unset($info['fileformat']);
167
+ return false;
168
+ }
169
+
170
+ $streamindex = 0;
171
+ switch ($RIFFsubtype) {
172
+
173
+ // http://en.wikipedia.org/wiki/Wav
174
+ case 'WAVE':
175
+ $info['fileformat'] = 'wav';
176
+
177
+ if (empty($thisfile_audio['bitrate_mode'])) {
178
+ $thisfile_audio['bitrate_mode'] = 'cbr';
179
+ }
180
+ if (empty($thisfile_audio_dataformat)) {
181
+ $thisfile_audio_dataformat = 'wav';
182
+ }
183
+
184
+ if (isset($thisfile_riff_WAVE['data'][0]['offset'])) {
185
+ $info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8;
186
+ $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size'];
187
+ }
188
+ if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) {
189
+
190
+ $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']);
191
+ $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
192
+ if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) {
193
+ $info['error'][] = 'Corrupt RIFF file: bitrate_audio == zero';
194
+ return false;
195
+ }
196
+ $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw'];
197
+ unset($thisfile_riff_audio[$streamindex]['raw']);
198
+ $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
199
+
200
+ $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
201
+ if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
202
+ $info['warning'][] = 'Audio codec = '.$thisfile_audio['codec'];
203
+ }
204
+ $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
205
+
206
+ if (empty($info['playtime_seconds'])) { // may already be set (e.g. DTS-WAV)
207
+ $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
208
+ }
209
+
210
+ $thisfile_audio['lossless'] = false;
211
+ if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
212
+ switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
213
+
214
+ case 0x0001: // PCM
215
+ $thisfile_audio['lossless'] = true;
216
+ break;
217
+
218
+ case 0x2000: // AC-3
219
+ $thisfile_audio_dataformat = 'ac3';
220
+ break;
221
+
222
+ default:
223
+ // do nothing
224
+ break;
225
+
226
+ }
227
+ }
228
+ $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag'];
229
+ $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
230
+ $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless'];
231
+ $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat;
232
+ }
233
+
234
+ if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) {
235
+
236
+ // shortcuts
237
+ $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data'];
238
+ $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array());
239
+ $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad'];
240
+ $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track'];
241
+ $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album'];
242
+
243
+ $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4));
244
+ $thisfile_riff_raw_rgad['nRadioRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 4, 2));
245
+ $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 6, 2));
246
+
247
+ $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
248
+ $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
249
+ $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
250
+ $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
251
+ $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
252
+ $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
253
+ $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
254
+ $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
255
+ $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
256
+ $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
257
+
258
+ $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude'];
259
+ if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) {
260
+ $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']);
261
+ $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']);
262
+ $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']);
263
+ }
264
+ if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) {
265
+ $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']);
266
+ $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']);
267
+ $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']);
268
+ }
269
+ }
270
+
271
+ if (isset($thisfile_riff_WAVE['fact'][0]['data'])) {
272
+ $thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4));
273
+
274
+ // This should be a good way of calculating exact playtime,
275
+ // but some sample files have had incorrect number of samples,
276
+ // so cannot use this method
277
+
278
+ // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) {
279
+ // $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec'];
280
+ // }
281
+ }
282
+ if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
283
+ $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8);
284
+ }
285
+
286
+ if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
287
+ // shortcut
288
+ $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
289
+
290
+ $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256));
291
+ $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32));
292
+ $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32));
293
+ $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10);
294
+ $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8);
295
+ $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8));
296
+ $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1));
297
+ $thisfile_riff_WAVE_bext_0['reserved'] = substr($thisfile_riff_WAVE_bext_0['data'], 347, 254);
298
+ $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601)));
299
+ if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) {
300
+ if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) {
301
+ list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date;
302
+ list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time;
303
+ $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']);
304
+ } else {
305
+ $info['warning'][] = 'RIFF.WAVE.BEXT.origin_time is invalid';
306
+ }
307
+ } else {
308
+ $info['warning'][] = 'RIFF.WAVE.BEXT.origin_date is invalid';
309
+ }
310
+ $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
311
+ $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title'];
312
+ }
313
+
314
+ if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) {
315
+ // shortcut
316
+ $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0];
317
+
318
+ $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2));
319
+ $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001);
320
+ if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) {
321
+ $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true;
322
+ $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004);
323
+ $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008);
324
+
325
+ $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2));
326
+ }
327
+ $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2));
328
+ $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2));
329
+ $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001);
330
+ $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002);
331
+ $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004);
332
+ }
333
+
334
+ if (isset($thisfile_riff_WAVE['cart'][0]['data'])) {
335
+ // shortcut
336
+ $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0];
337
+
338
+ $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4);
339
+ $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64));
340
+ $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64));
341
+ $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64));
342
+ $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64));
343
+ $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64));
344
+ $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64));
345
+ $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64));
346
+ $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10));
347
+ $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8));
348
+ $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10));
349
+ $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8));
350
+ $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64));
351
+ $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64));
352
+ $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64));
353
+ $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true);
354
+ for ($i = 0; $i < 8; $i++) {
355
+ $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4);
356
+ $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4));
357
+ }
358
+ $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024));
359
+ $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772)));
360
+
361
+ $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist'];
362
+ $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title'];
363
+ }
364
+
365
+ if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) {
366
+ // SoundMiner metadata
367
+
368
+ // shortcuts
369
+ $thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0];
370
+ $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data'];
371
+ $SNDM_startoffset = 0;
372
+ $SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size'];
373
+
374
+ while ($SNDM_startoffset < $SNDM_endoffset) {
375
+ $SNDM_thisTagOffset = 0;
376
+ $SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4));
377
+ $SNDM_thisTagOffset += 4;
378
+ $SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4);
379
+ $SNDM_thisTagOffset += 4;
380
+ $SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
381
+ $SNDM_thisTagOffset += 2;
382
+ $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
383
+ $SNDM_thisTagOffset += 2;
384
+ $SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize);
385
+ $SNDM_thisTagOffset += $SNDM_thisTagDataSize;
386
+
387
+ if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) {
388
+ $info['warning'][] = 'RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
389
+ break;
390
+ } elseif ($SNDM_thisTagSize <= 0) {
391
+ $info['warning'][] = 'RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
392
+ break;
393
+ }
394
+ $SNDM_startoffset += $SNDM_thisTagSize;
395
+
396
+ $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText;
397
+ if ($parsedkey = self::waveSNDMtagLookup($SNDM_thisTagKey)) {
398
+ $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText;
399
+ } else {
400
+ $info['warning'][] = 'RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
401
+ }
402
+ }
403
+
404
+ $tagmapping = array(
405
+ 'tracktitle'=>'title',
406
+ 'category' =>'genre',
407
+ 'cdtitle' =>'album',
408
+ 'tracktitle'=>'title',
409
+ );
410
+ foreach ($tagmapping as $fromkey => $tokey) {
411
+ if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) {
412
+ $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey];
413
+ }
414
+ }
415
+ }
416
+
417
+ if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) {
418
+ // requires functions simplexml_load_string and get_object_vars
419
+ if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) {
420
+ $thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML;
421
+ if (isset($parsedXML['SPEED']['MASTER_SPEED'])) {
422
+ @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']);
423
+ $thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000);
424
+ }
425
+ if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) {
426
+ @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']);
427
+ $thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000);
428
+ }
429
+ if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) {
430
+ $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0'));
431
+ $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE'];
432
+ $h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] / 3600);
433
+ $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600)) / 60);
434
+ $s = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60));
435
+ $f = ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate'];
436
+ $thisfile_riff_WAVE['iXML'][0]['timecode_string'] = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s, $f);
437
+ $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d', $h, $m, $s, round($f));
438
+ }
439
+ unset($parsedXML);
440
+ }
441
+ }
442
+
443
+
444
+
445
+ if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
446
+ $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
447
+ $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
448
+ }
449
+
450
+ if (!empty($info['wavpack'])) {
451
+ $thisfile_audio_dataformat = 'wavpack';
452
+ $thisfile_audio['bitrate_mode'] = 'vbr';
453
+ $thisfile_audio['encoder'] = 'WavPack v'.$info['wavpack']['version'];
454
+
455
+ // Reset to the way it was - RIFF parsing will have messed this up
456
+ $info['avdataend'] = $Original['avdataend'];
457
+ $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
458
+
459
+ $this->fseek($info['avdataoffset'] - 44);
460
+ $RIFFdata = $this->fread(44);
461
+ $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
462
+ $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
463
+
464
+ if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
465
+ $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
466
+ $this->fseek($info['avdataend']);
467
+ $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
468
+ }
469
+
470
+ // move the data chunk after all other chunks (if any)
471
+ // so that the RIFF parser doesn't see EOF when trying
472
+ // to skip over the data chunk
473
+ $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
474
+ $getid3_riff = new getid3_riff($this->getid3);
475
+ $getid3_riff->ParseRIFFdata($RIFFdata);
476
+ unset($getid3_riff);
477
+ }
478
+
479
+ if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
480
+ switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
481
+ case 0x0001: // PCM
482
+ if (!empty($info['ac3'])) {
483
+ // Dolby Digital WAV files masquerade as PCM-WAV, but they're not
484
+ $thisfile_audio['wformattag'] = 0x2000;
485
+ $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']);
486
+ $thisfile_audio['lossless'] = false;
487
+ $thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
488
+ $thisfile_audio['sample_rate'] = $info['ac3']['sample_rate'];
489
+ }
490
+ if (!empty($info['dts'])) {
491
+ // Dolby DTS files masquerade as PCM-WAV, but they're not
492
+ $thisfile_audio['wformattag'] = 0x2001;
493
+ $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']);
494
+ $thisfile_audio['lossless'] = false;
495
+ $thisfile_audio['bitrate'] = $info['dts']['bitrate'];
496
+ $thisfile_audio['sample_rate'] = $info['dts']['sample_rate'];
497
+ }
498
+ break;
499
+ case 0x08AE: // ClearJump LiteWave
500
+ $thisfile_audio['bitrate_mode'] = 'vbr';
501
+ $thisfile_audio_dataformat = 'litewave';
502
+
503
+ //typedef struct tagSLwFormat {
504
+ // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags
505
+ // DWORD m_dwScale; // scale factor for lossy compression
506
+ // DWORD m_dwBlockSize; // number of samples in encoded blocks
507
+ // WORD m_wQuality; // alias for the scale factor
508
+ // WORD m_wMarkDistance; // distance between marks in bytes
509
+ // WORD m_wReserved;
510
+ //
511
+ // //following paramters are ignored if CF_FILESRC is not set
512
+ // DWORD m_dwOrgSize; // original file size in bytes
513
+ // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file
514
+ // DWORD m_dwRiffChunkSize; // riff chunk size in the original file
515
+ //
516
+ // PCMWAVEFORMAT m_OrgWf; // original wave format
517
+ // }SLwFormat, *PSLwFormat;
518
+
519
+ // shortcut
520
+ $thisfile_riff['litewave']['raw'] = array();
521
+ $riff_litewave = &$thisfile_riff['litewave'];
522
+ $riff_litewave_raw = &$riff_litewave['raw'];
523
+
524
+ $flags = array(
525
+ 'compression_method' => 1,
526
+ 'compression_flags' => 1,
527
+ 'm_dwScale' => 4,
528
+ 'm_dwBlockSize' => 4,
529
+ 'm_wQuality' => 2,
530
+ 'm_wMarkDistance' => 2,
531
+ 'm_wReserved' => 2,
532
+ 'm_dwOrgSize' => 4,
533
+ 'm_bFactExists' => 2,
534
+ 'm_dwRiffChunkSize' => 4,
535
+ );
536
+ $litewave_offset = 18;
537
+ foreach ($flags as $flag => $length) {
538
+ $riff_litewave_raw[$flag] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], $litewave_offset, $length));
539
+ $litewave_offset += $length;
540
+ }
541
+
542
+ //$riff_litewave['quality_factor'] = intval(round((2000 - $riff_litewave_raw['m_dwScale']) / 20));
543
+ $riff_litewave['quality_factor'] = $riff_litewave_raw['m_wQuality'];
544
+
545
+ $riff_litewave['flags']['raw_source'] = ($riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
546
+ $riff_litewave['flags']['vbr_blocksize'] = ($riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
547
+ $riff_litewave['flags']['seekpoints'] = (bool) ($riff_litewave_raw['compression_flags'] & 0x04);
548
+
549
+ $thisfile_audio['lossless'] = (($riff_litewave_raw['m_wQuality'] == 100) ? true : false);
550
+ $thisfile_audio['encoder_options'] = '-q'.$riff_litewave['quality_factor'];
551
+ break;
552
+
553
+ default:
554
+ break;
555
+ }
556
+ }
557
+ if ($info['avdataend'] > $info['filesize']) {
558
+ switch (!empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') {
559
+ case 'wavpack': // WavPack
560
+ case 'lpac': // LPAC
561
+ case 'ofr': // OptimFROG
562
+ case 'ofs': // OptimFROG DualStream
563
+ // lossless compressed audio formats that keep original RIFF headers - skip warning
564
+ break;
565
+
566
+ case 'litewave':
567
+ if (($info['avdataend'] - $info['filesize']) == 1) {
568
+ // LiteWave appears to incorrectly *not* pad actual output file
569
+ // to nearest WORD boundary so may appear to be short by one
570
+ // byte, in which case - skip warning
571
+ } else {
572
+ // Short by more than one byte, throw warning
573
+ $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
574
+ $info['avdataend'] = $info['filesize'];
575
+ }
576
+ break;
577
+
578
+ default:
579
+ if ((($info['avdataend'] - $info['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($info['filesize'] - $info['avdataoffset']) % 2) == 1)) {
580
+ // output file appears to be incorrectly *not* padded to nearest WORD boundary
581
+ // Output less severe warning
582
+ $info['warning'][] = 'File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
583
+ $info['avdataend'] = $info['filesize'];
584
+ } else {
585
+ // Short by more than one byte, throw warning
586
+ $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
587
+ $info['avdataend'] = $info['filesize'];
588
+ }
589
+ break;
590
+ }
591
+ }
592
+ if (!empty($info['mpeg']['audio']['LAME']['audio_bytes'])) {
593
+ if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
594
+ $info['avdataend']--;
595
+ $info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
596
+ }
597
+ }
598
+ if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) {
599
+ unset($thisfile_audio['bits_per_sample']);
600
+ if (!empty($info['ac3']['bitrate']) && ($info['ac3']['bitrate'] != $thisfile_audio['bitrate'])) {
601
+ $thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
602
+ }
603
+ }
604
+ break;
605
+
606
+ // http://en.wikipedia.org/wiki/Audio_Video_Interleave
607
+ case 'AVI ':
608
+ $info['fileformat'] = 'avi';
609
+ $info['mime_type'] = 'video/avi';
610
+
611
+ $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
612
+ $thisfile_video['dataformat'] = 'avi';
613
+
614
+ if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) {
615
+ $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8;
616
+ if (isset($thisfile_riff['AVIX'])) {
617
+ $info['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size'];
618
+ } else {
619
+ $info['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size'];
620
+ }
621
+ if ($info['avdataend'] > $info['filesize']) {
622
+ $info['warning'][] = 'Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)';
623
+ $info['avdataend'] = $info['filesize'];
624
+ }
625
+ }
626
+
627
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) {
628
+ //$bIndexType = array(
629
+ // 0x00 => 'AVI_INDEX_OF_INDEXES',
630
+ // 0x01 => 'AVI_INDEX_OF_CHUNKS',
631
+ // 0x80 => 'AVI_INDEX_IS_DATA',
632
+ //);
633
+ //$bIndexSubtype = array(
634
+ // 0x01 => array(
635
+ // 0x01 => 'AVI_INDEX_2FIELD',
636
+ // ),
637
+ //);
638
+ foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) {
639
+ $ahsisd = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data'];
640
+
641
+ $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = $this->EitherEndian2Int(substr($ahsisd, 0, 2));
642
+ $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = $this->EitherEndian2Int(substr($ahsisd, 2, 1));
643
+ $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = $this->EitherEndian2Int(substr($ahsisd, 3, 1));
644
+ $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = $this->EitherEndian2Int(substr($ahsisd, 4, 4));
645
+ $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($ahsisd, 8, 4);
646
+ $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = $this->EitherEndian2Int(substr($ahsisd, 12, 4));
647
+
648
+ //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']];
649
+ //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']];
650
+
651
+ unset($ahsisd);
652
+ }
653
+ }
654
+ if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
655
+ $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'];
656
+
657
+ // shortcut
658
+ $thisfile_riff_raw['avih'] = array();
659
+ $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih'];
660
+
661
+ $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = $this->EitherEndian2Int(substr($avihData, 0, 4)); // frame display rate (or 0L)
662
+ if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) {
663
+ $info['error'][] = 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
664
+ return false;
665
+ }
666
+
667
+ $flags = array(
668
+ 'dwMaxBytesPerSec', // max. transfer rate
669
+ 'dwPaddingGranularity', // pad to multiples of this size; normally 2K.
670
+ 'dwFlags', // the ever-present flags
671
+ 'dwTotalFrames', // # frames in file
672
+ 'dwInitialFrames', //
673
+ 'dwStreams', //
674
+ 'dwSuggestedBufferSize', //
675
+ 'dwWidth', //
676
+ 'dwHeight', //
677
+ 'dwScale', //
678
+ 'dwRate', //
679
+ 'dwStart', //
680
+ 'dwLength', //
681
+ );
682
+ $avih_offset = 4;
683
+ foreach ($flags as $flag) {
684
+ $thisfile_riff_raw_avih[$flag] = $this->EitherEndian2Int(substr($avihData, $avih_offset, 4));
685
+ $avih_offset += 4;
686
+ }
687
+
688
+ $flags = array(
689
+ 'hasindex' => 0x00000010,
690
+ 'mustuseindex' => 0x00000020,
691
+ 'interleaved' => 0x00000100,
692
+ 'trustcktype' => 0x00000800,
693
+ 'capturedfile' => 0x00010000,
694
+ 'copyrighted' => 0x00020010,
695
+ );
696
+ foreach ($flags as $flag => $value) {
697
+ $thisfile_riff_raw_avih['flags'][$flag] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & $value);
698
+ }
699
+
700
+ // shortcut
701
+ $thisfile_riff_video[$streamindex] = array();
702
+ $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex];
703
+
704
+ if ($thisfile_riff_raw_avih['dwWidth'] > 0) {
705
+ $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth'];
706
+ $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width'];
707
+ }
708
+ if ($thisfile_riff_raw_avih['dwHeight'] > 0) {
709
+ $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight'];
710
+ $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height'];
711
+ }
712
+ if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) {
713
+ $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames'];
714
+ $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames'];
715
+ }
716
+
717
+ $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3);
718
+ $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate'];
719
+ }
720
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
721
+ if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) {
722
+ for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
723
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
724
+ $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
725
+ $strhfccType = substr($strhData, 0, 4);
726
+
727
+ if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
728
+ $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
729
+
730
+ // shortcut
731
+ $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex];
732
+
733
+ switch ($strhfccType) {
734
+ case 'auds':
735
+ $thisfile_audio['bitrate_mode'] = 'cbr';
736
+ $thisfile_audio_dataformat = 'wav';
737
+ if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) {
738
+ $streamindex = count($thisfile_riff_audio);
739
+ }
740
+
741
+ $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($strfData);
742
+ $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
743
+
744
+ // shortcut
745
+ $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
746
+ $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex];
747
+
748
+ if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) {
749
+ unset($thisfile_audio_streams_currentstream['bits_per_sample']);
750
+ }
751
+ $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag'];
752
+ unset($thisfile_audio_streams_currentstream['raw']);
753
+
754
+ // shortcut
755
+ $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw'];
756
+
757
+ unset($thisfile_riff_audio[$streamindex]['raw']);
758
+ $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
759
+
760
+ $thisfile_audio['lossless'] = false;
761
+ switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) {
762
+ case 0x0001: // PCM
763
+ $thisfile_audio_dataformat = 'wav';
764
+ $thisfile_audio['lossless'] = true;
765
+ break;
766
+
767
+ case 0x0050: // MPEG Layer 2 or Layer 1
768
+ $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2
769
+ break;
770
+
771
+ case 0x0055: // MPEG Layer 3
772
+ $thisfile_audio_dataformat = 'mp3';
773
+ break;
774
+
775
+ case 0x00FF: // AAC
776
+ $thisfile_audio_dataformat = 'aac';
777
+ break;
778
+
779
+ case 0x0161: // Windows Media v7 / v8 / v9
780
+ case 0x0162: // Windows Media Professional v9
781
+ case 0x0163: // Windows Media Lossess v9
782
+ $thisfile_audio_dataformat = 'wma';
783
+ break;
784
+
785
+ case 0x2000: // AC-3
786
+ $thisfile_audio_dataformat = 'ac3';
787
+ break;
788
+
789
+ case 0x2001: // DTS
790
+ $thisfile_audio_dataformat = 'dts';
791
+ break;
792
+
793
+ default:
794
+ $thisfile_audio_dataformat = 'wav';
795
+ break;
796
+ }
797
+ $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat;
798
+ $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless'];
799
+ $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
800
+ break;
801
+
802
+
803
+ case 'iavs':
804
+ case 'vids':
805
+ // shortcut
806
+ $thisfile_riff_raw['strh'][$i] = array();
807
+ $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i];
808
+
809
+ $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType;
810
+ $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4);
811
+ $thisfile_riff_raw_strh_current['dwFlags'] = $this->EitherEndian2Int(substr($strhData, 8, 4)); // Contains AVITF_* flags
812
+ $thisfile_riff_raw_strh_current['wPriority'] = $this->EitherEndian2Int(substr($strhData, 12, 2));
813
+ $thisfile_riff_raw_strh_current['wLanguage'] = $this->EitherEndian2Int(substr($strhData, 14, 2));
814
+ $thisfile_riff_raw_strh_current['dwInitialFrames'] = $this->EitherEndian2Int(substr($strhData, 16, 4));
815
+ $thisfile_riff_raw_strh_current['dwScale'] = $this->EitherEndian2Int(substr($strhData, 20, 4));
816
+ $thisfile_riff_raw_strh_current['dwRate'] = $this->EitherEndian2Int(substr($strhData, 24, 4));
817
+ $thisfile_riff_raw_strh_current['dwStart'] = $this->EitherEndian2Int(substr($strhData, 28, 4));
818
+ $thisfile_riff_raw_strh_current['dwLength'] = $this->EitherEndian2Int(substr($strhData, 32, 4));
819
+ $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($strhData, 36, 4));
820
+ $thisfile_riff_raw_strh_current['dwQuality'] = $this->EitherEndian2Int(substr($strhData, 40, 4));
821
+ $thisfile_riff_raw_strh_current['dwSampleSize'] = $this->EitherEndian2Int(substr($strhData, 44, 4));
822
+ $thisfile_riff_raw_strh_current['rcFrame'] = $this->EitherEndian2Int(substr($strhData, 48, 4));
823
+
824
+ $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strh_current['fccHandler']);
825
+ $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler'];
826
+ if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
827
+ $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']);
828
+ $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
829
+ }
830
+ $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
831
+ $thisfile_video['pixel_aspect_ratio'] = (float) 1;
832
+ switch ($thisfile_riff_raw_strh_current['fccHandler']) {
833
+ case 'HFYU': // Huffman Lossless Codec
834
+ case 'IRAW': // Intel YUV Uncompressed
835
+ case 'YUY2': // Uncompressed YUV 4:2:2
836
+ $thisfile_video['lossless'] = true;
837
+ break;
838
+
839
+ default:
840
+ $thisfile_video['lossless'] = false;
841
+ break;
842
+ }
843
+
844
+ switch ($strhfccType) {
845
+ case 'vids':
846
+ $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($this->container == 'riff'));
847
+ $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'];
848
+
849
+ if ($thisfile_riff_video_current['codec'] == 'DV') {
850
+ $thisfile_riff_video_current['dv_type'] = 2;
851
+ }
852
+ break;
853
+
854
+ case 'iavs':
855
+ $thisfile_riff_video_current['dv_type'] = 1;
856
+ break;
857
+ }
858
+ break;
859
+
860
+ default:
861
+ $info['warning'][] = 'Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"';
862
+ break;
863
+
864
+ }
865
+ }
866
+ }
867
+
868
+ if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
869
+
870
+ $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
871
+ if (self::fourccLookup($thisfile_video['fourcc'])) {
872
+ $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_video['fourcc']);
873
+ $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
874
+ }
875
+
876
+ switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) {
877
+ case 'HFYU': // Huffman Lossless Codec
878
+ case 'IRAW': // Intel YUV Uncompressed
879
+ case 'YUY2': // Uncompressed YUV 4:2:2
880
+ $thisfile_video['lossless'] = true;
881
+ //$thisfile_video['bits_per_sample'] = 24;
882
+ break;
883
+
884
+ default:
885
+ $thisfile_video['lossless'] = false;
886
+ //$thisfile_video['bits_per_sample'] = 24;
887
+ break;
888
+ }
889
+
890
+ }
891
+ }
892
+ }
893
+ }
894
+ break;
895
+
896
+
897
+ case 'AMV ':
898
+ $info['fileformat'] = 'amv';
899
+ $info['mime_type'] = 'video/amv';
900
+
901
+ $thisfile_video['bitrate_mode'] = 'vbr'; // it's MJPEG, presumably contant-quality encoding, thereby VBR
902
+ $thisfile_video['dataformat'] = 'mjpeg';
903
+ $thisfile_video['codec'] = 'mjpeg';
904
+ $thisfile_video['lossless'] = false;
905
+ $thisfile_video['bits_per_sample'] = 24;
906
+
907
+ $thisfile_audio['dataformat'] = 'adpcm';
908
+ $thisfile_audio['lossless'] = false;
909
+ break;
910
+
911
+
912
+ // http://en.wikipedia.org/wiki/CD-DA
913
+ case 'CDDA':
914
+ $info['fileformat'] = 'cda';
915
+ unset($info['mime_type']);
916
+
917
+ $thisfile_audio_dataformat = 'cda';
918
+
919
+ $info['avdataoffset'] = 44;
920
+
921
+ if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) {
922
+ // shortcut
923
+ $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0];
924
+
925
+ $thisfile_riff_CDDA_fmt_0['unknown1'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2));
926
+ $thisfile_riff_CDDA_fmt_0['track_num'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2));
927
+ $thisfile_riff_CDDA_fmt_0['disc_id'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4));
928
+ $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4));
929
+ $thisfile_riff_CDDA_fmt_0['playtime_frames'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4));
930
+ $thisfile_riff_CDDA_fmt_0['unknown6'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4));
931
+ $thisfile_riff_CDDA_fmt_0['unknown7'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4));
932
+
933
+ $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75;
934
+ $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75;
935
+ $info['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num'];
936
+ $info['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds'];
937
+
938
+ // hardcoded data for CD-audio
939
+ $thisfile_audio['lossless'] = true;
940
+ $thisfile_audio['sample_rate'] = 44100;
941
+ $thisfile_audio['channels'] = 2;
942
+ $thisfile_audio['bits_per_sample'] = 16;
943
+ $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample'];
944
+ $thisfile_audio['bitrate_mode'] = 'cbr';
945
+ }
946
+ break;
947
+
948
+ // http://en.wikipedia.org/wiki/AIFF
949
+ case 'AIFF':
950
+ case 'AIFC':
951
+ $info['fileformat'] = 'aiff';
952
+ $info['mime_type'] = 'audio/x-aiff';
953
+
954
+ $thisfile_audio['bitrate_mode'] = 'cbr';
955
+ $thisfile_audio_dataformat = 'aiff';
956
+ $thisfile_audio['lossless'] = true;
957
+
958
+ if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) {
959
+ $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8;
960
+ $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size'];
961
+ if ($info['avdataend'] > $info['filesize']) {
962
+ if (($info['avdataend'] == ($info['filesize'] + 1)) && (($info['filesize'] % 2) == 1)) {
963
+ // structures rounded to 2-byte boundary, but dumb encoders
964
+ // forget to pad end of file to make this actually work
965
+ } else {
966
+ $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
967
+ }
968
+ $info['avdataend'] = $info['filesize'];
969
+ }
970
+ }
971
+
972
+ if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) {
973
+
974
+ // shortcut
975
+ $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data'];
976
+
977
+ $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true);
978
+ $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false);
979
+ $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true);
980
+ $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10));
981
+
982
+ if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) {
983
+ $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4);
984
+ $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false);
985
+ $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize);
986
+ switch ($thisfile_riff_audio['codec_name']) {
987
+ case 'NONE':
988
+ $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
989
+ $thisfile_audio['lossless'] = true;
990
+ break;
991
+
992
+ case '':
993
+ switch ($thisfile_riff_audio['codec_fourcc']) {
994
+ // http://developer.apple.com/qa/snd/snd07.html
995
+ case 'sowt':
996
+ $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
997
+ $thisfile_audio['lossless'] = true;
998
+ break;
999
+
1000
+ case 'twos':
1001
+ $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
1002
+ $thisfile_audio['lossless'] = true;
1003
+ break;
1004
+
1005
+ default:
1006
+ break;
1007
+ }
1008
+ break;
1009
+
1010
+ default:
1011
+ $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name'];
1012
+ $thisfile_audio['lossless'] = false;
1013
+ break;
1014
+ }
1015
+ }
1016
+
1017
+ $thisfile_audio['channels'] = $thisfile_riff_audio['channels'];
1018
+ if ($thisfile_riff_audio['bits_per_sample'] > 0) {
1019
+ $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample'];
1020
+ }
1021
+ $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate'];
1022
+ if ($thisfile_audio['sample_rate'] == 0) {
1023
+ $info['error'][] = 'Corrupted AIFF file: sample_rate == zero';
1024
+ return false;
1025
+ }
1026
+ $info['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate'];
1027
+ }
1028
+
1029
+ if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) {
1030
+ $offset = 0;
1031
+ $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
1032
+ $offset += 2;
1033
+ for ($i = 0; $i < $CommentCount; $i++) {
1034
+ $info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false);
1035
+ $offset += 4;
1036
+ $info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true);
1037
+ $offset += 2;
1038
+ $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
1039
+ $offset += 2;
1040
+ $info['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength);
1041
+ $offset += $CommentLength;
1042
+
1043
+ $info['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($info['comments_raw'][$i]['timestamp']);
1044
+ $thisfile_riff['comments']['comment'][] = $info['comments_raw'][$i]['comment'];
1045
+ }
1046
+ }
1047
+
1048
+ $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
1049
+ foreach ($CommentsChunkNames as $key => $value) {
1050
+ if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
1051
+ $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
1052
+ }
1053
+ }
1054
+ /*
1055
+ if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) {
1056
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
1057
+ $getid3_temp = new getID3();
1058
+ $getid3_temp->openfile($this->getid3->filename);
1059
+ $getid3_id3v2 = new getid3_id3v2($getid3_temp);
1060
+ $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8;
1061
+ if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
1062
+ $info['id3v2'] = $getid3_temp->info['id3v2'];
1063
+ }
1064
+ unset($getid3_temp, $getid3_id3v2);
1065
+ }
1066
+ */
1067
+ break;
1068
+
1069
+ // http://en.wikipedia.org/wiki/8SVX
1070
+ case '8SVX':
1071
+ $info['fileformat'] = '8svx';
1072
+ $info['mime_type'] = 'audio/8svx';
1073
+
1074
+ $thisfile_audio['bitrate_mode'] = 'cbr';
1075
+ $thisfile_audio_dataformat = '8svx';
1076
+ $thisfile_audio['bits_per_sample'] = 8;
1077
+ $thisfile_audio['channels'] = 1; // overridden below, if need be
1078
+
1079
+ if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) {
1080
+ $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8;
1081
+ $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size'];
1082
+ if ($info['avdataend'] > $info['filesize']) {
1083
+ $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
1084
+ }
1085
+ }
1086
+
1087
+ if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) {
1088
+ // shortcut
1089
+ $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0];
1090
+
1091
+ $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4));
1092
+ $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4));
1093
+ $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4));
1094
+ $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2));
1095
+ $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1));
1096
+ $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1));
1097
+ $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4));
1098
+
1099
+ $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'];
1100
+
1101
+ switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) {
1102
+ case 0:
1103
+ $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
1104
+ $thisfile_audio['lossless'] = true;
1105
+ $ActualBitsPerSample = 8;
1106
+ break;
1107
+
1108
+ case 1:
1109
+ $thisfile_audio['codec'] = 'Fibonacci-delta encoding';
1110
+ $thisfile_audio['lossless'] = false;
1111
+ $ActualBitsPerSample = 4;
1112
+ break;
1113
+
1114
+ default:
1115
+ $info['warning'][] = 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"';
1116
+ break;
1117
+ }
1118
+ }
1119
+
1120
+ if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) {
1121
+ $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4));
1122
+ switch ($ChannelsIndex) {
1123
+ case 6: // Stereo
1124
+ $thisfile_audio['channels'] = 2;
1125
+ break;
1126
+
1127
+ case 2: // Left channel only
1128
+ case 4: // Right channel only
1129
+ $thisfile_audio['channels'] = 1;
1130
+ break;
1131
+
1132
+ default:
1133
+ $info['warning'][] = 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"';
1134
+ break;
1135
+ }
1136
+
1137
+ }
1138
+
1139
+ $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
1140
+ foreach ($CommentsChunkNames as $key => $value) {
1141
+ if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
1142
+ $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
1143
+ }
1144
+ }
1145
+
1146
+ $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels'];
1147
+ if (!empty($thisfile_audio['bitrate'])) {
1148
+ $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($thisfile_audio['bitrate'] / 8);
1149
+ }
1150
+ break;
1151
+
1152
+ case 'CDXA':
1153
+ $info['fileformat'] = 'vcd'; // Asume Video CD
1154
+ $info['mime_type'] = 'video/mpeg';
1155
+
1156
+ if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) {
1157
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true);
1158
+
1159
+ $getid3_temp = new getID3();
1160
+ $getid3_temp->openfile($this->getid3->filename);
1161
+ $getid3_mpeg = new getid3_mpeg($getid3_temp);
1162
+ $getid3_mpeg->Analyze();
1163
+ if (empty($getid3_temp->info['error'])) {
1164
+ $info['audio'] = $getid3_temp->info['audio'];
1165
+ $info['video'] = $getid3_temp->info['video'];
1166
+ $info['mpeg'] = $getid3_temp->info['mpeg'];
1167
+ $info['warning'] = $getid3_temp->info['warning'];
1168
+ }
1169
+ unset($getid3_temp, $getid3_mpeg);
1170
+ }
1171
+ break;
1172
+
1173
+
1174
+ default:
1175
+ $info['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$RIFFsubtype.'" instead';
1176
+ //unset($info['fileformat']);
1177
+ }
1178
+
1179
+ switch ($RIFFsubtype) {
1180
+ case 'WAVE':
1181
+ case 'AIFF':
1182
+ case 'AIFC':
1183
+ $ID3v2_key_good = 'id3 ';
1184
+ $ID3v2_keys_bad = array('ID3 ', 'tag ');
1185
+ foreach ($ID3v2_keys_bad as $ID3v2_key_bad) {
1186
+ if (isset($thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]) && !array_key_exists($ID3v2_key_good, $thisfile_riff[$RIFFsubtype])) {
1187
+ $thisfile_riff[$RIFFsubtype][$ID3v2_key_good] = $thisfile_riff[$RIFFsubtype][$ID3v2_key_bad];
1188
+ $info['warning'][] = 'mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"';
1189
+ }
1190
+ }
1191
+
1192
+ if (isset($thisfile_riff[$RIFFsubtype]['id3 '])) {
1193
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
1194
+
1195
+ $getid3_temp = new getID3();
1196
+ $getid3_temp->openfile($this->getid3->filename);
1197
+ $getid3_id3v2 = new getid3_id3v2($getid3_temp);
1198
+ $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8;
1199
+ if ($thisfile_riff[$RIFFsubtype]['id3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
1200
+ $info['id3v2'] = $getid3_temp->info['id3v2'];
1201
+ }
1202
+ unset($getid3_temp, $getid3_id3v2);
1203
+ }
1204
+ break;
1205
+ }
1206
+
1207
+ if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) {
1208
+ $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4));
1209
+ }
1210
+ if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) {
1211
+ self::parseComments($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']);
1212
+ }
1213
+ if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) {
1214
+ self::parseComments($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']);
1215
+ }
1216
+
1217
+ if (empty($thisfile_audio['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version'])) {
1218
+ $thisfile_audio['encoder'] = $info['mpeg']['audio']['LAME']['short_version'];
1219
+ }
1220
+
1221
+ if (!isset($info['playtime_seconds'])) {
1222
+ $info['playtime_seconds'] = 0;
1223
+ }
1224
+ if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
1225
+ // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie
1226
+ $info['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
1227
+ } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
1228
+ $info['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
1229
+ }
1230
+
1231
+ if ($info['playtime_seconds'] > 0) {
1232
+ if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
1233
+
1234
+ if (!isset($info['bitrate'])) {
1235
+ $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1236
+ }
1237
+
1238
+ } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) {
1239
+
1240
+ if (!isset($thisfile_audio['bitrate'])) {
1241
+ $thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1242
+ }
1243
+
1244
+ } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
1245
+
1246
+ if (!isset($thisfile_video['bitrate'])) {
1247
+ $thisfile_video['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1248
+ }
1249
+
1250
+ }
1251
+ }
1252
+
1253
+
1254
+ if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($info['playtime_seconds'] > 0)) {
1255
+
1256
+ $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
1257
+ $thisfile_audio['bitrate'] = 0;
1258
+ $thisfile_video['bitrate'] = $info['bitrate'];
1259
+ foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) {
1260
+ $thisfile_video['bitrate'] -= $audioinfoarray['bitrate'];
1261
+ $thisfile_audio['bitrate'] += $audioinfoarray['bitrate'];
1262
+ }
1263
+ if ($thisfile_video['bitrate'] <= 0) {
1264
+ unset($thisfile_video['bitrate']);
1265
+ }
1266
+ if ($thisfile_audio['bitrate'] <= 0) {
1267
+ unset($thisfile_audio['bitrate']);
1268
+ }
1269
+ }
1270
+
1271
+ if (isset($info['mpeg']['audio'])) {
1272
+ $thisfile_audio_dataformat = 'mp'.$info['mpeg']['audio']['layer'];
1273
+ $thisfile_audio['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1274
+ $thisfile_audio['channels'] = $info['mpeg']['audio']['channels'];
1275
+ $thisfile_audio['bitrate'] = $info['mpeg']['audio']['bitrate'];
1276
+ $thisfile_audio['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
1277
+ if (!empty($info['mpeg']['audio']['codec'])) {
1278
+ $thisfile_audio['codec'] = $info['mpeg']['audio']['codec'].' '.$thisfile_audio['codec'];
1279
+ }
1280
+ if (!empty($thisfile_audio['streams'])) {
1281
+ foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) {
1282
+ if ($streamdata['dataformat'] == $thisfile_audio_dataformat) {
1283
+ $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate'];
1284
+ $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels'];
1285
+ $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
1286
+ $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
1287
+ $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec'];
1288
+ }
1289
+ }
1290
+ }
1291
+ $getid3_mp3 = new getid3_mp3($this->getid3);
1292
+ $thisfile_audio['encoder_options'] = $getid3_mp3->GuessEncoderOptions();
1293
+ unset($getid3_mp3);
1294
+ }
1295
+
1296
+
1297
+ if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
1298
+ switch ($thisfile_audio_dataformat) {
1299
+ case 'ac3':
1300
+ // ignore bits_per_sample
1301
+ break;
1302
+
1303
+ default:
1304
+ $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample'];
1305
+ break;
1306
+ }
1307
+ }
1308
+
1309
+
1310
+ if (empty($thisfile_riff_raw)) {
1311
+ unset($thisfile_riff['raw']);
1312
+ }
1313
+ if (empty($thisfile_riff_audio)) {
1314
+ unset($thisfile_riff['audio']);
1315
+ }
1316
+ if (empty($thisfile_riff_video)) {
1317
+ unset($thisfile_riff['video']);
1318
+ }
1319
+
1320
+ return true;
1321
+ }
1322
+
1323
+ public function ParseRIFFAMV($startoffset, $maxoffset) {
1324
+ // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
1325
+
1326
+ // https://code.google.com/p/amv-codec-tools/wiki/AmvDocumentation
1327
+ //typedef struct _amvmainheader {
1328
+ //FOURCC fcc; // 'amvh'
1329
+ //DWORD cb;
1330
+ //DWORD dwMicroSecPerFrame;
1331
+ //BYTE reserve[28];
1332
+ //DWORD dwWidth;
1333
+ //DWORD dwHeight;
1334
+ //DWORD dwSpeed;
1335
+ //DWORD reserve0;
1336
+ //DWORD reserve1;
1337
+ //BYTE bTimeSec;
1338
+ //BYTE bTimeMin;
1339
+ //WORD wTimeHour;
1340
+ //} AMVMAINHEADER;
1341
+
1342
+ $info = &$this->getid3->info;
1343
+ $RIFFchunk = false;
1344
+
1345
+ try {
1346
+
1347
+ $this->fseek($startoffset);
1348
+ $maxoffset = min($maxoffset, $info['avdataend']);
1349
+ $AMVheader = $this->fread(284);
1350
+ if (substr($AMVheader, 0, 8) != 'hdrlamvh') {
1351
+ throw new Exception('expecting "hdrlamv" at offset '.($startoffset + 0).', found "'.substr($AMVheader, 0, 8).'"');
1352
+ }
1353
+ if (substr($AMVheader, 8, 4) != "\x38\x00\x00\x00") { // "amvh" chunk size, hardcoded to 0x38 = 56 bytes
1354
+ throw new Exception('expecting "0x38000000" at offset '.($startoffset + 8).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 8, 4)).'"');
1355
+ }
1356
+ $RIFFchunk = array();
1357
+ $RIFFchunk['amvh']['us_per_frame'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 12, 4));
1358
+ $RIFFchunk['amvh']['reserved28'] = substr($AMVheader, 16, 28); // null? reserved?
1359
+ $RIFFchunk['amvh']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 44, 4));
1360
+ $RIFFchunk['amvh']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 48, 4));
1361
+ $RIFFchunk['amvh']['frame_rate_int'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 52, 4));
1362
+ $RIFFchunk['amvh']['reserved0'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 56, 4)); // 1? reserved?
1363
+ $RIFFchunk['amvh']['reserved1'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 60, 4)); // 0? reserved?
1364
+ $RIFFchunk['amvh']['runtime_sec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 64, 1));
1365
+ $RIFFchunk['amvh']['runtime_min'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 65, 1));
1366
+ $RIFFchunk['amvh']['runtime_hrs'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 66, 2));
1367
+
1368
+ $info['video']['frame_rate'] = 1000000 / $RIFFchunk['amvh']['us_per_frame'];
1369
+ $info['video']['resolution_x'] = $RIFFchunk['amvh']['resolution_x'];
1370
+ $info['video']['resolution_y'] = $RIFFchunk['amvh']['resolution_y'];
1371
+ $info['playtime_seconds'] = ($RIFFchunk['amvh']['runtime_hrs'] * 3600) + ($RIFFchunk['amvh']['runtime_min'] * 60) + $RIFFchunk['amvh']['runtime_sec'];
1372
+
1373
+ // the rest is all hardcoded(?) and does not appear to be useful until you get to audio info at offset 256, even then everything is probably hardcoded
1374
+
1375
+ if (substr($AMVheader, 68, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x38\x00\x00\x00") {
1376
+ throw new Exception('expecting "LIST<0x00000000>strlstrh<0x38000000>" at offset '.($startoffset + 68).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 68, 20)).'"');
1377
+ }
1378
+ // followed by 56 bytes of null: substr($AMVheader, 88, 56) -> 144
1379
+ if (substr($AMVheader, 144, 8) != 'strf'."\x24\x00\x00\x00") {
1380
+ throw new Exception('expecting "strf<0x24000000>" at offset '.($startoffset + 144).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 144, 8)).'"');
1381
+ }
1382
+ // followed by 36 bytes of null: substr($AMVheader, 144, 36) -> 180
1383
+
1384
+ if (substr($AMVheader, 188, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x30\x00\x00\x00") {
1385
+ throw new Exception('expecting "LIST<0x00000000>strlstrh<0x30000000>" at offset '.($startoffset + 188).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 188, 20)).'"');
1386
+ }
1387
+ // followed by 48 bytes of null: substr($AMVheader, 208, 48) -> 256
1388
+ if (substr($AMVheader, 256, 8) != 'strf'."\x14\x00\x00\x00") {
1389
+ throw new Exception('expecting "strf<0x14000000>" at offset '.($startoffset + 256).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 256, 8)).'"');
1390
+ }
1391
+ // followed by 20 bytes of a modified WAVEFORMATEX:
1392
+ // typedef struct {
1393
+ // WORD wFormatTag; //(Fixme: this is equal to PCM's 0x01 format code)
1394
+ // WORD nChannels; //(Fixme: this is always 1)
1395
+ // DWORD nSamplesPerSec; //(Fixme: for all known sample files this is equal to 22050)
1396
+ // DWORD nAvgBytesPerSec; //(Fixme: for all known sample files this is equal to 44100)
1397
+ // WORD nBlockAlign; //(Fixme: this seems to be 2 in AMV files, is this correct ?)
1398
+ // WORD wBitsPerSample; //(Fixme: this seems to be 16 in AMV files instead of the expected 4)
1399
+ // WORD cbSize; //(Fixme: this seems to be 0 in AMV files)
1400
+ // WORD reserved;
1401
+ // } WAVEFORMATEX;
1402
+ $RIFFchunk['strf']['wformattag'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 264, 2));
1403
+ $RIFFchunk['strf']['nchannels'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 266, 2));
1404
+ $RIFFchunk['strf']['nsamplespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 268, 4));
1405
+ $RIFFchunk['strf']['navgbytespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 272, 4));
1406
+ $RIFFchunk['strf']['nblockalign'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 276, 2));
1407
+ $RIFFchunk['strf']['wbitspersample'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 278, 2));
1408
+ $RIFFchunk['strf']['cbsize'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 280, 2));
1409
+ $RIFFchunk['strf']['reserved'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 282, 2));
1410
+
1411
+
1412
+ $info['audio']['lossless'] = false;
1413
+ $info['audio']['sample_rate'] = $RIFFchunk['strf']['nsamplespersec'];
1414
+ $info['audio']['channels'] = $RIFFchunk['strf']['nchannels'];
1415
+ $info['audio']['bits_per_sample'] = $RIFFchunk['strf']['wbitspersample'];
1416
+ $info['audio']['bitrate'] = $info['audio']['sample_rate'] * $info['audio']['channels'] * $info['audio']['bits_per_sample'];
1417
+ $info['audio']['bitrate_mode'] = 'cbr';
1418
+
1419
+
1420
+ } catch (getid3_exception $e) {
1421
+ if ($e->getCode() == 10) {
1422
+ $this->warning('RIFFAMV parser: '.$e->getMessage());
1423
+ } else {
1424
+ throw $e;
1425
+ }
1426
+ }
1427
+
1428
+ return $RIFFchunk;
1429
+ }
1430
+
1431
+
1432
+ public function ParseRIFF($startoffset, $maxoffset) {
1433
+ $info = &$this->getid3->info;
1434
+
1435
+ $RIFFchunk = false;
1436
+ $FoundAllChunksWeNeed = false;
1437
+
1438
+ try {
1439
+ $this->fseek($startoffset);
1440
+ $maxoffset = min($maxoffset, $info['avdataend']);
1441
+ while ($this->ftell() < $maxoffset) {
1442
+ $chunknamesize = $this->fread(8);
1443
+ //$chunkname = substr($chunknamesize, 0, 4);
1444
+ $chunkname = str_replace("\x00", '_', substr($chunknamesize, 0, 4)); // note: chunk names of 4 null bytes do appear to be legal (has been observed inside INFO and PRMI chunks, for example), but makes traversing array keys more difficult
1445
+ $chunksize = $this->EitherEndian2Int(substr($chunknamesize, 4, 4));
1446
+ //if (strlen(trim($chunkname, "\x00")) < 4) {
1447
+ if (strlen($chunkname) < 4) {
1448
+ $this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.');
1449
+ break;
1450
+ }
1451
+ if (($chunksize == 0) && ($chunkname != 'JUNK')) {
1452
+ $this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.');
1453
+ break;
1454
+ }
1455
+ if (($chunksize % 2) != 0) {
1456
+ // all structures are packed on word boundaries
1457
+ $chunksize++;
1458
+ }
1459
+
1460
+ switch ($chunkname) {
1461
+ case 'LIST':
1462
+ $listname = $this->fread(4);
1463
+ if (preg_match('#^(movi|rec )$#i', $listname)) {
1464
+ $RIFFchunk[$listname]['offset'] = $this->ftell() - 4;
1465
+ $RIFFchunk[$listname]['size'] = $chunksize;
1466
+
1467
+ if (!$FoundAllChunksWeNeed) {
1468
+ $WhereWeWere = $this->ftell();
1469
+ $AudioChunkHeader = $this->fread(12);
1470
+ $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2);
1471
+ $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2);
1472
+ $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4));
1473
+
1474
+ if ($AudioChunkStreamType == 'wb') {
1475
+ $FirstFourBytes = substr($AudioChunkHeader, 8, 4);
1476
+ if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) {
1477
+ // MP3
1478
+ if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) {
1479
+ $getid3_temp = new getID3();
1480
+ $getid3_temp->openfile($this->getid3->filename);
1481
+ $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
1482
+ $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize;
1483
+ $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
1484
+ $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
1485
+ if (isset($getid3_temp->info['mpeg']['audio'])) {
1486
+ $info['mpeg']['audio'] = $getid3_temp->info['mpeg']['audio'];
1487
+ $info['audio'] = $getid3_temp->info['audio'];
1488
+ $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
1489
+ $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1490
+ $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
1491
+ $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1492
+ $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
1493
+ //$info['bitrate'] = $info['audio']['bitrate'];
1494
+ }
1495
+ unset($getid3_temp, $getid3_mp3);
1496
+ }
1497
+
1498
+ } elseif (strpos($FirstFourBytes, getid3_ac3::syncword) === 0) {
1499
+
1500
+ // AC3
1501
+ $getid3_temp = new getID3();
1502
+ $getid3_temp->openfile($this->getid3->filename);
1503
+ $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
1504
+ $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize;
1505
+ $getid3_ac3 = new getid3_ac3($getid3_temp);
1506
+ $getid3_ac3->Analyze();
1507
+ if (empty($getid3_temp->info['error'])) {
1508
+ $info['audio'] = $getid3_temp->info['audio'];
1509
+ $info['ac3'] = $getid3_temp->info['ac3'];
1510
+ if (!empty($getid3_temp->info['warning'])) {
1511
+ foreach ($getid3_temp->info['warning'] as $key => $value) {
1512
+ $info['warning'][] = $value;
1513
+ }
1514
+ }
1515
+ }
1516
+ unset($getid3_temp, $getid3_ac3);
1517
+ }
1518
+ }
1519
+ $FoundAllChunksWeNeed = true;
1520
+ $this->fseek($WhereWeWere);
1521
+ }
1522
+ $this->fseek($chunksize - 4, SEEK_CUR);
1523
+
1524
+ } else {
1525
+
1526
+ if (!isset($RIFFchunk[$listname])) {
1527
+ $RIFFchunk[$listname] = array();
1528
+ }
1529
+ $LISTchunkParent = $listname;
1530
+ $LISTchunkMaxOffset = $this->ftell() - 4 + $chunksize;
1531
+ if ($parsedChunk = $this->ParseRIFF($this->ftell(), $LISTchunkMaxOffset)) {
1532
+ $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk);
1533
+ }
1534
+
1535
+ }
1536
+ break;
1537
+
1538
+ default:
1539
+ if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) {
1540
+ $this->fseek($chunksize, SEEK_CUR);
1541
+ break;
1542
+ }
1543
+ $thisindex = 0;
1544
+ if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) {
1545
+ $thisindex = count($RIFFchunk[$chunkname]);
1546
+ }
1547
+ $RIFFchunk[$chunkname][$thisindex]['offset'] = $this->ftell() - 8;
1548
+ $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize;
1549
+ switch ($chunkname) {
1550
+ case 'data':
1551
+ $info['avdataoffset'] = $this->ftell();
1552
+ $info['avdataend'] = $info['avdataoffset'] + $chunksize;
1553
+
1554
+ $testData = $this->fread(36);
1555
+ if ($testData === '') {
1556
+ break;
1557
+ }
1558
+ if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($testData, 0, 4))) {
1559
+
1560
+ // Probably is MP3 data
1561
+ if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) {
1562
+ $getid3_temp = new getID3();
1563
+ $getid3_temp->openfile($this->getid3->filename);
1564
+ $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
1565
+ $getid3_temp->info['avdataend'] = $info['avdataend'];
1566
+ $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
1567
+ $getid3_mp3->getOnlyMPEGaudioInfo($info['avdataoffset'], false);
1568
+ if (empty($getid3_temp->info['error'])) {
1569
+ $info['audio'] = $getid3_temp->info['audio'];
1570
+ $info['mpeg'] = $getid3_temp->info['mpeg'];
1571
+ }
1572
+ unset($getid3_temp, $getid3_mp3);
1573
+ }
1574
+
1575
+ } elseif (($isRegularAC3 = (substr($testData, 0, 2) == getid3_ac3::syncword)) || substr($testData, 8, 2) == strrev(getid3_ac3::syncword)) {
1576
+
1577
+ // This is probably AC-3 data
1578
+ $getid3_temp = new getID3();
1579
+ if ($isRegularAC3) {
1580
+ $getid3_temp->openfile($this->getid3->filename);
1581
+ $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
1582
+ $getid3_temp->info['avdataend'] = $info['avdataend'];
1583
+ }
1584
+ $getid3_ac3 = new getid3_ac3($getid3_temp);
1585
+ if ($isRegularAC3) {
1586
+ $getid3_ac3->Analyze();
1587
+ } else {
1588
+ // Dolby Digital WAV
1589
+ // AC-3 content, but not encoded in same format as normal AC-3 file
1590
+ // For one thing, byte order is swapped
1591
+ $ac3_data = '';
1592
+ for ($i = 0; $i < 28; $i += 2) {
1593
+ $ac3_data .= substr($testData, 8 + $i + 1, 1);
1594
+ $ac3_data .= substr($testData, 8 + $i + 0, 1);
1595
+ }
1596
+ $getid3_ac3->AnalyzeString($ac3_data);
1597
+ }
1598
+
1599
+ if (empty($getid3_temp->info['error'])) {
1600
+ $info['audio'] = $getid3_temp->info['audio'];
1601
+ $info['ac3'] = $getid3_temp->info['ac3'];
1602
+ if (!empty($getid3_temp->info['warning'])) {
1603
+ foreach ($getid3_temp->info['warning'] as $newerror) {
1604
+ $this->warning('getid3_ac3() says: ['.$newerror.']');
1605
+ }
1606
+ }
1607
+ }
1608
+ unset($getid3_temp, $getid3_ac3);
1609
+
1610
+ } elseif (preg_match('/^('.implode('|', array_map('preg_quote', getid3_dts::$syncwords)).')/', $testData)) {
1611
+
1612
+ // This is probably DTS data
1613
+ $getid3_temp = new getID3();
1614
+ $getid3_temp->openfile($this->getid3->filename);
1615
+ $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
1616
+ $getid3_dts = new getid3_dts($getid3_temp);
1617
+ $getid3_dts->Analyze();
1618
+ if (empty($getid3_temp->info['error'])) {
1619
+ $info['audio'] = $getid3_temp->info['audio'];
1620
+ $info['dts'] = $getid3_temp->info['dts'];
1621
+ $info['playtime_seconds'] = $getid3_temp->info['playtime_seconds']; // may not match RIFF calculations since DTS-WAV often used 14/16 bit-word packing
1622
+ if (!empty($getid3_temp->info['warning'])) {
1623
+ foreach ($getid3_temp->info['warning'] as $newerror) {
1624
+ $this->warning('getid3_dts() says: ['.$newerror.']');
1625
+ }
1626
+ }
1627
+ }
1628
+
1629
+ unset($getid3_temp, $getid3_dts);
1630
+
1631
+ } elseif (substr($testData, 0, 4) == 'wvpk') {
1632
+
1633
+ // This is WavPack data
1634
+ $info['wavpack']['offset'] = $info['avdataoffset'];
1635
+ $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($testData, 4, 4));
1636
+ $this->parseWavPackHeader(substr($testData, 8, 28));
1637
+
1638
+ } else {
1639
+ // This is some other kind of data (quite possibly just PCM)
1640
+ // do nothing special, just skip it
1641
+ }
1642
+ $nextoffset = $info['avdataend'];
1643
+ $this->fseek($nextoffset);
1644
+ break;
1645
+
1646
+ case 'iXML':
1647
+ case 'bext':
1648
+ case 'cart':
1649
+ case 'fmt ':
1650
+ case 'strh':
1651
+ case 'strf':
1652
+ case 'indx':
1653
+ case 'MEXT':
1654
+ case 'DISP':
1655
+ // always read data in
1656
+ case 'JUNK':
1657
+ // should be: never read data in
1658
+ // but some programs write their version strings in a JUNK chunk (e.g. VirtualDub, AVIdemux, etc)
1659
+ if ($chunksize < 1048576) {
1660
+ if ($chunksize > 0) {
1661
+ $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize);
1662
+ if ($chunkname == 'JUNK') {
1663
+ if (preg_match('#^([\\x20-\\x7F]+)#', $RIFFchunk[$chunkname][$thisindex]['data'], $matches)) {
1664
+ // only keep text characters [chr(32)-chr(127)]
1665
+ $info['riff']['comments']['junk'][] = trim($matches[1]);
1666
+ }
1667
+ // but if nothing there, ignore
1668
+ // remove the key in either case
1669
+ unset($RIFFchunk[$chunkname][$thisindex]['data']);
1670
+ }
1671
+ }
1672
+ } else {
1673
+ $this->warning('Chunk "'.$chunkname.'" at offset '.$this->ftell().' is unexpectedly larger than 1MB (claims to be '.number_format($chunksize).' bytes), skipping data');
1674
+ $this->fseek($chunksize, SEEK_CUR);
1675
+ }
1676
+ break;
1677
+
1678
+ //case 'IDVX':
1679
+ // $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunksize));
1680
+ // break;
1681
+
1682
+ default:
1683
+ if (!empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) {
1684
+ $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
1685
+ $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size'];
1686
+ unset($RIFFchunk[$chunkname][$thisindex]['offset']);
1687
+ unset($RIFFchunk[$chunkname][$thisindex]['size']);
1688
+ if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) {
1689
+ unset($RIFFchunk[$chunkname][$thisindex]);
1690
+ }
1691
+ if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) {
1692
+ unset($RIFFchunk[$chunkname]);
1693
+ }
1694
+ $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = $this->fread($chunksize);
1695
+ } elseif ($chunksize < 2048) {
1696
+ // only read data in if smaller than 2kB
1697
+ $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize);
1698
+ } else {
1699
+ $this->fseek($chunksize, SEEK_CUR);
1700
+ }
1701
+ break;
1702
+ }
1703
+ break;
1704
+ }
1705
+ }
1706
+
1707
+ } catch (getid3_exception $e) {
1708
+ if ($e->getCode() == 10) {
1709
+ $this->warning('RIFF parser: '.$e->getMessage());
1710
+ } else {
1711
+ throw $e;
1712
+ }
1713
+ }
1714
+
1715
+ return $RIFFchunk;
1716
+ }
1717
+
1718
+ public function ParseRIFFdata(&$RIFFdata) {
1719
+ $info = &$this->getid3->info;
1720
+ if ($RIFFdata) {
1721
+ $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3');
1722
+ $fp_temp = fopen($tempfile, 'wb');
1723
+ $RIFFdataLength = strlen($RIFFdata);
1724
+ $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4);
1725
+ for ($i = 0; $i < 4; $i++) {
1726
+ $RIFFdata[($i + 4)] = $NewLengthString[$i];
1727
+ }
1728
+ fwrite($fp_temp, $RIFFdata);
1729
+ fclose($fp_temp);
1730
+
1731
+ $getid3_temp = new getID3();
1732
+ $getid3_temp->openfile($tempfile);
1733
+ $getid3_temp->info['filesize'] = $RIFFdataLength;
1734
+ $getid3_temp->info['filenamepath'] = $info['filenamepath'];
1735
+ $getid3_temp->info['tags'] = $info['tags'];
1736
+ $getid3_temp->info['warning'] = $info['warning'];
1737
+ $getid3_temp->info['error'] = $info['error'];
1738
+ $getid3_temp->info['comments'] = $info['comments'];
1739
+ $getid3_temp->info['audio'] = (isset($info['audio']) ? $info['audio'] : array());
1740
+ $getid3_temp->info['video'] = (isset($info['video']) ? $info['video'] : array());
1741
+ $getid3_riff = new getid3_riff($getid3_temp);
1742
+ $getid3_riff->Analyze();
1743
+
1744
+ $info['riff'] = $getid3_temp->info['riff'];
1745
+ $info['warning'] = $getid3_temp->info['warning'];
1746
+ $info['error'] = $getid3_temp->info['error'];
1747
+ $info['tags'] = $getid3_temp->info['tags'];
1748
+ $info['comments'] = $getid3_temp->info['comments'];
1749
+ unset($getid3_riff, $getid3_temp);
1750
+ unlink($tempfile);
1751
+ }
1752
+ return false;
1753
+ }
1754
+
1755
+ public static function parseComments(&$RIFFinfoArray, &$CommentsTargetArray) {
1756
+ $RIFFinfoKeyLookup = array(
1757
+ 'IARL'=>'archivallocation',
1758
+ 'IART'=>'artist',
1759
+ 'ICDS'=>'costumedesigner',
1760
+ 'ICMS'=>'commissionedby',
1761
+ 'ICMT'=>'comment',
1762
+ 'ICNT'=>'country',
1763
+ 'ICOP'=>'copyright',
1764
+ 'ICRD'=>'creationdate',
1765
+ 'IDIM'=>'dimensions',
1766
+ 'IDIT'=>'digitizationdate',
1767
+ 'IDPI'=>'resolution',
1768
+ 'IDST'=>'distributor',
1769
+ 'IEDT'=>'editor',
1770
+ 'IENG'=>'engineers',
1771
+ 'IFRM'=>'accountofparts',
1772
+ 'IGNR'=>'genre',
1773
+ 'IKEY'=>'keywords',
1774
+ 'ILGT'=>'lightness',
1775
+ 'ILNG'=>'language',
1776
+ 'IMED'=>'orignalmedium',
1777
+ 'IMUS'=>'composer',
1778
+ 'INAM'=>'title',
1779
+ 'IPDS'=>'productiondesigner',
1780
+ 'IPLT'=>'palette',
1781
+ 'IPRD'=>'product',
1782
+ 'IPRO'=>'producer',
1783
+ 'IPRT'=>'part',
1784
+ 'IRTD'=>'rating',
1785
+ 'ISBJ'=>'subject',
1786
+ 'ISFT'=>'software',
1787
+ 'ISGN'=>'secondarygenre',
1788
+ 'ISHP'=>'sharpness',
1789
+ 'ISRC'=>'sourcesupplier',
1790
+ 'ISRF'=>'digitizationsource',
1791
+ 'ISTD'=>'productionstudio',
1792
+ 'ISTR'=>'starring',
1793
+ 'ITCH'=>'encoded_by',
1794
+ 'IWEB'=>'url',
1795
+ 'IWRI'=>'writer',
1796
+ '____'=>'comment',
1797
+ );
1798
+ foreach ($RIFFinfoKeyLookup as $key => $value) {
1799
+ if (isset($RIFFinfoArray[$key])) {
1800
+ foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) {
1801
+ if (trim($commentdata['data']) != '') {
1802
+ if (isset($CommentsTargetArray[$value])) {
1803
+ $CommentsTargetArray[$value][] = trim($commentdata['data']);
1804
+ } else {
1805
+ $CommentsTargetArray[$value] = array(trim($commentdata['data']));
1806
+ }
1807
+ }
1808
+ }
1809
+ }
1810
+ }
1811
+ return true;
1812
+ }
1813
+
1814
+ public static function parseWAVEFORMATex($WaveFormatExData) {
1815
+ // shortcut
1816
+ $WaveFormatEx['raw'] = array();
1817
+ $WaveFormatEx_raw = &$WaveFormatEx['raw'];
1818
+
1819
+ $WaveFormatEx_raw['wFormatTag'] = substr($WaveFormatExData, 0, 2);
1820
+ $WaveFormatEx_raw['nChannels'] = substr($WaveFormatExData, 2, 2);
1821
+ $WaveFormatEx_raw['nSamplesPerSec'] = substr($WaveFormatExData, 4, 4);
1822
+ $WaveFormatEx_raw['nAvgBytesPerSec'] = substr($WaveFormatExData, 8, 4);
1823
+ $WaveFormatEx_raw['nBlockAlign'] = substr($WaveFormatExData, 12, 2);
1824
+ $WaveFormatEx_raw['wBitsPerSample'] = substr($WaveFormatExData, 14, 2);
1825
+ if (strlen($WaveFormatExData) > 16) {
1826
+ $WaveFormatEx_raw['cbSize'] = substr($WaveFormatExData, 16, 2);
1827
+ }
1828
+ $WaveFormatEx_raw = array_map('getid3_lib::LittleEndian2Int', $WaveFormatEx_raw);
1829
+
1830
+ $WaveFormatEx['codec'] = self::wFormatTagLookup($WaveFormatEx_raw['wFormatTag']);
1831
+ $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels'];
1832
+ $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec'];
1833
+ $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8;
1834
+ $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample'];
1835
+
1836
+ return $WaveFormatEx;
1837
+ }
1838
+
1839
+ public function parseWavPackHeader($WavPackChunkData) {
1840
+ // typedef struct {
1841
+ // char ckID [4];
1842
+ // long ckSize;
1843
+ // short version;
1844
+ // short bits; // added for version 2.00
1845
+ // short flags, shift; // added for version 3.00
1846
+ // long total_samples, crc, crc2;
1847
+ // char extension [4], extra_bc, extras [3];
1848
+ // } WavpackHeader;
1849
+
1850
+ // shortcut
1851
+ $info = &$this->getid3->info;
1852
+ $info['wavpack'] = array();
1853
+ $thisfile_wavpack = &$info['wavpack'];
1854
+
1855
+ $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2));
1856
+ if ($thisfile_wavpack['version'] >= 2) {
1857
+ $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2));
1858
+ }
1859
+ if ($thisfile_wavpack['version'] >= 3) {
1860
+ $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2));
1861
+ $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2));
1862
+ $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4));
1863
+ $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4));
1864
+ $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4));
1865
+ $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4);
1866
+ $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1));
1867
+ for ($i = 0; $i <= 2; $i++) {
1868
+ $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1));
1869
+ }
1870
+
1871
+ // shortcut
1872
+ $thisfile_wavpack['flags'] = array();
1873
+ $thisfile_wavpack_flags = &$thisfile_wavpack['flags'];
1874
+
1875
+ $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001);
1876
+ $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002);
1877
+ $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004);
1878
+ $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008);
1879
+ $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010);
1880
+ $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020);
1881
+ $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040);
1882
+ $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080);
1883
+ $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100);
1884
+ $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200);
1885
+ $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400);
1886
+ $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800);
1887
+ $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000);
1888
+ $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000);
1889
+ $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000);
1890
+ $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000);
1891
+ $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000);
1892
+ $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000);
1893
+ $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000);
1894
+ $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000);
1895
+ }
1896
+
1897
+ return true;
1898
+ }
1899
+
1900
+ public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) {
1901
+
1902
+ $parsed['biSize'] = substr($BITMAPINFOHEADER, 0, 4); // number of bytes required by the BITMAPINFOHEADER structure
1903
+ $parsed['biWidth'] = substr($BITMAPINFOHEADER, 4, 4); // width of the bitmap in pixels
1904
+ $parsed['biHeight'] = substr($BITMAPINFOHEADER, 8, 4); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
1905
+ $parsed['biPlanes'] = substr($BITMAPINFOHEADER, 12, 2); // number of color planes on the target device. In most cases this value must be set to 1
1906
+ $parsed['biBitCount'] = substr($BITMAPINFOHEADER, 14, 2); // Specifies the number of bits per pixels
1907
+ $parsed['biSizeImage'] = substr($BITMAPINFOHEADER, 20, 4); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
1908
+ $parsed['biXPelsPerMeter'] = substr($BITMAPINFOHEADER, 24, 4); // horizontal resolution, in pixels per metre, of the target device
1909
+ $parsed['biYPelsPerMeter'] = substr($BITMAPINFOHEADER, 28, 4); // vertical resolution, in pixels per metre, of the target device
1910
+ $parsed['biClrUsed'] = substr($BITMAPINFOHEADER, 32, 4); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
1911
+ $parsed['biClrImportant'] = substr($BITMAPINFOHEADER, 36, 4); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
1912
+ $parsed = array_map('getid3_lib::'.($littleEndian ? 'Little' : 'Big').'Endian2Int', $parsed);
1913
+
1914
+ $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier
1915
+
1916
+ return $parsed;
1917
+ }
1918
+
1919
+ public static function ParseDIVXTAG($DIVXTAG, $raw=false) {
1920
+ // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/
1921
+ // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip
1922
+ // 'Byte Layout: '1111111111111111
1923
+ // '32 for Movie - 1 '1111111111111111
1924
+ // '28 for Author - 6 '6666666666666666
1925
+ // '4 for year - 2 '6666666666662222
1926
+ // '3 for genre - 3 '7777777777777777
1927
+ // '48 for Comments - 7 '7777777777777777
1928
+ // '1 for Rating - 4 '7777777777777777
1929
+ // '5 for Future Additions - 0 '333400000DIVXTAG
1930
+ // '128 bytes total
1931
+
1932
+ static $DIVXTAGgenre = array(
1933
+ 0 => 'Action',
1934
+ 1 => 'Action/Adventure',
1935
+ 2 => 'Adventure',
1936
+ 3 => 'Adult',
1937
+ 4 => 'Anime',
1938
+ 5 => 'Cartoon',
1939
+ 6 => 'Claymation',
1940
+ 7 => 'Comedy',
1941
+ 8 => 'Commercial',
1942
+ 9 => 'Documentary',
1943
+ 10 => 'Drama',
1944
+ 11 => 'Home Video',
1945
+ 12 => 'Horror',
1946
+ 13 => 'Infomercial',
1947
+ 14 => 'Interactive',
1948
+ 15 => 'Mystery',
1949
+ 16 => 'Music Video',
1950
+ 17 => 'Other',
1951
+ 18 => 'Religion',
1952
+ 19 => 'Sci Fi',
1953
+ 20 => 'Thriller',
1954
+ 21 => 'Western',
1955
+ ),
1956
+ $DIVXTAGrating = array(
1957
+ 0 => 'Unrated',
1958
+ 1 => 'G',
1959
+ 2 => 'PG',
1960
+ 3 => 'PG-13',
1961
+ 4 => 'R',
1962
+ 5 => 'NC-17',
1963
+ );
1964
+
1965
+ $parsed['title'] = trim(substr($DIVXTAG, 0, 32));
1966
+ $parsed['artist'] = trim(substr($DIVXTAG, 32, 28));
1967
+ $parsed['year'] = intval(trim(substr($DIVXTAG, 60, 4)));
1968
+ $parsed['comment'] = trim(substr($DIVXTAG, 64, 48));
1969
+ $parsed['genre_id'] = intval(trim(substr($DIVXTAG, 112, 3)));
1970
+ $parsed['rating_id'] = ord(substr($DIVXTAG, 115, 1));
1971
+ //$parsed['padding'] = substr($DIVXTAG, 116, 5); // 5-byte null
1972
+ //$parsed['magic'] = substr($DIVXTAG, 121, 7); // "DIVXTAG"
1973
+
1974
+ $parsed['genre'] = (isset($DIVXTAGgenre[$parsed['genre_id']]) ? $DIVXTAGgenre[$parsed['genre_id']] : $parsed['genre_id']);
1975
+ $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']);
1976
+
1977
+ if (!$raw) {
1978
+ unset($parsed['genre_id'], $parsed['rating_id']);
1979
+ foreach ($parsed as $key => $value) {
1980
+ if (!$value === '') {
1981
+ unset($parsed['key']);
1982
+ }
1983
+ }
1984
+ }
1985
+
1986
+ foreach ($parsed as $tag => $value) {
1987
+ $parsed[$tag] = array($value);
1988
+ }
1989
+
1990
+ return $parsed;
1991
+ }
1992
+
1993
+ public static function waveSNDMtagLookup($tagshortname) {
1994
+ $begin = __LINE__;
1995
+
1996
+ /** This is not a comment!
1997
+
1998
+ ©kwd keywords
1999
+ ©BPM bpm
2000
+ ©trt tracktitle
2001
+ ©des description
2002
+ ©gen category
2003
+ ©fin featuredinstrument
2004
+ ©LID longid
2005
+ ©bex bwdescription
2006
+ ©pub publisher
2007
+ ©cdt cdtitle
2008
+ ©alb library
2009
+ ©com composer
2010
+
2011
+ */
2012
+
2013
+ return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm');
2014
+ }
2015
+
2016
+ public static function wFormatTagLookup($wFormatTag) {
2017
+
2018
+ $begin = __LINE__;
2019
+
2020
+ /** This is not a comment!
2021
+
2022
+ 0x0000 Microsoft Unknown Wave Format
2023
+ 0x0001 Pulse Code Modulation (PCM)
2024
+ 0x0002 Microsoft ADPCM
2025
+ 0x0003 IEEE Float
2026
+ 0x0004 Compaq Computer VSELP
2027
+ 0x0005 IBM CVSD
2028
+ 0x0006 Microsoft A-Law
2029
+ 0x0007 Microsoft mu-Law
2030
+ 0x0008 Microsoft DTS
2031
+ 0x0010 OKI ADPCM
2032
+ 0x0011 Intel DVI/IMA ADPCM
2033
+ 0x0012 Videologic MediaSpace ADPCM
2034
+ 0x0013 Sierra Semiconductor ADPCM
2035
+ 0x0014 Antex Electronics G.723 ADPCM
2036
+ 0x0015 DSP Solutions DigiSTD
2037
+ 0x0016 DSP Solutions DigiFIX
2038
+ 0x0017 Dialogic OKI ADPCM
2039
+ 0x0018 MediaVision ADPCM
2040
+ 0x0019 Hewlett-Packard CU
2041
+ 0x0020 Yamaha ADPCM
2042
+ 0x0021 Speech Compression Sonarc
2043
+ 0x0022 DSP Group TrueSpeech
2044
+ 0x0023 Echo Speech EchoSC1
2045
+ 0x0024 Audiofile AF36
2046
+ 0x0025 Audio Processing Technology APTX
2047
+ 0x0026 AudioFile AF10
2048
+ 0x0027 Prosody 1612
2049
+ 0x0028 LRC
2050
+ 0x0030 Dolby AC2
2051
+ 0x0031 Microsoft GSM 6.10
2052
+ 0x0032 MSNAudio
2053
+ 0x0033 Antex Electronics ADPCME
2054
+ 0x0034 Control Resources VQLPC
2055
+ 0x0035 DSP Solutions DigiREAL
2056
+ 0x0036 DSP Solutions DigiADPCM
2057
+ 0x0037 Control Resources CR10
2058
+ 0x0038 Natural MicroSystems VBXADPCM
2059
+ 0x0039 Crystal Semiconductor IMA ADPCM
2060
+ 0x003A EchoSC3
2061
+ 0x003B Rockwell ADPCM
2062
+ 0x003C Rockwell Digit LK
2063
+ 0x003D Xebec
2064
+ 0x0040 Antex Electronics G.721 ADPCM
2065
+ 0x0041 G.728 CELP
2066
+ 0x0042 MSG723
2067
+ 0x0050 MPEG Layer-2 or Layer-1
2068
+ 0x0052 RT24
2069
+ 0x0053 PAC
2070
+ 0x0055 MPEG Layer-3
2071
+ 0x0059 Lucent G.723
2072
+ 0x0060 Cirrus
2073
+ 0x0061 ESPCM
2074
+ 0x0062 Voxware
2075
+ 0x0063 Canopus Atrac
2076
+ 0x0064 G.726 ADPCM
2077
+ 0x0065 G.722 ADPCM
2078
+ 0x0066 DSAT
2079
+ 0x0067 DSAT Display
2080
+ 0x0069 Voxware Byte Aligned
2081
+ 0x0070 Voxware AC8
2082
+ 0x0071 Voxware AC10
2083
+ 0x0072 Voxware AC16
2084
+ 0x0073 Voxware AC20
2085
+ 0x0074 Voxware MetaVoice
2086
+ 0x0075 Voxware MetaSound
2087
+ 0x0076 Voxware RT29HW
2088
+ 0x0077 Voxware VR12
2089
+ 0x0078 Voxware VR18
2090
+ 0x0079 Voxware TQ40
2091
+ 0x0080 Softsound
2092
+ 0x0081 Voxware TQ60
2093
+ 0x0082 MSRT24
2094
+ 0x0083 G.729A
2095
+ 0x0084 MVI MV12
2096
+ 0x0085 DF G.726
2097
+ 0x0086 DF GSM610
2098
+ 0x0088 ISIAudio
2099
+ 0x0089 Onlive
2100
+ 0x0091 SBC24
2101
+ 0x0092 Dolby AC3 SPDIF
2102
+ 0x0093 MediaSonic G.723
2103
+ 0x0094 Aculab PLC Prosody 8kbps
2104
+ 0x0097 ZyXEL ADPCM
2105
+ 0x0098 Philips LPCBB
2106
+ 0x0099 Packed
2107
+ 0x00FF AAC
2108
+ 0x0100 Rhetorex ADPCM
2109
+ 0x0101 IBM mu-law
2110
+ 0x0102 IBM A-law
2111
+ 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM)
2112
+ 0x0111 Vivo G.723
2113
+ 0x0112 Vivo Siren
2114
+ 0x0123 Digital G.723
2115
+ 0x0125 Sanyo LD ADPCM
2116
+ 0x0130 Sipro Lab Telecom ACELP NET
2117
+ 0x0131 Sipro Lab Telecom ACELP 4800
2118
+ 0x0132 Sipro Lab Telecom ACELP 8V3
2119
+ 0x0133 Sipro Lab Telecom G.729
2120
+ 0x0134 Sipro Lab Telecom G.729A
2121
+ 0x0135 Sipro Lab Telecom Kelvin
2122
+ 0x0140 Windows Media Video V8
2123
+ 0x0150 Qualcomm PureVoice
2124
+ 0x0151 Qualcomm HalfRate
2125
+ 0x0155 Ring Zero Systems TUB GSM
2126
+ 0x0160 Microsoft Audio 1
2127
+ 0x0161 Windows Media Audio V7 / V8 / V9
2128
+ 0x0162 Windows Media Audio Professional V9
2129
+ 0x0163 Windows Media Audio Lossless V9
2130
+ 0x0200 Creative Labs ADPCM
2131
+ 0x0202 Creative Labs Fastspeech8
2132
+ 0x0203 Creative Labs Fastspeech10
2133
+ 0x0210 UHER Informatic GmbH ADPCM
2134
+ 0x0220 Quarterdeck
2135
+ 0x0230 I-link Worldwide VC
2136
+ 0x0240 Aureal RAW Sport
2137
+ 0x0250 Interactive Products HSX
2138
+ 0x0251 Interactive Products RPELP
2139
+ 0x0260 Consistent Software CS2
2140
+ 0x0270 Sony SCX
2141
+ 0x0300 Fujitsu FM Towns Snd
2142
+ 0x0400 BTV Digital
2143
+ 0x0401 Intel Music Coder
2144
+ 0x0450 QDesign Music
2145
+ 0x0680 VME VMPCM
2146
+ 0x0681 AT&T Labs TPC
2147
+ 0x08AE ClearJump LiteWave
2148
+ 0x1000 Olivetti GSM
2149
+ 0x1001 Olivetti ADPCM
2150
+ 0x1002 Olivetti CELP
2151
+ 0x1003 Olivetti SBC
2152
+ 0x1004 Olivetti OPR
2153
+ 0x1100 Lernout & Hauspie Codec (0x1100)
2154
+ 0x1101 Lernout & Hauspie CELP Codec (0x1101)
2155
+ 0x1102 Lernout & Hauspie SBC Codec (0x1102)
2156
+ 0x1103 Lernout & Hauspie SBC Codec (0x1103)
2157
+ 0x1104 Lernout & Hauspie SBC Codec (0x1104)
2158
+ 0x1400 Norris
2159
+ 0x1401 AT&T ISIAudio
2160
+ 0x1500 Soundspace Music Compression
2161
+ 0x181C VoxWare RT24 Speech
2162
+ 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com)
2163
+ 0x2000 Dolby AC3
2164
+ 0x2001 Dolby DTS
2165
+ 0x2002 WAVE_FORMAT_14_4
2166
+ 0x2003 WAVE_FORMAT_28_8
2167
+ 0x2004 WAVE_FORMAT_COOK
2168
+ 0x2005 WAVE_FORMAT_DNET
2169
+ 0x674F Ogg Vorbis 1
2170
+ 0x6750 Ogg Vorbis 2
2171
+ 0x6751 Ogg Vorbis 3
2172
+ 0x676F Ogg Vorbis 1+
2173
+ 0x6770 Ogg Vorbis 2+
2174
+ 0x6771 Ogg Vorbis 3+
2175
+ 0x7A21 GSM-AMR (CBR, no SID)
2176
+ 0x7A22 GSM-AMR (VBR, including SID)
2177
+ 0xFFFE WAVE_FORMAT_EXTENSIBLE
2178
+ 0xFFFF WAVE_FORMAT_DEVELOPMENT
2179
+
2180
+ */
2181
+
2182
+ return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag');
2183
+ }
2184
+
2185
+ public static function fourccLookup($fourcc) {
2186
+
2187
+ $begin = __LINE__;
2188
+
2189
+ /** This is not a comment!
2190
+
2191
+ swot http://developer.apple.com/qa/snd/snd07.html
2192
+ ____ No Codec (____)
2193
+ _BIT BI_BITFIELDS (Raw RGB)
2194
+ _JPG JPEG compressed
2195
+ _PNG PNG compressed W3C/ISO/IEC (RFC-2083)
2196
+ _RAW Full Frames (Uncompressed)
2197
+ _RGB Raw RGB Bitmap
2198
+ _RL4 RLE 4bpp RGB
2199
+ _RL8 RLE 8bpp RGB
2200
+ 3IV1 3ivx MPEG-4 v1
2201
+ 3IV2 3ivx MPEG-4 v2
2202
+ 3IVX 3ivx MPEG-4
2203
+ AASC Autodesk Animator
2204
+ ABYR Kensington ?ABYR?
2205
+ AEMI Array Microsystems VideoONE MPEG1-I Capture
2206
+ AFLC Autodesk Animator FLC
2207
+ AFLI Autodesk Animator FLI
2208
+ AMPG Array Microsystems VideoONE MPEG
2209
+ ANIM Intel RDX (ANIM)
2210
+ AP41 AngelPotion Definitive
2211
+ ASV1 Asus Video v1
2212
+ ASV2 Asus Video v2
2213
+ ASVX Asus Video 2.0 (audio)
2214
+ AUR2 AuraVision Aura 2 Codec - YUV 4:2:2
2215
+ AURA AuraVision Aura 1 Codec - YUV 4:1:1
2216
+ AVDJ Independent JPEG Group\'s codec (AVDJ)
2217
+ AVRN Independent JPEG Group\'s codec (AVRN)
2218
+ AYUV 4:4:4 YUV (AYUV)
2219
+ AZPR Quicktime Apple Video (AZPR)
2220
+ BGR Raw RGB32
2221
+ BLZ0 Blizzard DivX MPEG-4
2222
+ BTVC Conexant Composite Video
2223
+ BINK RAD Game Tools Bink Video
2224
+ BT20 Conexant Prosumer Video
2225
+ BTCV Conexant Composite Video Codec
2226
+ BW10 Data Translation Broadway MPEG Capture
2227
+ CC12 Intel YUV12
2228
+ CDVC Canopus DV
2229
+ CFCC Digital Processing Systems DPS Perception
2230
+ CGDI Microsoft Office 97 Camcorder Video
2231
+ CHAM Winnov Caviara Champagne
2232
+ CJPG Creative WebCam JPEG
2233
+ CLJR Cirrus Logic YUV 4:1:1
2234
+ CMYK Common Data Format in Printing (Colorgraph)
2235
+ CPLA Weitek 4:2:0 YUV Planar
2236
+ CRAM Microsoft Video 1 (CRAM)
2237
+ cvid Radius Cinepak
2238
+ CVID Radius Cinepak
2239
+ CWLT Microsoft Color WLT DIB
2240
+ CYUV Creative Labs YUV
2241
+ CYUY ATI YUV
2242
+ D261 H.261
2243
+ D263 H.263
2244
+ DIB Device Independent Bitmap
2245
+ DIV1 FFmpeg OpenDivX
2246
+ DIV2 Microsoft MPEG-4 v1/v2
2247
+ DIV3 DivX ;-) MPEG-4 v3.x Low-Motion
2248
+ DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion
2249
+ DIV5 DivX MPEG-4 v5.x
2250
+ DIV6 DivX ;-) (MS MPEG-4 v3.x)
2251
+ DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo)
2252
+ divx DivX MPEG-4
2253
+ DMB1 Matrox Rainbow Runner hardware MJPEG
2254
+ DMB2 Paradigm MJPEG
2255
+ DSVD ?DSVD?
2256
+ DUCK Duck TrueMotion 1.0
2257
+ DPS0 DPS/Leitch Reality Motion JPEG
2258
+ DPSC DPS/Leitch PAR Motion JPEG
2259
+ DV25 Matrox DVCPRO codec
2260
+ DV50 Matrox DVCPRO50 codec
2261
+ DVC IEC 61834 and SMPTE 314M (DVC/DV Video)
2262
+ DVCP IEC 61834 and SMPTE 314M (DVC/DV Video)
2263
+ DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps
2264
+ DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com)
2265
+ DVSL IEC Standard DV compressed in SD (SDL)
2266
+ DVAN ?DVAN?
2267
+ DVE2 InSoft DVE-2 Videoconferencing
2268
+ dvsd IEC 61834 and SMPTE 314M DVC/DV Video
2269
+ DVSD IEC 61834 and SMPTE 314M DVC/DV Video
2270
+ DVX1 Lucent DVX1000SP Video Decoder
2271
+ DVX2 Lucent DVX2000S Video Decoder
2272
+ DVX3 Lucent DVX3000S Video Decoder
2273
+ DX50 DivX v5
2274
+ DXT1 Microsoft DirectX Compressed Texture (DXT1)
2275
+ DXT2 Microsoft DirectX Compressed Texture (DXT2)
2276
+ DXT3 Microsoft DirectX Compressed Texture (DXT3)
2277
+ DXT4 Microsoft DirectX Compressed Texture (DXT4)
2278
+ DXT5 Microsoft DirectX Compressed Texture (DXT5)
2279
+ DXTC Microsoft DirectX Compressed Texture (DXTC)
2280
+ DXTn Microsoft DirectX Compressed Texture (DXTn)
2281
+ EM2V Etymonix MPEG-2 I-frame (www.etymonix.com)
2282
+ EKQ0 Elsa ?EKQ0?
2283
+ ELK0 Elsa ?ELK0?
2284
+ ESCP Eidos Escape
2285
+ ETV1 eTreppid Video ETV1
2286
+ ETV2 eTreppid Video ETV2
2287
+ ETVC eTreppid Video ETVC
2288
+ FLIC Autodesk FLI/FLC Animation
2289
+ FLV1 Sorenson Spark
2290
+ FLV4 On2 TrueMotion VP6
2291
+ FRWT Darim Vision Forward Motion JPEG (www.darvision.com)
2292
+ FRWU Darim Vision Forward Uncompressed (www.darvision.com)
2293
+ FLJP D-Vision Field Encoded Motion JPEG
2294
+ FPS1 FRAPS v1
2295
+ FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel
2296
+ FRWD SoftLab-Nsk Forward Motion JPEG
2297
+ FVF1 Iterated Systems Fractal Video Frame
2298
+ GLZW Motion LZW (gabest@freemail.hu)
2299
+ GPEG Motion JPEG (gabest@freemail.hu)
2300
+ GWLT Microsoft Greyscale WLT DIB
2301
+ H260 Intel ITU H.260 Videoconferencing
2302
+ H261 Intel ITU H.261 Videoconferencing
2303
+ H262 Intel ITU H.262 Videoconferencing
2304
+ H263 Intel ITU H.263 Videoconferencing
2305
+ H264 Intel ITU H.264 Videoconferencing
2306
+ H265 Intel ITU H.265 Videoconferencing
2307
+ H266 Intel ITU H.266 Videoconferencing
2308
+ H267 Intel ITU H.267 Videoconferencing
2309
+ H268 Intel ITU H.268 Videoconferencing
2310
+ H269 Intel ITU H.269 Videoconferencing
2311
+ HFYU Huffman Lossless Codec
2312
+ HMCR Rendition Motion Compensation Format (HMCR)
2313
+ HMRR Rendition Motion Compensation Format (HMRR)
2314
+ I263 FFmpeg I263 decoder
2315
+ IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane")
2316
+ IUYV Interlaced version of UYVY (www.leadtools.com)
2317
+ IY41 Interlaced version of Y41P (www.leadtools.com)
2318
+ IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
2319
+ IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard
2320
+ IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes)
2321
+ i263 Intel ITU H.263 Videoconferencing (i263)
2322
+ I420 Intel Indeo 4
2323
+ IAN Intel Indeo 4 (RDX)
2324
+ ICLB InSoft CellB Videoconferencing
2325
+ IGOR Power DVD
2326
+ IJPG Intergraph JPEG
2327
+ ILVC Intel Layered Video
2328
+ ILVR ITU-T H.263+
2329
+ IPDV I-O Data Device Giga AVI DV Codec
2330
+ IR21 Intel Indeo 2.1
2331
+ IRAW Intel YUV Uncompressed
2332
+ IV30 Intel Indeo 3.0
2333
+ IV31 Intel Indeo 3.1
2334
+ IV32 Ligos Indeo 3.2
2335
+ IV33 Ligos Indeo 3.3
2336
+ IV34 Ligos Indeo 3.4
2337
+ IV35 Ligos Indeo 3.5
2338
+ IV36 Ligos Indeo 3.6
2339
+ IV37 Ligos Indeo 3.7
2340
+ IV38 Ligos Indeo 3.8
2341
+ IV39 Ligos Indeo 3.9
2342
+ IV40 Ligos Indeo Interactive 4.0
2343
+ IV41 Ligos Indeo Interactive 4.1
2344
+ IV42 Ligos Indeo Interactive 4.2
2345
+ IV43 Ligos Indeo Interactive 4.3
2346
+ IV44 Ligos Indeo Interactive 4.4
2347
+ IV45 Ligos Indeo Interactive 4.5
2348
+ IV46 Ligos Indeo Interactive 4.6
2349
+ IV47 Ligos Indeo Interactive 4.7
2350
+ IV48 Ligos Indeo Interactive 4.8
2351
+ IV49 Ligos Indeo Interactive 4.9
2352
+ IV50 Ligos Indeo Interactive 5.0
2353
+ JBYR Kensington ?JBYR?
2354
+ JPEG Still Image JPEG DIB
2355
+ JPGL Pegasus Lossless Motion JPEG
2356
+ KMVC Team17 Software Karl Morton\'s Video Codec
2357
+ LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com)
2358
+ LEAD LEAD Video Codec
2359
+ Ljpg LEAD MJPEG Codec
2360
+ MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de)
2361
+ MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com)
2362
+ MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com)
2363
+ MMES Matrox MPEG-2 I-frame
2364
+ MP2v Microsoft S-Mpeg 4 version 1 (MP2v)
2365
+ MP42 Microsoft S-Mpeg 4 version 2 (MP42)
2366
+ MP43 Microsoft S-Mpeg 4 version 3 (MP43)
2367
+ MP4S Microsoft S-Mpeg 4 version 3 (MP4S)
2368
+ MP4V FFmpeg MPEG-4
2369
+ MPG1 FFmpeg MPEG 1/2
2370
+ MPG2 FFmpeg MPEG 1/2
2371
+ MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3)
2372
+ MPG4 Microsoft MPEG-4
2373
+ MPGI Sigma Designs MPEG
2374
+ MPNG PNG images decoder
2375
+ MSS1 Microsoft Windows Screen Video
2376
+ MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
2377
+ M261 Microsoft H.261
2378
+ M263 Microsoft H.263
2379
+ M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2)
2380
+ m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2)
2381
+ MC12 ATI Motion Compensation Format (MC12)
2382
+ MCAM ATI Motion Compensation Format (MCAM)
2383
+ MJ2C Morgan Multimedia Motion JPEG2000
2384
+ mJPG IBM Motion JPEG w/ Huffman Tables
2385
+ MJPG Microsoft Motion JPEG DIB
2386
+ MP42 Microsoft MPEG-4 (low-motion)
2387
+ MP43 Microsoft MPEG-4 (fast-motion)
2388
+ MP4S Microsoft MPEG-4 (MP4S)
2389
+ mp4s Microsoft MPEG-4 (mp4s)
2390
+ MPEG Chromatic Research MPEG-1 Video I-Frame
2391
+ MPG4 Microsoft MPEG-4 Video High Speed Compressor
2392
+ MPGI Sigma Designs MPEG
2393
+ MRCA FAST Multimedia Martin Regen Codec
2394
+ MRLE Microsoft Run Length Encoding
2395
+ MSVC Microsoft Video 1
2396
+ MTX1 Matrox ?MTX1?
2397
+ MTX2 Matrox ?MTX2?
2398
+ MTX3 Matrox ?MTX3?
2399
+ MTX4 Matrox ?MTX4?
2400
+ MTX5 Matrox ?MTX5?
2401
+ MTX6 Matrox ?MTX6?
2402
+ MTX7 Matrox ?MTX7?
2403
+ MTX8 Matrox ?MTX8?
2404
+ MTX9 Matrox ?MTX9?
2405
+ MV12 Motion Pixels Codec (old)
2406
+ MWV1 Aware Motion Wavelets
2407
+ nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm)
2408
+ NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com)
2409
+ NUV1 NuppelVideo
2410
+ NTN1 Nogatech Video Compression 1
2411
+ NVS0 nVidia GeForce Texture (NVS0)
2412
+ NVS1 nVidia GeForce Texture (NVS1)
2413
+ NVS2 nVidia GeForce Texture (NVS2)
2414
+ NVS3 nVidia GeForce Texture (NVS3)
2415
+ NVS4 nVidia GeForce Texture (NVS4)
2416
+ NVS5 nVidia GeForce Texture (NVS5)
2417
+ NVT0 nVidia GeForce Texture (NVT0)
2418
+ NVT1 nVidia GeForce Texture (NVT1)
2419
+ NVT2 nVidia GeForce Texture (NVT2)
2420
+ NVT3 nVidia GeForce Texture (NVT3)
2421
+ NVT4 nVidia GeForce Texture (NVT4)
2422
+ NVT5 nVidia GeForce Texture (NVT5)
2423
+ PIXL MiroXL, Pinnacle PCTV
2424
+ PDVC I-O Data Device Digital Video Capture DV codec
2425
+ PGVV Radius Video Vision
2426
+ PHMO IBM Photomotion
2427
+ PIM1 MPEG Realtime (Pinnacle Cards)
2428
+ PIM2 Pegasus Imaging ?PIM2?
2429
+ PIMJ Pegasus Imaging Lossless JPEG
2430
+ PVEZ Horizons Technology PowerEZ
2431
+ PVMM PacketVideo Corporation MPEG-4
2432
+ PVW2 Pegasus Imaging Wavelet Compression
2433
+ Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de)
2434
+ Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de)
2435
+ QPEG Q-Team QPEG 1.0
2436
+ qpeq Q-Team QPEG 1.1
2437
+ RGB Raw BGR32
2438
+ RGBA Raw RGB w/ Alpha
2439
+ RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com)
2440
+ ROQV Id RoQ File Video Decoder
2441
+ RPZA Quicktime Apple Video (RPZA)
2442
+ RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/)
2443
+ RV10 RealVideo 1.0 (aka RealVideo 5.0)
2444
+ RV13 RealVideo 1.0 (RV13)
2445
+ RV20 RealVideo G2
2446
+ RV30 RealVideo 8
2447
+ RV40 RealVideo 9
2448
+ RGBT Raw RGB w/ Transparency
2449
+ RLE Microsoft Run Length Encoder
2450
+ RLE4 Run Length Encoded (4bpp, 16-color)
2451
+ RLE8 Run Length Encoded (8bpp, 256-color)
2452
+ RT21 Intel Indeo RealTime Video 2.1
2453
+ rv20 RealVideo G2
2454
+ rv30 RealVideo 8
2455
+ RVX Intel RDX (RVX )
2456
+ SMC Apple Graphics (SMC )
2457
+ SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2
2458
+ SPIG Radius Spigot
2459
+ SVQ3 Sorenson Video 3 (Apple Quicktime 5)
2460
+ s422 Tekram VideoCap C210 YUV 4:2:2
2461
+ SDCC Sun Communication Digital Camera Codec
2462
+ SFMC CrystalNet Surface Fitting Method
2463
+ SMSC Radius SMSC
2464
+ SMSD Radius SMSD
2465
+ smsv WorldConnect Wavelet Video
2466
+ SPIG Radius Spigot
2467
+ SPLC Splash Studios ACM Audio Codec (www.splashstudios.net)
2468
+ SQZ2 Microsoft VXTreme Video Codec V2
2469
+ STVA ST Microelectronics CMOS Imager Data (Bayer)
2470
+ STVB ST Microelectronics CMOS Imager Data (Nudged Bayer)
2471
+ STVC ST Microelectronics CMOS Imager Data (Bunched)
2472
+ STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format)
2473
+ STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data)
2474
+ SV10 Sorenson Video R1
2475
+ SVQ1 Sorenson Video
2476
+ T420 Toshiba YUV 4:2:0
2477
+ TM2A Duck TrueMotion Archiver 2.0 (www.duck.com)
2478
+ TVJP Pinnacle/Truevision Targa 2000 board (TVJP)
2479
+ TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ)
2480
+ TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com)
2481
+ TY2C Trident Decompression Driver
2482
+ TLMS TeraLogic Motion Intraframe Codec (TLMS)
2483
+ TLST TeraLogic Motion Intraframe Codec (TLST)
2484
+ TM20 Duck TrueMotion 2.0
2485
+ TM2X Duck TrueMotion 2X
2486
+ TMIC TeraLogic Motion Intraframe Codec (TMIC)
2487
+ TMOT Horizons Technology TrueMotion S
2488
+ tmot Horizons TrueMotion Video Compression
2489
+ TR20 Duck TrueMotion RealTime 2.0
2490
+ TSCC TechSmith Screen Capture Codec
2491
+ TV10 Tecomac Low-Bit Rate Codec
2492
+ TY2N Trident ?TY2N?
2493
+ U263 UB Video H.263/H.263+/H.263++ Decoder
2494
+ UMP4 UB Video MPEG 4 (www.ubvideo.com)
2495
+ UYNV Nvidia UYVY packed 4:2:2
2496
+ UYVP Evans & Sutherland YCbCr 4:2:2 extended precision
2497
+ UCOD eMajix.com ClearVideo
2498
+ ULTI IBM Ultimotion
2499
+ UYVY UYVY packed 4:2:2
2500
+ V261 Lucent VX2000S
2501
+ VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/)
2502
+ VIV1 FFmpeg H263+ decoder
2503
+ VIV2 Vivo H.263
2504
+ VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf)
2505
+ VTLP Alaris VideoGramPiX
2506
+ VYU9 ATI YUV (VYU9)
2507
+ VYUY ATI YUV (VYUY)
2508
+ V261 Lucent VX2000S
2509
+ V422 Vitec Multimedia 24-bit YUV 4:2:2 Format
2510
+ V655 Vitec Multimedia 16-bit YUV 4:2:2 Format
2511
+ VCR1 ATI Video Codec 1
2512
+ VCR2 ATI Video Codec 2
2513
+ VCR3 ATI VCR 3.0
2514
+ VCR4 ATI VCR 4.0
2515
+ VCR5 ATI VCR 5.0
2516
+ VCR6 ATI VCR 6.0
2517
+ VCR7 ATI VCR 7.0
2518
+ VCR8 ATI VCR 8.0
2519
+ VCR9 ATI VCR 9.0
2520
+ VDCT Vitec Multimedia Video Maker Pro DIB
2521
+ VDOM VDOnet VDOWave
2522
+ VDOW VDOnet VDOLive (H.263)
2523
+ VDTZ Darim Vison VideoTizer YUV
2524
+ VGPX Alaris VideoGramPiX
2525
+ VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422
2526
+ VIVO Vivo H.263 v2.00
2527
+ vivo Vivo H.263
2528
+ VIXL Miro/Pinnacle Video XL
2529
+ VLV1 VideoLogic/PURE Digital Videologic Capture
2530
+ VP30 On2 VP3.0
2531
+ VP31 On2 VP3.1
2532
+ VP6F On2 TrueMotion VP6
2533
+ VX1K Lucent VX1000S Video Codec
2534
+ VX2K Lucent VX2000S Video Codec
2535
+ VXSP Lucent VX1000SP Video Codec
2536
+ WBVC Winbond W9960
2537
+ WHAM Microsoft Video 1 (WHAM)
2538
+ WINX Winnov Software Compression
2539
+ WJPG AverMedia Winbond JPEG
2540
+ WMV1 Windows Media Video V7
2541
+ WMV2 Windows Media Video V8
2542
+ WMV3 Windows Media Video V9
2543
+ WNV1 Winnov Hardware Compression
2544
+ XYZP Extended PAL format XYZ palette (www.riff.org)
2545
+ x263 Xirlink H.263
2546
+ XLV0 NetXL Video Decoder
2547
+ XMPG Xing MPEG (I-Frame only)
2548
+ XVID XviD MPEG-4 (www.xvid.org)
2549
+ XXAN ?XXAN?
2550
+ YU92 Intel YUV (YU92)
2551
+ YUNV Nvidia Uncompressed YUV 4:2:2
2552
+ YUVP Extended PAL format YUV palette (www.riff.org)
2553
+ Y211 YUV 2:1:1 Packed
2554
+ Y411 YUV 4:1:1 Packed
2555
+ Y41B Weitek YUV 4:1:1 Planar
2556
+ Y41P Brooktree PC1 YUV 4:1:1 Packed
2557
+ Y41T Brooktree PC1 YUV 4:1:1 with transparency
2558
+ Y42B Weitek YUV 4:2:2 Planar
2559
+ Y42T Brooktree UYUV 4:2:2 with transparency
2560
+ Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera
2561
+ Y800 Simple, single Y plane for monochrome images
2562
+ Y8 Grayscale video
2563
+ YC12 Intel YUV 12 codec
2564
+ YUV8 Winnov Caviar YUV8
2565
+ YUV9 Intel YUV9
2566
+ YUY2 Uncompressed YUV 4:2:2
2567
+ YUYV Canopus YUV
2568
+ YV12 YVU12 Planar
2569
+ YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes)
2570
+ YVYU YVYU 4:2:2 Packed
2571
+ ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
2572
+ ZPEG Metheus Video Zipper
2573
+
2574
+ */
2575
+
2576
+ return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc');
2577
+ }
2578
+
2579
+ private function EitherEndian2Int($byteword, $signed=false) {
2580
+ if ($this->container == 'riff') {
2581
+ return getid3_lib::LittleEndian2Int($byteword, $signed);
2582
+ }
2583
+ return getid3_lib::BigEndian2Int($byteword, false, $signed);
2584
+ }
2585
+
2586
+ }
getid3/module.audio.aac.php CHANGED
@@ -1,515 +1,513 @@
1
- <?php
2
- /////////////////////////////////////////////////////////////////
3
- /// getID3() by James Heinrich <info@getid3.org> //
4
- // available at http://getid3.sourceforge.net //
5
- // or http://www.getid3.org //
6
- /////////////////////////////////////////////////////////////////
7
- // See readme.txt for more details //
8
- /////////////////////////////////////////////////////////////////
9
- // //
10
- // module.audio.aac.php //
11
- // module for analyzing AAC Audio files //
12
- // dependencies: NONE //
13
- // ///
14
- /////////////////////////////////////////////////////////////////
15
-
16
-
17
- class getid3_aac extends getid3_handler
18
- {
19
- function Analyze() {
20
- $info = &$this->getid3->info;
21
- fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
22
- if (fread($this->getid3->fp, 4) == 'ADIF') {
23
- $this->getAACADIFheaderFilepointer();
24
- } else {
25
- $this->getAACADTSheaderFilepointer();
26
- }
27
- return true;
28
- }
29
-
30
-
31
-
32
- function getAACADIFheaderFilepointer() {
33
- $info = &$this->getid3->info;
34
- $info['fileformat'] = 'aac';
35
- $info['audio']['dataformat'] = 'aac';
36
- $info['audio']['lossless'] = false;
37
-
38
- fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
39
- $AACheader = fread($this->getid3->fp, 1024);
40
- $offset = 0;
41
-
42
- if (substr($AACheader, 0, 4) == 'ADIF') {
43
-
44
- // http://faac.sourceforge.net/wiki/index.php?page=ADIF
45
-
46
- // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf
47
- // adif_header() {
48
- // adif_id 32
49
- // copyright_id_present 1
50
- // if( copyright_id_present )
51
- // copyright_id 72
52
- // original_copy 1
53
- // home 1
54
- // bitstream_type 1
55
- // bitrate 23
56
- // num_program_config_elements 4
57
- // for (i = 0; i < num_program_config_elements + 1; i++ ) {
58
- // if( bitstream_type == '0' )
59
- // adif_buffer_fullness 20
60
- // program_config_element()
61
- // }
62
- // }
63
-
64
- $AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader);
65
- $bitoffset = 0;
66
-
67
- $info['aac']['header_type'] = 'ADIF';
68
- $bitoffset += 32;
69
- $info['aac']['header']['mpeg_version'] = 4;
70
-
71
- $info['aac']['header']['copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
72
- $bitoffset += 1;
73
- if ($info['aac']['header']['copyright']) {
74
- $info['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72));
75
- $bitoffset += 72;
76
- }
77
- $info['aac']['header']['original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
78
- $bitoffset += 1;
79
- $info['aac']['header']['home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
80
- $bitoffset += 1;
81
- $info['aac']['header']['is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
82
- $bitoffset += 1;
83
- if ($info['aac']['header']['is_vbr']) {
84
- $info['audio']['bitrate_mode'] = 'vbr';
85
- $info['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
86
- $bitoffset += 23;
87
- } else {
88
- $info['audio']['bitrate_mode'] = 'cbr';
89
- $info['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
90
- $bitoffset += 23;
91
- $info['audio']['bitrate'] = $info['aac']['header']['bitrate'];
92
- }
93
- if ($info['audio']['bitrate'] == 0) {
94
- $info['error'][] = 'Corrupt AAC file: bitrate_audio == zero';
95
- return false;
96
- }
97
- $info['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
98
- $bitoffset += 4;
99
-
100
- for ($i = 0; $i < $info['aac']['header']['num_program_configs']; $i++) {
101
- // http://www.audiocoding.com/wiki/index.php?page=program_config_element
102
-
103
- // buffer_fullness 20
104
-
105
- // element_instance_tag 4
106
- // object_type 2
107
- // sampling_frequency_index 4
108
- // num_front_channel_elements 4
109
- // num_side_channel_elements 4
110
- // num_back_channel_elements 4
111
- // num_lfe_channel_elements 2
112
- // num_assoc_data_elements 3
113
- // num_valid_cc_elements 4
114
- // mono_mixdown_present 1
115
- // mono_mixdown_element_number 4 if mono_mixdown_present == 1
116
- // stereo_mixdown_present 1
117
- // stereo_mixdown_element_number 4 if stereo_mixdown_present == 1
118
- // matrix_mixdown_idx_present 1
119
- // matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1
120
- // pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1
121
- // for (i = 0; i < num_front_channel_elements; i++) {
122
- // front_element_is_cpe[i] 1
123
- // front_element_tag_select[i] 4
124
- // }
125
- // for (i = 0; i < num_side_channel_elements; i++) {
126
- // side_element_is_cpe[i] 1
127
- // side_element_tag_select[i] 4
128
- // }
129
- // for (i = 0; i < num_back_channel_elements; i++) {
130
- // back_element_is_cpe[i] 1
131
- // back_element_tag_select[i] 4
132
- // }
133
- // for (i = 0; i < num_lfe_channel_elements; i++) {
134
- // lfe_element_tag_select[i] 4
135
- // }
136
- // for (i = 0; i < num_assoc_data_elements; i++) {
137
- // assoc_data_element_tag_select[i] 4
138
- // }
139
- // for (i = 0; i < num_valid_cc_elements; i++) {
140
- // cc_element_is_ind_sw[i] 1
141
- // valid_cc_element_tag_select[i] 4
142
- // }
143
- // byte_alignment() VAR
144
- // comment_field_bytes 8
145
- // for (i = 0; i < comment_field_bytes; i++) {
146
- // comment_field_data[i] 8
147
- // }
148
-
149
- if (!$info['aac']['header']['is_vbr']) {
150
- $info['aac']['program_configs'][$i]['buffer_fullness'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20));
151
- $bitoffset += 20;
152
- }
153
- $info['aac']['program_configs'][$i]['element_instance_tag'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
154
- $bitoffset += 4;
155
- $info['aac']['program_configs'][$i]['object_type'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
156
- $bitoffset += 2;
157
- $info['aac']['program_configs'][$i]['sampling_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
158
- $bitoffset += 4;
159
- $info['aac']['program_configs'][$i]['num_front_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
160
- $bitoffset += 4;
161
- $info['aac']['program_configs'][$i]['num_side_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
162
- $bitoffset += 4;
163
- $info['aac']['program_configs'][$i]['num_back_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
164
- $bitoffset += 4;
165
- $info['aac']['program_configs'][$i]['num_lfe_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
166
- $bitoffset += 2;
167
- $info['aac']['program_configs'][$i]['num_assoc_data_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3));
168
- $bitoffset += 3;
169
- $info['aac']['program_configs'][$i]['num_valid_cc_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
170
- $bitoffset += 4;
171
- $info['aac']['program_configs'][$i]['mono_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
172
- $bitoffset += 1;
173
- if ($info['aac']['program_configs'][$i]['mono_mixdown_present']) {
174
- $info['aac']['program_configs'][$i]['mono_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
175
- $bitoffset += 4;
176
- }
177
- $info['aac']['program_configs'][$i]['stereo_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
178
- $bitoffset += 1;
179
- if ($info['aac']['program_configs'][$i]['stereo_mixdown_present']) {
180
- $info['aac']['program_configs'][$i]['stereo_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
181
- $bitoffset += 4;
182
- }
183
- $info['aac']['program_configs'][$i]['matrix_mixdown_idx_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
184
- $bitoffset += 1;
185
- if ($info['aac']['program_configs'][$i]['matrix_mixdown_idx_present']) {
186
- $info['aac']['program_configs'][$i]['matrix_mixdown_idx'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
187
- $bitoffset += 2;
188
- $info['aac']['program_configs'][$i]['pseudo_surround_enable'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
189
- $bitoffset += 1;
190
- }
191
- for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_front_channel_elements']; $j++) {
192
- $info['aac']['program_configs'][$i]['front_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
193
- $bitoffset += 1;
194
- $info['aac']['program_configs'][$i]['front_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
195
- $bitoffset += 4;
196
- }
197
- for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_side_channel_elements']; $j++) {
198
- $info['aac']['program_configs'][$i]['side_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
199
- $bitoffset += 1;
200
- $info['aac']['program_configs'][$i]['side_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
201
- $bitoffset += 4;
202
- }
203
- for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_back_channel_elements']; $j++) {
204
- $info['aac']['program_configs'][$i]['back_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
205
- $bitoffset += 1;
206
- $info['aac']['program_configs'][$i]['back_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
207
- $bitoffset += 4;
208
- }
209
- for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_lfe_channel_elements']; $j++) {
210
- $info['aac']['program_configs'][$i]['lfe_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
211
- $bitoffset += 4;
212
- }
213
- for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_assoc_data_elements']; $j++) {
214
- $info['aac']['program_configs'][$i]['assoc_data_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
215
- $bitoffset += 4;
216
- }
217
- for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_valid_cc_elements']; $j++) {
218
- $info['aac']['program_configs'][$i]['cc_element_is_ind_sw'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
219
- $bitoffset += 1;
220
- $info['aac']['program_configs'][$i]['valid_cc_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
221
- $bitoffset += 4;
222
- }
223
-
224
- $bitoffset = ceil($bitoffset / 8) * 8;
225
-
226
- $info['aac']['program_configs'][$i]['comment_field_bytes'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8));
227
- $bitoffset += 8;
228
- $info['aac']['program_configs'][$i]['comment_field'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $info['aac']['program_configs'][$i]['comment_field_bytes']));
229
- $bitoffset += 8 * $info['aac']['program_configs'][$i]['comment_field_bytes'];
230
-
231
-
232
- $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['program_configs'][$i]['object_type'], $info['aac']['header']['mpeg_version']);
233
- $info['aac']['program_configs'][$i]['sampling_frequency'] = self::AACsampleRateLookup($info['aac']['program_configs'][$i]['sampling_frequency_index']);
234
- $info['audio']['sample_rate'] = $info['aac']['program_configs'][$i]['sampling_frequency'];
235
- $info['audio']['channels'] = self::AACchannelCountCalculate($info['aac']['program_configs'][$i]);
236
- if ($info['aac']['program_configs'][$i]['comment_field']) {
237
- $info['aac']['comments'][] = $info['aac']['program_configs'][$i]['comment_field'];
238
- }
239
- }
240
- $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate'];
241
-
242
- $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile'];
243
-
244
-
245
-
246
- return true;
247
-
248
- } else {
249
-
250
- unset($info['fileformat']);
251
- unset($info['aac']);
252
- $info['error'][] = 'AAC-ADIF synch not found at offset '.$info['avdataoffset'].' (expected "ADIF", found "'.substr($AACheader, 0, 4).'" instead)';
253
- return false;
254
-
255
- }
256
-
257
- }
258
-
259
-
260
- function getAACADTSheaderFilepointer($MaxFramesToScan=1000000, $ReturnExtendedInfo=false) {
261
- $info = &$this->getid3->info;
262
-
263
- // based loosely on code from AACfile by Jurgen Faul <jfaul�gmx.de>
264
- // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
265
-
266
-
267
- // http://faac.sourceforge.net/wiki/index.php?page=ADTS // dead link
268
- // http://wiki.multimedia.cx/index.php?title=ADTS
269
-
270
- // * ADTS Fixed Header: these don't change from frame to frame
271
- // syncword 12 always: '111111111111'
272
- // ID 1 0: MPEG-4, 1: MPEG-2
273
- // MPEG layer 2 If you send AAC in MPEG-TS, set to 0
274
- // protection_absent 1 0: CRC present; 1: no CRC
275
- // profile 2 0: AAC Main; 1: AAC LC (Low Complexity); 2: AAC SSR (Scalable Sample Rate); 3: AAC LTP (Long Term Prediction)
276
- // sampling_frequency_index 4 15 not allowed
277
- // private_bit 1 usually 0
278
- // channel_configuration 3
279
- // original/copy 1 0: original; 1: copy
280
- // home 1 usually 0
281
- // emphasis 2 only if ID == 0 (ie MPEG-4) // not present in some documentation?
282
-
283
- // * ADTS Variable Header: these can change from frame to frame
284
- // copyright_identification_bit 1
285
- // copyright_identification_start 1
286
- // aac_frame_length 13 length of the frame including header (in bytes)
287
- // adts_buffer_fullness 11 0x7FF indicates VBR
288
- // no_raw_data_blocks_in_frame 2
289
-
290
- // * ADTS Error check
291
- // crc_check 16 only if protection_absent == 0
292
-
293
- $byteoffset = $info['avdataoffset'];
294
- $framenumber = 0;
295
-
296
- // Init bit pattern array
297
- static $decbin = array();
298
-
299
- // Populate $bindec
300
- for ($i = 0; $i < 256; $i++) {
301
- $decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT);
302
- }
303
-
304
- // used to calculate bitrate below
305
- $BitrateCache = array();
306
-
307
-
308
- while (true) {
309
- // breaks out when end-of-file encountered, or invalid data found,
310
- // or MaxFramesToScan frames have been scanned
311
-
312
- if (!getid3_lib::intValueSupported($byteoffset)) {
313
- $info['warning'][] = 'Unable to parse AAC file beyond '.ftell($this->getid3->fp).' (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)';
314
- return false;
315
- }
316
- fseek($this->getid3->fp, $byteoffset, SEEK_SET);
317
-
318
- // First get substring
319
- $substring = fread($this->getid3->fp, 9); // header is 7 bytes (or 9 if CRC is present)
320
- $substringlength = strlen($substring);
321
- if ($substringlength != 9) {
322
- $info['error'][] = 'Failed to read 7 bytes at offset '.(ftell($this->getid3->fp) - $substringlength).' (only read '.$substringlength.' bytes)';
323
- return false;
324
- }
325
- // this would be easier with 64-bit math, but split it up to allow for 32-bit:
326
- $header1 = getid3_lib::BigEndian2Int(substr($substring, 0, 2));
327
- $header2 = getid3_lib::BigEndian2Int(substr($substring, 2, 4));
328
- $header3 = getid3_lib::BigEndian2Int(substr($substring, 6, 1));
329
-
330
- $info['aac']['header']['raw']['syncword'] = ($header1 & 0xFFF0) >> 4;
331
- if ($info['aac']['header']['raw']['syncword'] != 0x0FFF) {
332
- $info['error'][] = 'Synch pattern (0x0FFF) not found at offset '.(ftell($this->getid3->fp) - $substringlength).' (found 0x0'.strtoupper(dechex($info['aac']['header']['raw']['syncword'])).' instead)';
333
- //if ($info['fileformat'] == 'aac') {
334
- // return true;
335
- //}
336
- unset($info['aac']);
337
- return false;
338
- }
339
-
340
- // Gather info for first frame only - this takes time to do 1000 times!
341
- if ($framenumber == 0) {
342
- $info['aac']['header_type'] = 'ADTS';
343
- $info['fileformat'] = 'aac';
344
- $info['audio']['dataformat'] = 'aac';
345
-
346
- $info['aac']['header']['raw']['mpeg_version'] = ($header1 & 0x0008) >> 3;
347
- $info['aac']['header']['raw']['mpeg_layer'] = ($header1 & 0x0006) >> 1;
348
- $info['aac']['header']['raw']['protection_absent'] = ($header1 & 0x0001) >> 0;
349
-
350
- $info['aac']['header']['raw']['profile_code'] = ($header2 & 0xC0000000) >> 30;
351
- $info['aac']['header']['raw']['sample_rate_code'] = ($header2 & 0x3C000000) >> 26;
352
- $info['aac']['header']['raw']['private_stream'] = ($header2 & 0x02000000) >> 25;
353
- $info['aac']['header']['raw']['channels_code'] = ($header2 & 0x01C00000) >> 22;
354
- $info['aac']['header']['raw']['original'] = ($header2 & 0x00200000) >> 21;
355
- $info['aac']['header']['raw']['home'] = ($header2 & 0x00100000) >> 20;
356
- $info['aac']['header']['raw']['copyright_stream'] = ($header2 & 0x00080000) >> 19;
357
- $info['aac']['header']['raw']['copyright_start'] = ($header2 & 0x00040000) >> 18;
358
- $info['aac']['header']['raw']['frame_length'] = ($header2 & 0x0003FFE0) >> 5;
359
-
360
- $info['aac']['header']['mpeg_version'] = ($info['aac']['header']['raw']['mpeg_version'] ? 2 : 4);
361
- $info['aac']['header']['crc_present'] = ($info['aac']['header']['raw']['protection_absent'] ? false: true);
362
- $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['header']['raw']['profile_code'], $info['aac']['header']['mpeg_version']);
363
- $info['aac']['header']['sample_frequency'] = self::AACsampleRateLookup($info['aac']['header']['raw']['sample_rate_code']);
364
- $info['aac']['header']['private'] = (bool) $info['aac']['header']['raw']['private_stream'];
365
- $info['aac']['header']['original'] = (bool) $info['aac']['header']['raw']['original'];
366
- $info['aac']['header']['home'] = (bool) $info['aac']['header']['raw']['home'];
367
- $info['aac']['header']['channels'] = (($info['aac']['header']['raw']['channels_code'] == 7) ? 8 : $info['aac']['header']['raw']['channels_code']);
368
- if ($ReturnExtendedInfo) {
369
- $info['aac'][$framenumber]['copyright_id_bit'] = (bool) $info['aac']['header']['raw']['copyright_stream'];
370
- $info['aac'][$framenumber]['copyright_id_start'] = (bool) $info['aac']['header']['raw']['copyright_start'];
371
- }
372
-
373
- if ($info['aac']['header']['raw']['mpeg_layer'] != 0) {
374
- $info['warning'][] = 'Layer error - expected "0", found "'.$info['aac']['header']['raw']['mpeg_layer'].'" instead';
375
- }
376
- if ($info['aac']['header']['sample_frequency'] == 0) {
377
- $info['error'][] = 'Corrupt AAC file: sample_frequency == zero';
378
- return false;
379
- }
380
-
381
- $info['audio']['sample_rate'] = $info['aac']['header']['sample_frequency'];
382
- $info['audio']['channels'] = $info['aac']['header']['channels'];
383
- }
384
-
385
- $FrameLength = ($header2 & 0x0003FFE0) >> 5;
386
-
387
- if (!isset($BitrateCache[$FrameLength])) {
388
- $BitrateCache[$FrameLength] = ($info['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8;
389
- }
390
- getid3_lib::safe_inc($info['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]], 1);
391
-
392
- $info['aac'][$framenumber]['aac_frame_length'] = $FrameLength;
393
-
394
- $info['aac'][$framenumber]['adts_buffer_fullness'] = (($header2 & 0x0000001F) << 6) & (($header3 & 0xFC) >> 2);
395
- if ($info['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) {
396
- $info['audio']['bitrate_mode'] = 'vbr';
397
- } else {
398
- $info['audio']['bitrate_mode'] = 'cbr';
399
- }
400
- $info['aac'][$framenumber]['num_raw_data_blocks'] = (($header3 & 0x03) >> 0);
401
-
402
- if ($info['aac']['header']['crc_present']) {
403
- //$info['aac'][$framenumber]['crc'] = getid3_lib::BigEndian2Int(substr($substring, 7, 2);
404
- }
405
-
406
- if (!$ReturnExtendedInfo) {
407
- unset($info['aac'][$framenumber]);
408
- }
409
-
410
- /*
411
- $rounded_precision = 5000;
412
- $info['aac']['bitrate_distribution_rounded'] = array();
413
- foreach ($info['aac']['bitrate_distribution'] as $bitrate => $count) {
414
- $rounded_bitrate = round($bitrate / $rounded_precision) * $rounded_precision;
415
- getid3_lib::safe_inc($info['aac']['bitrate_distribution_rounded'][$rounded_bitrate], $count);
416
- }
417
- ksort($info['aac']['bitrate_distribution_rounded']);
418
- */
419
-
420
- $byteoffset += $FrameLength;
421
- if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $info['avdataend'])) {
422
-
423
- // keep scanning
424
-
425
- } else {
426
-
427
- $info['aac']['frames'] = $framenumber;
428
- $info['playtime_seconds'] = ($info['avdataend'] / $byteoffset) * (($framenumber * 1024) / $info['aac']['header']['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds
429
- if ($info['playtime_seconds'] == 0) {
430
- $info['error'][] = 'Corrupt AAC file: playtime_seconds == zero';
431
- return false;
432
- }
433
- $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
434
- ksort($info['aac']['bitrate_distribution']);
435
-
436
- $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile'];
437
-
438
- return true;
439
-
440
- }
441
- }
442
- // should never get here.
443
- }
444
-
445
- public static function AACsampleRateLookup($samplerateid) {
446
- static $AACsampleRateLookup = array();
447
- if (empty($AACsampleRateLookup)) {
448
- $AACsampleRateLookup[0] = 96000;
449
- $AACsampleRateLookup[1] = 88200;
450
- $AACsampleRateLookup[2] = 64000;
451
- $AACsampleRateLookup[3] = 48000;
452
- $AACsampleRateLookup[4] = 44100;
453
- $AACsampleRateLookup[5] = 32000;
454
- $AACsampleRateLookup[6] = 24000;
455
- $AACsampleRateLookup[7] = 22050;
456
- $AACsampleRateLookup[8] = 16000;
457
- $AACsampleRateLookup[9] = 12000;
458
- $AACsampleRateLookup[10] = 11025;
459
- $AACsampleRateLookup[11] = 8000;
460
- $AACsampleRateLookup[12] = 0;
461
- $AACsampleRateLookup[13] = 0;
462
- $AACsampleRateLookup[14] = 0;
463
- $AACsampleRateLookup[15] = 0;
464
- }
465
- return (isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid');
466
- }
467
-
468
- public static function AACprofileLookup($profileid, $mpegversion) {
469
- static $AACprofileLookup = array();
470
- if (empty($AACprofileLookup)) {
471
- $AACprofileLookup[2][0] = 'Main profile';
472
- $AACprofileLookup[2][1] = 'Low Complexity profile (LC)';
473
- $AACprofileLookup[2][2] = 'Scalable Sample Rate profile (SSR)';
474
- $AACprofileLookup[2][3] = '(reserved)';
475
- $AACprofileLookup[4][0] = 'AAC_MAIN';
476
- $AACprofileLookup[4][1] = 'AAC_LC';
477
- $AACprofileLookup[4][2] = 'AAC_SSR';
478
- $AACprofileLookup[4][3] = 'AAC_LTP';
479
- }
480
- return (isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid');
481
- }
482
-
483
- public static function AACchannelCountCalculate($program_configs) {
484
- $channels = 0;
485
- for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) {
486
- $channels++;
487
- if ($program_configs['front_element_is_cpe'][$i]) {
488
- // each front element is channel pair (CPE = Channel Pair Element)
489
- $channels++;
490
- }
491
- }
492
- for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) {
493
- $channels++;
494
- if ($program_configs['side_element_is_cpe'][$i]) {
495
- // each side element is channel pair (CPE = Channel Pair Element)
496
- $channels++;
497
- }
498
- }
499
- for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) {
500
- $channels++;
501
- if ($program_configs['back_element_is_cpe'][$i]) {
502
- // each back element is channel pair (CPE = Channel Pair Element)
503
- $channels++;
504
- }
505
- }
506
- for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) {
507
- $channels++;
508
- }
509
- return $channels;
510
- }
511
-
512
- }
513
-
514
-
515
- ?>
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // See readme.txt for more details //
9
+ /////////////////////////////////////////////////////////////////
10
+ // //
11
+ // module.audio.aac.php //
12
+ // module for analyzing AAC Audio files //
13
+ // dependencies: NONE //
14
+ // ///
15
+ /////////////////////////////////////////////////////////////////
16
+
17
+
18
+ class getid3_aac extends getid3_handler
19
+ {
20
+ public function Analyze() {
21
+ $info = &$this->getid3->info;
22
+ $this->fseek($info['avdataoffset']);
23
+ if ($this->fread(4) == 'ADIF') {
24
+ $this->getAACADIFheaderFilepointer();
25
+ } else {
26
+ $this->getAACADTSheaderFilepointer();
27
+ }
28
+ return true;
29
+ }
30
+
31
+
32
+
33
+ public function getAACADIFheaderFilepointer() {
34
+ $info = &$this->getid3->info;
35
+ $info['fileformat'] = 'aac';
36
+ $info['audio']['dataformat'] = 'aac';
37
+ $info['audio']['lossless'] = false;
38
+
39
+ $this->fseek($info['avdataoffset']);
40
+ $AACheader = $this->fread(1024);
41
+ $offset = 0;
42
+
43
+ if (substr($AACheader, 0, 4) == 'ADIF') {
44
+
45
+ // http://faac.sourceforge.net/wiki/index.php?page=ADIF
46
+
47
+ // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf
48
+ // adif_header() {
49
+ // adif_id 32
50
+ // copyright_id_present 1
51
+ // if( copyright_id_present )
52
+ // copyright_id 72
53
+ // original_copy 1
54
+ // home 1
55
+ // bitstream_type 1
56
+ // bitrate 23
57
+ // num_program_config_elements 4
58
+ // for (i = 0; i < num_program_config_elements + 1; i++ ) {
59
+ // if( bitstream_type == '0' )
60
+ // adif_buffer_fullness 20
61
+ // program_config_element()
62
+ // }
63
+ // }
64
+
65
+ $AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader);
66
+ $bitoffset = 0;
67
+
68
+ $info['aac']['header_type'] = 'ADIF';
69
+ $bitoffset += 32;
70
+ $info['aac']['header']['mpeg_version'] = 4;
71
+
72
+ $info['aac']['header']['copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
73
+ $bitoffset += 1;
74
+ if ($info['aac']['header']['copyright']) {
75
+ $info['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72));
76
+ $bitoffset += 72;
77
+ }
78
+ $info['aac']['header']['original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
79
+ $bitoffset += 1;
80
+ $info['aac']['header']['home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
81
+ $bitoffset += 1;
82
+ $info['aac']['header']['is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1');
83
+ $bitoffset += 1;
84
+ if ($info['aac']['header']['is_vbr']) {
85
+ $info['audio']['bitrate_mode'] = 'vbr';
86
+ $info['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
87
+ $bitoffset += 23;
88
+ } else {
89
+ $info['audio']['bitrate_mode'] = 'cbr';
90
+ $info['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
91
+ $bitoffset += 23;
92
+ $info['audio']['bitrate'] = $info['aac']['header']['bitrate'];
93
+ }
94
+ if ($info['audio']['bitrate'] == 0) {
95
+ $info['error'][] = 'Corrupt AAC file: bitrate_audio == zero';
96
+ return false;
97
+ }
98
+ $info['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
99
+ $bitoffset += 4;
100
+
101
+ for ($i = 0; $i < $info['aac']['header']['num_program_configs']; $i++) {
102
+ // http://www.audiocoding.com/wiki/index.php?page=program_config_element
103
+
104
+ // buffer_fullness 20
105
+
106
+ // element_instance_tag 4
107
+ // object_type 2
108
+ // sampling_frequency_index 4
109
+ // num_front_channel_elements 4
110
+ // num_side_channel_elements 4
111
+ // num_back_channel_elements 4
112
+ // num_lfe_channel_elements 2
113
+ // num_assoc_data_elements 3
114
+ // num_valid_cc_elements 4
115
+ // mono_mixdown_present 1
116
+ // mono_mixdown_element_number 4 if mono_mixdown_present == 1
117
+ // stereo_mixdown_present 1
118
+ // stereo_mixdown_element_number 4 if stereo_mixdown_present == 1
119
+ // matrix_mixdown_idx_present 1
120
+ // matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1
121
+ // pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1
122
+ // for (i = 0; i < num_front_channel_elements; i++) {
123
+ // front_element_is_cpe[i] 1
124
+ // front_element_tag_select[i] 4
125
+ // }
126
+ // for (i = 0; i < num_side_channel_elements; i++) {
127
+ // side_element_is_cpe[i] 1
128
+ // side_element_tag_select[i] 4
129
+ // }
130
+ // for (i = 0; i < num_back_channel_elements; i++) {
131
+ // back_element_is_cpe[i] 1
132
+ // back_element_tag_select[i] 4
133
+ // }
134
+ // for (i = 0; i < num_lfe_channel_elements; i++) {
135
+ // lfe_element_tag_select[i] 4
136
+ // }
137
+ // for (i = 0; i < num_assoc_data_elements; i++) {
138
+ // assoc_data_element_tag_select[i] 4
139
+ // }
140
+ // for (i = 0; i < num_valid_cc_elements; i++) {
141
+ // cc_element_is_ind_sw[i] 1
142
+ // valid_cc_element_tag_select[i] 4
143
+ // }
144
+ // byte_alignment() VAR
145
+ // comment_field_bytes 8
146
+ // for (i = 0; i < comment_field_bytes; i++) {
147
+ // comment_field_data[i] 8
148
+ // }
149
+
150
+ if (!$info['aac']['header']['is_vbr']) {
151
+ $info['aac']['program_configs'][$i]['buffer_fullness'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20));
152
+ $bitoffset += 20;
153
+ }
154
+ $info['aac']['program_configs'][$i]['element_instance_tag'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
155
+ $bitoffset += 4;
156
+ $info['aac']['program_configs'][$i]['object_type'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
157
+ $bitoffset += 2;
158
+ $info['aac']['program_configs'][$i]['sampling_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
159
+ $bitoffset += 4;
160
+ $info['aac']['program_configs'][$i]['num_front_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
161
+ $bitoffset += 4;
162
+ $info['aac']['program_configs'][$i]['num_side_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
163
+ $bitoffset += 4;
164
+ $info['aac']['program_configs'][$i]['num_back_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
165
+ $bitoffset += 4;
166
+ $info['aac']['program_configs'][$i]['num_lfe_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
167
+ $bitoffset += 2;
168
+ $info['aac']['program_configs'][$i]['num_assoc_data_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3));
169
+ $bitoffset += 3;
170
+ $info['aac']['program_configs'][$i]['num_valid_cc_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
171
+ $bitoffset += 4;
172
+ $info['aac']['program_configs'][$i]['mono_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
173
+ $bitoffset += 1;
174
+ if ($info['aac']['program_configs'][$i]['mono_mixdown_present']) {
175
+ $info['aac']['program_configs'][$i]['mono_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
176
+ $bitoffset += 4;
177
+ }
178
+ $info['aac']['program_configs'][$i]['stereo_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
179
+ $bitoffset += 1;
180
+ if ($info['aac']['program_configs'][$i]['stereo_mixdown_present']) {
181
+ $info['aac']['program_configs'][$i]['stereo_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
182
+ $bitoffset += 4;
183
+ }
184
+ $info['aac']['program_configs'][$i]['matrix_mixdown_idx_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
185
+ $bitoffset += 1;
186
+ if ($info['aac']['program_configs'][$i]['matrix_mixdown_idx_present']) {
187
+ $info['aac']['program_configs'][$i]['matrix_mixdown_idx'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
188
+ $bitoffset += 2;
189
+ $info['aac']['program_configs'][$i]['pseudo_surround_enable'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
190
+ $bitoffset += 1;
191
+ }
192
+ for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_front_channel_elements']; $j++) {
193
+ $info['aac']['program_configs'][$i]['front_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
194
+ $bitoffset += 1;
195
+ $info['aac']['program_configs'][$i]['front_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
196
+ $bitoffset += 4;
197
+ }
198
+ for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_side_channel_elements']; $j++) {
199
+ $info['aac']['program_configs'][$i]['side_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
200
+ $bitoffset += 1;
201
+ $info['aac']['program_configs'][$i]['side_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
202
+ $bitoffset += 4;
203
+ }
204
+ for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_back_channel_elements']; $j++) {
205
+ $info['aac']['program_configs'][$i]['back_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
206
+ $bitoffset += 1;
207
+ $info['aac']['program_configs'][$i]['back_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
208
+ $bitoffset += 4;
209
+ }
210
+ for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_lfe_channel_elements']; $j++) {
211
+ $info['aac']['program_configs'][$i]['lfe_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
212
+ $bitoffset += 4;
213
+ }
214
+ for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_assoc_data_elements']; $j++) {
215
+ $info['aac']['program_configs'][$i]['assoc_data_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
216
+ $bitoffset += 4;
217
+ }
218
+ for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_valid_cc_elements']; $j++) {
219
+ $info['aac']['program_configs'][$i]['cc_element_is_ind_sw'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
220
+ $bitoffset += 1;
221
+ $info['aac']['program_configs'][$i]['valid_cc_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
222
+ $bitoffset += 4;
223
+ }
224
+
225
+ $bitoffset = ceil($bitoffset / 8) * 8;
226
+
227
+ $info['aac']['program_configs'][$i]['comment_field_bytes'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8));
228
+ $bitoffset += 8;
229
+ $info['aac']['program_configs'][$i]['comment_field'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $info['aac']['program_configs'][$i]['comment_field_bytes']));
230
+ $bitoffset += 8 * $info['aac']['program_configs'][$i]['comment_field_bytes'];
231
+
232
+
233
+ $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['program_configs'][$i]['object_type'], $info['aac']['header']['mpeg_version']);
234
+ $info['aac']['program_configs'][$i]['sampling_frequency'] = self::AACsampleRateLookup($info['aac']['program_configs'][$i]['sampling_frequency_index']);
235
+ $info['audio']['sample_rate'] = $info['aac']['program_configs'][$i]['sampling_frequency'];
236
+ $info['audio']['channels'] = self::AACchannelCountCalculate($info['aac']['program_configs'][$i]);
237
+ if ($info['aac']['program_configs'][$i]['comment_field']) {
238
+ $info['aac']['comments'][] = $info['aac']['program_configs'][$i]['comment_field'];
239
+ }
240
+ }
241
+ $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate'];
242
+
243
+ $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile'];
244
+
245
+
246
+
247
+ return true;
248
+
249
+ } else {
250
+
251
+ unset($info['fileformat']);
252
+ unset($info['aac']);
253
+ $info['error'][] = 'AAC-ADIF synch not found at offset '.$info['avdataoffset'].' (expected "ADIF", found "'.substr($AACheader, 0, 4).'" instead)';
254
+ return false;
255
+
256
+ }
257
+
258
+ }
259
+
260
+
261
+ public function getAACADTSheaderFilepointer($MaxFramesToScan=1000000, $ReturnExtendedInfo=false) {
262
+ $info = &$this->getid3->info;
263
+
264
+ // based loosely on code from AACfile by Jurgen Faul <jfaulØgmx.de>
265
+ // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
266
+
267
+
268
+ // http://faac.sourceforge.net/wiki/index.php?page=ADTS // dead link
269
+ // http://wiki.multimedia.cx/index.php?title=ADTS
270
+
271
+ // * ADTS Fixed Header: these don't change from frame to frame
272
+ // syncword 12 always: '111111111111'
273
+ // ID 1 0: MPEG-4, 1: MPEG-2
274
+ // MPEG layer 2 If you send AAC in MPEG-TS, set to 0
275
+ // protection_absent 1 0: CRC present; 1: no CRC
276
+ // profile 2 0: AAC Main; 1: AAC LC (Low Complexity); 2: AAC SSR (Scalable Sample Rate); 3: AAC LTP (Long Term Prediction)
277
+ // sampling_frequency_index 4 15 not allowed
278
+ // private_bit 1 usually 0
279
+ // channel_configuration 3
280
+ // original/copy 1 0: original; 1: copy
281
+ // home 1 usually 0
282
+ // emphasis 2 only if ID == 0 (ie MPEG-4) // not present in some documentation?
283
+
284
+ // * ADTS Variable Header: these can change from frame to frame
285
+ // copyright_identification_bit 1
286
+ // copyright_identification_start 1
287
+ // aac_frame_length 13 length of the frame including header (in bytes)
288
+ // adts_buffer_fullness 11 0x7FF indicates VBR
289
+ // no_raw_data_blocks_in_frame 2
290
+
291
+ // * ADTS Error check
292
+ // crc_check 16 only if protection_absent == 0
293
+
294
+ $byteoffset = $info['avdataoffset'];
295
+ $framenumber = 0;
296
+
297
+ // Init bit pattern array
298
+ static $decbin = array();
299
+
300
+ // Populate $bindec
301
+ for ($i = 0; $i < 256; $i++) {
302
+ $decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT);
303
+ }
304
+
305
+ // used to calculate bitrate below
306
+ $BitrateCache = array();
307
+
308
+
309
+ while (true) {
310
+ // breaks out when end-of-file encountered, or invalid data found,
311
+ // or MaxFramesToScan frames have been scanned
312
+
313
+ if (!getid3_lib::intValueSupported($byteoffset)) {
314
+ $info['warning'][] = 'Unable to parse AAC file beyond '.$this->ftell().' (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)';
315
+ return false;
316
+ }
317
+ $this->fseek($byteoffset);
318
+
319
+ // First get substring
320
+ $substring = $this->fread(9); // header is 7 bytes (or 9 if CRC is present)
321
+ $substringlength = strlen($substring);
322
+ if ($substringlength != 9) {
323
+ $info['error'][] = 'Failed to read 7 bytes at offset '.($this->ftell() - $substringlength).' (only read '.$substringlength.' bytes)';
324
+ return false;
325
+ }
326
+ // this would be easier with 64-bit math, but split it up to allow for 32-bit:
327
+ $header1 = getid3_lib::BigEndian2Int(substr($substring, 0, 2));
328
+ $header2 = getid3_lib::BigEndian2Int(substr($substring, 2, 4));
329
+ $header3 = getid3_lib::BigEndian2Int(substr($substring, 6, 1));
330
+
331
+ $info['aac']['header']['raw']['syncword'] = ($header1 & 0xFFF0) >> 4;
332
+ if ($info['aac']['header']['raw']['syncword'] != 0x0FFF) {
333
+ $info['error'][] = 'Synch pattern (0x0FFF) not found at offset '.($this->ftell() - $substringlength).' (found 0x0'.strtoupper(dechex($info['aac']['header']['raw']['syncword'])).' instead)';
334
+ //if ($info['fileformat'] == 'aac') {
335
+ // return true;
336
+ //}
337
+ unset($info['aac']);
338
+ return false;
339
+ }
340
+
341
+ // Gather info for first frame only - this takes time to do 1000 times!
342
+ if ($framenumber == 0) {
343
+ $info['aac']['header_type'] = 'ADTS';
344
+ $info['fileformat'] = 'aac';
345
+ $info['audio']['dataformat'] = 'aac';
346
+
347
+ $info['aac']['header']['raw']['mpeg_version'] = ($header1 & 0x0008) >> 3;
348
+ $info['aac']['header']['raw']['mpeg_layer'] = ($header1 & 0x0006) >> 1;
349
+ $info['aac']['header']['raw']['protection_absent'] = ($header1 & 0x0001) >> 0;
350
+
351
+ $info['aac']['header']['raw']['profile_code'] = ($header2 & 0xC0000000) >> 30;
352
+ $info['aac']['header']['raw']['sample_rate_code'] = ($header2 & 0x3C000000) >> 26;
353
+ $info['aac']['header']['raw']['private_stream'] = ($header2 & 0x02000000) >> 25;
354
+ $info['aac']['header']['raw']['channels_code'] = ($header2 & 0x01C00000) >> 22;
355
+ $info['aac']['header']['raw']['original'] = ($header2 & 0x00200000) >> 21;
356
+ $info['aac']['header']['raw']['home'] = ($header2 & 0x00100000) >> 20;
357
+ $info['aac']['header']['raw']['copyright_stream'] = ($header2 & 0x00080000) >> 19;
358
+ $info['aac']['header']['raw']['copyright_start'] = ($header2 & 0x00040000) >> 18;
359
+ $info['aac']['header']['raw']['frame_length'] = ($header2 & 0x0003FFE0) >> 5;
360
+
361
+ $info['aac']['header']['mpeg_version'] = ($info['aac']['header']['raw']['mpeg_version'] ? 2 : 4);
362
+ $info['aac']['header']['crc_present'] = ($info['aac']['header']['raw']['protection_absent'] ? false: true);
363
+ $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['header']['raw']['profile_code'], $info['aac']['header']['mpeg_version']);
364
+ $info['aac']['header']['sample_frequency'] = self::AACsampleRateLookup($info['aac']['header']['raw']['sample_rate_code']);
365
+ $info['aac']['header']['private'] = (bool) $info['aac']['header']['raw']['private_stream'];
366
+ $info['aac']['header']['original'] = (bool) $info['aac']['header']['raw']['original'];
367
+ $info['aac']['header']['home'] = (bool) $info['aac']['header']['raw']['home'];
368
+ $info['aac']['header']['channels'] = (($info['aac']['header']['raw']['channels_code'] == 7) ? 8 : $info['aac']['header']['raw']['channels_code']);
369
+ if ($ReturnExtendedInfo) {
370
+ $info['aac'][$framenumber]['copyright_id_bit'] = (bool) $info['aac']['header']['raw']['copyright_stream'];
371
+ $info['aac'][$framenumber]['copyright_id_start'] = (bool) $info['aac']['header']['raw']['copyright_start'];
372
+ }
373
+
374
+ if ($info['aac']['header']['raw']['mpeg_layer'] != 0) {
375
+ $info['warning'][] = 'Layer error - expected "0", found "'.$info['aac']['header']['raw']['mpeg_layer'].'" instead';
376
+ }
377
+ if ($info['aac']['header']['sample_frequency'] == 0) {
378
+ $info['error'][] = 'Corrupt AAC file: sample_frequency == zero';
379
+ return false;
380
+ }
381
+
382
+ $info['audio']['sample_rate'] = $info['aac']['header']['sample_frequency'];
383
+ $info['audio']['channels'] = $info['aac']['header']['channels'];
384
+ }
385
+
386
+ $FrameLength = ($header2 & 0x0003FFE0) >> 5;
387
+
388
+ if (!isset($BitrateCache[$FrameLength])) {
389
+ $BitrateCache[$FrameLength] = ($info['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8;
390
+ }
391
+ getid3_lib::safe_inc($info['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]], 1);
392
+
393
+ $info['aac'][$framenumber]['aac_frame_length'] = $FrameLength;
394
+
395
+ $info['aac'][$framenumber]['adts_buffer_fullness'] = (($header2 & 0x0000001F) << 6) & (($header3 & 0xFC) >> 2);
396
+ if ($info['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) {
397
+ $info['audio']['bitrate_mode'] = 'vbr';
398
+ } else {
399
+ $info['audio']['bitrate_mode'] = 'cbr';
400
+ }
401
+ $info['aac'][$framenumber]['num_raw_data_blocks'] = (($header3 & 0x03) >> 0);
402
+
403
+ if ($info['aac']['header']['crc_present']) {
404
+ //$info['aac'][$framenumber]['crc'] = getid3_lib::BigEndian2Int(substr($substring, 7, 2);
405
+ }
406
+
407
+ if (!$ReturnExtendedInfo) {
408
+ unset($info['aac'][$framenumber]);
409
+ }
410
+
411
+ /*
412
+ $rounded_precision = 5000;
413
+ $info['aac']['bitrate_distribution_rounded'] = array();
414
+ foreach ($info['aac']['bitrate_distribution'] as $bitrate => $count) {
415
+ $rounded_bitrate = round($bitrate / $rounded_precision) * $rounded_precision;
416
+ getid3_lib::safe_inc($info['aac']['bitrate_distribution_rounded'][$rounded_bitrate], $count);
417
+ }
418
+ ksort($info['aac']['bitrate_distribution_rounded']);
419
+ */
420
+
421
+ $byteoffset += $FrameLength;
422
+ if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $info['avdataend'])) {
423
+
424
+ // keep scanning
425
+
426
+ } else {
427
+
428
+ $info['aac']['frames'] = $framenumber;
429
+ $info['playtime_seconds'] = ($info['avdataend'] / $byteoffset) * (($framenumber * 1024) / $info['aac']['header']['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds
430
+ if ($info['playtime_seconds'] == 0) {
431
+ $info['error'][] = 'Corrupt AAC file: playtime_seconds == zero';
432
+ return false;
433
+ }
434
+ $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
435
+ ksort($info['aac']['bitrate_distribution']);
436
+
437
+ $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile'];
438
+
439
+ return true;
440
+
441
+ }
442
+ }
443
+ // should never get here.
444
+ }
445
+
446
+ public static function AACsampleRateLookup($samplerateid) {
447
+ static $AACsampleRateLookup = array();
448
+ if (empty($AACsampleRateLookup)) {
449
+ $AACsampleRateLookup[0] = 96000;
450
+ $AACsampleRateLookup[1] = 88200;
451
+ $AACsampleRateLookup[2] = 64000;
452
+ $AACsampleRateLookup[3] = 48000;
453
+ $AACsampleRateLookup[4] = 44100;
454
+ $AACsampleRateLookup[5] = 32000;
455
+ $AACsampleRateLookup[6] = 24000;
456
+ $AACsampleRateLookup[7] = 22050;
457
+ $AACsampleRateLookup[8] = 16000;
458
+ $AACsampleRateLookup[9] = 12000;
459
+ $AACsampleRateLookup[10] = 11025;
460
+ $AACsampleRateLookup[11] = 8000;
461
+ $AACsampleRateLookup[12] = 0;
462
+ $AACsampleRateLookup[13] = 0;
463
+ $AACsampleRateLookup[14] = 0;
464
+ $AACsampleRateLookup[15] = 0;
465
+ }
466
+ return (isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid');
467
+ }
468
+
469
+ public static function AACprofileLookup($profileid, $mpegversion) {
470
+ static $AACprofileLookup = array();
471
+ if (empty($AACprofileLookup)) {
472
+ $AACprofileLookup[2][0] = 'Main profile';
473
+ $AACprofileLookup[2][1] = 'Low Complexity profile (LC)';
474
+ $AACprofileLookup[2][2] = 'Scalable Sample Rate profile (SSR)';
475
+ $AACprofileLookup[2][3] = '(reserved)';
476
+ $AACprofileLookup[4][0] = 'AAC_MAIN';
477
+ $AACprofileLookup[4][1] = 'AAC_LC';
478
+ $AACprofileLookup[4][2] = 'AAC_SSR';
479
+ $AACprofileLookup[4][3] = 'AAC_LTP';
480
+ }
481
+ return (isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid');
482
+ }
483
+
484
+ public static function AACchannelCountCalculate($program_configs) {
485
+ $channels = 0;
486
+ for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) {
487
+ $channels++;
488
+ if ($program_configs['front_element_is_cpe'][$i]) {
489
+ // each front element is channel pair (CPE = Channel Pair Element)
490
+ $channels++;
491
+ }
492
+ }
493
+ for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) {
494
+ $channels++;
495
+ if ($program_configs['side_element_is_cpe'][$i]) {
496
+ // each side element is channel pair (CPE = Channel Pair Element)
497
+ $channels++;
498
+ }
499
+ }
500
+ for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) {
501
+ $channels++;
502
+ if ($program_configs['back_element_is_cpe'][$i]) {
503
+ // each back element is channel pair (CPE = Channel Pair Element)
504
+ $channels++;
505
+ }
506
+ }
507
+ for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) {
508
+ $channels++;
509
+ }
510
+ return $channels;
511
+ }
512
+
513
+ }
 
 
getid3/module.audio.flac.php ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // See readme.txt for more details //
9
+ /////////////////////////////////////////////////////////////////
10
+ // //
11
+ // module.audio.flac.php //
12
+ // module for analyzing FLAC and OggFLAC audio files //
13
+ // dependencies: module.audio.ogg.php //
14
+ // ///
15
+ /////////////////////////////////////////////////////////////////
16
+
17
+
18
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true);
19
+
20
+ /**
21
+ * @tutorial http://flac.sourceforge.net/format.html
22
+ */
23
+ class getid3_flac extends getid3_handler
24
+ {
25
+ const syncword = 'fLaC';
26
+
27
+ public function Analyze() {
28
+ $info = &$this->getid3->info;
29
+
30
+ $this->fseek($info['avdataoffset']);
31
+ $StreamMarker = $this->fread(4);
32
+ if ($StreamMarker != self::syncword) {
33
+ return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($StreamMarker).'"');
34
+ }
35
+ $info['fileformat'] = 'flac';
36
+ $info['audio']['dataformat'] = 'flac';
37
+ $info['audio']['bitrate_mode'] = 'vbr';
38
+ $info['audio']['lossless'] = true;
39
+
40
+ // parse flac container
41
+ return $this->parseMETAdata();
42
+ }
43
+
44
+ public function parseMETAdata() {
45
+ $info = &$this->getid3->info;
46
+ do {
47
+ $BlockOffset = $this->ftell();
48
+ $BlockHeader = $this->fread(4);
49
+ $LBFBT = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1));
50
+ $LastBlockFlag = (bool) ($LBFBT & 0x80);
51
+ $BlockType = ($LBFBT & 0x7F);
52
+ $BlockLength = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3));
53
+ $BlockTypeText = self::metaBlockTypeLookup($BlockType);
54
+
55
+ if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) {
56
+ $this->error('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file');
57
+ break;
58
+ }
59
+ if ($BlockLength < 1) {
60
+ $this->error('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockLength.') at offset '.$BlockOffset.' is invalid');
61
+ break;
62
+ }
63
+
64
+ $info['flac'][$BlockTypeText]['raw'] = array();
65
+ $BlockTypeText_raw = &$info['flac'][$BlockTypeText]['raw'];
66
+
67
+ $BlockTypeText_raw['offset'] = $BlockOffset;
68
+ $BlockTypeText_raw['last_meta_block'] = $LastBlockFlag;
69
+ $BlockTypeText_raw['block_type'] = $BlockType;
70
+ $BlockTypeText_raw['block_type_text'] = $BlockTypeText;
71
+ $BlockTypeText_raw['block_length'] = $BlockLength;
72
+ if ($BlockTypeText_raw['block_type'] != 0x06) { // do not read attachment data automatically
73
+ $BlockTypeText_raw['block_data'] = $this->fread($BlockLength);
74
+ }
75
+
76
+ switch ($BlockTypeText) {
77
+ case 'STREAMINFO': // 0x00
78
+ if (!$this->parseSTREAMINFO($BlockTypeText_raw['block_data'])) {
79
+ return false;
80
+ }
81
+ break;
82
+
83
+ case 'PADDING': // 0x01
84
+ unset($info['flac']['PADDING']); // ignore
85
+ break;
86
+
87
+ case 'APPLICATION': // 0x02
88
+ if (!$this->parseAPPLICATION($BlockTypeText_raw['block_data'])) {
89
+ return false;
90
+ }
91
+ break;
92
+
93
+ case 'SEEKTABLE': // 0x03
94
+ if (!$this->parseSEEKTABLE($BlockTypeText_raw['block_data'])) {
95
+ return false;
96
+ }
97
+ break;
98
+
99
+ case 'VORBIS_COMMENT': // 0x04
100
+ if (!$this->parseVORBIS_COMMENT($BlockTypeText_raw['block_data'])) {
101
+ return false;
102
+ }
103
+ break;
104
+
105
+ case 'CUESHEET': // 0x05
106
+ if (!$this->parseCUESHEET($BlockTypeText_raw['block_data'])) {
107
+ return false;
108
+ }
109
+ break;
110
+
111
+ case 'PICTURE': // 0x06
112
+ if (!$this->parsePICTURE()) {
113
+ return false;
114
+ }
115
+ break;
116
+
117
+ default:
118
+ $this->warning('Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockType.') at offset '.$BlockOffset);
119
+ }
120
+
121
+ unset($info['flac'][$BlockTypeText]['raw']);
122
+ $info['avdataoffset'] = $this->ftell();
123
+ }
124
+ while ($LastBlockFlag === false);
125
+
126
+ // handle tags
127
+ if (!empty($info['flac']['VORBIS_COMMENT']['comments'])) {
128
+ $info['flac']['comments'] = $info['flac']['VORBIS_COMMENT']['comments'];
129
+ }
130
+ if (!empty($info['flac']['VORBIS_COMMENT']['vendor'])) {
131
+ $info['audio']['encoder'] = str_replace('reference ', '', $info['flac']['VORBIS_COMMENT']['vendor']);
132
+ }
133
+
134
+ // copy attachments to 'comments' array if nesesary
135
+ if (isset($info['flac']['PICTURE']) && ($this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE)) {
136
+ foreach ($info['flac']['PICTURE'] as $entry) {
137
+ if (!empty($entry['data'])) {
138
+ $info['flac']['comments']['picture'][] = array('image_mime'=>$entry['image_mime'], 'data'=>$entry['data']);
139
+ }
140
+ }
141
+ }
142
+
143
+ if (isset($info['flac']['STREAMINFO'])) {
144
+ if (!$this->isDependencyFor('matroska')) {
145
+ $info['flac']['compressed_audio_bytes'] = $info['avdataend'] - $info['avdataoffset'];
146
+ }
147
+ $info['flac']['uncompressed_audio_bytes'] = $info['flac']['STREAMINFO']['samples_stream'] * $info['flac']['STREAMINFO']['channels'] * ($info['flac']['STREAMINFO']['bits_per_sample'] / 8);
148
+ if ($info['flac']['uncompressed_audio_bytes'] == 0) {
149
+ return $this->error('Corrupt FLAC file: uncompressed_audio_bytes == zero');
150
+ }
151
+ if (!empty($info['flac']['compressed_audio_bytes'])) {
152
+ $info['flac']['compression_ratio'] = $info['flac']['compressed_audio_bytes'] / $info['flac']['uncompressed_audio_bytes'];
153
+ }
154
+ }
155
+
156
+ // set md5_data_source - built into flac 0.5+
157
+ if (isset($info['flac']['STREAMINFO']['audio_signature'])) {
158
+
159
+ if ($info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) {
160
+ $this->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)');
161
+ }
162
+ else {
163
+ $info['md5_data_source'] = '';
164
+ $md5 = $info['flac']['STREAMINFO']['audio_signature'];
165
+ for ($i = 0; $i < strlen($md5); $i++) {
166
+ $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT);
167
+ }
168
+ if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) {
169
+ unset($info['md5_data_source']);
170
+ }
171
+ }
172
+ }
173
+
174
+ if (isset($info['flac']['STREAMINFO']['bits_per_sample'])) {
175
+ $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample'];
176
+ if ($info['audio']['bits_per_sample'] == 8) {
177
+ // special case
178
+ // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value
179
+ // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed
180
+ $this->warning('FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file');
181
+ }
182
+ }
183
+
184
+ return true;
185
+ }
186
+
187
+ private function parseSTREAMINFO($BlockData) {
188
+ $info = &$this->getid3->info;
189
+
190
+ $info['flac']['STREAMINFO'] = array();
191
+ $streaminfo = &$info['flac']['STREAMINFO'];
192
+
193
+ $streaminfo['min_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2));
194
+ $streaminfo['max_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2));
195
+ $streaminfo['min_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3));
196
+ $streaminfo['max_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3));
197
+
198
+ $SRCSBSS = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8));
199
+ $streaminfo['sample_rate'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 0, 20));
200
+ $streaminfo['channels'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 20, 3)) + 1;
201
+ $streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23, 5)) + 1;
202
+ $streaminfo['samples_stream'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36));
203
+
204
+ $streaminfo['audio_signature'] = substr($BlockData, 18, 16);
205
+
206
+ if (!empty($streaminfo['sample_rate'])) {
207
+
208
+ $info['audio']['bitrate_mode'] = 'vbr';
209
+ $info['audio']['sample_rate'] = $streaminfo['sample_rate'];
210
+ $info['audio']['channels'] = $streaminfo['channels'];
211
+ $info['audio']['bits_per_sample'] = $streaminfo['bits_per_sample'];
212
+ $info['playtime_seconds'] = $streaminfo['samples_stream'] / $streaminfo['sample_rate'];
213
+ if ($info['playtime_seconds'] > 0) {
214
+ if (!$this->isDependencyFor('matroska')) {
215
+ $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
216
+ }
217
+ else {
218
+ $this->warning('Cannot determine audio bitrate because total stream size is unknown');
219
+ }
220
+ }
221
+
222
+ } else {
223
+ return $this->error('Corrupt METAdata block: STREAMINFO');
224
+ }
225
+
226
+ return true;
227
+ }
228
+
229
+ private function parseAPPLICATION($BlockData) {
230
+ $info = &$this->getid3->info;
231
+
232
+ $ApplicationID = getid3_lib::BigEndian2Int(substr($BlockData, 0, 4));
233
+ $info['flac']['APPLICATION'][$ApplicationID]['name'] = self::applicationIDLookup($ApplicationID);
234
+ $info['flac']['APPLICATION'][$ApplicationID]['data'] = substr($BlockData, 4);
235
+
236
+ return true;
237
+ }
238
+
239
+ private function parseSEEKTABLE($BlockData) {
240
+ $info = &$this->getid3->info;
241
+
242
+ $offset = 0;
243
+ $BlockLength = strlen($BlockData);
244
+ $placeholderpattern = str_repeat("\xFF", 8);
245
+ while ($offset < $BlockLength) {
246
+ $SampleNumberString = substr($BlockData, $offset, 8);
247
+ $offset += 8;
248
+ if ($SampleNumberString == $placeholderpattern) {
249
+
250
+ // placeholder point
251
+ getid3_lib::safe_inc($info['flac']['SEEKTABLE']['placeholders'], 1);
252
+ $offset += 10;
253
+
254
+ } else {
255
+
256
+ $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString);
257
+ $info['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
258
+ $offset += 8;
259
+ $info['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 2));
260
+ $offset += 2;
261
+
262
+ }
263
+ }
264
+
265
+ return true;
266
+ }
267
+
268
+ private function parseVORBIS_COMMENT($BlockData) {
269
+ $info = &$this->getid3->info;
270
+
271
+ $getid3_ogg = new getid3_ogg($this->getid3);
272
+ if ($this->isDependencyFor('matroska')) {
273
+ $getid3_ogg->setStringMode($this->data_string);
274
+ }
275
+ $getid3_ogg->ParseVorbisComments();
276
+ if (isset($info['ogg'])) {
277
+ unset($info['ogg']['comments_raw']);
278
+ $info['flac']['VORBIS_COMMENT'] = $info['ogg'];
279
+ unset($info['ogg']);
280
+ }
281
+
282
+ unset($getid3_ogg);
283
+
284
+ return true;
285
+ }
286
+
287
+ private function parseCUESHEET($BlockData) {
288
+ $info = &$this->getid3->info;
289
+ $offset = 0;
290
+ $info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($BlockData, $offset, 128), "\0");
291
+ $offset += 128;
292
+ $info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
293
+ $offset += 8;
294
+ $info['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)) & 0x80);
295
+ $offset += 1;
296
+
297
+ $offset += 258; // reserved
298
+
299
+ $info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
300
+ $offset += 1;
301
+
302
+ for ($track = 0; $track < $info['flac']['CUESHEET']['number_tracks']; $track++) {
303
+ $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
304
+ $offset += 8;
305
+ $TrackNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
306
+ $offset += 1;
307
+
308
+ $info['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset;
309
+
310
+ $info['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($BlockData, $offset, 12);
311
+ $offset += 12;
312
+
313
+ $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
314
+ $offset += 1;
315
+ $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80);
316
+ $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40);
317
+
318
+ $offset += 13; // reserved
319
+
320
+ $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
321
+ $offset += 1;
322
+
323
+ for ($index = 0; $index < $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) {
324
+ $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
325
+ $offset += 8;
326
+ $IndexNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
327
+ $offset += 1;
328
+
329
+ $offset += 3; // reserved
330
+
331
+ $info['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset;
332
+ }
333
+ }
334
+
335
+ return true;
336
+ }
337
+
338
+ /**
339
+ * Parse METADATA_BLOCK_PICTURE flac structure and extract attachment
340
+ * External usage: audio.ogg
341
+ */
342
+ public function parsePICTURE() {
343
+ $info = &$this->getid3->info;
344
+
345
+ $picture['typeid'] = getid3_lib::BigEndian2Int($this->fread(4));
346
+ $picture['type'] = self::pictureTypeLookup($picture['typeid']);
347
+ $picture['image_mime'] = $this->fread(getid3_lib::BigEndian2Int($this->fread(4)));
348
+ $descr_length = getid3_lib::BigEndian2Int($this->fread(4));
349
+ if ($descr_length) {
350
+ $picture['description'] = $this->fread($descr_length);
351
+ }
352
+ $picture['width'] = getid3_lib::BigEndian2Int($this->fread(4));
353
+ $picture['height'] = getid3_lib::BigEndian2Int($this->fread(4));
354
+ $picture['color_depth'] = getid3_lib::BigEndian2Int($this->fread(4));
355
+ $picture['colors_indexed'] = getid3_lib::BigEndian2Int($this->fread(4));
356
+ $data_length = getid3_lib::BigEndian2Int($this->fread(4));
357
+
358
+ if ($picture['image_mime'] == '-->') {
359
+ $picture['data'] = $this->fread($data_length);
360
+ } else {
361
+ $picture['data'] = $this->saveAttachment(
362
+ str_replace('/', '_', $picture['type']).'_'.$this->ftell(),
363
+ $this->ftell(),
364
+ $data_length,
365
+ $picture['image_mime']);
366
+ }
367
+
368
+ $info['flac']['PICTURE'][] = $picture;
369
+
370
+ return true;
371
+ }
372
+
373
+ public static function metaBlockTypeLookup($blocktype) {
374
+ static $lookup = array(
375
+ 0 => 'STREAMINFO',
376
+ 1 => 'PADDING',
377
+ 2 => 'APPLICATION',
378
+ 3 => 'SEEKTABLE',
379
+ 4 => 'VORBIS_COMMENT',
380
+ 5 => 'CUESHEET',
381
+ 6 => 'PICTURE',
382
+ );
383
+ return (isset($lookup[$blocktype]) ? $lookup[$blocktype] : 'reserved');
384
+ }
385
+
386
+ public static function applicationIDLookup($applicationid) {
387
+ // http://flac.sourceforge.net/id.html
388
+ static $lookup = array(
389
+ 0x41544348 => 'FlacFile', // "ATCH"
390
+ 0x42534F4C => 'beSolo', // "BSOL"
391
+ 0x42554753 => 'Bugs Player', // "BUGS"
392
+ 0x43756573 => 'GoldWave cue points (specification)', // "Cues"
393
+ 0x46696361 => 'CUE Splitter', // "Fica"
394
+ 0x46746F6C => 'flac-tools', // "Ftol"
395
+ 0x4D4F5442 => 'MOTB MetaCzar', // "MOTB"
396
+ 0x4D505345 => 'MP3 Stream Editor', // "MPSE"
397
+ 0x4D754D4C => 'MusicML: Music Metadata Language', // "MuML"
398
+ 0x52494646 => 'Sound Devices RIFF chunk storage', // "RIFF"
399
+ 0x5346464C => 'Sound Font FLAC', // "SFFL"
400
+ 0x534F4E59 => 'Sony Creative Software', // "SONY"
401
+ 0x5351455A => 'flacsqueeze', // "SQEZ"
402
+ 0x54745776 => 'TwistedWave', // "TtWv"
403
+ 0x55495453 => 'UITS Embedding tools', // "UITS"
404
+ 0x61696666 => 'FLAC AIFF chunk storage', // "aiff"
405
+ 0x696D6167 => 'flac-image application for storing arbitrary files in APPLICATION metadata blocks', // "imag"
406
+ 0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // "peem"
407
+ 0x71667374 => 'QFLAC Studio', // "qfst"
408
+ 0x72696666 => 'FLAC RIFF chunk storage', // "riff"
409
+ 0x74756E65 => 'TagTuner', // "tune"
410
+ 0x78626174 => 'XBAT', // "xbat"
411
+ 0x786D6364 => 'xmcd', // "xmcd"
412
+ );
413
+ return (isset($lookup[$applicationid]) ? $lookup[$applicationid] : 'reserved');
414
+ }
415
+
416
+ public static function pictureTypeLookup($type_id) {
417
+ static $lookup = array (
418
+ 0 => 'Other',
419
+ 1 => '32x32 pixels \'file icon\' (PNG only)',
420
+ 2 => 'Other file icon',
421
+ 3 => 'Cover (front)',
422
+ 4 => 'Cover (back)',
423
+ 5 => 'Leaflet page',
424
+ 6 => 'Media (e.g. label side of CD)',
425
+ 7 => 'Lead artist/lead performer/soloist',
426
+ 8 => 'Artist/performer',
427
+ 9 => 'Conductor',
428
+ 10 => 'Band/Orchestra',
429
+ 11 => 'Composer',
430
+ 12 => 'Lyricist/text writer',
431
+ 13 => 'Recording Location',
432
+ 14 => 'During recording',
433
+ 15 => 'During performance',
434
+ 16 => 'Movie/video screen capture',
435
+ 17 => 'A bright coloured fish',
436
+ 18 => 'Illustration',
437
+ 19 => 'Band/artist logotype',
438
+ 20 => 'Publisher/Studio logotype',
439
+ );
440
+ return (isset($lookup[$type_id]) ? $lookup[$type_id] : 'reserved');
441
+ }
442
+
443
+ }
getid3/module.audio.mp3.php CHANGED
@@ -1,2011 +1,2012 @@
1
- <?php
2
- /////////////////////////////////////////////////////////////////
3
- /// getID3() by James Heinrich <info@getid3.org> //
4
- // available at http://getid3.sourceforge.net //
5
- // or http://www.getid3.org //
6
- /////////////////////////////////////////////////////////////////
7
- // See readme.txt for more details //
8
- /////////////////////////////////////////////////////////////////
9
- // //
10
- // module.audio.mp3.php //
11
- // module for analyzing MP3 files //
12
- // dependencies: NONE //
13
- // ///
14
- /////////////////////////////////////////////////////////////////
15
-
16
-
17
- // number of frames to scan to determine if MPEG-audio sequence is valid
18
- // Lower this number to 5-20 for faster scanning
19
- // Increase this number to 50+ for most accurate detection of valid VBR/CBR
20
- // mpeg-audio streams
21
- define('GETID3_MP3_VALID_CHECK_FRAMES', 35);
22
-
23
-
24
- class getid3_mp3 extends getid3_handler
25
- {
26
-
27
- var $allow_bruteforce = false; // forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, unrecommended, but may provide data from otherwise-unusuable files
28
-
29
- function Analyze() {
30
- $info = &$this->getid3->info;
31
-
32
- $initialOffset = $info['avdataoffset'];
33
-
34
- if (!$this->getOnlyMPEGaudioInfo($info['avdataoffset'])) {
35
- if ($this->allow_bruteforce) {
36
- $info['error'][] = 'Rescanning file in BruteForce mode';
37
- $this->getOnlyMPEGaudioInfoBruteForce($this->getid3->fp, $info);
38
- }
39
- }
40
-
41
-
42
- if (isset($info['mpeg']['audio']['bitrate_mode'])) {
43
- $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
44
- }
45
-
46
- if (((isset($info['id3v2']['headerlength']) && ($info['avdataoffset'] > $info['id3v2']['headerlength'])) || (!isset($info['id3v2']) && ($info['avdataoffset'] > 0) && ($info['avdataoffset'] != $initialOffset)))) {
47
-
48
- $synchoffsetwarning = 'Unknown data before synch ';
49
- if (isset($info['id3v2']['headerlength'])) {
50
- $synchoffsetwarning .= '(ID3v2 header ends at '.$info['id3v2']['headerlength'].', then '.($info['avdataoffset'] - $info['id3v2']['headerlength']).' bytes garbage, ';
51
- } elseif ($initialOffset > 0) {
52
- $synchoffsetwarning .= '(should be at '.$initialOffset.', ';
53
- } else {
54
- $synchoffsetwarning .= '(should be at beginning of file, ';
55
- }
56
- $synchoffsetwarning .= 'synch detected at '.$info['avdataoffset'].')';
57
- if (isset($info['audio']['bitrate_mode']) && ($info['audio']['bitrate_mode'] == 'cbr')) {
58
-
59
- if (!empty($info['id3v2']['headerlength']) && (($info['avdataoffset'] - $info['id3v2']['headerlength']) == $info['mpeg']['audio']['framelength'])) {
60
-
61
- $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.';
62
- $info['audio']['codec'] = 'LAME';
63
- $CurrentDataLAMEversionString = 'LAME3.';
64
-
65
- } elseif (empty($info['id3v2']['headerlength']) && ($info['avdataoffset'] == $info['mpeg']['audio']['framelength'])) {
66
-
67
- $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.';
68
- $info['audio']['codec'] = 'LAME';
69
- $CurrentDataLAMEversionString = 'LAME3.';
70
-
71
- }
72
-
73
- }
74
- $info['warning'][] = $synchoffsetwarning;
75
-
76
- }
77
-
78
- if (isset($info['mpeg']['audio']['LAME'])) {
79
- $info['audio']['codec'] = 'LAME';
80
- if (!empty($info['mpeg']['audio']['LAME']['long_version'])) {
81
- $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['long_version'], "\x00");
82
- } elseif (!empty($info['mpeg']['audio']['LAME']['short_version'])) {
83
- $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['short_version'], "\x00");
84
- }
85
- }
86
-
87
- $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : (isset($info['audio']['encoder']) ? $info['audio']['encoder'] : ''));
88
- if (!empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) == 'LAME3.') && !preg_match('[0-9\)]', substr($CurrentDataLAMEversionString, -1))) {
89
- // a version number of LAME that does not end with a number like "LAME3.92"
90
- // or with a closing parenthesis like "LAME3.88 (alpha)"
91
- // or a version of LAME with the LAMEtag-not-filled-in-DLL-mode bug (3.90-3.92)
92
-
93
- // not sure what the actual last frame length will be, but will be less than or equal to 1441
94
- $PossiblyLongerLAMEversion_FrameLength = 1441;
95
-
96
- // Not sure what version of LAME this is - look in padding of last frame for longer version string
97
- $PossibleLAMEversionStringOffset = $info['avdataend'] - $PossiblyLongerLAMEversion_FrameLength;
98
- fseek($this->getid3->fp, $PossibleLAMEversionStringOffset);
99
- $PossiblyLongerLAMEversion_Data = fread($this->getid3->fp, $PossiblyLongerLAMEversion_FrameLength);
100
- switch (substr($CurrentDataLAMEversionString, -1)) {
101
- case 'a':
102
- case 'b':
103
- // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example
104
- // need to trim off "a" to match longer string
105
- $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, -1);
106
- break;
107
- }
108
- if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !== false) {
109
- if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) {
110
- $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)"
111
- if (empty($info['audio']['encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen($info['audio']['encoder']))) {
112
- $info['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString;
113
- }
114
- }
115
- }
116
- }
117
- if (!empty($info['audio']['encoder'])) {
118
- $info['audio']['encoder'] = rtrim($info['audio']['encoder'], "\x00 ");
119
- }
120
-
121
- switch (isset($info['mpeg']['audio']['layer']) ? $info['mpeg']['audio']['layer'] : '') {
122
- case 1:
123
- case 2:
124
- $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
125
- break;
126
- }
127
- if (isset($info['fileformat']) && ($info['fileformat'] == 'mp3')) {
128
- switch ($info['audio']['dataformat']) {
129
- case 'mp1':
130
- case 'mp2':
131
- case 'mp3':
132
- $info['fileformat'] = $info['audio']['dataformat'];
133
- break;
134
-
135
- default:
136
- $info['warning'][] = 'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"';
137
- break;
138
- }
139
- }
140
-
141
- if (empty($info['fileformat'])) {
142
- unset($info['fileformat']);
143
- unset($info['audio']['bitrate_mode']);
144
- unset($info['avdataoffset']);
145
- unset($info['avdataend']);
146
- return false;
147
- }
148
-
149
- $info['mime_type'] = 'audio/mpeg';
150
- $info['audio']['lossless'] = false;
151
-
152
- // Calculate playtime
153
- if (!isset($info['playtime_seconds']) && isset($info['audio']['bitrate']) && ($info['audio']['bitrate'] > 0)) {
154
- $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['audio']['bitrate'];
155
- }
156
-
157
- $info['audio']['encoder_options'] = $this->GuessEncoderOptions();
158
-
159
- return true;
160
- }
161
-
162
-
163
- function GuessEncoderOptions() {
164
- // shortcuts
165
- $info = &$this->getid3->info;
166
- if (!empty($info['mpeg']['audio'])) {
167
- $thisfile_mpeg_audio = &$info['mpeg']['audio'];
168
- if (!empty($thisfile_mpeg_audio['LAME'])) {
169
- $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
170
- }
171
- }
172
-
173
- $encoder_options = '';
174
- static $NamedPresetBitrates = array(16, 24, 40, 56, 112, 128, 160, 192, 256);
175
-
176
- if (isset($thisfile_mpeg_audio['VBR_method']) && ($thisfile_mpeg_audio['VBR_method'] == 'Fraunhofer') && !empty($thisfile_mpeg_audio['VBR_quality'])) {
177
-
178
- $encoder_options = 'VBR q'.$thisfile_mpeg_audio['VBR_quality'];
179
-
180
- } elseif (!empty($thisfile_mpeg_audio_lame['preset_used']) && (!in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates))) {
181
-
182
- $encoder_options = $thisfile_mpeg_audio_lame['preset_used'];
183
-
184
- } elseif (!empty($thisfile_mpeg_audio_lame['vbr_quality'])) {
185
-
186
- static $KnownEncoderValues = array();
187
- if (empty($KnownEncoderValues)) {
188
-
189
- //$KnownEncoderValues[abrbitrate_minbitrate][vbr_quality][raw_vbr_method][raw_noise_shaping][raw_stereo_mode][ath_type][lowpass_frequency] = 'preset name';
190
- $KnownEncoderValues[0xFF][58][1][1][3][2][20500] = '--alt-preset insane'; // 3.90, 3.90.1, 3.92
191
- $KnownEncoderValues[0xFF][58][1][1][3][2][20600] = '--alt-preset insane'; // 3.90.2, 3.90.3, 3.91
192
- $KnownEncoderValues[0xFF][57][1][1][3][4][20500] = '--alt-preset insane'; // 3.94, 3.95
193
- $KnownEncoderValues['**'][78][3][2][3][2][19500] = '--alt-preset extreme'; // 3.90, 3.90.1, 3.92
194
- $KnownEncoderValues['**'][78][3][2][3][2][19600] = '--alt-preset extreme'; // 3.90.2, 3.91
195
- $KnownEncoderValues['**'][78][3][1][3][2][19600] = '--alt-preset extreme'; // 3.90.3
196
- $KnownEncoderValues['**'][78][4][2][3][2][19500] = '--alt-preset fast extreme'; // 3.90, 3.90.1, 3.92
197
- $KnownEncoderValues['**'][78][4][2][3][2][19600] = '--alt-preset fast extreme'; // 3.90.2, 3.90.3, 3.91
198
- $KnownEncoderValues['**'][78][3][2][3][4][19000] = '--alt-preset standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
199
- $KnownEncoderValues['**'][78][3][1][3][4][19000] = '--alt-preset standard'; // 3.90.3
200
- $KnownEncoderValues['**'][78][4][2][3][4][19000] = '--alt-preset fast standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
201
- $KnownEncoderValues['**'][78][4][1][3][4][19000] = '--alt-preset fast standard'; // 3.90.3
202
- $KnownEncoderValues['**'][88][4][1][3][3][19500] = '--r3mix'; // 3.90, 3.90.1, 3.92
203
- $KnownEncoderValues['**'][88][4][1][3][3][19600] = '--r3mix'; // 3.90.2, 3.90.3, 3.91
204
- $KnownEncoderValues['**'][67][4][1][3][4][18000] = '--r3mix'; // 3.94, 3.95
205
- $KnownEncoderValues['**'][68][3][2][3][4][18000] = '--alt-preset medium'; // 3.90.3
206
- $KnownEncoderValues['**'][68][4][2][3][4][18000] = '--alt-preset fast medium'; // 3.90.3
207
-
208
- $KnownEncoderValues[0xFF][99][1][1][1][2][0] = '--preset studio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
209
- $KnownEncoderValues[0xFF][58][2][1][3][2][20600] = '--preset studio'; // 3.90.3, 3.93.1
210
- $KnownEncoderValues[0xFF][58][2][1][3][2][20500] = '--preset studio'; // 3.93
211
- $KnownEncoderValues[0xFF][57][2][1][3][4][20500] = '--preset studio'; // 3.94, 3.95
212
- $KnownEncoderValues[0xC0][88][1][1][1][2][0] = '--preset cd'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
213
- $KnownEncoderValues[0xC0][58][2][2][3][2][19600] = '--preset cd'; // 3.90.3, 3.93.1
214
- $KnownEncoderValues[0xC0][58][2][2][3][2][19500] = '--preset cd'; // 3.93
215
- $KnownEncoderValues[0xC0][57][2][1][3][4][19500] = '--preset cd'; // 3.94, 3.95
216
- $KnownEncoderValues[0xA0][78][1][1][3][2][18000] = '--preset hifi'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
217
- $KnownEncoderValues[0xA0][58][2][2][3][2][18000] = '--preset hifi'; // 3.90.3, 3.93, 3.93.1
218
- $KnownEncoderValues[0xA0][57][2][1][3][4][18000] = '--preset hifi'; // 3.94, 3.95
219
- $KnownEncoderValues[0x80][67][1][1][3][2][18000] = '--preset tape'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
220
- $KnownEncoderValues[0x80][67][1][1][3][2][15000] = '--preset radio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
221
- $KnownEncoderValues[0x70][67][1][1][3][2][15000] = '--preset fm'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
222
- $KnownEncoderValues[0x70][58][2][2][3][2][16000] = '--preset tape/radio/fm'; // 3.90.3, 3.93, 3.93.1
223
- $KnownEncoderValues[0x70][57][2][1][3][4][16000] = '--preset tape/radio/fm'; // 3.94, 3.95
224
- $KnownEncoderValues[0x38][58][2][2][0][2][10000] = '--preset voice'; // 3.90.3, 3.93, 3.93.1
225
- $KnownEncoderValues[0x38][57][2][1][0][4][15000] = '--preset voice'; // 3.94, 3.95
226
- $KnownEncoderValues[0x38][57][2][1][0][4][16000] = '--preset voice'; // 3.94a14
227
- $KnownEncoderValues[0x28][65][1][1][0][2][7500] = '--preset mw-us'; // 3.90, 3.90.1, 3.92
228
- $KnownEncoderValues[0x28][65][1][1][0][2][7600] = '--preset mw-us'; // 3.90.2, 3.91
229
- $KnownEncoderValues[0x28][58][2][2][0][2][7000] = '--preset mw-us'; // 3.90.3, 3.93, 3.93.1
230
- $KnownEncoderValues[0x28][57][2][1][0][4][10500] = '--preset mw-us'; // 3.94, 3.95
231
- $KnownEncoderValues[0x28][57][2][1][0][4][11200] = '--preset mw-us'; // 3.94a14
232
- $KnownEncoderValues[0x28][57][2][1][0][4][8800] = '--preset mw-us'; // 3.94a15
233
- $KnownEncoderValues[0x18][58][2][2][0][2][4000] = '--preset phon+/lw/mw-eu/sw'; // 3.90.3, 3.93.1
234
- $KnownEncoderValues[0x18][58][2][2][0][2][3900] = '--preset phon+/lw/mw-eu/sw'; // 3.93
235
- $KnownEncoderValues[0x18][57][2][1][0][4][5900] = '--preset phon+/lw/mw-eu/sw'; // 3.94, 3.95
236
- $KnownEncoderValues[0x18][57][2][1][0][4][6200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a14
237
- $KnownEncoderValues[0x18][57][2][1][0][4][3200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a15
238
- $KnownEncoderValues[0x10][58][2][2][0][2][3800] = '--preset phone'; // 3.90.3, 3.93.1
239
- $KnownEncoderValues[0x10][58][2][2][0][2][3700] = '--preset phone'; // 3.93
240
- $KnownEncoderValues[0x10][57][2][1][0][4][5600] = '--preset phone'; // 3.94, 3.95
241
- }
242
-
243
- if (isset($KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) {
244
-
245
- $encoder_options = $KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']];
246
-
247
- } elseif (isset($KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) {
248
-
249
- $encoder_options = $KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']];
250
-
251
- } elseif ($info['audio']['bitrate_mode'] == 'vbr') {
252
-
253
- // http://gabriel.mp3-tech.org/mp3infotag.html
254
- // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h
255
-
256
-
257
- $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame['vbr_quality'] / 10);
258
- $LAME_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($LAME_V_value * 10);
259
- $encoder_options = '-V'.$LAME_V_value.' -q'.$LAME_q_value;
260
-
261
- } elseif ($info['audio']['bitrate_mode'] == 'cbr') {
262
-
263
- $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
264
-
265
- } else {
266
-
267
- $encoder_options = strtoupper($info['audio']['bitrate_mode']);
268
-
269
- }
270
-
271
- } elseif (!empty($thisfile_mpeg_audio_lame['bitrate_abr'])) {
272
-
273
- $encoder_options = 'ABR'.$thisfile_mpeg_audio_lame['bitrate_abr'];
274
-
275
- } elseif (!empty($info['audio']['bitrate'])) {
276
-
277
- if ($info['audio']['bitrate_mode'] == 'cbr') {
278
- $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
279
- } else {
280
- $encoder_options = strtoupper($info['audio']['bitrate_mode']);
281
- }
282
-
283
- }
284
- if (!empty($thisfile_mpeg_audio_lame['bitrate_min'])) {
285
- $encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min'];
286
- }
287
-
288
- if (!empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev']) || !empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])) {
289
- $encoder_options .= ' --nogap';
290
- }
291
-
292
- if (!empty($thisfile_mpeg_audio_lame['lowpass_frequency'])) {
293
- $ExplodedOptions = explode(' ', $encoder_options, 4);
294
- if ($ExplodedOptions[0] == '--r3mix') {
295
- $ExplodedOptions[1] = 'r3mix';
296
- }
297
- switch ($ExplodedOptions[0]) {
298
- case '--preset':
299
- case '--alt-preset':
300
- case '--r3mix':
301
- if ($ExplodedOptions[1] == 'fast') {
302
- $ExplodedOptions[1] .= ' '.$ExplodedOptions[2];
303
- }
304
- switch ($ExplodedOptions[1]) {
305
- case 'portable':
306
- case 'medium':
307
- case 'standard':
308
- case 'extreme':
309
- case 'insane':
310
- case 'fast portable':
311
- case 'fast medium':
312
- case 'fast standard':
313
- case 'fast extreme':
314
- case 'fast insane':
315
- case 'r3mix':
316
- static $ExpectedLowpass = array(
317
- 'insane|20500' => 20500,
318
- 'insane|20600' => 20600, // 3.90.2, 3.90.3, 3.91
319
- 'medium|18000' => 18000,
320
- 'fast medium|18000' => 18000,
321
- 'extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
322
- 'extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
323
- 'fast extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
324
- 'fast extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
325
- 'standard|19000' => 19000,
326
- 'fast standard|19000' => 19000,
327
- 'r3mix|19500' => 19500, // 3.90, 3.90.1, 3.92
328
- 'r3mix|19600' => 19600, // 3.90.2, 3.90.3, 3.91
329
- 'r3mix|18000' => 18000, // 3.94, 3.95
330
- );
331
- if (!isset($ExpectedLowpass[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio_lame['lowpass_frequency']]) && ($thisfile_mpeg_audio_lame['lowpass_frequency'] < 22050) && (round($thisfile_mpeg_audio_lame['lowpass_frequency'] / 1000) < round($thisfile_mpeg_audio['sample_rate'] / 2000))) {
332
- $encoder_options .= ' --lowpass '.$thisfile_mpeg_audio_lame['lowpass_frequency'];
333
- }
334
- break;
335
-
336
- default:
337
- break;
338
- }
339
- break;
340
- }
341
- }
342
-
343
- if (isset($thisfile_mpeg_audio_lame['raw']['source_sample_freq'])) {
344
- if (($thisfile_mpeg_audio['sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 1)) {
345
- $encoder_options .= ' --resample 44100';
346
- } elseif (($thisfile_mpeg_audio['sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 2)) {
347
- $encoder_options .= ' --resample 48000';
348
- } elseif ($thisfile_mpeg_audio['sample_rate'] < 44100) {
349
- switch ($thisfile_mpeg_audio_lame['raw']['source_sample_freq']) {
350
- case 0: // <= 32000
351
- // may or may not be same as source frequency - ignore
352
- break;
353
- case 1: // 44100
354
- case 2: // 48000
355
- case 3: // 48000+
356
- $ExplodedOptions = explode(' ', $encoder_options, 4);
357
- switch ($ExplodedOptions[0]) {
358
- case '--preset':
359
- case '--alt-preset':
360
- switch ($ExplodedOptions[1]) {
361
- case 'fast':
362
- case 'portable':
363
- case 'medium':
364
- case 'standard':
365
- case 'extreme':
366
- case 'insane':
367
- $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
368
- break;
369
-
370
- default:
371
- static $ExpectedResampledRate = array(
372
- 'phon+/lw/mw-eu/sw|16000' => 16000,
373
- 'mw-us|24000' => 24000, // 3.95
374
- 'mw-us|32000' => 32000, // 3.93
375
- 'mw-us|16000' => 16000, // 3.92
376
- 'phone|16000' => 16000,
377
- 'phone|11025' => 11025, // 3.94a15
378
- 'radio|32000' => 32000, // 3.94a15
379
- 'fm/radio|32000' => 32000, // 3.92
380
- 'fm|32000' => 32000, // 3.90
381
- 'voice|32000' => 32000);
382
- if (!isset($ExpectedResampledRate[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio['sample_rate']])) {
383
- $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
384
- }
385
- break;
386
- }
387
- break;
388
-
389
- case '--r3mix':
390
- default:
391
- $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
392
- break;
393
- }
394
- break;
395
- }
396
- }
397
- }
398
- if (empty($encoder_options) && !empty($info['audio']['bitrate']) && !empty($info['audio']['bitrate_mode'])) {
399
- //$encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
400
- $encoder_options = strtoupper($info['audio']['bitrate_mode']);
401
- }
402
-
403
- return $encoder_options;
404
- }
405
-
406
-
407
- function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) {
408
- static $MPEGaudioVersionLookup;
409
- static $MPEGaudioLayerLookup;
410
- static $MPEGaudioBitrateLookup;
411
- static $MPEGaudioFrequencyLookup;
412
- static $MPEGaudioChannelModeLookup;
413
- static $MPEGaudioModeExtensionLookup;
414
- static $MPEGaudioEmphasisLookup;
415
- if (empty($MPEGaudioVersionLookup)) {
416
- $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray();
417
- $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray();
418
- $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray();
419
- $MPEGaudioFrequencyLookup = getid3_mp3::MPEGaudioFrequencyArray();
420
- $MPEGaudioChannelModeLookup = getid3_mp3::MPEGaudioChannelModeArray();
421
- $MPEGaudioModeExtensionLookup = getid3_mp3::MPEGaudioModeExtensionArray();
422
- $MPEGaudioEmphasisLookup = getid3_mp3::MPEGaudioEmphasisArray();
423
- }
424
-
425
- if (fseek($this->getid3->fp, $offset, SEEK_SET) != 0) {
426
- $info['error'][] = 'decodeMPEGaudioHeader() failed to seek to next offset at '.$offset;
427
- return false;
428
- }
429
- //$headerstring = fread($this->getid3->fp, 1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame
430
- $headerstring = fread($this->getid3->fp, 226); // LAME header at offset 36 + 190 bytes of Xing/LAME data
431
-
432
- // MP3 audio frame structure:
433
- // $aa $aa $aa $aa [$bb $bb] $cc...
434
- // where $aa..$aa is the four-byte mpeg-audio header (below)
435
- // $bb $bb is the optional 2-byte CRC
436
- // and $cc... is the audio data
437
-
438
- $head4 = substr($headerstring, 0, 4);
439
-
440
- static $MPEGaudioHeaderDecodeCache = array();
441
- if (isset($MPEGaudioHeaderDecodeCache[$head4])) {
442
- $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
443
- } else {
444
- $MPEGheaderRawArray = getid3_mp3::MPEGaudioHeaderDecode($head4);
445
- $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
446
- }
447
-
448
- static $MPEGaudioHeaderValidCache = array();
449
- if (!isset($MPEGaudioHeaderValidCache[$head4])) { // Not in cache
450
- //$MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)
451
- $MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);
452
- }
453
-
454
- // shortcut
455
- if (!isset($info['mpeg']['audio'])) {
456
- $info['mpeg']['audio'] = array();
457
- }
458
- $thisfile_mpeg_audio = &$info['mpeg']['audio'];
459
-
460
-
461
- if ($MPEGaudioHeaderValidCache[$head4]) {
462
- $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray;
463
- } else {
464
- $info['error'][] = 'Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset;
465
- return false;
466
- }
467
-
468
- if (!$FastMPEGheaderScan) {
469
- $thisfile_mpeg_audio['version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']];
470
- $thisfile_mpeg_audio['layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']];
471
-
472
- $thisfile_mpeg_audio['channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio['raw']['channelmode']];
473
- $thisfile_mpeg_audio['channels'] = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2);
474
- $thisfile_mpeg_audio['sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']];
475
- $thisfile_mpeg_audio['protection'] = !$thisfile_mpeg_audio['raw']['protection'];
476
- $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private'];
477
- $thisfile_mpeg_audio['modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']];
478
- $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright'];
479
- $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original'];
480
- $thisfile_mpeg_audio['emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']];
481
-
482
- $info['audio']['channels'] = $thisfile_mpeg_audio['channels'];
483
- $info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate'];
484
-
485
- if ($thisfile_mpeg_audio['protection']) {
486
- $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($headerstring, 4, 2));
487
- }
488
- }
489
-
490
- if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) {
491
- // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0
492
- $info['warning'][] = 'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';
493
- $thisfile_mpeg_audio['raw']['bitrate'] = 0;
494
- }
495
- $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding'];
496
- $thisfile_mpeg_audio['bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']];
497
-
498
- if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $info['avdataoffset'])) {
499
- // only skip multiple frame check if free-format bitstream found at beginning of file
500
- // otherwise is quite possibly simply corrupted data
501
- $recursivesearch = false;
502
- }
503
-
504
- // For Layer 2 there are some combinations of bitrate and mode which are not allowed.
505
- if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio['layer'] == '2')) {
506
-
507
- $info['audio']['dataformat'] = 'mp2';
508
- switch ($thisfile_mpeg_audio['channelmode']) {
509
-
510
- case 'mono':
511
- if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000)) {
512
- // these are ok
513
- } else {
514
- $info['error'][] = $thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
515
- return false;
516
- }
517
- break;
518
-
519
- case 'stereo':
520
- case 'joint stereo':
521
- case 'dual channel':
522
- if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000)) {
523
- // these are ok
524
- } else {
525
- $info['error'][] = intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
526
- return false;
527
- }
528
- break;
529
-
530
- }
531
-
532
- }
533
-
534
-
535
- if ($info['audio']['sample_rate'] > 0) {
536
- $thisfile_mpeg_audio['framelength'] = getid3_mp3::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $info['audio']['sample_rate']);
537
- }
538
-
539
- $nextframetestoffset = $offset + 1;
540
- if ($thisfile_mpeg_audio['bitrate'] != 'free') {
541
-
542
- $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
543
-
544
- if (isset($thisfile_mpeg_audio['framelength'])) {
545
- $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength'];
546
- } else {
547
- $info['error'][] = 'Frame at offset('.$offset.') is has an invalid frame length.';
548
- return false;
549
- }
550
-
551
- }
552
-
553
- $ExpectedNumberOfAudioBytes = 0;
554
-
555
- ////////////////////////////////////////////////////////////////////////////////////
556
- // Variable-bitrate headers
557
-
558
- if (substr($headerstring, 4 + 32, 4) == 'VBRI') {
559
- // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36)
560
- // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html
561
-
562
- $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
563
- $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer';
564
- $info['audio']['codec'] = 'Fraunhofer';
565
-
566
- $SideInfoData = substr($headerstring, 4 + 2, 32);
567
-
568
- $FraunhoferVBROffset = 36;
569
-
570
- $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); // VbriVersion
571
- $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); // VbriDelay
572
- $thisfile_mpeg_audio['VBR_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); // VbriQuality
573
- $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); // VbriStreamBytes
574
- $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); // VbriStreamFrames
575
- $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); // VbriTableSize
576
- $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 2)); // VbriTableScale
577
- $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 22, 2)); // VbriEntryBytes
578
- $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); // VbriEntryFrames
579
-
580
- $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio['VBR_bytes'];
581
-
582
- $previousbyteoffset = $offset;
583
- for ($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i++) {
584
- $Fraunhofer_OffsetN = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, $thisfile_mpeg_audio['VBR_entry_bytes']));
585
- $FraunhoferVBROffset += $thisfile_mpeg_audio['VBR_entry_bytes'];
586
- $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']);
587
- $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']) + $previousbyteoffset;
588
- $previousbyteoffset += $Fraunhofer_OffsetN;
589
- }
590
-
591
-
592
- } else {
593
-
594
- // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36)
595
- // depending on MPEG layer and number of channels
596
-
597
- $VBRidOffset = getid3_mp3::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']);
598
- $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4);
599
-
600
- if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) {
601
- // 'Xing' is traditional Xing VBR frame
602
- // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.)
603
- // 'Info' *can* legally be used to specify a VBR file as well, however.
604
-
605
- // http://www.multiweb.cz/twoinches/MP3inside.htm
606
- //00..03 = "Xing" or "Info"
607
- //04..07 = Flags:
608
- // 0x01 Frames Flag set if value for number of frames in file is stored
609
- // 0x02 Bytes Flag set if value for filesize in bytes is stored
610
- // 0x04 TOC Flag set if values for TOC are stored
611
- // 0x08 VBR Scale Flag set if values for VBR scale is stored
612
- //08..11 Frames: Number of frames in file (including the first Xing/Info one)
613
- //12..15 Bytes: File length in Bytes
614
- //16..115 TOC (Table of Contents):
615
- // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file.
616
- // Each Byte has a value according this formula:
617
- // (TOC[i] / 256) * fileLenInBytes
618
- // So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000 000 Bytes length) you can use:
619
- // TOC[(60/240)*100] = TOC[25]
620
- // and corresponding Byte in file is then approximately at:
621
- // (TOC[25]/256) * 5000000
622
- //116..119 VBR Scale
623
-
624
-
625
- // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME
626
- // if (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Xing') {
627
- $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
628
- $thisfile_mpeg_audio['VBR_method'] = 'Xing';
629
- // } else {
630
- // $ScanAsCBR = true;
631
- // $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
632
- // }
633
-
634
- $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4));
635
-
636
- $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000001);
637
- $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000002);
638
- $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000004);
639
- $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000008);
640
-
641
- if ($thisfile_mpeg_audio['xing_flags']['frames']) {
642
- $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4));
643
- //$thisfile_mpeg_audio['VBR_frames']--; // don't count header Xing/Info frame
644
- }
645
- if ($thisfile_mpeg_audio['xing_flags']['bytes']) {
646
- $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4));
647
- }
648
-
649
- //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
650
- if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
651
-
652
- $framelengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'];
653
-
654
- if ($thisfile_mpeg_audio['layer'] == '1') {
655
- // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
656
- //$info['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12;
657
- $info['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 12;
658
- } else {
659
- // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
660
- //$info['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
661
- $info['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144;
662
- }
663
- $thisfile_mpeg_audio['framelength'] = floor($framelengthfloat);
664
- }
665
-
666
- if ($thisfile_mpeg_audio['xing_flags']['toc']) {
667
- $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100);
668
- for ($i = 0; $i < 100; $i++) {
669
- $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData{$i});
670
- }
671
- }
672
- if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) {
673
- $thisfile_mpeg_audio['VBR_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4));
674
- }
675
-
676
-
677
- // http://gabriel.mp3-tech.org/mp3infotag.html
678
- if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') {
679
-
680
- // shortcut
681
- $thisfile_mpeg_audio['LAME'] = array();
682
- $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
683
-
684
-
685
- $thisfile_mpeg_audio_lame['long_version'] = substr($headerstring, $VBRidOffset + 120, 20);
686
- $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9);
687
-
688
- if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') {
689
-
690
- // extra 11 chars are not part of version string when LAMEtag present
691
- unset($thisfile_mpeg_audio_lame['long_version']);
692
-
693
- // It the LAME tag was only introduced in LAME v3.90
694
- // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933
695
-
696
- // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html
697
- // are assuming a 'Xing' identifier offset of 0x24, which is the case for
698
- // MPEG-1 non-mono, but not for other combinations
699
- $LAMEtagOffsetContant = $VBRidOffset - 0x24;
700
-
701
- // shortcuts
702
- $thisfile_mpeg_audio_lame['RGAD'] = array('track'=>array(), 'album'=>array());
703
- $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD'];
704
- $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track'];
705
- $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album'];
706
- $thisfile_mpeg_audio_lame['raw'] = array();
707
- $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw'];
708
-
709
- // byte $9B VBR Quality
710
- // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications.
711
- // Actually overwrites original Xing bytes
712
- unset($thisfile_mpeg_audio['VBR_scale']);
713
- $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1));
714
-
715
- // bytes $9C-$A4 Encoder short VersionString
716
- $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9);
717
-
718
- // byte $A5 Info Tag revision + VBR method
719
- $LAMEtagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1));
720
-
721
- $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4;
722
- $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F;
723
- $thisfile_mpeg_audio_lame['vbr_method'] = getid3_mp3::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']);
724
- $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr'
725
-
726
- // byte $A6 Lowpass filter value
727
- $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;
728
-
729
- // bytes $A7-$AE Replay Gain
730
- // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
731
- // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude"
732
- if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') {
733
- // LAME 3.94a16 and later - 9.23 fixed point
734
- // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375
735
- $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608);
736
- } else {
737
- // LAME 3.94a15 and earlier - 32-bit floating point
738
- // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15
739
- $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4));
740
- }
741
- if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0) {
742
- unset($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']);
743
- } else {
744
- $thisfile_mpeg_audio_lame_RGAD['peak_db'] = getid3_lib::RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']);
745
- }
746
-
747
- $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2));
748
- $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2));
749
-
750
-
751
- if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) {
752
-
753
- $thisfile_mpeg_audio_lame_RGAD_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xE000) >> 13;
754
- $thisfile_mpeg_audio_lame_RGAD_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1C00) >> 10;
755
- $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x0200) >> 9;
756
- $thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x01FF;
757
- $thisfile_mpeg_audio_lame_RGAD_track['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['name']);
758
- $thisfile_mpeg_audio_lame_RGAD_track['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['originator']);
759
- $thisfile_mpeg_audio_lame_RGAD_track['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit']);
760
-
761
- if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) {
762
- $info['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'];
763
- }
764
- $info['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_RGAD_track['originator'];
765
- $info['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track['gain_db'];
766
- } else {
767
- unset($thisfile_mpeg_audio_lame_RGAD['track']);
768
- }
769
- if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) {
770
-
771
- $thisfile_mpeg_audio_lame_RGAD_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xE000) >> 13;
772
- $thisfile_mpeg_audio_lame_RGAD_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1C00) >> 10;
773
- $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x0200) >> 9;
774
- $thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x01FF;
775
- $thisfile_mpeg_audio_lame_RGAD_album['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['name']);
776
- $thisfile_mpeg_audio_lame_RGAD_album['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['originator']);
777
- $thisfile_mpeg_audio_lame_RGAD_album['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit']);
778
-
779
- if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) {
780
- $info['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'];
781
- }
782
- $info['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_RGAD_album['originator'];
783
- $info['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album['gain_db'];
784
- } else {
785
- unset($thisfile_mpeg_audio_lame_RGAD['album']);
786
- }
787
- if (empty($thisfile_mpeg_audio_lame_RGAD)) {
788
- unset($thisfile_mpeg_audio_lame['RGAD']);
789
- }
790
-
791
-
792
- // byte $AF Encoding flags + ATH Type
793
- $EncodingFlagsATHtype = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1));
794
- $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10);
795
- $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20);
796
- $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40);
797
- $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80);
798
- $thisfile_mpeg_audio_lame['ath_type'] = $EncodingFlagsATHtype & 0x0F;
799
-
800
- // byte $B0 if ABR {specified bitrate} else {minimal bitrate}
801
- $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1));
802
- if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR)
803
- $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'];
804
- } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR)
805
- // ignore
806
- } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate
807
- $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'];
808
- }
809
-
810
- // bytes $B1-$B3 Encoder delays
811
- $EncoderDelays = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3));
812
- $thisfile_mpeg_audio_lame['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12;
813
- $thisfile_mpeg_audio_lame['end_padding'] = $EncoderDelays & 0x000FFF;
814
-
815
- // byte $B4 Misc
816
- $MiscByte = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1));
817
- $thisfile_mpeg_audio_lame_raw['noise_shaping'] = ($MiscByte & 0x03);
818
- $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($MiscByte & 0x1C) >> 2;
819
- $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($MiscByte & 0x20) >> 5;
820
- $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($MiscByte & 0xC0) >> 6;
821
- $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping'];
822
- $thisfile_mpeg_audio_lame['stereo_mode'] = getid3_mp3::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']);
823
- $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality'];
824
- $thisfile_mpeg_audio_lame['source_sample_freq'] = getid3_mp3::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']);
825
-
826
- // byte $B5 MP3 Gain
827
- $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true);
828
- $thisfile_mpeg_audio_lame['mp3_gain_db'] = (getid3_lib::RGADamplitude2dB(2) / 4) * $thisfile_mpeg_audio_lame_raw['mp3_gain'];
829
- $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame['mp3_gain_db'] / 6));
830
-
831
- // bytes $B6-$B7 Preset and surround info
832
- $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2));
833
- // Reserved = ($PresetSurroundBytes & 0xC000);
834
- $thisfile_mpeg_audio_lame_raw['surround_info'] = ($PresetSurroundBytes & 0x3800);
835
- $thisfile_mpeg_audio_lame['surround_info'] = getid3_mp3::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']);
836
- $thisfile_mpeg_audio_lame['preset_used_id'] = ($PresetSurroundBytes & 0x07FF);
837
- $thisfile_mpeg_audio_lame['preset_used'] = getid3_mp3::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame);
838
- if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) {
839
- $info['warning'][] = 'Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org';
840
- }
841
- if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) {
842
- // this may change if 3.90.4 ever comes out
843
- $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3';
844
- }
845
-
846
- // bytes $B8-$BB MusicLength
847
- $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4));
848
- $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame['audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']);
849
-
850
- // bytes $BC-$BD MusicCRC
851
- $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2));
852
-
853
- // bytes $BE-$BF CRC-16 of Info Tag
854
- $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2));
855
-
856
-
857
- // LAME CBR
858
- if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) {
859
-
860
- $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
861
- $thisfile_mpeg_audio['bitrate'] = getid3_mp3::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']);
862
- $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
863
- //if (empty($thisfile_mpeg_audio['bitrate']) || (!empty($thisfile_mpeg_audio_lame['bitrate_min']) && ($thisfile_mpeg_audio_lame['bitrate_min'] != 255))) {
864
- // $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio_lame['bitrate_min'];
865
- //}
866
-
867
- }
868
-
869
- }
870
- }
871
-
872
- } else {
873
-
874
- // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header)
875
- $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
876
- if ($recursivesearch) {
877
- $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
878
- if ($this->RecursiveFrameScanning($offset, $nextframetestoffset, true)) {
879
- $recursivesearch = false;
880
- $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
881
- }
882
- if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') {
883
- $info['warning'][] = 'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.';
884
- }
885
- }
886
-
887
- }
888
-
889
- }
890
-
891
- if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($info['avdataend'] - $info['avdataoffset']))) {
892
- if ($ExpectedNumberOfAudioBytes > ($info['avdataend'] - $info['avdataoffset'])) {
893
- if (isset($info['fileformat']) && ($info['fileformat'] == 'riff')) {
894
- // ignore, audio data is broken into chunks so will always be data "missing"
895
- } elseif (($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) {
896
- $info['warning'][] = 'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)';
897
- } else {
898
- $info['warning'][] = 'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)';
899
- }
900
- } else {
901
- if ((($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) {
902
- // $prenullbytefileoffset = ftell($this->getid3->fp);
903
- // fseek($this->getid3->fp, $info['avdataend'], SEEK_SET);
904
- // $PossibleNullByte = fread($this->getid3->fp, 1);
905
- // fseek($this->getid3->fp, $prenullbytefileoffset, SEEK_SET);
906
- // if ($PossibleNullByte === "\x00") {
907
- $info['avdataend']--;
908
- // $info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
909
- // } else {
910
- // $info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';
911
- // }
912
- } else {
913
- $info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';
914
- }
915
- }
916
- }
917
-
918
- if (($thisfile_mpeg_audio['bitrate'] == 'free') && empty($info['audio']['bitrate'])) {
919
- if (($offset == $info['avdataoffset']) && empty($thisfile_mpeg_audio['VBR_frames'])) {
920
- $framebytelength = $this->FreeFormatFrameLength($offset, true);
921
- if ($framebytelength > 0) {
922
- $thisfile_mpeg_audio['framelength'] = $framebytelength;
923
- if ($thisfile_mpeg_audio['layer'] == '1') {
924
- // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
925
- $info['audio']['bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12;
926
- } else {
927
- // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
928
- $info['audio']['bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
929
- }
930
- } else {
931
- $info['error'][] = 'Error calculating frame length of free-format MP3 without Xing/LAME header';
932
- }
933
- }
934
- }
935
-
936
- if (isset($thisfile_mpeg_audio['VBR_frames']) ? $thisfile_mpeg_audio['VBR_frames'] : '') {
937
- switch ($thisfile_mpeg_audio['bitrate_mode']) {
938
- case 'vbr':
939
- case 'abr':
940
- $bytes_per_frame = 1152;
941
- if (($thisfile_mpeg_audio['version'] == '1') && ($thisfile_mpeg_audio['layer'] == 1)) {
942
- $bytes_per_frame = 384;
943
- } elseif ((($thisfile_mpeg_audio['version'] == '2') || ($thisfile_mpeg_audio['version'] == '2.5')) && ($thisfile_mpeg_audio['layer'] == 3)) {
944
- $bytes_per_frame = 576;
945
- }
946
- $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / $bytes_per_frame) : 0);
947
- if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) {
948
- $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate'];
949
- $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion
950
- }
951
- break;
952
- }
953
- }
954
-
955
- // End variable-bitrate headers
956
- ////////////////////////////////////////////////////////////////////////////////////
957
-
958
- if ($recursivesearch) {
959
-
960
- if (!$this->RecursiveFrameScanning($offset, $nextframetestoffset, $ScanAsCBR)) {
961
- return false;
962
- }
963
-
964
- }
965
-
966
-
967
- //if (false) {
968
- // // experimental side info parsing section - not returning anything useful yet
969
- //
970
- // $SideInfoBitstream = getid3_lib::BigEndian2Bin($SideInfoData);
971
- // $SideInfoOffset = 0;
972
- //
973
- // if ($thisfile_mpeg_audio['version'] == '1') {
974
- // if ($thisfile_mpeg_audio['channelmode'] == 'mono') {
975
- // // MPEG-1 (mono)
976
- // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9);
977
- // $SideInfoOffset += 9;
978
- // $SideInfoOffset += 5;
979
- // } else {
980
- // // MPEG-1 (stereo, joint-stereo, dual-channel)
981
- // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9);
982
- // $SideInfoOffset += 9;
983
- // $SideInfoOffset += 3;
984
- // }
985
- // } else { // 2 or 2.5
986
- // if ($thisfile_mpeg_audio['channelmode'] == 'mono') {
987
- // // MPEG-2, MPEG-2.5 (mono)
988
- // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8);
989
- // $SideInfoOffset += 8;
990
- // $SideInfoOffset += 1;
991
- // } else {
992
- // // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel)
993
- // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8);
994
- // $SideInfoOffset += 8;
995
- // $SideInfoOffset += 2;
996
- // }
997
- // }
998
- //
999
- // if ($thisfile_mpeg_audio['version'] == '1') {
1000
- // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) {
1001
- // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) {
1002
- // $thisfile_mpeg_audio['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1003
- // $SideInfoOffset += 2;
1004
- // }
1005
- // }
1006
- // }
1007
- // for ($granule = 0; $granule < (($thisfile_mpeg_audio['version'] == '1') ? 2 : 1); $granule++) {
1008
- // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) {
1009
- // $thisfile_mpeg_audio['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12);
1010
- // $SideInfoOffset += 12;
1011
- // $thisfile_mpeg_audio['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9);
1012
- // $SideInfoOffset += 9;
1013
- // $thisfile_mpeg_audio['global_gain'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 8);
1014
- // $SideInfoOffset += 8;
1015
- // if ($thisfile_mpeg_audio['version'] == '1') {
1016
- // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4);
1017
- // $SideInfoOffset += 4;
1018
- // } else {
1019
- // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9);
1020
- // $SideInfoOffset += 9;
1021
- // }
1022
- // $thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1023
- // $SideInfoOffset += 1;
1024
- //
1025
- // if ($thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] == '1') {
1026
- //
1027
- // $thisfile_mpeg_audio['block_type'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 2);
1028
- // $SideInfoOffset += 2;
1029
- // $thisfile_mpeg_audio['mixed_block_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1030
- // $SideInfoOffset += 1;
1031
- //
1032
- // for ($region = 0; $region < 2; $region++) {
1033
- // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5);
1034
- // $SideInfoOffset += 5;
1035
- // }
1036
- // $thisfile_mpeg_audio['table_select'][$granule][$channel][2] = 0;
1037
- //
1038
- // for ($window = 0; $window < 3; $window++) {
1039
- // $thisfile_mpeg_audio['subblock_gain'][$granule][$channel][$window] = substr($SideInfoBitstream, $SideInfoOffset, 3);
1040
- // $SideInfoOffset += 3;
1041
- // }
1042
- //
1043
- // } else {
1044
- //
1045
- // for ($region = 0; $region < 3; $region++) {
1046
- // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5);
1047
- // $SideInfoOffset += 5;
1048
- // }
1049
- //
1050
- // $thisfile_mpeg_audio['region0_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4);
1051
- // $SideInfoOffset += 4;
1052
- // $thisfile_mpeg_audio['region1_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 3);
1053
- // $SideInfoOffset += 3;
1054
- // $thisfile_mpeg_audio['block_type'][$granule][$channel] = 0;
1055
- // }
1056
- //
1057
- // if ($thisfile_mpeg_audio['version'] == '1') {
1058
- // $thisfile_mpeg_audio['preflag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1059
- // $SideInfoOffset += 1;
1060
- // }
1061
- // $thisfile_mpeg_audio['scalefac_scale'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1062
- // $SideInfoOffset += 1;
1063
- // $thisfile_mpeg_audio['count1table_select'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1064
- // $SideInfoOffset += 1;
1065
- // }
1066
- // }
1067
- //}
1068
-
1069
- return true;
1070
- }
1071
-
1072
- function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR) {
1073
- $info = &$this->getid3->info;
1074
- $firstframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
1075
- $this->decodeMPEGaudioHeader($offset, $firstframetestarray, false);
1076
-
1077
- for ($i = 0; $i < GETID3_MP3_VALID_CHECK_FRAMES; $i++) {
1078
- // check next GETID3_MP3_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch
1079
- if (($nextframetestoffset + 4) >= $info['avdataend']) {
1080
- // end of file
1081
- return true;
1082
- }
1083
-
1084
- $nextframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
1085
- if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) {
1086
- if ($ScanAsCBR) {
1087
- // force CBR mode, used for trying to pick out invalid audio streams with valid(?) VBR headers, or VBR streams with no VBR header
1088
- if (!isset($nextframetestarray['mpeg']['audio']['bitrate']) || !isset($firstframetestarray['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $firstframetestarray['mpeg']['audio']['bitrate'])) {
1089
- return false;
1090
- }
1091
- }
1092
-
1093
-
1094
- // next frame is OK, get ready to check the one after that
1095
- if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) {
1096
- $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength'];
1097
- } else {
1098
- $info['error'][] = 'Frame at offset ('.$offset.') is has an invalid frame length.';
1099
- return false;
1100
- }
1101
-
1102
- } elseif (!empty($firstframetestarray['mpeg']['audio']['framelength']) && (($nextframetestoffset + $firstframetestarray['mpeg']['audio']['framelength']) > $info['avdataend'])) {
1103
-
1104
- // it's not the end of the file, but there's not enough data left for another frame, so assume it's garbage/padding and return OK
1105
- return true;
1106
-
1107
- } else {
1108
-
1109
- // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence
1110
- $info['warning'][] = 'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.';
1111
-
1112
- return false;
1113
- }
1114
- }
1115
- return true;
1116
- }
1117
-
1118
- function FreeFormatFrameLength($offset, $deepscan=false) {
1119
- $info = &$this->getid3->info;
1120
-
1121
- fseek($this->getid3->fp, $offset, SEEK_SET);
1122
- $MPEGaudioData = fread($this->getid3->fp, 32768);
1123
-
1124
- $SyncPattern1 = substr($MPEGaudioData, 0, 4);
1125
- // may be different pattern due to padding
1126
- $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) | 0x02).$SyncPattern1{3};
1127
- if ($SyncPattern2 === $SyncPattern1) {
1128
- $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) & 0xFD).$SyncPattern1{3};
1129
- }
1130
-
1131
- $framelength = false;
1132
- $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4);
1133
- $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4);
1134
- if ($framelength1 > 4) {
1135
- $framelength = $framelength1;
1136
- }
1137
- if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1138
- $framelength = $framelength2;
1139
- }
1140
- if (!$framelength) {
1141
-
1142
- // LAME 3.88 has a different value for modeextension on the first frame vs the rest
1143
- $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4);
1144
- $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4);
1145
-
1146
- if ($framelength1 > 4) {
1147
- $framelength = $framelength1;
1148
- }
1149
- if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1150
- $framelength = $framelength2;
1151
- }
1152
- if (!$framelength) {
1153
- $info['error'][] = 'Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset;
1154
- return false;
1155
- } else {
1156
- $info['warning'][] = 'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)';
1157
- $info['audio']['codec'] = 'LAME';
1158
- $info['audio']['encoder'] = 'LAME3.88';
1159
- $SyncPattern1 = substr($SyncPattern1, 0, 3);
1160
- $SyncPattern2 = substr($SyncPattern2, 0, 3);
1161
- }
1162
- }
1163
-
1164
- if ($deepscan) {
1165
-
1166
- $ActualFrameLengthValues = array();
1167
- $nextoffset = $offset + $framelength;
1168
- while ($nextoffset < ($info['avdataend'] - 6)) {
1169
- fseek($this->getid3->fp, $nextoffset - 1, SEEK_SET);
1170
- $NextSyncPattern = fread($this->getid3->fp, 6);
1171
- if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) {
1172
- // good - found where expected
1173
- $ActualFrameLengthValues[] = $framelength;
1174
- } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) {
1175
- // ok - found one byte earlier than expected (last frame wasn't padded, first frame was)
1176
- $ActualFrameLengthValues[] = ($framelength - 1);
1177
- $nextoffset--;
1178
- } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) {
1179
- // ok - found one byte later than expected (last frame was padded, first frame wasn't)
1180
- $ActualFrameLengthValues[] = ($framelength + 1);
1181
- $nextoffset++;
1182
- } else {
1183
- $info['error'][] = 'Did not find expected free-format sync pattern at offset '.$nextoffset;
1184
- return false;
1185
- }
1186
- $nextoffset += $framelength;
1187
- }
1188
- if (count($ActualFrameLengthValues) > 0) {
1189
- $framelength = intval(round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues)));
1190
- }
1191
- }
1192
- return $framelength;
1193
- }
1194
-
1195
- function getOnlyMPEGaudioInfoBruteForce() {
1196
- $MPEGaudioHeaderDecodeCache = array();
1197
- $MPEGaudioHeaderValidCache = array();
1198
- $MPEGaudioHeaderLengthCache = array();
1199
- $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray();
1200
- $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray();
1201
- $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray();
1202
- $MPEGaudioFrequencyLookup = getid3_mp3::MPEGaudioFrequencyArray();
1203
- $MPEGaudioChannelModeLookup = getid3_mp3::MPEGaudioChannelModeArray();
1204
- $MPEGaudioModeExtensionLookup = getid3_mp3::MPEGaudioModeExtensionArray();
1205
- $MPEGaudioEmphasisLookup = getid3_mp3::MPEGaudioEmphasisArray();
1206
- $LongMPEGversionLookup = array();
1207
- $LongMPEGlayerLookup = array();
1208
- $LongMPEGbitrateLookup = array();
1209
- $LongMPEGpaddingLookup = array();
1210
- $LongMPEGfrequencyLookup = array();
1211
- $Distribution['bitrate'] = array();
1212
- $Distribution['frequency'] = array();
1213
- $Distribution['layer'] = array();
1214
- $Distribution['version'] = array();
1215
- $Distribution['padding'] = array();
1216
-
1217
- $info = &$this->getid3->info;
1218
- fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
1219
-
1220
- $max_frames_scan = 5000;
1221
- $frames_scanned = 0;
1222
-
1223
- $previousvalidframe = $info['avdataoffset'];
1224
- while (ftell($this->getid3->fp) < $info['avdataend']) {
1225
- set_time_limit(30);
1226
- $head4 = fread($this->getid3->fp, 4);
1227
- if (strlen($head4) < 4) {
1228
- break;
1229
- }
1230
- if ($head4{0} != "\xFF") {
1231
- for ($i = 1; $i < 4; $i++) {
1232
- if ($head4{$i} == "\xFF") {
1233
- fseek($this->getid3->fp, $i - 4, SEEK_CUR);
1234
- continue 2;
1235
- }
1236
- }
1237
- continue;
1238
- }
1239
- if (!isset($MPEGaudioHeaderDecodeCache[$head4])) {
1240
- $MPEGaudioHeaderDecodeCache[$head4] = getid3_mp3::MPEGaudioHeaderDecode($head4);
1241
- }
1242
- if (!isset($MPEGaudioHeaderValidCache[$head4])) {
1243
- $MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$head4], false, false);
1244
- }
1245
- if ($MPEGaudioHeaderValidCache[$head4]) {
1246
-
1247
- if (!isset($MPEGaudioHeaderLengthCache[$head4])) {
1248
- $LongMPEGversionLookup[$head4] = $MPEGaudioVersionLookup[$MPEGaudioHeaderDecodeCache[$head4]['version']];
1249
- $LongMPEGlayerLookup[$head4] = $MPEGaudioLayerLookup[$MPEGaudioHeaderDecodeCache[$head4]['layer']];
1250
- $LongMPEGbitrateLookup[$head4] = $MPEGaudioBitrateLookup[$LongMPEGversionLookup[$head4]][$LongMPEGlayerLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['bitrate']];
1251
- $LongMPEGpaddingLookup[$head4] = (bool) $MPEGaudioHeaderDecodeCache[$head4]['padding'];
1252
- $LongMPEGfrequencyLookup[$head4] = $MPEGaudioFrequencyLookup[$LongMPEGversionLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['sample_rate']];
1253
- $MPEGaudioHeaderLengthCache[$head4] = getid3_mp3::MPEGaudioFrameLength(
1254
- $LongMPEGbitrateLookup[$head4],
1255
- $LongMPEGversionLookup[$head4],
1256
- $LongMPEGlayerLookup[$head4],
1257
- $LongMPEGpaddingLookup[$head4],
1258
- $LongMPEGfrequencyLookup[$head4]);
1259
- }
1260
- if ($MPEGaudioHeaderLengthCache[$head4] > 4) {
1261
- $WhereWeWere = ftell($this->getid3->fp);
1262
- fseek($this->getid3->fp, $MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR);
1263
- $next4 = fread($this->getid3->fp, 4);
1264
- if ($next4{0} == "\xFF") {
1265
- if (!isset($MPEGaudioHeaderDecodeCache[$next4])) {
1266
- $MPEGaudioHeaderDecodeCache[$next4] = getid3_mp3::MPEGaudioHeaderDecode($next4);
1267
- }
1268
- if (!isset($MPEGaudioHeaderValidCache[$next4])) {
1269
- $MPEGaudioHeaderValidCache[$next4] = getid3_mp3::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$next4], false, false);
1270
- }
1271
- if ($MPEGaudioHeaderValidCache[$next4]) {
1272
- fseek($this->getid3->fp, -4, SEEK_CUR);
1273
-
1274
- getid3_lib::safe_inc($Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]]);
1275
- getid3_lib::safe_inc($Distribution['layer'][$LongMPEGlayerLookup[$head4]]);
1276
- getid3_lib::safe_inc($Distribution['version'][$LongMPEGversionLookup[$head4]]);
1277
- getid3_lib::safe_inc($Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])]);
1278
- getid3_lib::safe_inc($Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]]);
1279
- if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) {
1280
- $pct_data_scanned = (ftell($this->getid3->fp) - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']);
1281
- $info['warning'][] = 'too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
1282
- foreach ($Distribution as $key1 => $value1) {
1283
- foreach ($value1 as $key2 => $value2) {
1284
- $Distribution[$key1][$key2] = round($value2 / $pct_data_scanned);
1285
- }
1286
- }
1287
- break;
1288
- }
1289
- continue;
1290
- }
1291
- }
1292
- unset($next4);
1293
- fseek($this->getid3->fp, $WhereWeWere - 3, SEEK_SET);
1294
- }
1295
-
1296
- }
1297
- }
1298
- foreach ($Distribution as $key => $value) {
1299
- ksort($Distribution[$key], SORT_NUMERIC);
1300
- }
1301
- ksort($Distribution['version'], SORT_STRING);
1302
- $info['mpeg']['audio']['bitrate_distribution'] = $Distribution['bitrate'];
1303
- $info['mpeg']['audio']['frequency_distribution'] = $Distribution['frequency'];
1304
- $info['mpeg']['audio']['layer_distribution'] = $Distribution['layer'];
1305
- $info['mpeg']['audio']['version_distribution'] = $Distribution['version'];
1306
- $info['mpeg']['audio']['padding_distribution'] = $Distribution['padding'];
1307
- if (count($Distribution['version']) > 1) {
1308
- $info['error'][] = 'Corrupt file - more than one MPEG version detected';
1309
- }
1310
- if (count($Distribution['layer']) > 1) {
1311
- $info['error'][] = 'Corrupt file - more than one MPEG layer detected';
1312
- }
1313
- if (count($Distribution['frequency']) > 1) {
1314
- $info['error'][] = 'Corrupt file - more than one MPEG sample rate detected';
1315
- }
1316
-
1317
-
1318
- $bittotal = 0;
1319
- foreach ($Distribution['bitrate'] as $bitratevalue => $bitratecount) {
1320
- if ($bitratevalue != 'free') {
1321
- $bittotal += ($bitratevalue * $bitratecount);
1322
- }
1323
- }
1324
- $info['mpeg']['audio']['frame_count'] = array_sum($Distribution['bitrate']);
1325
- if ($info['mpeg']['audio']['frame_count'] == 0) {
1326
- $info['error'][] = 'no MPEG audio frames found';
1327
- return false;
1328
- }
1329
- $info['mpeg']['audio']['bitrate'] = ($bittotal / $info['mpeg']['audio']['frame_count']);
1330
- $info['mpeg']['audio']['bitrate_mode'] = ((count($Distribution['bitrate']) > 0) ? 'vbr' : 'cbr');
1331
- $info['mpeg']['audio']['sample_rate'] = getid3_lib::array_max($Distribution['frequency'], true);
1332
-
1333
- $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1334
- $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode'];
1335
- $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1336
- $info['audio']['dataformat'] = 'mp'.getid3_lib::array_max($Distribution['layer'], true);
1337
- $info['fileformat'] = $info['audio']['dataformat'];
1338
-
1339
- return true;
1340
- }
1341
-
1342
-
1343
- function getOnlyMPEGaudioInfo($avdataoffset, $BitrateHistogram=false) {
1344
- // looks for synch, decodes MPEG audio header
1345
-
1346
- $info = &$this->getid3->info;
1347
-
1348
- static $MPEGaudioVersionLookup;
1349
- static $MPEGaudioLayerLookup;
1350
- static $MPEGaudioBitrateLookup;
1351
- if (empty($MPEGaudioVersionLookup)) {
1352
- $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray();
1353
- $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray();
1354
- $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray();
1355
-
1356
- }
1357
-
1358
- fseek($this->getid3->fp, $avdataoffset, SEEK_SET);
1359
- $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset);
1360
- if ($sync_seek_buffer_size <= 0) {
1361
- $info['error'][] = 'Invalid $sync_seek_buffer_size at offset '.$avdataoffset;
1362
- return false;
1363
- }
1364
- $header = fread($this->getid3->fp, $sync_seek_buffer_size);
1365
- $sync_seek_buffer_size = strlen($header);
1366
- $SynchSeekOffset = 0;
1367
- while ($SynchSeekOffset < $sync_seek_buffer_size) {
1368
- if ((($avdataoffset + $SynchSeekOffset) < $info['avdataend']) && !feof($this->getid3->fp)) {
1369
-
1370
- if ($SynchSeekOffset > $sync_seek_buffer_size) {
1371
- // if a synch's not found within the first 128k bytes, then give up
1372
- $info['error'][] = 'Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB';
1373
- if (isset($info['audio']['bitrate'])) {
1374
- unset($info['audio']['bitrate']);
1375
- }
1376
- if (isset($info['mpeg']['audio'])) {
1377
- unset($info['mpeg']['audio']);
1378
- }
1379
- if (empty($info['mpeg'])) {
1380
- unset($info['mpeg']);
1381
- }
1382
- return false;
1383
-
1384
- } elseif (feof($this->getid3->fp)) {
1385
-
1386
- $info['error'][] = 'Could not find valid MPEG audio synch before end of file';
1387
- if (isset($info['audio']['bitrate'])) {
1388
- unset($info['audio']['bitrate']);
1389
- }
1390
- if (isset($info['mpeg']['audio'])) {
1391
- unset($info['mpeg']['audio']);
1392
- }
1393
- if (isset($info['mpeg']) && (!is_array($info['mpeg']) || (count($info['mpeg']) == 0))) {
1394
- unset($info['mpeg']);
1395
- }
1396
- return false;
1397
- }
1398
- }
1399
-
1400
- if (($SynchSeekOffset + 1) >= strlen($header)) {
1401
- $info['error'][] = 'Could not find valid MPEG synch before end of file';
1402
- return false;
1403
- }
1404
-
1405
- if (($header{$SynchSeekOffset} == "\xFF") && ($header{($SynchSeekOffset + 1)} > "\xE0")) { // synch detected
1406
- if (!isset($FirstFrameThisfileInfo) && !isset($info['mpeg']['audio'])) {
1407
- $FirstFrameThisfileInfo = $info;
1408
- $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset;
1409
- if (!$this->decodeMPEGaudioHeader($FirstFrameAVDataOffset, $FirstFrameThisfileInfo, false)) {
1410
- // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's
1411
- // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below
1412
- unset($FirstFrameThisfileInfo);
1413
- }
1414
- }
1415
-
1416
- $dummy = $info; // only overwrite real data if valid header found
1417
- if ($this->decodeMPEGaudioHeader($avdataoffset + $SynchSeekOffset, $dummy, true)) {
1418
- $info = $dummy;
1419
- $info['avdataoffset'] = $avdataoffset + $SynchSeekOffset;
1420
- switch (isset($info['fileformat']) ? $info['fileformat'] : '') {
1421
- case '':
1422
- case 'id3':
1423
- case 'ape':
1424
- case 'mp3':
1425
- $info['fileformat'] = 'mp3';
1426
- $info['audio']['dataformat'] = 'mp3';
1427
- break;
1428
- }
1429
- if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) {
1430
- if (!(abs($info['audio']['bitrate'] - $FirstFrameThisfileInfo['audio']['bitrate']) <= 1)) {
1431
- // If there is garbage data between a valid VBR header frame and a sequence
1432
- // of valid MPEG-audio frames the VBR data is no longer discarded.
1433
- $info = $FirstFrameThisfileInfo;
1434
- $info['avdataoffset'] = $FirstFrameAVDataOffset;
1435
- $info['fileformat'] = 'mp3';
1436
- $info['audio']['dataformat'] = 'mp3';
1437
- $dummy = $info;
1438
- unset($dummy['mpeg']['audio']);
1439
- $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength'];
1440
- $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset;
1441
- if ($this->decodeMPEGaudioHeader($GarbageOffsetEnd, $dummy, true, true)) {
1442
- $info = $dummy;
1443
- $info['avdataoffset'] = $GarbageOffsetEnd;
1444
- $info['warning'][] = 'apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd;
1445
- } else {
1446
- $info['warning'][] = 'using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')';
1447
- }
1448
- }
1449
- }
1450
- if (isset($info['mpeg']['audio']['bitrate_mode']) && ($info['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($info['mpeg']['audio']['VBR_method'])) {
1451
- // VBR file with no VBR header
1452
- $BitrateHistogram = true;
1453
- }
1454
-
1455
- if ($BitrateHistogram) {
1456
-
1457
- $info['mpeg']['audio']['stereo_distribution'] = array('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0);
1458
- $info['mpeg']['audio']['version_distribution'] = array('1'=>0, '2'=>0, '2.5'=>0);
1459
-
1460
- if ($info['mpeg']['audio']['version'] == '1') {
1461
- if ($info['mpeg']['audio']['layer'] == 3) {
1462
- $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0);
1463
- } elseif ($info['mpeg']['audio']['layer'] == 2) {
1464
- $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0, 384000=>0);
1465
- } elseif ($info['mpeg']['audio']['layer'] == 1) {
1466
- $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 64000=>0, 96000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 288000=>0, 320000=>0, 352000=>0, 384000=>0, 416000=>0, 448000=>0);
1467
- }
1468
- } elseif ($info['mpeg']['audio']['layer'] == 1) {
1469
- $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0, 176000=>0, 192000=>0, 224000=>0, 256000=>0);
1470
- } else {
1471
- $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 8000=>0, 16000=>0, 24000=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0);
1472
- }
1473
-
1474
- $dummy = array('error'=>$info['error'], 'warning'=>$info['warning'], 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
1475
- $synchstartoffset = $info['avdataoffset'];
1476
- fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
1477
-
1478
- // you can play with these numbers:
1479
- $max_frames_scan = 50000;
1480
- $max_scan_segments = 10;
1481
-
1482
- // don't play with these numbers:
1483
- $FastMode = false;
1484
- $SynchErrorsFound = 0;
1485
- $frames_scanned = 0;
1486
- $this_scan_segment = 0;
1487
- $frames_scan_per_segment = ceil($max_frames_scan / $max_scan_segments);
1488
- $pct_data_scanned = 0;
1489
- for ($current_segment = 0; $current_segment < $max_scan_segments; $current_segment++) {
1490
- $frames_scanned_this_segment = 0;
1491
- if (ftell($this->getid3->fp) >= $info['avdataend']) {
1492
- break;
1493
- }
1494
- $scan_start_offset[$current_segment] = max(ftell($this->getid3->fp), $info['avdataoffset'] + round($current_segment * (($info['avdataend'] - $info['avdataoffset']) / $max_scan_segments)));
1495
- if ($current_segment > 0) {
1496
- fseek($this->getid3->fp, $scan_start_offset[$current_segment], SEEK_SET);
1497
- $buffer_4k = fread($this->getid3->fp, 4096);
1498
- for ($j = 0; $j < (strlen($buffer_4k) - 4); $j++) {
1499
- if (($buffer_4k{$j} == "\xFF") && ($buffer_4k{($j + 1)} > "\xE0")) { // synch detected
1500
- if ($this->decodeMPEGaudioHeader($scan_start_offset[$current_segment] + $j, $dummy, false, false, $FastMode)) {
1501
- $calculated_next_offset = $scan_start_offset[$current_segment] + $j + $dummy['mpeg']['audio']['framelength'];
1502
- if ($this->decodeMPEGaudioHeader($calculated_next_offset, $dummy, false, false, $FastMode)) {
1503
- $scan_start_offset[$current_segment] += $j;
1504
- break;
1505
- }
1506
- }
1507
- }
1508
- }
1509
- }
1510
- $synchstartoffset = $scan_start_offset[$current_segment];
1511
- while ($this->decodeMPEGaudioHeader($synchstartoffset, $dummy, false, false, $FastMode)) {
1512
- $FastMode = true;
1513
- $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']];
1514
-
1515
- if (empty($dummy['mpeg']['audio']['framelength'])) {
1516
- $SynchErrorsFound++;
1517
- $synchstartoffset++;
1518
- } else {
1519
- getid3_lib::safe_inc($info['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]);
1520
- getid3_lib::safe_inc($info['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]);
1521
- getid3_lib::safe_inc($info['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]);
1522
- $synchstartoffset += $dummy['mpeg']['audio']['framelength'];
1523
- }
1524
- $frames_scanned++;
1525
- if ($frames_scan_per_segment && (++$frames_scanned_this_segment >= $frames_scan_per_segment)) {
1526
- $this_pct_scanned = (ftell($this->getid3->fp) - $scan_start_offset[$current_segment]) / ($info['avdataend'] - $info['avdataoffset']);
1527
- if (($current_segment == 0) && (($this_pct_scanned * $max_scan_segments) >= 1)) {
1528
- // file likely contains < $max_frames_scan, just scan as one segment
1529
- $max_scan_segments = 1;
1530
- $frames_scan_per_segment = $max_frames_scan;
1531
- } else {
1532
- $pct_data_scanned += $this_pct_scanned;
1533
- break;
1534
- }
1535
- }
1536
- }
1537
- }
1538
- if ($pct_data_scanned > 0) {
1539
- $info['warning'][] = 'too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
1540
- foreach ($info['mpeg']['audio'] as $key1 => $value1) {
1541
- if (!preg_match('#_distribution$#i', $key1)) {
1542
- continue;
1543
- }
1544
- foreach ($value1 as $key2 => $value2) {
1545
- $info['mpeg']['audio'][$key1][$key2] = round($value2 / $pct_data_scanned);
1546
- }
1547
- }
1548
- }
1549
-
1550
- if ($SynchErrorsFound > 0) {
1551
- $info['warning'][] = 'Found '.$SynchErrorsFound.' synch errors in histogram analysis';
1552
- //return false;
1553
- }
1554
-
1555
- $bittotal = 0;
1556
- $framecounter = 0;
1557
- foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) {
1558
- $framecounter += $bitratecount;
1559
- if ($bitratevalue != 'free') {
1560
- $bittotal += ($bitratevalue * $bitratecount);
1561
- }
1562
- }
1563
- if ($framecounter == 0) {
1564
- $info['error'][] = 'Corrupt MP3 file: framecounter == zero';
1565
- return false;
1566
- }
1567
- $info['mpeg']['audio']['frame_count'] = getid3_lib::CastAsInt($framecounter);
1568
- $info['mpeg']['audio']['bitrate'] = ($bittotal / $framecounter);
1569
-
1570
- $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1571
-
1572
-
1573
- // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently
1574
- $distinct_bitrates = 0;
1575
- foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) {
1576
- if ($bitrate_count > 0) {
1577
- $distinct_bitrates++;
1578
- }
1579
- }
1580
- if ($distinct_bitrates > 1) {
1581
- $info['mpeg']['audio']['bitrate_mode'] = 'vbr';
1582
- } else {
1583
- $info['mpeg']['audio']['bitrate_mode'] = 'cbr';
1584
- }
1585
- $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode'];
1586
-
1587
- }
1588
-
1589
- break; // exit while()
1590
- }
1591
- }
1592
-
1593
- $SynchSeekOffset++;
1594
- if (($avdataoffset + $SynchSeekOffset) >= $info['avdataend']) {
1595
- // end of file/data
1596
-
1597
- if (empty($info['mpeg']['audio'])) {
1598
-
1599
- $info['error'][] = 'could not find valid MPEG synch before end of file';
1600
- if (isset($info['audio']['bitrate'])) {
1601
- unset($info['audio']['bitrate']);
1602
- }
1603
- if (isset($info['mpeg']['audio'])) {
1604
- unset($info['mpeg']['audio']);
1605
- }
1606
- if (isset($info['mpeg']) && (!is_array($info['mpeg']) || empty($info['mpeg']))) {
1607
- unset($info['mpeg']);
1608
- }
1609
- return false;
1610
-
1611
- }
1612
- break;
1613
- }
1614
-
1615
- }
1616
- $info['audio']['channels'] = ( !empty($info['mpeg']['audio']['channels']) ? $info['mpeg']['audio']['channels']:''); // FIX BY POWERPRESS
1617
- $info['audio']['channelmode'] = ( !empty($info['mpeg']['audio']['channelmode']) ? $info['mpeg']['audio']['channelmode']:''); // FIX BY POWERPRESS
1618
- $info['audio']['sample_rate'] = ( !empty($info['mpeg']['audio']['sample_rate']) ? $info['mpeg']['audio']['sample_rate']:''); // FIX BY POWERPRESS
1619
- return true;
1620
- }
1621
-
1622
-
1623
- static function MPEGaudioVersionArray() {
1624
- static $MPEGaudioVersion = array('2.5', false, '2', '1');
1625
- return $MPEGaudioVersion;
1626
- }
1627
-
1628
- static function MPEGaudioLayerArray() {
1629
- static $MPEGaudioLayer = array(false, 3, 2, 1);
1630
- return $MPEGaudioLayer;
1631
- }
1632
-
1633
- static function MPEGaudioBitrateArray() {
1634
- static $MPEGaudioBitrate;
1635
- if (empty($MPEGaudioBitrate)) {
1636
- $MPEGaudioBitrate = array (
1637
- '1' => array (1 => array('free', 32000, 64000, 96000, 128000, 160000, 192000, 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000),
1638
- 2 => array('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000),
1639
- 3 => array('free', 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000)
1640
- ),
1641
-
1642
- '2' => array (1 => array('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 176000, 192000, 224000, 256000),
1643
- 2 => array('free', 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000),
1644
- )
1645
- );
1646
- $MPEGaudioBitrate['2'][3] = $MPEGaudioBitrate['2'][2];
1647
- $MPEGaudioBitrate['2.5'] = $MPEGaudioBitrate['2'];
1648
- }
1649
- return $MPEGaudioBitrate;
1650
- }
1651
-
1652
- static function MPEGaudioFrequencyArray() {
1653
- static $MPEGaudioFrequency;
1654
- if (empty($MPEGaudioFrequency)) {
1655
- $MPEGaudioFrequency = array (
1656
- '1' => array(44100, 48000, 32000),
1657
- '2' => array(22050, 24000, 16000),
1658
- '2.5' => array(11025, 12000, 8000)
1659
- );
1660
- }
1661
- return $MPEGaudioFrequency;
1662
- }
1663
-
1664
- static function MPEGaudioChannelModeArray() {
1665
- static $MPEGaudioChannelMode = array('stereo', 'joint stereo', 'dual channel', 'mono');
1666
- return $MPEGaudioChannelMode;
1667
- }
1668
-
1669
- static function MPEGaudioModeExtensionArray() {
1670
- static $MPEGaudioModeExtension;
1671
- if (empty($MPEGaudioModeExtension)) {
1672
- $MPEGaudioModeExtension = array (
1673
- 1 => array('4-31', '8-31', '12-31', '16-31'),
1674
- 2 => array('4-31', '8-31', '12-31', '16-31'),
1675
- 3 => array('', 'IS', 'MS', 'IS+MS')
1676
- );
1677
- }
1678
- return $MPEGaudioModeExtension;
1679
- }
1680
-
1681
- static function MPEGaudioEmphasisArray() {
1682
- static $MPEGaudioEmphasis = array('none', '50/15ms', false, 'CCIT J.17');
1683
- return $MPEGaudioEmphasis;
1684
- }
1685
-
1686
- static function MPEGaudioHeaderBytesValid($head4, $allowBitrate15=false) {
1687
- return getid3_mp3::MPEGaudioHeaderValid(getid3_mp3::MPEGaudioHeaderDecode($head4), false, $allowBitrate15);
1688
- }
1689
-
1690
- static function MPEGaudioHeaderValid($rawarray, $echoerrors=false, $allowBitrate15=false) {
1691
- if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) {
1692
- return false;
1693
- }
1694
-
1695
- static $MPEGaudioVersionLookup;
1696
- static $MPEGaudioLayerLookup;
1697
- static $MPEGaudioBitrateLookup;
1698
- static $MPEGaudioFrequencyLookup;
1699
- static $MPEGaudioChannelModeLookup;
1700
- static $MPEGaudioModeExtensionLookup;
1701
- static $MPEGaudioEmphasisLookup;
1702
- if (empty($MPEGaudioVersionLookup)) {
1703
- $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray();
1704
- $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray();
1705
- $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray();
1706
- $MPEGaudioFrequencyLookup = getid3_mp3::MPEGaudioFrequencyArray();
1707
- $MPEGaudioChannelModeLookup = getid3_mp3::MPEGaudioChannelModeArray();
1708
- $MPEGaudioModeExtensionLookup = getid3_mp3::MPEGaudioModeExtensionArray();
1709
- $MPEGaudioEmphasisLookup = getid3_mp3::MPEGaudioEmphasisArray();
1710
- }
1711
-
1712
- if (isset($MPEGaudioVersionLookup[$rawarray['version']])) {
1713
- $decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']];
1714
- } else {
1715
- echo ($echoerrors ? "\n".'invalid Version ('.$rawarray['version'].')' : '');
1716
- return false;
1717
- }
1718
- if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) {
1719
- $decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']];
1720
- } else {
1721
- echo ($echoerrors ? "\n".'invalid Layer ('.$rawarray['layer'].')' : '');
1722
- return false;
1723
- }
1724
- if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) {
1725
- echo ($echoerrors ? "\n".'invalid Bitrate ('.$rawarray['bitrate'].')' : '');
1726
- if ($rawarray['bitrate'] == 15) {
1727
- // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0
1728
- // let it go through here otherwise file will not be identified
1729
- if (!$allowBitrate15) {
1730
- return false;
1731
- }
1732
- } else {
1733
- return false;
1734
- }
1735
- }
1736
- if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) {
1737
- echo ($echoerrors ? "\n".'invalid Frequency ('.$rawarray['sample_rate'].')' : '');
1738
- return false;
1739
- }
1740
- if (!isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) {
1741
- echo ($echoerrors ? "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')' : '');
1742
- return false;
1743
- }
1744
- if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) {
1745
- echo ($echoerrors ? "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')' : '');
1746
- return false;
1747
- }
1748
- if (!isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) {
1749
- echo ($echoerrors ? "\n".'invalid Emphasis ('.$rawarray['emphasis'].')' : '');
1750
- return false;
1751
- }
1752
- // These are just either set or not set, you can't mess that up :)
1753
- // $rawarray['protection'];
1754
- // $rawarray['padding'];
1755
- // $rawarray['private'];
1756
- // $rawarray['copyright'];
1757
- // $rawarray['original'];
1758
-
1759
- return true;
1760
- }
1761
-
1762
- static function MPEGaudioHeaderDecode($Header4Bytes) {
1763
- // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM
1764
- // A - Frame sync (all bits set)
1765
- // B - MPEG Audio version ID
1766
- // C - Layer description
1767
- // D - Protection bit
1768
- // E - Bitrate index
1769
- // F - Sampling rate frequency index
1770
- // G - Padding bit
1771
- // H - Private bit
1772
- // I - Channel Mode
1773
- // J - Mode extension (Only if Joint stereo)
1774
- // K - Copyright
1775
- // L - Original
1776
- // M - Emphasis
1777
-
1778
- if (strlen($Header4Bytes) != 4) {
1779
- return false;
1780
- }
1781
-
1782
- $MPEGrawHeader['synch'] = (getid3_lib::BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4;
1783
- $MPEGrawHeader['version'] = (ord($Header4Bytes{1}) & 0x18) >> 3; // BB
1784
- $MPEGrawHeader['layer'] = (ord($Header4Bytes{1}) & 0x06) >> 1; // CC
1785
- $MPEGrawHeader['protection'] = (ord($Header4Bytes{1}) & 0x01); // D
1786
- $MPEGrawHeader['bitrate'] = (ord($Header4Bytes{2}) & 0xF0) >> 4; // EEEE
1787
- $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes{2}) & 0x0C) >> 2; // FF
1788
- $MPEGrawHeader['padding'] = (ord($Header4Bytes{2}) & 0x02) >> 1; // G
1789
- $MPEGrawHeader['private'] = (ord($Header4Bytes{2}) & 0x01); // H
1790
- $MPEGrawHeader['channelmode'] = (ord($Header4Bytes{3}) & 0xC0) >> 6; // II
1791
- $MPEGrawHeader['modeextension'] = (ord($Header4Bytes{3}) & 0x30) >> 4; // JJ
1792
- $MPEGrawHeader['copyright'] = (ord($Header4Bytes{3}) & 0x08) >> 3; // K
1793
- $MPEGrawHeader['original'] = (ord($Header4Bytes{3}) & 0x04) >> 2; // L
1794
- $MPEGrawHeader['emphasis'] = (ord($Header4Bytes{3}) & 0x03); // MM
1795
-
1796
- return $MPEGrawHeader;
1797
- }
1798
-
1799
- static function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) {
1800
- static $AudioFrameLengthCache = array();
1801
-
1802
- if (!isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) {
1803
- $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = false;
1804
- if ($bitrate != 'free') {
1805
-
1806
- if ($version == '1') {
1807
-
1808
- if ($layer == '1') {
1809
-
1810
- // For Layer I slot is 32 bits long
1811
- $FrameLengthCoefficient = 48;
1812
- $SlotLength = 4;
1813
-
1814
- } else { // Layer 2 / 3
1815
-
1816
- // for Layer 2 and Layer 3 slot is 8 bits long.
1817
- $FrameLengthCoefficient = 144;
1818
- $SlotLength = 1;
1819
-
1820
- }
1821
-
1822
- } else { // MPEG-2 / MPEG-2.5
1823
-
1824
- if ($layer == '1') {
1825
-
1826
- // For Layer I slot is 32 bits long
1827
- $FrameLengthCoefficient = 24;
1828
- $SlotLength = 4;
1829
-
1830
- } elseif ($layer == '2') {
1831
-
1832
- // for Layer 2 and Layer 3 slot is 8 bits long.
1833
- $FrameLengthCoefficient = 144;
1834
- $SlotLength = 1;
1835
-
1836
- } else { // layer 3
1837
-
1838
- // for Layer 2 and Layer 3 slot is 8 bits long.
1839
- $FrameLengthCoefficient = 72;
1840
- $SlotLength = 1;
1841
-
1842
- }
1843
-
1844
- }
1845
-
1846
- // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding
1847
- if ($samplerate > 0) {
1848
- $NewFramelength = ($FrameLengthCoefficient * $bitrate) / $samplerate;
1849
- $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength; // round to next-lower multiple of SlotLength (1 byte for Layer 2/3, 4 bytes for Layer I)
1850
- if ($padding) {
1851
- $NewFramelength += $SlotLength;
1852
- }
1853
- $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength;
1854
- }
1855
- }
1856
- }
1857
- return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate];
1858
- }
1859
-
1860
- static function ClosestStandardMP3Bitrate($bit_rate) {
1861
- static $standard_bit_rates = array (320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000);
1862
- static $bit_rate_table = array (0=>'-');
1863
- $round_bit_rate = intval(round($bit_rate, -3));
1864
- if (!isset($bit_rate_table[$round_bit_rate])) {
1865
- if ($round_bit_rate > max($standard_bit_rates)) {
1866
- $bit_rate_table[$round_bit_rate] = round($bit_rate, 2 - strlen($bit_rate));
1867
- } else {
1868
- $bit_rate_table[$round_bit_rate] = max($standard_bit_rates);
1869
- foreach ($standard_bit_rates as $standard_bit_rate) {
1870
- if ($round_bit_rate >= $standard_bit_rate + (($bit_rate_table[$round_bit_rate] - $standard_bit_rate) / 2)) {
1871
- break;
1872
- }
1873
- $bit_rate_table[$round_bit_rate] = $standard_bit_rate;
1874
- }
1875
- }
1876
- }
1877
- return $bit_rate_table[$round_bit_rate];
1878
- }
1879
-
1880
- static function XingVBRidOffset($version, $channelmode) {
1881
- static $XingVBRidOffsetCache = array();
1882
- if (empty($XingVBRidOffset)) {
1883
- $XingVBRidOffset = array (
1884
- '1' => array ('mono' => 0x15, // 4 + 17 = 21
1885
- 'stereo' => 0x24, // 4 + 32 = 36
1886
- 'joint stereo' => 0x24,
1887
- 'dual channel' => 0x24
1888
- ),
1889
-
1890
- '2' => array ('mono' => 0x0D, // 4 + 9 = 13
1891
- 'stereo' => 0x15, // 4 + 17 = 21
1892
- 'joint stereo' => 0x15,
1893
- 'dual channel' => 0x15
1894
- ),
1895
-
1896
- '2.5' => array ('mono' => 0x15,
1897
- 'stereo' => 0x15,
1898
- 'joint stereo' => 0x15,
1899
- 'dual channel' => 0x15
1900
- )
1901
- );
1902
- }
1903
- return $XingVBRidOffset[$version][$channelmode];
1904
- }
1905
-
1906
- static function LAMEvbrMethodLookup($VBRmethodID) {
1907
- static $LAMEvbrMethodLookup = array(
1908
- 0x00 => 'unknown',
1909
- 0x01 => 'cbr',
1910
- 0x02 => 'abr',
1911
- 0x03 => 'vbr-old / vbr-rh',
1912
- 0x04 => 'vbr-new / vbr-mtrh',
1913
- 0x05 => 'vbr-mt',
1914
- 0x06 => 'vbr (full vbr method 4)',
1915
- 0x08 => 'cbr (constant bitrate 2 pass)',
1916
- 0x09 => 'abr (2 pass)',
1917
- 0x0F => 'reserved'
1918
- );
1919
- return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : '');
1920
- }
1921
-
1922
- static function LAMEmiscStereoModeLookup($StereoModeID) {
1923
- static $LAMEmiscStereoModeLookup = array(
1924
- 0 => 'mono',
1925
- 1 => 'stereo',
1926
- 2 => 'dual mono',
1927
- 3 => 'joint stereo',
1928
- 4 => 'forced stereo',
1929
- 5 => 'auto',
1930
- 6 => 'intensity stereo',
1931
- 7 => 'other'
1932
- );
1933
- return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : '');
1934
- }
1935
-
1936
- static function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) {
1937
- static $LAMEmiscSourceSampleFrequencyLookup = array(
1938
- 0 => '<= 32 kHz',
1939
- 1 => '44.1 kHz',
1940
- 2 => '48 kHz',
1941
- 3 => '> 48kHz'
1942
- );
1943
- return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : '');
1944
- }
1945
-
1946
- static function LAMEsurroundInfoLookup($SurroundInfoID) {
1947
- static $LAMEsurroundInfoLookup = array(
1948
- 0 => 'no surround info',
1949
- 1 => 'DPL encoding',
1950
- 2 => 'DPL2 encoding',
1951
- 3 => 'Ambisonic encoding'
1952
- );
1953
- return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved');
1954
- }
1955
-
1956
- static function LAMEpresetUsedLookup($LAMEtag) {
1957
-
1958
- if ($LAMEtag['preset_used_id'] == 0) {
1959
- // no preset used (LAME >=3.93)
1960
- // no preset recorded (LAME <3.93)
1961
- return '';
1962
- }
1963
- $LAMEpresetUsedLookup = array();
1964
-
1965
- ///// THIS PART CANNOT BE STATIC .
1966
- for ($i = 8; $i <= 320; $i++) {
1967
- switch ($LAMEtag['vbr_method']) {
1968
- case 'cbr':
1969
- $LAMEpresetUsedLookup[$i] = '--alt-preset '.$LAMEtag['vbr_method'].' '.$i;
1970
- break;
1971
- case 'abr':
1972
- default: // other VBR modes shouldn't be here(?)
1973
- $LAMEpresetUsedLookup[$i] = '--alt-preset '.$i;
1974
- break;
1975
- }
1976
- }
1977
-
1978
- // named old-style presets (studio, phone, voice, etc) are handled in GuessEncoderOptions()
1979
-
1980
- // named alt-presets
1981
- $LAMEpresetUsedLookup[1000] = '--r3mix';
1982
- $LAMEpresetUsedLookup[1001] = '--alt-preset standard';
1983
- $LAMEpresetUsedLookup[1002] = '--alt-preset extreme';
1984
- $LAMEpresetUsedLookup[1003] = '--alt-preset insane';
1985
- $LAMEpresetUsedLookup[1004] = '--alt-preset fast standard';
1986
- $LAMEpresetUsedLookup[1005] = '--alt-preset fast extreme';
1987
- $LAMEpresetUsedLookup[1006] = '--alt-preset medium';
1988
- $LAMEpresetUsedLookup[1007] = '--alt-preset fast medium';
1989
-
1990
- // LAME 3.94 additions/changes
1991
- $LAMEpresetUsedLookup[1010] = '--preset portable'; // 3.94a15 Oct 21 2003
1992
- $LAMEpresetUsedLookup[1015] = '--preset radio'; // 3.94a15 Oct 21 2003
1993
-
1994
- $LAMEpresetUsedLookup[320] = '--preset insane'; // 3.94a15 Nov 12 2003
1995
- $LAMEpresetUsedLookup[410] = '-V9';
1996
- $LAMEpresetUsedLookup[420] = '-V8';
1997
- $LAMEpresetUsedLookup[440] = '-V6';
1998
- $LAMEpresetUsedLookup[430] = '--preset radio'; // 3.94a15 Nov 12 2003
1999
- $LAMEpresetUsedLookup[450] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'portable'; // 3.94a15 Nov 12 2003
2000
- $LAMEpresetUsedLookup[460] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'medium'; // 3.94a15 Nov 12 2003
2001
- $LAMEpresetUsedLookup[470] = '--r3mix'; // 3.94b1 Dec 18 2003
2002
- $LAMEpresetUsedLookup[480] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'standard'; // 3.94a15 Nov 12 2003
2003
- $LAMEpresetUsedLookup[490] = '-V1';
2004
- $LAMEpresetUsedLookup[500] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'extreme'; // 3.94a15 Nov 12 2003
2005
-
2006
- return (isset($LAMEpresetUsedLookup[$LAMEtag['preset_used_id']]) ? $LAMEpresetUsedLookup[$LAMEtag['preset_used_id']] : 'new/unknown preset: '.$LAMEtag['preset_used_id'].' - report to info@getid3.org');
2007
- }
2008
-
2009
- }
2010
-
2011
- ?>
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // See readme.txt for more details //
9
+ /////////////////////////////////////////////////////////////////
10
+ // //
11
+ // module.audio.mp3.php //
12
+ // module for analyzing MP3 files //
13
+ // dependencies: NONE //
14
+ // ///
15
+ /////////////////////////////////////////////////////////////////
16
+
17
+
18
+ // number of frames to scan to determine if MPEG-audio sequence is valid
19
+ // Lower this number to 5-20 for faster scanning
20
+ // Increase this number to 50+ for most accurate detection of valid VBR/CBR
21
+ // mpeg-audio streams
22
+ define('GETID3_MP3_VALID_CHECK_FRAMES', 35);
23
+
24
+
25
+ class getid3_mp3 extends getid3_handler
26
+ {
27
+
28
+ public $allow_bruteforce = false; // forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, unrecommended, but may provide data from otherwise-unusuable files
29
+
30
+ public function Analyze() {
31
+ $info = &$this->getid3->info;
32
+
33
+ $initialOffset = $info['avdataoffset'];
34
+
35
+ if (!$this->getOnlyMPEGaudioInfo($info['avdataoffset'])) {
36
+ if ($this->allow_bruteforce) {
37
+ $info['error'][] = 'Rescanning file in BruteForce mode';
38
+ $this->getOnlyMPEGaudioInfoBruteForce($this->getid3->fp, $info);
39
+ }
40
+ }
41
+
42
+
43
+ if (isset($info['mpeg']['audio']['bitrate_mode'])) {
44
+ $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
45
+ }
46
+
47
+ if (((isset($info['id3v2']['headerlength']) && ($info['avdataoffset'] > $info['id3v2']['headerlength'])) || (!isset($info['id3v2']) && ($info['avdataoffset'] > 0) && ($info['avdataoffset'] != $initialOffset)))) {
48
+
49
+ $synchoffsetwarning = 'Unknown data before synch ';
50
+ if (isset($info['id3v2']['headerlength'])) {
51
+ $synchoffsetwarning .= '(ID3v2 header ends at '.$info['id3v2']['headerlength'].', then '.($info['avdataoffset'] - $info['id3v2']['headerlength']).' bytes garbage, ';
52
+ } elseif ($initialOffset > 0) {
53
+ $synchoffsetwarning .= '(should be at '.$initialOffset.', ';
54
+ } else {
55
+ $synchoffsetwarning .= '(should be at beginning of file, ';
56
+ }
57
+ $synchoffsetwarning .= 'synch detected at '.$info['avdataoffset'].')';
58
+ if (isset($info['audio']['bitrate_mode']) && ($info['audio']['bitrate_mode'] == 'cbr')) {
59
+
60
+ if (!empty($info['id3v2']['headerlength']) && (($info['avdataoffset'] - $info['id3v2']['headerlength']) == $info['mpeg']['audio']['framelength'])) {
61
+
62
+ $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.';
63
+ $info['audio']['codec'] = 'LAME';
64
+ $CurrentDataLAMEversionString = 'LAME3.';
65
+
66
+ } elseif (empty($info['id3v2']['headerlength']) && ($info['avdataoffset'] == $info['mpeg']['audio']['framelength'])) {
67
+
68
+ $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.';
69
+ $info['audio']['codec'] = 'LAME';
70
+ $CurrentDataLAMEversionString = 'LAME3.';
71
+
72
+ }
73
+
74
+ }
75
+ $info['warning'][] = $synchoffsetwarning;
76
+
77
+ }
78
+
79
+ if (isset($info['mpeg']['audio']['LAME'])) {
80
+ $info['audio']['codec'] = 'LAME';
81
+ if (!empty($info['mpeg']['audio']['LAME']['long_version'])) {
82
+ $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['long_version'], "\x00");
83
+ } elseif (!empty($info['mpeg']['audio']['LAME']['short_version'])) {
84
+ $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['short_version'], "\x00");
85
+ }
86
+ }
87
+
88
+ $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : (isset($info['audio']['encoder']) ? $info['audio']['encoder'] : ''));
89
+ if (!empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) == 'LAME3.') && !preg_match('[0-9\)]', substr($CurrentDataLAMEversionString, -1))) {
90
+ // a version number of LAME that does not end with a number like "LAME3.92"
91
+ // or with a closing parenthesis like "LAME3.88 (alpha)"
92
+ // or a version of LAME with the LAMEtag-not-filled-in-DLL-mode bug (3.90-3.92)
93
+
94
+ // not sure what the actual last frame length will be, but will be less than or equal to 1441
95
+ $PossiblyLongerLAMEversion_FrameLength = 1441;
96
+
97
+ // Not sure what version of LAME this is - look in padding of last frame for longer version string
98
+ $PossibleLAMEversionStringOffset = $info['avdataend'] - $PossiblyLongerLAMEversion_FrameLength;
99
+ $this->fseek($PossibleLAMEversionStringOffset);
100
+ $PossiblyLongerLAMEversion_Data = $this->fread($PossiblyLongerLAMEversion_FrameLength);
101
+ switch (substr($CurrentDataLAMEversionString, -1)) {
102
+ case 'a':
103
+ case 'b':
104
+ // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example
105
+ // need to trim off "a" to match longer string
106
+ $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, -1);
107
+ break;
108
+ }
109
+ if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !== false) {
110
+ if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) {
111
+ $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)"
112
+ if (empty($info['audio']['encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen($info['audio']['encoder']))) {
113
+ $info['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ if (!empty($info['audio']['encoder'])) {
119
+ $info['audio']['encoder'] = rtrim($info['audio']['encoder'], "\x00 ");
120
+ }
121
+
122
+ switch (isset($info['mpeg']['audio']['layer']) ? $info['mpeg']['audio']['layer'] : '') {
123
+ case 1:
124
+ case 2:
125
+ $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
126
+ break;
127
+ }
128
+ if (isset($info['fileformat']) && ($info['fileformat'] == 'mp3')) {
129
+ switch ($info['audio']['dataformat']) {
130
+ case 'mp1':
131
+ case 'mp2':
132
+ case 'mp3':
133
+ $info['fileformat'] = $info['audio']['dataformat'];
134
+ break;
135
+
136
+ default:
137
+ $info['warning'][] = 'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"';
138
+ break;
139
+ }
140
+ }
141
+
142
+ if (empty($info['fileformat'])) {
143
+ unset($info['fileformat']);
144
+ unset($info['audio']['bitrate_mode']);
145
+ unset($info['avdataoffset']);
146
+ unset($info['avdataend']);
147
+ return false;
148
+ }
149
+
150
+ $info['mime_type'] = 'audio/mpeg';
151
+ $info['audio']['lossless'] = false;
152
+
153
+ // Calculate playtime
154
+ if (!isset($info['playtime_seconds']) && isset($info['audio']['bitrate']) && ($info['audio']['bitrate'] > 0)) {
155
+ $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['audio']['bitrate'];
156
+ }
157
+
158
+ $info['audio']['encoder_options'] = $this->GuessEncoderOptions();
159
+
160
+ return true;
161
+ }
162
+
163
+
164
+ public function GuessEncoderOptions() {
165
+ // shortcuts
166
+ $info = &$this->getid3->info;
167
+ if (!empty($info['mpeg']['audio'])) {
168
+ $thisfile_mpeg_audio = &$info['mpeg']['audio'];
169
+ if (!empty($thisfile_mpeg_audio['LAME'])) {
170
+ $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
171
+ }
172
+ }
173
+
174
+ $encoder_options = '';
175
+ static $NamedPresetBitrates = array(16, 24, 40, 56, 112, 128, 160, 192, 256);
176
+
177
+ if (isset($thisfile_mpeg_audio['VBR_method']) && ($thisfile_mpeg_audio['VBR_method'] == 'Fraunhofer') && !empty($thisfile_mpeg_audio['VBR_quality'])) {
178
+
179
+ $encoder_options = 'VBR q'.$thisfile_mpeg_audio['VBR_quality'];
180
+
181
+ } elseif (!empty($thisfile_mpeg_audio_lame['preset_used']) && (!in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates))) {
182
+
183
+ $encoder_options = $thisfile_mpeg_audio_lame['preset_used'];
184
+
185
+ } elseif (!empty($thisfile_mpeg_audio_lame['vbr_quality'])) {
186
+
187
+ static $KnownEncoderValues = array();
188
+ if (empty($KnownEncoderValues)) {
189
+
190
+ //$KnownEncoderValues[abrbitrate_minbitrate][vbr_quality][raw_vbr_method][raw_noise_shaping][raw_stereo_mode][ath_type][lowpass_frequency] = 'preset name';
191
+ $KnownEncoderValues[0xFF][58][1][1][3][2][20500] = '--alt-preset insane'; // 3.90, 3.90.1, 3.92
192
+ $KnownEncoderValues[0xFF][58][1][1][3][2][20600] = '--alt-preset insane'; // 3.90.2, 3.90.3, 3.91
193
+ $KnownEncoderValues[0xFF][57][1][1][3][4][20500] = '--alt-preset insane'; // 3.94, 3.95
194
+ $KnownEncoderValues['**'][78][3][2][3][2][19500] = '--alt-preset extreme'; // 3.90, 3.90.1, 3.92
195
+ $KnownEncoderValues['**'][78][3][2][3][2][19600] = '--alt-preset extreme'; // 3.90.2, 3.91
196
+ $KnownEncoderValues['**'][78][3][1][3][2][19600] = '--alt-preset extreme'; // 3.90.3
197
+ $KnownEncoderValues['**'][78][4][2][3][2][19500] = '--alt-preset fast extreme'; // 3.90, 3.90.1, 3.92
198
+ $KnownEncoderValues['**'][78][4][2][3][2][19600] = '--alt-preset fast extreme'; // 3.90.2, 3.90.3, 3.91
199
+ $KnownEncoderValues['**'][78][3][2][3][4][19000] = '--alt-preset standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
200
+ $KnownEncoderValues['**'][78][3][1][3][4][19000] = '--alt-preset standard'; // 3.90.3
201
+ $KnownEncoderValues['**'][78][4][2][3][4][19000] = '--alt-preset fast standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
202
+ $KnownEncoderValues['**'][78][4][1][3][4][19000] = '--alt-preset fast standard'; // 3.90.3
203
+ $KnownEncoderValues['**'][88][4][1][3][3][19500] = '--r3mix'; // 3.90, 3.90.1, 3.92
204
+ $KnownEncoderValues['**'][88][4][1][3][3][19600] = '--r3mix'; // 3.90.2, 3.90.3, 3.91
205
+ $KnownEncoderValues['**'][67][4][1][3][4][18000] = '--r3mix'; // 3.94, 3.95
206
+ $KnownEncoderValues['**'][68][3][2][3][4][18000] = '--alt-preset medium'; // 3.90.3
207
+ $KnownEncoderValues['**'][68][4][2][3][4][18000] = '--alt-preset fast medium'; // 3.90.3
208
+
209
+ $KnownEncoderValues[0xFF][99][1][1][1][2][0] = '--preset studio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
210
+ $KnownEncoderValues[0xFF][58][2][1][3][2][20600] = '--preset studio'; // 3.90.3, 3.93.1
211
+ $KnownEncoderValues[0xFF][58][2][1][3][2][20500] = '--preset studio'; // 3.93
212
+ $KnownEncoderValues[0xFF][57][2][1][3][4][20500] = '--preset studio'; // 3.94, 3.95
213
+ $KnownEncoderValues[0xC0][88][1][1][1][2][0] = '--preset cd'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
214
+ $KnownEncoderValues[0xC0][58][2][2][3][2][19600] = '--preset cd'; // 3.90.3, 3.93.1
215
+ $KnownEncoderValues[0xC0][58][2][2][3][2][19500] = '--preset cd'; // 3.93
216
+ $KnownEncoderValues[0xC0][57][2][1][3][4][19500] = '--preset cd'; // 3.94, 3.95
217
+ $KnownEncoderValues[0xA0][78][1][1][3][2][18000] = '--preset hifi'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
218
+ $KnownEncoderValues[0xA0][58][2][2][3][2][18000] = '--preset hifi'; // 3.90.3, 3.93, 3.93.1
219
+ $KnownEncoderValues[0xA0][57][2][1][3][4][18000] = '--preset hifi'; // 3.94, 3.95
220
+ $KnownEncoderValues[0x80][67][1][1][3][2][18000] = '--preset tape'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
221
+ $KnownEncoderValues[0x80][67][1][1][3][2][15000] = '--preset radio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
222
+ $KnownEncoderValues[0x70][67][1][1][3][2][15000] = '--preset fm'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
223
+ $KnownEncoderValues[0x70][58][2][2][3][2][16000] = '--preset tape/radio/fm'; // 3.90.3, 3.93, 3.93.1
224
+ $KnownEncoderValues[0x70][57][2][1][3][4][16000] = '--preset tape/radio/fm'; // 3.94, 3.95
225
+ $KnownEncoderValues[0x38][58][2][2][0][2][10000] = '--preset voice'; // 3.90.3, 3.93, 3.93.1
226
+ $KnownEncoderValues[0x38][57][2][1][0][4][15000] = '--preset voice'; // 3.94, 3.95
227
+ $KnownEncoderValues[0x38][57][2][1][0][4][16000] = '--preset voice'; // 3.94a14
228
+ $KnownEncoderValues[0x28][65][1][1][0][2][7500] = '--preset mw-us'; // 3.90, 3.90.1, 3.92
229
+ $KnownEncoderValues[0x28][65][1][1][0][2][7600] = '--preset mw-us'; // 3.90.2, 3.91
230
+ $KnownEncoderValues[0x28][58][2][2][0][2][7000] = '--preset mw-us'; // 3.90.3, 3.93, 3.93.1
231
+ $KnownEncoderValues[0x28][57][2][1][0][4][10500] = '--preset mw-us'; // 3.94, 3.95
232
+ $KnownEncoderValues[0x28][57][2][1][0][4][11200] = '--preset mw-us'; // 3.94a14
233
+ $KnownEncoderValues[0x28][57][2][1][0][4][8800] = '--preset mw-us'; // 3.94a15
234
+ $KnownEncoderValues[0x18][58][2][2][0][2][4000] = '--preset phon+/lw/mw-eu/sw'; // 3.90.3, 3.93.1
235
+ $KnownEncoderValues[0x18][58][2][2][0][2][3900] = '--preset phon+/lw/mw-eu/sw'; // 3.93
236
+ $KnownEncoderValues[0x18][57][2][1][0][4][5900] = '--preset phon+/lw/mw-eu/sw'; // 3.94, 3.95
237
+ $KnownEncoderValues[0x18][57][2][1][0][4][6200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a14
238
+ $KnownEncoderValues[0x18][57][2][1][0][4][3200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a15
239
+ $KnownEncoderValues[0x10][58][2][2][0][2][3800] = '--preset phone'; // 3.90.3, 3.93.1
240
+ $KnownEncoderValues[0x10][58][2][2][0][2][3700] = '--preset phone'; // 3.93
241
+ $KnownEncoderValues[0x10][57][2][1][0][4][5600] = '--preset phone'; // 3.94, 3.95
242
+ }
243
+
244
+ if (isset($KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) {
245
+
246
+ $encoder_options = $KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']];
247
+
248
+ } elseif (isset($KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) {
249
+
250
+ $encoder_options = $KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']];
251
+
252
+ } elseif ($info['audio']['bitrate_mode'] == 'vbr') {
253
+
254
+ // http://gabriel.mp3-tech.org/mp3infotag.html
255
+ // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h
256
+
257
+
258
+ $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame['vbr_quality'] / 10);
259
+ $LAME_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($LAME_V_value * 10);
260
+ $encoder_options = '-V'.$LAME_V_value.' -q'.$LAME_q_value;
261
+
262
+ } elseif ($info['audio']['bitrate_mode'] == 'cbr') {
263
+
264
+ $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
265
+
266
+ } else {
267
+
268
+ $encoder_options = strtoupper($info['audio']['bitrate_mode']);
269
+
270
+ }
271
+
272
+ } elseif (!empty($thisfile_mpeg_audio_lame['bitrate_abr'])) {
273
+
274
+ $encoder_options = 'ABR'.$thisfile_mpeg_audio_lame['bitrate_abr'];
275
+
276
+ } elseif (!empty($info['audio']['bitrate'])) {
277
+
278
+ if ($info['audio']['bitrate_mode'] == 'cbr') {
279
+ $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
280
+ } else {
281
+ $encoder_options = strtoupper($info['audio']['bitrate_mode']);
282
+ }
283
+
284
+ }
285
+ if (!empty($thisfile_mpeg_audio_lame['bitrate_min'])) {
286
+ $encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min'];
287
+ }
288
+
289
+ if (!empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev']) || !empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])) {
290
+ $encoder_options .= ' --nogap';
291
+ }
292
+
293
+ if (!empty($thisfile_mpeg_audio_lame['lowpass_frequency'])) {
294
+ $ExplodedOptions = explode(' ', $encoder_options, 4);
295
+ if ($ExplodedOptions[0] == '--r3mix') {
296
+ $ExplodedOptions[1] = 'r3mix';
297
+ }
298
+ switch ($ExplodedOptions[0]) {
299
+ case '--preset':
300
+ case '--alt-preset':
301
+ case '--r3mix':
302
+ if ($ExplodedOptions[1] == 'fast') {
303
+ $ExplodedOptions[1] .= ' '.$ExplodedOptions[2];
304
+ }
305
+ switch ($ExplodedOptions[1]) {
306
+ case 'portable':
307
+ case 'medium':
308
+ case 'standard':
309
+ case 'extreme':
310
+ case 'insane':
311
+ case 'fast portable':
312
+ case 'fast medium':
313
+ case 'fast standard':
314
+ case 'fast extreme':
315
+ case 'fast insane':
316
+ case 'r3mix':
317
+ static $ExpectedLowpass = array(
318
+ 'insane|20500' => 20500,
319
+ 'insane|20600' => 20600, // 3.90.2, 3.90.3, 3.91
320
+ 'medium|18000' => 18000,
321
+ 'fast medium|18000' => 18000,
322
+ 'extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
323
+ 'extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
324
+ 'fast extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
325
+ 'fast extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
326
+ 'standard|19000' => 19000,
327
+ 'fast standard|19000' => 19000,
328
+ 'r3mix|19500' => 19500, // 3.90, 3.90.1, 3.92
329
+ 'r3mix|19600' => 19600, // 3.90.2, 3.90.3, 3.91
330
+ 'r3mix|18000' => 18000, // 3.94, 3.95
331
+ );
332
+ if (!isset($ExpectedLowpass[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio_lame['lowpass_frequency']]) && ($thisfile_mpeg_audio_lame['lowpass_frequency'] < 22050) && (round($thisfile_mpeg_audio_lame['lowpass_frequency'] / 1000) < round($thisfile_mpeg_audio['sample_rate'] / 2000))) {
333
+ $encoder_options .= ' --lowpass '.$thisfile_mpeg_audio_lame['lowpass_frequency'];
334
+ }
335
+ break;
336
+
337
+ default:
338
+ break;
339
+ }
340
+ break;
341
+ }
342
+ }
343
+
344
+ if (isset($thisfile_mpeg_audio_lame['raw']['source_sample_freq'])) {
345
+ if (($thisfile_mpeg_audio['sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 1)) {
346
+ $encoder_options .= ' --resample 44100';
347
+ } elseif (($thisfile_mpeg_audio['sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 2)) {
348
+ $encoder_options .= ' --resample 48000';
349
+ } elseif ($thisfile_mpeg_audio['sample_rate'] < 44100) {
350
+ switch ($thisfile_mpeg_audio_lame['raw']['source_sample_freq']) {
351
+ case 0: // <= 32000
352
+ // may or may not be same as source frequency - ignore
353
+ break;
354
+ case 1: // 44100
355
+ case 2: // 48000
356
+ case 3: // 48000+
357
+ $ExplodedOptions = explode(' ', $encoder_options, 4);
358
+ switch ($ExplodedOptions[0]) {
359
+ case '--preset':
360
+ case '--alt-preset':
361
+ switch ($ExplodedOptions[1]) {
362
+ case 'fast':
363
+ case 'portable':
364
+ case 'medium':
365
+ case 'standard':
366
+ case 'extreme':
367
+ case 'insane':
368
+ $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
369
+ break;
370
+
371
+ default:
372
+ static $ExpectedResampledRate = array(
373
+ 'phon+/lw/mw-eu/sw|16000' => 16000,
374
+ 'mw-us|24000' => 24000, // 3.95
375
+ 'mw-us|32000' => 32000, // 3.93
376
+ 'mw-us|16000' => 16000, // 3.92
377
+ 'phone|16000' => 16000,
378
+ 'phone|11025' => 11025, // 3.94a15
379
+ 'radio|32000' => 32000, // 3.94a15
380
+ 'fm/radio|32000' => 32000, // 3.92
381
+ 'fm|32000' => 32000, // 3.90
382
+ 'voice|32000' => 32000);
383
+ if (!isset($ExpectedResampledRate[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio['sample_rate']])) {
384
+ $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
385
+ }
386
+ break;
387
+ }
388
+ break;
389
+
390
+ case '--r3mix':
391
+ default:
392
+ $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
393
+ break;
394
+ }
395
+ break;
396
+ }
397
+ }
398
+ }
399
+ if (empty($encoder_options) && !empty($info['audio']['bitrate']) && !empty($info['audio']['bitrate_mode'])) {
400
+ //$encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
401
+ $encoder_options = strtoupper($info['audio']['bitrate_mode']);
402
+ }
403
+
404
+ return $encoder_options;
405
+ }
406
+
407
+
408
+ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) {
409
+ static $MPEGaudioVersionLookup;
410
+ static $MPEGaudioLayerLookup;
411
+ static $MPEGaudioBitrateLookup;
412
+ static $MPEGaudioFrequencyLookup;
413
+ static $MPEGaudioChannelModeLookup;
414
+ static $MPEGaudioModeExtensionLookup;
415
+ static $MPEGaudioEmphasisLookup;
416
+ if (empty($MPEGaudioVersionLookup)) {
417
+ $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
418
+ $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
419
+ $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
420
+ $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray();
421
+ $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray();
422
+ $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();
423
+ $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray();
424
+ }
425
+
426
+ if ($this->fseek($offset) != 0) {
427
+ $info['error'][] = 'decodeMPEGaudioHeader() failed to seek to next offset at '.$offset;
428
+ return false;
429
+ }
430
+ //$headerstring = $this->fread(1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame
431
+ $headerstring = $this->fread(226); // LAME header at offset 36 + 190 bytes of Xing/LAME data
432
+
433
+ // MP3 audio frame structure:
434
+ // $aa $aa $aa $aa [$bb $bb] $cc...
435
+ // where $aa..$aa is the four-byte mpeg-audio header (below)
436
+ // $bb $bb is the optional 2-byte CRC
437
+ // and $cc... is the audio data
438
+
439
+ $head4 = substr($headerstring, 0, 4);
440
+
441
+ static $MPEGaudioHeaderDecodeCache = array();
442
+ if (isset($MPEGaudioHeaderDecodeCache[$head4])) {
443
+ $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
444
+ } else {
445
+ $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4);
446
+ $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
447
+ }
448
+
449
+ static $MPEGaudioHeaderValidCache = array();
450
+ if (!isset($MPEGaudioHeaderValidCache[$head4])) { // Not in cache
451
+ //$MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)
452
+ $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);
453
+ }
454
+
455
+ // shortcut
456
+ if (!isset($info['mpeg']['audio'])) {
457
+ $info['mpeg']['audio'] = array();
458
+ }
459
+ $thisfile_mpeg_audio = &$info['mpeg']['audio'];
460
+
461
+
462
+ if ($MPEGaudioHeaderValidCache[$head4]) {
463
+ $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray;
464
+ } else {
465
+ $info['error'][] = 'Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset;
466
+ return false;
467
+ }
468
+
469
+ if (!$FastMPEGheaderScan) {
470
+ $thisfile_mpeg_audio['version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']];
471
+ $thisfile_mpeg_audio['layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']];
472
+
473
+ $thisfile_mpeg_audio['channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio['raw']['channelmode']];
474
+ $thisfile_mpeg_audio['channels'] = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2);
475
+ $thisfile_mpeg_audio['sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']];
476
+ $thisfile_mpeg_audio['protection'] = !$thisfile_mpeg_audio['raw']['protection'];
477
+ $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private'];
478
+ $thisfile_mpeg_audio['modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']];
479
+ $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright'];
480
+ $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original'];
481
+ $thisfile_mpeg_audio['emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']];
482
+
483
+ $info['audio']['channels'] = $thisfile_mpeg_audio['channels'];
484
+ $info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate'];
485
+
486
+ if ($thisfile_mpeg_audio['protection']) {
487
+ $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($headerstring, 4, 2));
488
+ }
489
+ }
490
+
491
+ if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) {
492
+ // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0
493
+ $info['warning'][] = 'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';
494
+ $thisfile_mpeg_audio['raw']['bitrate'] = 0;
495
+ }
496
+ $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding'];
497
+ $thisfile_mpeg_audio['bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']];
498
+
499
+ if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $info['avdataoffset'])) {
500
+ // only skip multiple frame check if free-format bitstream found at beginning of file
501
+ // otherwise is quite possibly simply corrupted data
502
+ $recursivesearch = false;
503
+ }
504
+
505
+ // For Layer 2 there are some combinations of bitrate and mode which are not allowed.
506
+ if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio['layer'] == '2')) {
507
+
508
+ $info['audio']['dataformat'] = 'mp2';
509
+ switch ($thisfile_mpeg_audio['channelmode']) {
510
+
511
+ case 'mono':
512
+ if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000)) {
513
+ // these are ok
514
+ } else {
515
+ $info['error'][] = $thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
516
+ return false;
517
+ }
518
+ break;
519
+
520
+ case 'stereo':
521
+ case 'joint stereo':
522
+ case 'dual channel':
523
+ if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000)) {
524
+ // these are ok
525
+ } else {
526
+ $info['error'][] = intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
527
+ return false;
528
+ }
529
+ break;
530
+
531
+ }
532
+
533
+ }
534
+
535
+
536
+ if ($info['audio']['sample_rate'] > 0) {
537
+ $thisfile_mpeg_audio['framelength'] = self::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $info['audio']['sample_rate']);
538
+ }
539
+
540
+ $nextframetestoffset = $offset + 1;
541
+ if ($thisfile_mpeg_audio['bitrate'] != 'free') {
542
+
543
+ $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
544
+
545
+ if (isset($thisfile_mpeg_audio['framelength'])) {
546
+ $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength'];
547
+ } else {
548
+ $info['error'][] = 'Frame at offset('.$offset.') is has an invalid frame length.';
549
+ return false;
550
+ }
551
+
552
+ }
553
+
554
+ $ExpectedNumberOfAudioBytes = 0;
555
+
556
+ ////////////////////////////////////////////////////////////////////////////////////
557
+ // Variable-bitrate headers
558
+
559
+ if (substr($headerstring, 4 + 32, 4) == 'VBRI') {
560
+ // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36)
561
+ // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html
562
+
563
+ $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
564
+ $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer';
565
+ $info['audio']['codec'] = 'Fraunhofer';
566
+
567
+ $SideInfoData = substr($headerstring, 4 + 2, 32);
568
+
569
+ $FraunhoferVBROffset = 36;
570
+
571
+ $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); // VbriVersion
572
+ $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); // VbriDelay
573
+ $thisfile_mpeg_audio['VBR_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); // VbriQuality
574
+ $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); // VbriStreamBytes
575
+ $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); // VbriStreamFrames
576
+ $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); // VbriTableSize
577
+ $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 2)); // VbriTableScale
578
+ $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 22, 2)); // VbriEntryBytes
579
+ $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); // VbriEntryFrames
580
+
581
+ $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio['VBR_bytes'];
582
+
583
+ $previousbyteoffset = $offset;
584
+ for ($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i++) {
585
+ $Fraunhofer_OffsetN = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, $thisfile_mpeg_audio['VBR_entry_bytes']));
586
+ $FraunhoferVBROffset += $thisfile_mpeg_audio['VBR_entry_bytes'];
587
+ $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']);
588
+ $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']) + $previousbyteoffset;
589
+ $previousbyteoffset += $Fraunhofer_OffsetN;
590
+ }
591
+
592
+
593
+ } else {
594
+
595
+ // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36)
596
+ // depending on MPEG layer and number of channels
597
+
598
+ $VBRidOffset = self::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']);
599
+ $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4);
600
+
601
+ if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) {
602
+ // 'Xing' is traditional Xing VBR frame
603
+ // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.)
604
+ // 'Info' *can* legally be used to specify a VBR file as well, however.
605
+
606
+ // http://www.multiweb.cz/twoinches/MP3inside.htm
607
+ //00..03 = "Xing" or "Info"
608
+ //04..07 = Flags:
609
+ // 0x01 Frames Flag set if value for number of frames in file is stored
610
+ // 0x02 Bytes Flag set if value for filesize in bytes is stored
611
+ // 0x04 TOC Flag set if values for TOC are stored
612
+ // 0x08 VBR Scale Flag set if values for VBR scale is stored
613
+ //08..11 Frames: Number of frames in file (including the first Xing/Info one)
614
+ //12..15 Bytes: File length in Bytes
615
+ //16..115 TOC (Table of Contents):
616
+ // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file.
617
+ // Each Byte has a value according this formula:
618
+ // (TOC[i] / 256) * fileLenInBytes
619
+ // So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000 000 Bytes length) you can use:
620
+ // TOC[(60/240)*100] = TOC[25]
621
+ // and corresponding Byte in file is then approximately at:
622
+ // (TOC[25]/256) * 5000000
623
+ //116..119 VBR Scale
624
+
625
+
626
+ // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME
627
+ // if (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Xing') {
628
+ $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
629
+ $thisfile_mpeg_audio['VBR_method'] = 'Xing';
630
+ // } else {
631
+ // $ScanAsCBR = true;
632
+ // $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
633
+ // }
634
+
635
+ $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4));
636
+
637
+ $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000001);
638
+ $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000002);
639
+ $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000004);
640
+ $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000008);
641
+
642
+ if ($thisfile_mpeg_audio['xing_flags']['frames']) {
643
+ $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4));
644
+ //$thisfile_mpeg_audio['VBR_frames']--; // don't count header Xing/Info frame
645
+ }
646
+ if ($thisfile_mpeg_audio['xing_flags']['bytes']) {
647
+ $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4));
648
+ }
649
+
650
+ //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
651
+ if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
652
+
653
+ $framelengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'];
654
+
655
+ if ($thisfile_mpeg_audio['layer'] == '1') {
656
+ // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
657
+ //$info['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12;
658
+ $info['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 12;
659
+ } else {
660
+ // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
661
+ //$info['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
662
+ $info['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144;
663
+ }
664
+ $thisfile_mpeg_audio['framelength'] = floor($framelengthfloat);
665
+ }
666
+
667
+ if ($thisfile_mpeg_audio['xing_flags']['toc']) {
668
+ $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100);
669
+ for ($i = 0; $i < 100; $i++) {
670
+ $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData{$i});
671
+ }
672
+ }
673
+ if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) {
674
+ $thisfile_mpeg_audio['VBR_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4));
675
+ }
676
+
677
+
678
+ // http://gabriel.mp3-tech.org/mp3infotag.html
679
+ if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') {
680
+
681
+ // shortcut
682
+ $thisfile_mpeg_audio['LAME'] = array();
683
+ $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
684
+
685
+
686
+ $thisfile_mpeg_audio_lame['long_version'] = substr($headerstring, $VBRidOffset + 120, 20);
687
+ $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9);
688
+
689
+ if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') {
690
+
691
+ // extra 11 chars are not part of version string when LAMEtag present
692
+ unset($thisfile_mpeg_audio_lame['long_version']);
693
+
694
+ // It the LAME tag was only introduced in LAME v3.90
695
+ // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933
696
+
697
+ // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html
698
+ // are assuming a 'Xing' identifier offset of 0x24, which is the case for
699
+ // MPEG-1 non-mono, but not for other combinations
700
+ $LAMEtagOffsetContant = $VBRidOffset - 0x24;
701
+
702
+ // shortcuts
703
+ $thisfile_mpeg_audio_lame['RGAD'] = array('track'=>array(), 'album'=>array());
704
+ $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD'];
705
+ $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track'];
706
+ $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album'];
707
+ $thisfile_mpeg_audio_lame['raw'] = array();
708
+ $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw'];
709
+
710
+ // byte $9B VBR Quality
711
+ // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications.
712
+ // Actually overwrites original Xing bytes
713
+ unset($thisfile_mpeg_audio['VBR_scale']);
714
+ $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1));
715
+
716
+ // bytes $9C-$A4 Encoder short VersionString
717
+ $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9);
718
+
719
+ // byte $A5 Info Tag revision + VBR method
720
+ $LAMEtagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1));
721
+
722
+ $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4;
723
+ $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F;
724
+ $thisfile_mpeg_audio_lame['vbr_method'] = self::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']);
725
+ $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr'
726
+
727
+ // byte $A6 Lowpass filter value
728
+ $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;
729
+
730
+ // bytes $A7-$AE Replay Gain
731
+ // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
732
+ // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude"
733
+ if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') {
734
+ // LAME 3.94a16 and later - 9.23 fixed point
735
+ // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375
736
+ $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608);
737
+ } else {
738
+ // LAME 3.94a15 and earlier - 32-bit floating point
739
+ // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15
740
+ $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4));
741
+ }
742
+ if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0) {
743
+ unset($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']);
744
+ } else {
745
+ $thisfile_mpeg_audio_lame_RGAD['peak_db'] = getid3_lib::RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']);
746
+ }
747
+
748
+ $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2));
749
+ $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2));
750
+
751
+
752
+ if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) {
753
+
754
+ $thisfile_mpeg_audio_lame_RGAD_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xE000) >> 13;
755
+ $thisfile_mpeg_audio_lame_RGAD_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1C00) >> 10;
756
+ $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x0200) >> 9;
757
+ $thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x01FF;
758
+ $thisfile_mpeg_audio_lame_RGAD_track['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['name']);
759
+ $thisfile_mpeg_audio_lame_RGAD_track['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['originator']);
760
+ $thisfile_mpeg_audio_lame_RGAD_track['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit']);
761
+
762
+ if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) {
763
+ $info['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'];
764
+ }
765
+ $info['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_RGAD_track['originator'];
766
+ $info['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track['gain_db'];
767
+ } else {
768
+ unset($thisfile_mpeg_audio_lame_RGAD['track']);
769
+ }
770
+ if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) {
771
+
772
+ $thisfile_mpeg_audio_lame_RGAD_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xE000) >> 13;
773
+ $thisfile_mpeg_audio_lame_RGAD_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1C00) >> 10;
774
+ $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x0200) >> 9;
775
+ $thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x01FF;
776
+ $thisfile_mpeg_audio_lame_RGAD_album['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['name']);
777
+ $thisfile_mpeg_audio_lame_RGAD_album['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['originator']);
778
+ $thisfile_mpeg_audio_lame_RGAD_album['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit']);
779
+
780
+ if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) {
781
+ $info['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'];
782
+ }
783
+ $info['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_RGAD_album['originator'];
784
+ $info['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album['gain_db'];
785
+ } else {
786
+ unset($thisfile_mpeg_audio_lame_RGAD['album']);
787
+ }
788
+ if (empty($thisfile_mpeg_audio_lame_RGAD)) {
789
+ unset($thisfile_mpeg_audio_lame['RGAD']);
790
+ }
791
+
792
+
793
+ // byte $AF Encoding flags + ATH Type
794
+ $EncodingFlagsATHtype = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1));
795
+ $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10);
796
+ $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20);
797
+ $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40);
798
+ $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80);
799
+ $thisfile_mpeg_audio_lame['ath_type'] = $EncodingFlagsATHtype & 0x0F;
800
+
801
+ // byte $B0 if ABR {specified bitrate} else {minimal bitrate}
802
+ $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1));
803
+ if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR)
804
+ $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'];
805
+ } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR)
806
+ // ignore
807
+ } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate
808
+ $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'];
809
+ }
810
+
811
+ // bytes $B1-$B3 Encoder delays
812
+ $EncoderDelays = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3));
813
+ $thisfile_mpeg_audio_lame['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12;
814
+ $thisfile_mpeg_audio_lame['end_padding'] = $EncoderDelays & 0x000FFF;
815
+
816
+ // byte $B4 Misc
817
+ $MiscByte = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1));
818
+ $thisfile_mpeg_audio_lame_raw['noise_shaping'] = ($MiscByte & 0x03);
819
+ $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($MiscByte & 0x1C) >> 2;
820
+ $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($MiscByte & 0x20) >> 5;
821
+ $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($MiscByte & 0xC0) >> 6;
822
+ $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping'];
823
+ $thisfile_mpeg_audio_lame['stereo_mode'] = self::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']);
824
+ $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality'];
825
+ $thisfile_mpeg_audio_lame['source_sample_freq'] = self::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']);
826
+
827
+ // byte $B5 MP3 Gain
828
+ $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true);
829
+ $thisfile_mpeg_audio_lame['mp3_gain_db'] = (getid3_lib::RGADamplitude2dB(2) / 4) * $thisfile_mpeg_audio_lame_raw['mp3_gain'];
830
+ $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame['mp3_gain_db'] / 6));
831
+
832
+ // bytes $B6-$B7 Preset and surround info
833
+ $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2));
834
+ // Reserved = ($PresetSurroundBytes & 0xC000);
835
+ $thisfile_mpeg_audio_lame_raw['surround_info'] = ($PresetSurroundBytes & 0x3800);
836
+ $thisfile_mpeg_audio_lame['surround_info'] = self::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']);
837
+ $thisfile_mpeg_audio_lame['preset_used_id'] = ($PresetSurroundBytes & 0x07FF);
838
+ $thisfile_mpeg_audio_lame['preset_used'] = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame);
839
+ if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) {
840
+ $info['warning'][] = 'Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org';
841
+ }
842
+ if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) {
843
+ // this may change if 3.90.4 ever comes out
844
+ $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3';
845
+ }
846
+
847
+ // bytes $B8-$BB MusicLength
848
+ $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4));
849
+ $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame['audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']);
850
+
851
+ // bytes $BC-$BD MusicCRC
852
+ $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2));
853
+
854
+ // bytes $BE-$BF CRC-16 of Info Tag
855
+ $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2));
856
+
857
+
858
+ // LAME CBR
859
+ if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) {
860
+
861
+ $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
862
+ $thisfile_mpeg_audio['bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']);
863
+ $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
864
+ //if (empty($thisfile_mpeg_audio['bitrate']) || (!empty($thisfile_mpeg_audio_lame['bitrate_min']) && ($thisfile_mpeg_audio_lame['bitrate_min'] != 255))) {
865
+ // $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio_lame['bitrate_min'];
866
+ //}
867
+
868
+ }
869
+
870
+ }
871
+ }
872
+
873
+ } else {
874
+
875
+ // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header)
876
+ $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
877
+ if ($recursivesearch) {
878
+ $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
879
+ if ($this->RecursiveFrameScanning($offset, $nextframetestoffset, true)) {
880
+ $recursivesearch = false;
881
+ $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
882
+ }
883
+ if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') {
884
+ $info['warning'][] = 'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.';
885
+ }
886
+ }
887
+
888
+ }
889
+
890
+ }
891
+
892
+ if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($info['avdataend'] - $info['avdataoffset']))) {
893
+ if ($ExpectedNumberOfAudioBytes > ($info['avdataend'] - $info['avdataoffset'])) {
894
+ if ($this->isDependencyFor('matroska') || $this->isDependencyFor('riff')) {
895
+ // ignore, audio data is broken into chunks so will always be data "missing"
896
+ }
897
+ elseif (($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) {
898
+ $this->warning('Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)');
899
+ }
900
+ else {
901
+ $this->warning('Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)');
902
+ }
903
+ } else {
904
+ if ((($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) {
905
+ // $prenullbytefileoffset = $this->ftell();
906
+ // $this->fseek($info['avdataend']);
907
+ // $PossibleNullByte = $this->fread(1);
908
+ // $this->fseek($prenullbytefileoffset);
909
+ // if ($PossibleNullByte === "\x00") {
910
+ $info['avdataend']--;
911
+ // $info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
912
+ // } else {
913
+ // $info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';
914
+ // }
915
+ } else {
916
+ $info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';
917
+ }
918
+ }
919
+ }
920
+
921
+ if (($thisfile_mpeg_audio['bitrate'] == 'free') && empty($info['audio']['bitrate'])) {
922
+ if (($offset == $info['avdataoffset']) && empty($thisfile_mpeg_audio['VBR_frames'])) {
923
+ $framebytelength = $this->FreeFormatFrameLength($offset, true);
924
+ if ($framebytelength > 0) {
925
+ $thisfile_mpeg_audio['framelength'] = $framebytelength;
926
+ if ($thisfile_mpeg_audio['layer'] == '1') {
927
+ // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
928
+ $info['audio']['bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12;
929
+ } else {
930
+ // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
931
+ $info['audio']['bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
932
+ }
933
+ } else {
934
+ $info['error'][] = 'Error calculating frame length of free-format MP3 without Xing/LAME header';
935
+ }
936
+ }
937
+ }
938
+
939
+ if (isset($thisfile_mpeg_audio['VBR_frames']) ? $thisfile_mpeg_audio['VBR_frames'] : '') {
940
+ switch ($thisfile_mpeg_audio['bitrate_mode']) {
941
+ case 'vbr':
942
+ case 'abr':
943
+ $bytes_per_frame = 1152;
944
+ if (($thisfile_mpeg_audio['version'] == '1') && ($thisfile_mpeg_audio['layer'] == 1)) {
945
+ $bytes_per_frame = 384;
946
+ } elseif ((($thisfile_mpeg_audio['version'] == '2') || ($thisfile_mpeg_audio['version'] == '2.5')) && ($thisfile_mpeg_audio['layer'] == 3)) {
947
+ $bytes_per_frame = 576;
948
+ }
949
+ $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / $bytes_per_frame) : 0);
950
+ if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) {
951
+ $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate'];
952
+ $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion
953
+ }
954
+ break;
955
+ }
956
+ }
957
+
958
+ // End variable-bitrate headers
959
+ ////////////////////////////////////////////////////////////////////////////////////
960
+
961
+ if ($recursivesearch) {
962
+
963
+ if (!$this->RecursiveFrameScanning($offset, $nextframetestoffset, $ScanAsCBR)) {
964
+ return false;
965
+ }
966
+
967
+ }
968
+
969
+
970
+ //if (false) {
971
+ // // experimental side info parsing section - not returning anything useful yet
972
+ //
973
+ // $SideInfoBitstream = getid3_lib::BigEndian2Bin($SideInfoData);
974
+ // $SideInfoOffset = 0;
975
+ //
976
+ // if ($thisfile_mpeg_audio['version'] == '1') {
977
+ // if ($thisfile_mpeg_audio['channelmode'] == 'mono') {
978
+ // // MPEG-1 (mono)
979
+ // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9);
980
+ // $SideInfoOffset += 9;
981
+ // $SideInfoOffset += 5;
982
+ // } else {
983
+ // // MPEG-1 (stereo, joint-stereo, dual-channel)
984
+ // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9);
985
+ // $SideInfoOffset += 9;
986
+ // $SideInfoOffset += 3;
987
+ // }
988
+ // } else { // 2 or 2.5
989
+ // if ($thisfile_mpeg_audio['channelmode'] == 'mono') {
990
+ // // MPEG-2, MPEG-2.5 (mono)
991
+ // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8);
992
+ // $SideInfoOffset += 8;
993
+ // $SideInfoOffset += 1;
994
+ // } else {
995
+ // // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel)
996
+ // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8);
997
+ // $SideInfoOffset += 8;
998
+ // $SideInfoOffset += 2;
999
+ // }
1000
+ // }
1001
+ //
1002
+ // if ($thisfile_mpeg_audio['version'] == '1') {
1003
+ // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) {
1004
+ // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) {
1005
+ // $thisfile_mpeg_audio['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1006
+ // $SideInfoOffset += 2;
1007
+ // }
1008
+ // }
1009
+ // }
1010
+ // for ($granule = 0; $granule < (($thisfile_mpeg_audio['version'] == '1') ? 2 : 1); $granule++) {
1011
+ // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) {
1012
+ // $thisfile_mpeg_audio['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12);
1013
+ // $SideInfoOffset += 12;
1014
+ // $thisfile_mpeg_audio['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9);
1015
+ // $SideInfoOffset += 9;
1016
+ // $thisfile_mpeg_audio['global_gain'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 8);
1017
+ // $SideInfoOffset += 8;
1018
+ // if ($thisfile_mpeg_audio['version'] == '1') {
1019
+ // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4);
1020
+ // $SideInfoOffset += 4;
1021
+ // } else {
1022
+ // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9);
1023
+ // $SideInfoOffset += 9;
1024
+ // }
1025
+ // $thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1026
+ // $SideInfoOffset += 1;
1027
+ //
1028
+ // if ($thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] == '1') {
1029
+ //
1030
+ // $thisfile_mpeg_audio['block_type'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 2);
1031
+ // $SideInfoOffset += 2;
1032
+ // $thisfile_mpeg_audio['mixed_block_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1033
+ // $SideInfoOffset += 1;
1034
+ //
1035
+ // for ($region = 0; $region < 2; $region++) {
1036
+ // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5);
1037
+ // $SideInfoOffset += 5;
1038
+ // }
1039
+ // $thisfile_mpeg_audio['table_select'][$granule][$channel][2] = 0;
1040
+ //
1041
+ // for ($window = 0; $window < 3; $window++) {
1042
+ // $thisfile_mpeg_audio['subblock_gain'][$granule][$channel][$window] = substr($SideInfoBitstream, $SideInfoOffset, 3);
1043
+ // $SideInfoOffset += 3;
1044
+ // }
1045
+ //
1046
+ // } else {
1047
+ //
1048
+ // for ($region = 0; $region < 3; $region++) {
1049
+ // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5);
1050
+ // $SideInfoOffset += 5;
1051
+ // }
1052
+ //
1053
+ // $thisfile_mpeg_audio['region0_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4);
1054
+ // $SideInfoOffset += 4;
1055
+ // $thisfile_mpeg_audio['region1_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 3);
1056
+ // $SideInfoOffset += 3;
1057
+ // $thisfile_mpeg_audio['block_type'][$granule][$channel] = 0;
1058
+ // }
1059
+ //
1060
+ // if ($thisfile_mpeg_audio['version'] == '1') {
1061
+ // $thisfile_mpeg_audio['preflag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1062
+ // $SideInfoOffset += 1;
1063
+ // }
1064
+ // $thisfile_mpeg_audio['scalefac_scale'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1065
+ // $SideInfoOffset += 1;
1066
+ // $thisfile_mpeg_audio['count1table_select'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1);
1067
+ // $SideInfoOffset += 1;
1068
+ // }
1069
+ // }
1070
+ //}
1071
+
1072
+ return true;
1073
+ }
1074
+
1075
+ public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR) {
1076
+ $info = &$this->getid3->info;
1077
+ $firstframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
1078
+ $this->decodeMPEGaudioHeader($offset, $firstframetestarray, false);
1079
+
1080
+ for ($i = 0; $i < GETID3_MP3_VALID_CHECK_FRAMES; $i++) {
1081
+ // check next GETID3_MP3_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch
1082
+ if (($nextframetestoffset + 4) >= $info['avdataend']) {
1083
+ // end of file
1084
+ return true;
1085
+ }
1086
+
1087
+ $nextframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
1088
+ if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) {
1089
+ if ($ScanAsCBR) {
1090
+ // force CBR mode, used for trying to pick out invalid audio streams with valid(?) VBR headers, or VBR streams with no VBR header
1091
+ if (!isset($nextframetestarray['mpeg']['audio']['bitrate']) || !isset($firstframetestarray['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $firstframetestarray['mpeg']['audio']['bitrate'])) {
1092
+ return false;
1093
+ }
1094
+ }
1095
+
1096
+
1097
+ // next frame is OK, get ready to check the one after that
1098
+ if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) {
1099
+ $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength'];
1100
+ } else {
1101
+ $info['error'][] = 'Frame at offset ('.$offset.') is has an invalid frame length.';
1102
+ return false;
1103
+ }
1104
+
1105
+ } elseif (!empty($firstframetestarray['mpeg']['audio']['framelength']) && (($nextframetestoffset + $firstframetestarray['mpeg']['audio']['framelength']) > $info['avdataend'])) {
1106
+
1107
+ // it's not the end of the file, but there's not enough data left for another frame, so assume it's garbage/padding and return OK
1108
+ return true;
1109
+
1110
+ } else {
1111
+
1112
+ // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence
1113
+ $info['warning'][] = 'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.';
1114
+
1115
+ return false;
1116
+ }
1117
+ }
1118
+ return true;
1119
+ }
1120
+
1121
+ public function FreeFormatFrameLength($offset, $deepscan=false) {
1122
+ $info = &$this->getid3->info;
1123
+
1124
+ $this->fseek($offset);
1125
+ $MPEGaudioData = $this->fread(32768);
1126
+
1127
+ $SyncPattern1 = substr($MPEGaudioData, 0, 4);
1128
+ // may be different pattern due to padding
1129
+ $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) | 0x02).$SyncPattern1{3};
1130
+ if ($SyncPattern2 === $SyncPattern1) {
1131
+ $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) & 0xFD).$SyncPattern1{3};
1132
+ }
1133
+
1134
+ $framelength = false;
1135
+ $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4);
1136
+ $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4);
1137
+ if ($framelength1 > 4) {
1138
+ $framelength = $framelength1;
1139
+ }
1140
+ if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1141
+ $framelength = $framelength2;
1142
+ }
1143
+ if (!$framelength) {
1144
+
1145
+ // LAME 3.88 has a different value for modeextension on the first frame vs the rest
1146
+ $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4);
1147
+ $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4);
1148
+
1149
+ if ($framelength1 > 4) {
1150
+ $framelength = $framelength1;
1151
+ }
1152
+ if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1153
+ $framelength = $framelength2;
1154
+ }
1155
+ if (!$framelength) {
1156
+ $info['error'][] = 'Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset;
1157
+ return false;
1158
+ } else {
1159
+ $info['warning'][] = 'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)';
1160
+ $info['audio']['codec'] = 'LAME';
1161
+ $info['audio']['encoder'] = 'LAME3.88';
1162
+ $SyncPattern1 = substr($SyncPattern1, 0, 3);
1163
+ $SyncPattern2 = substr($SyncPattern2, 0, 3);
1164
+ }
1165
+ }
1166
+
1167
+ if ($deepscan) {
1168
+
1169
+ $ActualFrameLengthValues = array();
1170
+ $nextoffset = $offset + $framelength;
1171
+ while ($nextoffset < ($info['avdataend'] - 6)) {
1172
+ $this->fseek($nextoffset - 1);
1173
+ $NextSyncPattern = $this->fread(6);
1174
+ if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) {
1175
+ // good - found where expected
1176
+ $ActualFrameLengthValues[] = $framelength;
1177
+ } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) {
1178
+ // ok - found one byte earlier than expected (last frame wasn't padded, first frame was)
1179
+ $ActualFrameLengthValues[] = ($framelength - 1);
1180
+ $nextoffset--;
1181
+ } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) {
1182
+ // ok - found one byte later than expected (last frame was padded, first frame wasn't)
1183
+ $ActualFrameLengthValues[] = ($framelength + 1);
1184
+ $nextoffset++;
1185
+ } else {
1186
+ $info['error'][] = 'Did not find expected free-format sync pattern at offset '.$nextoffset;
1187
+ return false;
1188
+ }
1189
+ $nextoffset += $framelength;
1190
+ }
1191
+ if (count($ActualFrameLengthValues) > 0) {
1192
+ $framelength = intval(round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues)));
1193
+ }
1194
+ }
1195
+ return $framelength;
1196
+ }
1197
+
1198
+ public function getOnlyMPEGaudioInfoBruteForce() {
1199
+ $MPEGaudioHeaderDecodeCache = array();
1200
+ $MPEGaudioHeaderValidCache = array();
1201
+ $MPEGaudioHeaderLengthCache = array();
1202
+ $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
1203
+ $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
1204
+ $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
1205
+ $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray();
1206
+ $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray();
1207
+ $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();
1208
+ $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray();
1209
+ $LongMPEGversionLookup = array();
1210
+ $LongMPEGlayerLookup = array();
1211
+ $LongMPEGbitrateLookup = array();
1212
+ $LongMPEGpaddingLookup = array();
1213
+ $LongMPEGfrequencyLookup = array();
1214
+ $Distribution['bitrate'] = array();
1215
+ $Distribution['frequency'] = array();
1216
+ $Distribution['layer'] = array();
1217
+ $Distribution['version'] = array();
1218
+ $Distribution['padding'] = array();
1219
+
1220
+ $info = &$this->getid3->info;
1221
+ $this->fseek($info['avdataoffset']);
1222
+
1223
+ $max_frames_scan = 5000;
1224
+ $frames_scanned = 0;
1225
+
1226
+ $previousvalidframe = $info['avdataoffset'];
1227
+ while ($this->ftell() < $info['avdataend']) {
1228
+ set_time_limit(30);
1229
+ $head4 = $this->fread(4);
1230
+ if (strlen($head4) < 4) {
1231
+ break;
1232
+ }
1233
+ if ($head4{0} != "\xFF") {
1234
+ for ($i = 1; $i < 4; $i++) {
1235
+ if ($head4{$i} == "\xFF") {
1236
+ $this->fseek($i - 4, SEEK_CUR);
1237
+ continue 2;
1238
+ }
1239
+ }
1240
+ continue;
1241
+ }
1242
+ if (!isset($MPEGaudioHeaderDecodeCache[$head4])) {
1243
+ $MPEGaudioHeaderDecodeCache[$head4] = self::MPEGaudioHeaderDecode($head4);
1244
+ }
1245
+ if (!isset($MPEGaudioHeaderValidCache[$head4])) {
1246
+ $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$head4], false, false);
1247
+ }
1248
+ if ($MPEGaudioHeaderValidCache[$head4]) {
1249
+
1250
+ if (!isset($MPEGaudioHeaderLengthCache[$head4])) {
1251
+ $LongMPEGversionLookup[$head4] = $MPEGaudioVersionLookup[$MPEGaudioHeaderDecodeCache[$head4]['version']];
1252
+ $LongMPEGlayerLookup[$head4] = $MPEGaudioLayerLookup[$MPEGaudioHeaderDecodeCache[$head4]['layer']];
1253
+ $LongMPEGbitrateLookup[$head4] = $MPEGaudioBitrateLookup[$LongMPEGversionLookup[$head4]][$LongMPEGlayerLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['bitrate']];
1254
+ $LongMPEGpaddingLookup[$head4] = (bool) $MPEGaudioHeaderDecodeCache[$head4]['padding'];
1255
+ $LongMPEGfrequencyLookup[$head4] = $MPEGaudioFrequencyLookup[$LongMPEGversionLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['sample_rate']];
1256
+ $MPEGaudioHeaderLengthCache[$head4] = self::MPEGaudioFrameLength(
1257
+ $LongMPEGbitrateLookup[$head4],
1258
+ $LongMPEGversionLookup[$head4],
1259
+ $LongMPEGlayerLookup[$head4],
1260
+ $LongMPEGpaddingLookup[$head4],
1261
+ $LongMPEGfrequencyLookup[$head4]);
1262
+ }
1263
+ if ($MPEGaudioHeaderLengthCache[$head4] > 4) {
1264
+ $WhereWeWere = $this->ftell();
1265
+ $this->fseek($MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR);
1266
+ $next4 = $this->fread(4);
1267
+ if ($next4{0} == "\xFF") {
1268
+ if (!isset($MPEGaudioHeaderDecodeCache[$next4])) {
1269
+ $MPEGaudioHeaderDecodeCache[$next4] = self::MPEGaudioHeaderDecode($next4);
1270
+ }
1271
+ if (!isset($MPEGaudioHeaderValidCache[$next4])) {
1272
+ $MPEGaudioHeaderValidCache[$next4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$next4], false, false);
1273
+ }
1274
+ if ($MPEGaudioHeaderValidCache[$next4]) {
1275
+ $this->fseek(-4, SEEK_CUR);
1276
+
1277
+ getid3_lib::safe_inc($Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]]);
1278
+ getid3_lib::safe_inc($Distribution['layer'][$LongMPEGlayerLookup[$head4]]);
1279
+ getid3_lib::safe_inc($Distribution['version'][$LongMPEGversionLookup[$head4]]);
1280
+ getid3_lib::safe_inc($Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])]);
1281
+ getid3_lib::safe_inc($Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]]);
1282
+ if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) {
1283
+ $pct_data_scanned = ($this->ftell() - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']);
1284
+ $info['warning'][] = 'too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
1285
+ foreach ($Distribution as $key1 => $value1) {
1286
+ foreach ($value1 as $key2 => $value2) {
1287
+ $Distribution[$key1][$key2] = round($value2 / $pct_data_scanned);
1288
+ }
1289
+ }
1290
+ break;
1291
+ }
1292
+ continue;
1293
+ }
1294
+ }
1295
+ unset($next4);
1296
+ $this->fseek($WhereWeWere - 3);
1297
+ }
1298
+
1299
+ }
1300
+ }
1301
+ foreach ($Distribution as $key => $value) {
1302
+ ksort($Distribution[$key], SORT_NUMERIC);
1303
+ }
1304
+ ksort($Distribution['version'], SORT_STRING);
1305
+ $info['mpeg']['audio']['bitrate_distribution'] = $Distribution['bitrate'];
1306
+ $info['mpeg']['audio']['frequency_distribution'] = $Distribution['frequency'];
1307
+ $info['mpeg']['audio']['layer_distribution'] = $Distribution['layer'];
1308
+ $info['mpeg']['audio']['version_distribution'] = $Distribution['version'];
1309
+ $info['mpeg']['audio']['padding_distribution'] = $Distribution['padding'];
1310
+ if (count($Distribution['version']) > 1) {
1311
+ $info['error'][] = 'Corrupt file - more than one MPEG version detected';
1312
+ }
1313
+ if (count($Distribution['layer']) > 1) {
1314
+ $info['error'][] = 'Corrupt file - more than one MPEG layer detected';
1315
+ }
1316
+ if (count($Distribution['frequency']) > 1) {
1317
+ $info['error'][] = 'Corrupt file - more than one MPEG sample rate detected';
1318
+ }
1319
+
1320
+
1321
+ $bittotal = 0;
1322
+ foreach ($Distribution['bitrate'] as $bitratevalue => $bitratecount) {
1323
+ if ($bitratevalue != 'free') {
1324
+ $bittotal += ($bitratevalue * $bitratecount);
1325
+ }
1326
+ }
1327
+ $info['mpeg']['audio']['frame_count'] = array_sum($Distribution['bitrate']);
1328
+ if ($info['mpeg']['audio']['frame_count'] == 0) {
1329
+ $info['error'][] = 'no MPEG audio frames found';
1330
+ return false;
1331
+ }
1332
+ $info['mpeg']['audio']['bitrate'] = ($bittotal / $info['mpeg']['audio']['frame_count']);
1333
+ $info['mpeg']['audio']['bitrate_mode'] = ((count($Distribution['bitrate']) > 0) ? 'vbr' : 'cbr');
1334
+ $info['mpeg']['audio']['sample_rate'] = getid3_lib::array_max($Distribution['frequency'], true);
1335
+
1336
+ $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1337
+ $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode'];
1338
+ $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1339
+ $info['audio']['dataformat'] = 'mp'.getid3_lib::array_max($Distribution['layer'], true);
1340
+ $info['fileformat'] = $info['audio']['dataformat'];
1341
+
1342
+ return true;
1343
+ }
1344
+
1345
+
1346
+ public function getOnlyMPEGaudioInfo($avdataoffset, $BitrateHistogram=false) {
1347
+ // looks for synch, decodes MPEG audio header
1348
+
1349
+ $info = &$this->getid3->info;
1350
+
1351
+ static $MPEGaudioVersionLookup;
1352
+ static $MPEGaudioLayerLookup;
1353
+ static $MPEGaudioBitrateLookup;
1354
+ if (empty($MPEGaudioVersionLookup)) {
1355
+ $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
1356
+ $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
1357
+ $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
1358
+
1359
+ }
1360
+
1361
+ $this->fseek($avdataoffset);
1362
+ $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset);
1363
+ if ($sync_seek_buffer_size <= 0) {
1364
+ $info['error'][] = 'Invalid $sync_seek_buffer_size at offset '.$avdataoffset;
1365
+ return false;
1366
+ }
1367
+ $header = $this->fread($sync_seek_buffer_size);
1368
+ $sync_seek_buffer_size = strlen($header);
1369
+ $SynchSeekOffset = 0;
1370
+ while ($SynchSeekOffset < $sync_seek_buffer_size) {
1371
+ if ((($avdataoffset + $SynchSeekOffset) < $info['avdataend']) && !feof($this->getid3->fp)) {
1372
+
1373
+ if ($SynchSeekOffset > $sync_seek_buffer_size) {
1374
+ // if a synch's not found within the first 128k bytes, then give up
1375
+ $info['error'][] = 'Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB';
1376
+ if (isset($info['audio']['bitrate'])) {
1377
+ unset($info['audio']['bitrate']);
1378
+ }
1379
+ if (isset($info['mpeg']['audio'])) {
1380
+ unset($info['mpeg']['audio']);
1381
+ }
1382
+ if (empty($info['mpeg'])) {
1383
+ unset($info['mpeg']);
1384
+ }
1385
+ return false;
1386
+
1387
+ } elseif (feof($this->getid3->fp)) {
1388
+
1389
+ $info['error'][] = 'Could not find valid MPEG audio synch before end of file';
1390
+ if (isset($info['audio']['bitrate'])) {
1391
+ unset($info['audio']['bitrate']);
1392
+ }
1393
+ if (isset($info['mpeg']['audio'])) {
1394
+ unset($info['mpeg']['audio']);
1395
+ }
1396
+ if (isset($info['mpeg']) && (!is_array($info['mpeg']) || (count($info['mpeg']) == 0))) {
1397
+ unset($info['mpeg']);
1398
+ }
1399
+ return false;
1400
+ }
1401
+ }
1402
+
1403
+ if (($SynchSeekOffset + 1) >= strlen($header)) {
1404
+ $info['error'][] = 'Could not find valid MPEG synch before end of file';
1405
+ return false;
1406
+ }
1407
+
1408
+ if (($header{$SynchSeekOffset} == "\xFF") && ($header{($SynchSeekOffset + 1)} > "\xE0")) { // synch detected
1409
+ if (!isset($FirstFrameThisfileInfo) && !isset($info['mpeg']['audio'])) {
1410
+ $FirstFrameThisfileInfo = $info;
1411
+ $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset;
1412
+ if (!$this->decodeMPEGaudioHeader($FirstFrameAVDataOffset, $FirstFrameThisfileInfo, false)) {
1413
+ // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's
1414
+ // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below
1415
+ unset($FirstFrameThisfileInfo);
1416
+ }
1417
+ }
1418
+
1419
+ $dummy = $info; // only overwrite real data if valid header found
1420
+ if ($this->decodeMPEGaudioHeader($avdataoffset + $SynchSeekOffset, $dummy, true)) {
1421
+ $info = $dummy;
1422
+ $info['avdataoffset'] = $avdataoffset + $SynchSeekOffset;
1423
+ switch (isset($info['fileformat']) ? $info['fileformat'] : '') {
1424
+ case '':
1425
+ case 'id3':
1426
+ case 'ape':
1427
+ case 'mp3':
1428
+ $info['fileformat'] = 'mp3';
1429
+ $info['audio']['dataformat'] = 'mp3';
1430
+ break;
1431
+ }
1432
+ if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) {
1433
+ if (!(abs($info['audio']['bitrate'] - $FirstFrameThisfileInfo['audio']['bitrate']) <= 1)) {
1434
+ // If there is garbage data between a valid VBR header frame and a sequence
1435
+ // of valid MPEG-audio frames the VBR data is no longer discarded.
1436
+ $info = $FirstFrameThisfileInfo;
1437
+ $info['avdataoffset'] = $FirstFrameAVDataOffset;
1438
+ $info['fileformat'] = 'mp3';
1439
+ $info['audio']['dataformat'] = 'mp3';
1440
+ $dummy = $info;
1441
+ unset($dummy['mpeg']['audio']);
1442
+ $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength'];
1443
+ $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset;
1444
+ if ($this->decodeMPEGaudioHeader($GarbageOffsetEnd, $dummy, true, true)) {
1445
+ $info = $dummy;
1446
+ $info['avdataoffset'] = $GarbageOffsetEnd;
1447
+ $info['warning'][] = 'apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd;
1448
+ } else {
1449
+ $info['warning'][] = 'using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')';
1450
+ }
1451
+ }
1452
+ }
1453
+ if (isset($info['mpeg']['audio']['bitrate_mode']) && ($info['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($info['mpeg']['audio']['VBR_method'])) {
1454
+ // VBR file with no VBR header
1455
+ $BitrateHistogram = true;
1456
+ }
1457
+
1458
+ if ($BitrateHistogram) {
1459
+
1460
+ $info['mpeg']['audio']['stereo_distribution'] = array('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0);
1461
+ $info['mpeg']['audio']['version_distribution'] = array('1'=>0, '2'=>0, '2.5'=>0);
1462
+
1463
+ if ($info['mpeg']['audio']['version'] == '1') {
1464
+ if ($info['mpeg']['audio']['layer'] == 3) {
1465
+ $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0);
1466
+ } elseif ($info['mpeg']['audio']['layer'] == 2) {
1467
+ $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0, 384000=>0);
1468
+ } elseif ($info['mpeg']['audio']['layer'] == 1) {
1469
+ $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 64000=>0, 96000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 288000=>0, 320000=>0, 352000=>0, 384000=>0, 416000=>0, 448000=>0);
1470
+ }
1471
+ } elseif ($info['mpeg']['audio']['layer'] == 1) {
1472
+ $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0, 176000=>0, 192000=>0, 224000=>0, 256000=>0);
1473
+ } else {
1474
+ $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 8000=>0, 16000=>0, 24000=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0);
1475
+ }
1476
+
1477
+ $dummy = array('error'=>$info['error'], 'warning'=>$info['warning'], 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
1478
+ $synchstartoffset = $info['avdataoffset'];
1479
+ $this->fseek($info['avdataoffset']);
1480
+
1481
+ // you can play with these numbers:
1482
+ $max_frames_scan = 50000;
1483
+ $max_scan_segments = 10;
1484
+
1485
+ // don't play with these numbers:
1486
+ $FastMode = false;
1487
+ $SynchErrorsFound = 0;
1488
+ $frames_scanned = 0;
1489
+ $this_scan_segment = 0;
1490
+ $frames_scan_per_segment = ceil($max_frames_scan / $max_scan_segments);
1491
+ $pct_data_scanned = 0;
1492
+ for ($current_segment = 0; $current_segment < $max_scan_segments; $current_segment++) {
1493
+ $frames_scanned_this_segment = 0;
1494
+ if ($this->ftell() >= $info['avdataend']) {
1495
+ break;
1496
+ }
1497
+ $scan_start_offset[$current_segment] = max($this->ftell(), $info['avdataoffset'] + round($current_segment * (($info['avdataend'] - $info['avdataoffset']) / $max_scan_segments)));
1498
+ if ($current_segment > 0) {
1499
+ $this->fseek($scan_start_offset[$current_segment]);
1500
+ $buffer_4k = $this->fread(4096);
1501
+ for ($j = 0; $j < (strlen($buffer_4k) - 4); $j++) {
1502
+ if (($buffer_4k{$j} == "\xFF") && ($buffer_4k{($j + 1)} > "\xE0")) { // synch detected
1503
+ if ($this->decodeMPEGaudioHeader($scan_start_offset[$current_segment] + $j, $dummy, false, false, $FastMode)) {
1504
+ $calculated_next_offset = $scan_start_offset[$current_segment] + $j + $dummy['mpeg']['audio']['framelength'];
1505
+ if ($this->decodeMPEGaudioHeader($calculated_next_offset, $dummy, false, false, $FastMode)) {
1506
+ $scan_start_offset[$current_segment] += $j;
1507
+ break;
1508
+ }
1509
+ }
1510
+ }
1511
+ }
1512
+ }
1513
+ $synchstartoffset = $scan_start_offset[$current_segment];
1514
+ while ($this->decodeMPEGaudioHeader($synchstartoffset, $dummy, false, false, $FastMode)) {
1515
+ $FastMode = true;
1516
+ $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']];
1517
+
1518
+ if (empty($dummy['mpeg']['audio']['framelength'])) {
1519
+ $SynchErrorsFound++;
1520
+ $synchstartoffset++;
1521
+ } else {
1522
+ getid3_lib::safe_inc($info['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]);
1523
+ getid3_lib::safe_inc($info['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]);
1524
+ getid3_lib::safe_inc($info['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]);
1525
+ $synchstartoffset += $dummy['mpeg']['audio']['framelength'];
1526
+ }
1527
+ $frames_scanned++;
1528
+ if ($frames_scan_per_segment && (++$frames_scanned_this_segment >= $frames_scan_per_segment)) {
1529
+ $this_pct_scanned = ($this->ftell() - $scan_start_offset[$current_segment]) / ($info['avdataend'] - $info['avdataoffset']);
1530
+ if (($current_segment == 0) && (($this_pct_scanned * $max_scan_segments) >= 1)) {
1531
+ // file likely contains < $max_frames_scan, just scan as one segment
1532
+ $max_scan_segments = 1;
1533
+ $frames_scan_per_segment = $max_frames_scan;
1534
+ } else {
1535
+ $pct_data_scanned += $this_pct_scanned;
1536
+ break;
1537
+ }
1538
+ }
1539
+ }
1540
+ }
1541
+ if ($pct_data_scanned > 0) {
1542
+ $info['warning'][] = 'too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
1543
+ foreach ($info['mpeg']['audio'] as $key1 => $value1) {
1544
+ if (!preg_match('#_distribution$#i', $key1)) {
1545
+ continue;
1546
+ }
1547
+ foreach ($value1 as $key2 => $value2) {
1548
+ $info['mpeg']['audio'][$key1][$key2] = round($value2 / $pct_data_scanned);
1549
+ }
1550
+ }
1551
+ }
1552
+
1553
+ if ($SynchErrorsFound > 0) {
1554
+ $info['warning'][] = 'Found '.$SynchErrorsFound.' synch errors in histogram analysis';
1555
+ //return false;
1556
+ }
1557
+
1558
+ $bittotal = 0;
1559
+ $framecounter = 0;
1560
+ foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) {
1561
+ $framecounter += $bitratecount;
1562
+ if ($bitratevalue != 'free') {
1563
+ $bittotal += ($bitratevalue * $bitratecount);
1564
+ }
1565
+ }
1566
+ if ($framecounter == 0) {
1567
+ $info['error'][] = 'Corrupt MP3 file: framecounter == zero';
1568
+ return false;
1569
+ }
1570
+ $info['mpeg']['audio']['frame_count'] = getid3_lib::CastAsInt($framecounter);
1571
+ $info['mpeg']['audio']['bitrate'] = ($bittotal / $framecounter);
1572
+
1573
+ $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1574
+
1575
+
1576
+ // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently
1577
+ $distinct_bitrates = 0;
1578
+ foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) {
1579
+ if ($bitrate_count > 0) {
1580
+ $distinct_bitrates++;
1581
+ }
1582
+ }
1583
+ if ($distinct_bitrates > 1) {
1584
+ $info['mpeg']['audio']['bitrate_mode'] = 'vbr';
1585
+ } else {
1586
+ $info['mpeg']['audio']['bitrate_mode'] = 'cbr';
1587
+ }
1588
+ $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode'];
1589
+
1590
+ }
1591
+
1592
+ break; // exit while()
1593
+ }
1594
+ }
1595
+
1596
+ $SynchSeekOffset++;
1597
+ if (($avdataoffset + $SynchSeekOffset) >= $info['avdataend']) {
1598
+ // end of file/data
1599
+
1600
+ if (empty($info['mpeg']['audio'])) {
1601
+
1602
+ $info['error'][] = 'could not find valid MPEG synch before end of file';
1603
+ if (isset($info['audio']['bitrate'])) {
1604
+ unset($info['audio']['bitrate']);
1605
+ }
1606
+ if (isset($info['mpeg']['audio'])) {
1607
+ unset($info['mpeg']['audio']);
1608
+ }
1609
+ if (isset($info['mpeg']) && (!is_array($info['mpeg']) || empty($info['mpeg']))) {
1610
+ unset($info['mpeg']);
1611
+ }
1612
+ return false;
1613
+
1614
+ }
1615
+ break;
1616
+ }
1617
+
1618
+ }
1619
+ $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
1620
+ $info['audio']['channelmode'] = $info['mpeg']['audio']['channelmode'];
1621
+ $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1622
+ return true;
1623
+ }
1624
+
1625
+
1626
+ public static function MPEGaudioVersionArray() {
1627
+ static $MPEGaudioVersion = array('2.5', false, '2', '1');
1628
+ return $MPEGaudioVersion;
1629
+ }
1630
+
1631
+ public static function MPEGaudioLayerArray() {
1632
+ static $MPEGaudioLayer = array(false, 3, 2, 1);
1633
+ return $MPEGaudioLayer;
1634
+ }
1635
+
1636
+ public static function MPEGaudioBitrateArray() {
1637
+ static $MPEGaudioBitrate;
1638
+ if (empty($MPEGaudioBitrate)) {
1639
+ $MPEGaudioBitrate = array (
1640
+ '1' => array (1 => array('free', 32000, 64000, 96000, 128000, 160000, 192000, 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000),
1641
+ 2 => array('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000),
1642
+ 3 => array('free', 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000)
1643
+ ),
1644
+
1645
+ '2' => array (1 => array('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 176000, 192000, 224000, 256000),
1646
+ 2 => array('free', 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000),
1647
+ )
1648
+ );
1649
+ $MPEGaudioBitrate['2'][3] = $MPEGaudioBitrate['2'][2];
1650
+ $MPEGaudioBitrate['2.5'] = $MPEGaudioBitrate['2'];
1651
+ }
1652
+ return $MPEGaudioBitrate;
1653
+ }
1654
+
1655
+ public static function MPEGaudioFrequencyArray() {
1656
+ static $MPEGaudioFrequency;
1657
+ if (empty($MPEGaudioFrequency)) {
1658
+ $MPEGaudioFrequency = array (
1659
+ '1' => array(44100, 48000, 32000),
1660
+ '2' => array(22050, 24000, 16000),
1661
+ '2.5' => array(11025, 12000, 8000)
1662
+ );
1663
+ }
1664
+ return $MPEGaudioFrequency;
1665
+ }
1666
+
1667
+ public static function MPEGaudioChannelModeArray() {
1668
+ static $MPEGaudioChannelMode = array('stereo', 'joint stereo', 'dual channel', 'mono');
1669
+ return $MPEGaudioChannelMode;
1670
+ }
1671
+
1672
+ public static function MPEGaudioModeExtensionArray() {
1673
+ static $MPEGaudioModeExtension;
1674
+ if (empty($MPEGaudioModeExtension)) {
1675
+ $MPEGaudioModeExtension = array (
1676
+ 1 => array('4-31', '8-31', '12-31', '16-31'),
1677
+ 2 => array('4-31', '8-31', '12-31', '16-31'),
1678
+ 3 => array('', 'IS', 'MS', 'IS+MS')
1679
+ );
1680
+ }
1681
+ return $MPEGaudioModeExtension;
1682
+ }
1683
+
1684
+ public static function MPEGaudioEmphasisArray() {
1685
+ static $MPEGaudioEmphasis = array('none', '50/15ms', false, 'CCIT J.17');
1686
+ return $MPEGaudioEmphasis;
1687
+ }
1688
+
1689
+ public static function MPEGaudioHeaderBytesValid($head4, $allowBitrate15=false) {
1690
+ return self::MPEGaudioHeaderValid(self::MPEGaudioHeaderDecode($head4), false, $allowBitrate15);
1691
+ }
1692
+
1693
+ public static function MPEGaudioHeaderValid($rawarray, $echoerrors=false, $allowBitrate15=false) {
1694
+ if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) {
1695
+ return false;
1696
+ }
1697
+
1698
+ static $MPEGaudioVersionLookup;
1699
+ static $MPEGaudioLayerLookup;
1700
+ static $MPEGaudioBitrateLookup;
1701
+ static $MPEGaudioFrequencyLookup;
1702
+ static $MPEGaudioChannelModeLookup;
1703
+ static $MPEGaudioModeExtensionLookup;
1704
+ static $MPEGaudioEmphasisLookup;
1705
+ if (empty($MPEGaudioVersionLookup)) {
1706
+ $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
1707
+ $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
1708
+ $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
1709
+ $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray();
1710
+ $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray();
1711
+ $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();
1712
+ $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray();
1713
+ }
1714
+
1715
+ if (isset($MPEGaudioVersionLookup[$rawarray['version']])) {
1716
+ $decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']];
1717
+ } else {
1718
+ echo ($echoerrors ? "\n".'invalid Version ('.$rawarray['version'].')' : '');
1719
+ return false;
1720
+ }
1721
+ if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) {
1722
+ $decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']];
1723
+ } else {
1724
+ echo ($echoerrors ? "\n".'invalid Layer ('.$rawarray['layer'].')' : '');
1725
+ return false;
1726
+ }
1727
+ if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) {
1728
+ echo ($echoerrors ? "\n".'invalid Bitrate ('.$rawarray['bitrate'].')' : '');
1729
+ if ($rawarray['bitrate'] == 15) {
1730
+ // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0
1731
+ // let it go through here otherwise file will not be identified
1732
+ if (!$allowBitrate15) {
1733
+ return false;
1734
+ }
1735
+ } else {
1736
+ return false;
1737
+ }
1738
+ }
1739
+ if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) {
1740
+ echo ($echoerrors ? "\n".'invalid Frequency ('.$rawarray['sample_rate'].')' : '');
1741
+ return false;
1742
+ }
1743
+ if (!isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) {
1744
+ echo ($echoerrors ? "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')' : '');
1745
+ return false;
1746
+ }
1747
+ if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) {
1748
+ echo ($echoerrors ? "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')' : '');
1749
+ return false;
1750
+ }
1751
+ if (!isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) {
1752
+ echo ($echoerrors ? "\n".'invalid Emphasis ('.$rawarray['emphasis'].')' : '');
1753
+ return false;
1754
+ }
1755
+ // These are just either set or not set, you can't mess that up :)
1756
+ // $rawarray['protection'];
1757
+ // $rawarray['padding'];
1758
+ // $rawarray['private'];
1759
+ // $rawarray['copyright'];
1760
+ // $rawarray['original'];
1761
+
1762
+ return true;
1763
+ }
1764
+
1765
+ public static function MPEGaudioHeaderDecode($Header4Bytes) {
1766
+ // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM
1767
+ // A - Frame sync (all bits set)
1768
+ // B - MPEG Audio version ID
1769
+ // C - Layer description
1770
+ // D - Protection bit
1771
+ // E - Bitrate index
1772
+ // F - Sampling rate frequency index
1773
+ // G - Padding bit
1774
+ // H - Private bit
1775
+ // I - Channel Mode
1776
+ // J - Mode extension (Only if Joint stereo)
1777
+ // K - Copyright
1778
+ // L - Original
1779
+ // M - Emphasis
1780
+
1781
+ if (strlen($Header4Bytes) != 4) {
1782
+ return false;
1783
+ }
1784
+
1785
+ $MPEGrawHeader['synch'] = (getid3_lib::BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4;
1786
+ $MPEGrawHeader['version'] = (ord($Header4Bytes{1}) & 0x18) >> 3; // BB
1787
+ $MPEGrawHeader['layer'] = (ord($Header4Bytes{1}) & 0x06) >> 1; // CC
1788
+ $MPEGrawHeader['protection'] = (ord($Header4Bytes{1}) & 0x01); // D
1789
+ $MPEGrawHeader['bitrate'] = (ord($Header4Bytes{2}) & 0xF0) >> 4; // EEEE
1790
+ $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes{2}) & 0x0C) >> 2; // FF
1791
+ $MPEGrawHeader['padding'] = (ord($Header4Bytes{2}) & 0x02) >> 1; // G
1792
+ $MPEGrawHeader['private'] = (ord($Header4Bytes{2}) & 0x01); // H
1793
+ $MPEGrawHeader['channelmode'] = (ord($Header4Bytes{3}) & 0xC0) >> 6; // II
1794
+ $MPEGrawHeader['modeextension'] = (ord($Header4Bytes{3}) & 0x30) >> 4; // JJ
1795
+ $MPEGrawHeader['copyright'] = (ord($Header4Bytes{3}) & 0x08) >> 3; // K
1796
+ $MPEGrawHeader['original'] = (ord($Header4Bytes{3}) & 0x04) >> 2; // L
1797
+ $MPEGrawHeader['emphasis'] = (ord($Header4Bytes{3}) & 0x03); // MM
1798
+
1799
+ return $MPEGrawHeader;
1800
+ }
1801
+
1802
+ public static function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) {
1803
+ static $AudioFrameLengthCache = array();
1804
+
1805
+ if (!isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) {
1806
+ $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = false;
1807
+ if ($bitrate != 'free') {
1808
+
1809
+ if ($version == '1') {
1810
+
1811
+ if ($layer == '1') {
1812
+
1813
+ // For Layer I slot is 32 bits long
1814
+ $FrameLengthCoefficient = 48;
1815
+ $SlotLength = 4;
1816
+
1817
+ } else { // Layer 2 / 3
1818
+
1819
+ // for Layer 2 and Layer 3 slot is 8 bits long.
1820
+ $FrameLengthCoefficient = 144;
1821
+ $SlotLength = 1;
1822
+
1823
+ }
1824
+
1825
+ } else { // MPEG-2 / MPEG-2.5
1826
+
1827
+ if ($layer == '1') {
1828
+
1829
+ // For Layer I slot is 32 bits long
1830
+ $FrameLengthCoefficient = 24;
1831
+ $SlotLength = 4;
1832
+
1833
+ } elseif ($layer == '2') {
1834
+
1835
+ // for Layer 2 and Layer 3 slot is 8 bits long.
1836
+ $FrameLengthCoefficient = 144;
1837
+ $SlotLength = 1;
1838
+
1839
+ } else { // layer 3
1840
+
1841
+ // for Layer 2 and Layer 3 slot is 8 bits long.
1842
+ $FrameLengthCoefficient = 72;
1843
+ $SlotLength = 1;
1844
+
1845
+ }
1846
+
1847
+ }
1848
+
1849
+ // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding
1850
+ if ($samplerate > 0) {
1851
+ $NewFramelength = ($FrameLengthCoefficient * $bitrate) / $samplerate;
1852
+ $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength; // round to next-lower multiple of SlotLength (1 byte for Layer 2/3, 4 bytes for Layer I)
1853
+ if ($padding) {
1854
+ $NewFramelength += $SlotLength;
1855
+ }
1856
+ $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength;
1857
+ }
1858
+ }
1859
+ }
1860
+ return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate];
1861
+ }
1862
+
1863
+ public static function ClosestStandardMP3Bitrate($bit_rate) {
1864
+ static $standard_bit_rates = array (320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000);
1865
+ static $bit_rate_table = array (0=>'-');
1866
+ $round_bit_rate = intval(round($bit_rate, -3));
1867
+ if (!isset($bit_rate_table[$round_bit_rate])) {
1868
+ if ($round_bit_rate > max($standard_bit_rates)) {
1869
+ $bit_rate_table[$round_bit_rate] = round($bit_rate, 2 - strlen($bit_rate));
1870
+ } else {
1871
+ $bit_rate_table[$round_bit_rate] = max($standard_bit_rates);
1872
+ foreach ($standard_bit_rates as $standard_bit_rate) {
1873
+ if ($round_bit_rate >= $standard_bit_rate + (($bit_rate_table[$round_bit_rate] - $standard_bit_rate) / 2)) {
1874
+ break;
1875
+ }
1876
+ $bit_rate_table[$round_bit_rate] = $standard_bit_rate;
1877
+ }
1878
+ }
1879
+ }
1880
+ return $bit_rate_table[$round_bit_rate];
1881
+ }
1882
+
1883
+ public static function XingVBRidOffset($version, $channelmode) {
1884
+ static $XingVBRidOffsetCache = array();
1885
+ if (empty($XingVBRidOffset)) {
1886
+ $XingVBRidOffset = array (
1887
+ '1' => array ('mono' => 0x15, // 4 + 17 = 21
1888
+ 'stereo' => 0x24, // 4 + 32 = 36
1889
+ 'joint stereo' => 0x24,
1890
+ 'dual channel' => 0x24
1891
+ ),
1892
+
1893
+ '2' => array ('mono' => 0x0D, // 4 + 9 = 13
1894
+ 'stereo' => 0x15, // 4 + 17 = 21
1895
+ 'joint stereo' => 0x15,
1896
+ 'dual channel' => 0x15
1897
+ ),
1898
+
1899
+ '2.5' => array ('mono' => 0x15,
1900
+ 'stereo' => 0x15,
1901
+ 'joint stereo' => 0x15,
1902
+ 'dual channel' => 0x15
1903
+ )
1904
+ );
1905
+ }
1906
+ return $XingVBRidOffset[$version][$channelmode];
1907
+ }
1908
+
1909
+ public static function LAMEvbrMethodLookup($VBRmethodID) {
1910
+ static $LAMEvbrMethodLookup = array(
1911
+ 0x00 => 'unknown',
1912
+ 0x01 => 'cbr',
1913
+ 0x02 => 'abr',
1914
+ 0x03 => 'vbr-old / vbr-rh',
1915
+ 0x04 => 'vbr-new / vbr-mtrh',
1916
+ 0x05 => 'vbr-mt',
1917
+ 0x06 => 'vbr (full vbr method 4)',
1918
+ 0x08 => 'cbr (constant bitrate 2 pass)',
1919
+ 0x09 => 'abr (2 pass)',
1920
+ 0x0F => 'reserved'
1921
+ );
1922
+ return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : '');
1923
+ }
1924
+
1925
+ public static function LAMEmiscStereoModeLookup($StereoModeID) {
1926
+ static $LAMEmiscStereoModeLookup = array(
1927
+ 0 => 'mono',
1928
+ 1 => 'stereo',
1929
+ 2 => 'dual mono',
1930
+ 3 => 'joint stereo',
1931
+ 4 => 'forced stereo',
1932
+ 5 => 'auto',
1933
+ 6 => 'intensity stereo',
1934
+ 7 => 'other'
1935
+ );
1936
+ return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : '');
1937
+ }
1938
+
1939
+ public static function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) {
1940
+ static $LAMEmiscSourceSampleFrequencyLookup = array(
1941
+ 0 => '<= 32 kHz',
1942
+ 1 => '44.1 kHz',
1943
+ 2 => '48 kHz',
1944
+ 3 => '> 48kHz'
1945
+ );
1946
+ return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : '');
1947
+ }
1948
+
1949
+ public static function LAMEsurroundInfoLookup($SurroundInfoID) {
1950
+ static $LAMEsurroundInfoLookup = array(
1951
+ 0 => 'no surround info',
1952
+ 1 => 'DPL encoding',
1953
+ 2 => 'DPL2 encoding',
1954
+ 3 => 'Ambisonic encoding'
1955
+ );
1956
+ return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved');
1957
+ }
1958
+
1959
+ public static function LAMEpresetUsedLookup($LAMEtag) {
1960
+
1961
+ if ($LAMEtag['preset_used_id'] == 0) {
1962
+ // no preset used (LAME >=3.93)
1963
+ // no preset recorded (LAME <3.93)
1964
+ return '';
1965
+ }
1966
+ $LAMEpresetUsedLookup = array();
1967
+
1968
+ ///// THIS PART CANNOT BE STATIC .
1969
+ for ($i = 8; $i <= 320; $i++) {
1970
+ switch ($LAMEtag['vbr_method']) {
1971
+ case 'cbr':
1972
+ $LAMEpresetUsedLookup[$i] = '--alt-preset '.$LAMEtag['vbr_method'].' '.$i;
1973
+ break;
1974
+ case 'abr':
1975
+ default: // other VBR modes shouldn't be here(?)
1976
+ $LAMEpresetUsedLookup[$i] = '--alt-preset '.$i;
1977
+ break;
1978
+ }
1979
+ }
1980
+
1981
+ // named old-style presets (studio, phone, voice, etc) are handled in GuessEncoderOptions()
1982
+
1983
+ // named alt-presets
1984
+ $LAMEpresetUsedLookup[1000] = '--r3mix';
1985
+ $LAMEpresetUsedLookup[1001] = '--alt-preset standard';
1986
+ $LAMEpresetUsedLookup[1002] = '--alt-preset extreme';
1987
+ $LAMEpresetUsedLookup[1003] = '--alt-preset insane';
1988
+ $LAMEpresetUsedLookup[1004] = '--alt-preset fast standard';
1989
+ $LAMEpresetUsedLookup[1005] = '--alt-preset fast extreme';
1990
+ $LAMEpresetUsedLookup[1006] = '--alt-preset medium';
1991
+ $LAMEpresetUsedLookup[1007] = '--alt-preset fast medium';
1992
+
1993
+ // LAME 3.94 additions/changes
1994
+ $LAMEpresetUsedLookup[1010] = '--preset portable'; // 3.94a15 Oct 21 2003
1995
+ $LAMEpresetUsedLookup[1015] = '--preset radio'; // 3.94a15 Oct 21 2003
1996
+
1997
+ $LAMEpresetUsedLookup[320] = '--preset insane'; // 3.94a15 Nov 12 2003
1998
+ $LAMEpresetUsedLookup[410] = '-V9';
1999
+ $LAMEpresetUsedLookup[420] = '-V8';
2000
+ $LAMEpresetUsedLookup[440] = '-V6';
2001
+ $LAMEpresetUsedLookup[430] = '--preset radio'; // 3.94a15 Nov 12 2003
2002
+ $LAMEpresetUsedLookup[450] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'portable'; // 3.94a15 Nov 12 2003
2003
+ $LAMEpresetUsedLookup[460] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'medium'; // 3.94a15 Nov 12 2003
2004
+ $LAMEpresetUsedLookup[470] = '--r3mix'; // 3.94b1 Dec 18 2003
2005
+ $LAMEpresetUsedLookup[480] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'standard'; // 3.94a15 Nov 12 2003
2006
+ $LAMEpresetUsedLookup[490] = '-V1';
2007
+ $LAMEpresetUsedLookup[500] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'extreme'; // 3.94a15 Nov 12 2003
2008
+
2009
+ return (isset($LAMEpresetUsedLookup[$LAMEtag['preset_used_id']]) ? $LAMEpresetUsedLookup[$LAMEtag['preset_used_id']] : 'new/unknown preset: '.$LAMEtag['preset_used_id'].' - report to info@getid3.org');
2010
+ }
2011
+
2012
+ }
getid3/module.audio.ogg.php ADDED
@@ -0,0 +1,756 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // See readme.txt for more details //
9
+ /////////////////////////////////////////////////////////////////
10
+ // //
11
+ // module.audio.ogg.php //
12
+ // module for analyzing Ogg Vorbis, OggFLAC and Speex files //
13
+ // dependencies: module.audio.flac.php //
14
+ // ///
15
+ /////////////////////////////////////////////////////////////////
16
+
17
+ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.flac.php', __FILE__, true);
18
+
19
+ class getid3_ogg extends getid3_handler
20
+ {
21
+ // http://xiph.org/vorbis/doc/Vorbis_I_spec.html
22
+ public function Analyze() {
23
+ $info = &$this->getid3->info;
24
+
25
+ $info['fileformat'] = 'ogg';
26
+
27
+ // Warn about illegal tags - only vorbiscomments are allowed
28
+ if (isset($info['id3v2'])) {
29
+ $info['warning'][] = 'Illegal ID3v2 tag present.';
30
+ }
31
+ if (isset($info['id3v1'])) {
32
+ $info['warning'][] = 'Illegal ID3v1 tag present.';
33
+ }
34
+ if (isset($info['ape'])) {
35
+ $info['warning'][] = 'Illegal APE tag present.';
36
+ }
37
+
38
+
39
+ // Page 1 - Stream Header
40
+
41
+ $this->fseek($info['avdataoffset']);
42
+
43
+ $oggpageinfo = $this->ParseOggPageHeader();
44
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
45
+
46
+ if ($this->ftell() >= $this->getid3->fread_buffer_size()) {
47
+ $info['error'][] = 'Could not find start of Ogg page in the first '.$this->getid3->fread_buffer_size().' bytes (this might not be an Ogg-Vorbis file?)';
48
+ unset($info['fileformat']);
49
+ unset($info['ogg']);
50
+ return false;
51
+ }
52
+
53
+ $filedata = $this->fread($oggpageinfo['page_length']);
54
+ $filedataoffset = 0;
55
+
56
+ if (substr($filedata, 0, 4) == 'fLaC') {
57
+
58
+ $info['audio']['dataformat'] = 'flac';
59
+ $info['audio']['bitrate_mode'] = 'vbr';
60
+ $info['audio']['lossless'] = true;
61
+
62
+ } elseif (substr($filedata, 1, 6) == 'vorbis') {
63
+
64
+ $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo);
65
+
66
+ } elseif (substr($filedata, 0, 8) == 'Speex ') {
67
+
68
+ // http://www.speex.org/manual/node10.html
69
+
70
+ $info['audio']['dataformat'] = 'speex';
71
+ $info['mime_type'] = 'audio/speex';
72
+ $info['audio']['bitrate_mode'] = 'abr';
73
+ $info['audio']['lossless'] = false;
74
+
75
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_string'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'Speex '
76
+ $filedataoffset += 8;
77
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version'] = substr($filedata, $filedataoffset, 20);
78
+ $filedataoffset += 20;
79
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version_id'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
80
+ $filedataoffset += 4;
81
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['header_size'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
82
+ $filedataoffset += 4;
83
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
84
+ $filedataoffset += 4;
85
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
86
+ $filedataoffset += 4;
87
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode_bitstream_version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
88
+ $filedataoffset += 4;
89
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
90
+ $filedataoffset += 4;
91
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['bitrate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
92
+ $filedataoffset += 4;
93
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['framesize'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
94
+ $filedataoffset += 4;
95
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
96
+ $filedataoffset += 4;
97
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['frames_per_packet'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
98
+ $filedataoffset += 4;
99
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['extra_headers'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
100
+ $filedataoffset += 4;
101
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved1'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
102
+ $filedataoffset += 4;
103
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved2'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
104
+ $filedataoffset += 4;
105
+
106
+ $info['speex']['speex_version'] = trim($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version']);
107
+ $info['speex']['sample_rate'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'];
108
+ $info['speex']['channels'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'];
109
+ $info['speex']['vbr'] = (bool) $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'];
110
+ $info['speex']['band_type'] = $this->SpeexBandModeLookup($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode']);
111
+
112
+ $info['audio']['sample_rate'] = $info['speex']['sample_rate'];
113
+ $info['audio']['channels'] = $info['speex']['channels'];
114
+ if ($info['speex']['vbr']) {
115
+ $info['audio']['bitrate_mode'] = 'vbr';
116
+ }
117
+
118
+ } elseif (substr($filedata, 0, 7) == "\x80".'theora') {
119
+
120
+ // http://www.theora.org/doc/Theora.pdf (section 6.2)
121
+
122
+ $info['ogg']['pageheader']['theora']['theora_magic'] = substr($filedata, $filedataoffset, 7); // hard-coded to "\x80.'theora'
123
+ $filedataoffset += 7;
124
+ $info['ogg']['pageheader']['theora']['version_major'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
125
+ $filedataoffset += 1;
126
+ $info['ogg']['pageheader']['theora']['version_minor'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
127
+ $filedataoffset += 1;
128
+ $info['ogg']['pageheader']['theora']['version_revision'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
129
+ $filedataoffset += 1;
130
+ $info['ogg']['pageheader']['theora']['frame_width_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2));
131
+ $filedataoffset += 2;
132
+ $info['ogg']['pageheader']['theora']['frame_height_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2));
133
+ $filedataoffset += 2;
134
+ $info['ogg']['pageheader']['theora']['resolution_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
135
+ $filedataoffset += 3;
136
+ $info['ogg']['pageheader']['theora']['resolution_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
137
+ $filedataoffset += 3;
138
+ $info['ogg']['pageheader']['theora']['picture_offset_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
139
+ $filedataoffset += 1;
140
+ $info['ogg']['pageheader']['theora']['picture_offset_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
141
+ $filedataoffset += 1;
142
+ $info['ogg']['pageheader']['theora']['frame_rate_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4));
143
+ $filedataoffset += 4;
144
+ $info['ogg']['pageheader']['theora']['frame_rate_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4));
145
+ $filedataoffset += 4;
146
+ $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
147
+ $filedataoffset += 3;
148
+ $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
149
+ $filedataoffset += 3;
150
+ $info['ogg']['pageheader']['theora']['color_space_id'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1));
151
+ $filedataoffset += 1;
152
+ $info['ogg']['pageheader']['theora']['nominal_bitrate'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3));
153
+ $filedataoffset += 3;
154
+ $info['ogg']['pageheader']['theora']['flags'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2));
155
+ $filedataoffset += 2;
156
+
157
+ $info['ogg']['pageheader']['theora']['quality'] = ($info['ogg']['pageheader']['theora']['flags'] & 0xFC00) >> 10;
158
+ $info['ogg']['pageheader']['theora']['kfg_shift'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x03E0) >> 5;
159
+ $info['ogg']['pageheader']['theora']['pixel_format_id'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0018) >> 3;
160
+ $info['ogg']['pageheader']['theora']['reserved'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0007) >> 0; // should be 0
161
+ $info['ogg']['pageheader']['theora']['color_space'] = self::TheoraColorSpace($info['ogg']['pageheader']['theora']['color_space_id']);
162
+ $info['ogg']['pageheader']['theora']['pixel_format'] = self::TheoraPixelFormat($info['ogg']['pageheader']['theora']['pixel_format_id']);
163
+
164
+ $info['video']['dataformat'] = 'theora';
165
+ $info['mime_type'] = 'video/ogg';
166
+ //$info['audio']['bitrate_mode'] = 'abr';
167
+ //$info['audio']['lossless'] = false;
168
+ $info['video']['resolution_x'] = $info['ogg']['pageheader']['theora']['resolution_x'];
169
+ $info['video']['resolution_y'] = $info['ogg']['pageheader']['theora']['resolution_y'];
170
+ if ($info['ogg']['pageheader']['theora']['frame_rate_denominator'] > 0) {
171
+ $info['video']['frame_rate'] = (float) $info['ogg']['pageheader']['theora']['frame_rate_numerator'] / $info['ogg']['pageheader']['theora']['frame_rate_denominator'];
172
+ }
173
+ if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) {
174
+ $info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'];
175
+ }
176
+ $info['warning'][] = 'Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable';
177
+
178
+
179
+ } elseif (substr($filedata, 0, 8) == "fishead\x00") {
180
+
181
+ // Ogg Skeleton version 3.0 Format Specification
182
+ // http://xiph.org/ogg/doc/skeleton.html
183
+ $filedataoffset += 8;
184
+ $info['ogg']['skeleton']['fishead']['raw']['version_major'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2));
185
+ $filedataoffset += 2;
186
+ $info['ogg']['skeleton']['fishead']['raw']['version_minor'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2));
187
+ $filedataoffset += 2;
188
+ $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
189
+ $filedataoffset += 8;
190
+ $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
191
+ $filedataoffset += 8;
192
+ $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
193
+ $filedataoffset += 8;
194
+ $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
195
+ $filedataoffset += 8;
196
+ $info['ogg']['skeleton']['fishead']['raw']['utc'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 20));
197
+ $filedataoffset += 20;
198
+
199
+ $info['ogg']['skeleton']['fishead']['version'] = $info['ogg']['skeleton']['fishead']['raw']['version_major'].'.'.$info['ogg']['skeleton']['fishead']['raw']['version_minor'];
200
+ $info['ogg']['skeleton']['fishead']['presentationtime'] = $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator'];
201
+ $info['ogg']['skeleton']['fishead']['basetime'] = $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator'];
202
+ $info['ogg']['skeleton']['fishead']['utc'] = $info['ogg']['skeleton']['fishead']['raw']['utc'];
203
+
204
+
205
+ $counter = 0;
206
+ do {
207
+ $oggpageinfo = $this->ParseOggPageHeader();
208
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno'].'.'.$counter++] = $oggpageinfo;
209
+ $filedata = $this->fread($oggpageinfo['page_length']);
210
+ $this->fseek($oggpageinfo['page_end_offset']);
211
+
212
+ if (substr($filedata, 0, 8) == "fisbone\x00") {
213
+
214
+ $filedataoffset = 8;
215
+ $info['ogg']['skeleton']['fisbone']['raw']['message_header_offset'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
216
+ $filedataoffset += 4;
217
+ $info['ogg']['skeleton']['fisbone']['raw']['serial_number'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
218
+ $filedataoffset += 4;
219
+ $info['ogg']['skeleton']['fisbone']['raw']['number_header_packets'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
220
+ $filedataoffset += 4;
221
+ $info['ogg']['skeleton']['fisbone']['raw']['granulerate_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
222
+ $filedataoffset += 8;
223
+ $info['ogg']['skeleton']['fisbone']['raw']['granulerate_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
224
+ $filedataoffset += 8;
225
+ $info['ogg']['skeleton']['fisbone']['raw']['basegranule'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
226
+ $filedataoffset += 8;
227
+ $info['ogg']['skeleton']['fisbone']['raw']['preroll'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
228
+ $filedataoffset += 4;
229
+ $info['ogg']['skeleton']['fisbone']['raw']['granuleshift'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
230
+ $filedataoffset += 1;
231
+ $info['ogg']['skeleton']['fisbone']['raw']['padding'] = substr($filedata, $filedataoffset, 3);
232
+ $filedataoffset += 3;
233
+
234
+ } elseif (substr($filedata, 1, 6) == 'theora') {
235
+
236
+ $info['video']['dataformat'] = 'theora1';
237
+ $info['error'][] = 'Ogg Theora (v1) not correctly handled in this version of getID3 ['.$this->getid3->version().']';
238
+ //break;
239
+
240
+ } elseif (substr($filedata, 1, 6) == 'vorbis') {
241
+
242
+ $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo);
243
+
244
+ } else {
245
+ $info['error'][] = 'unexpected';
246
+ //break;
247
+ }
248
+ //} while ($oggpageinfo['page_seqno'] == 0);
249
+ } while (($oggpageinfo['page_seqno'] == 0) && (substr($filedata, 0, 8) != "fisbone\x00"));
250
+
251
+ $this->fseek($oggpageinfo['page_start_offset']);
252
+
253
+ $info['error'][] = 'Ogg Skeleton not correctly handled in this version of getID3 ['.$this->getid3->version().']';
254
+ //return false;
255
+
256
+ } else {
257
+
258
+ $info['error'][] = 'Expecting either "Speex " or "vorbis" identifier strings, found "'.substr($filedata, 0, 8).'"';
259
+ unset($info['ogg']);
260
+ unset($info['mime_type']);
261
+ return false;
262
+
263
+ }
264
+
265
+ // Page 2 - Comment Header
266
+ $oggpageinfo = $this->ParseOggPageHeader();
267
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
268
+
269
+ switch ($info['audio']['dataformat']) {
270
+ case 'vorbis':
271
+ $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
272
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, 0, 1));
273
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 1, 6); // hard-coded to 'vorbis'
274
+
275
+ $this->ParseVorbisComments();
276
+ break;
277
+
278
+ case 'flac':
279
+ $flac = new getid3_flac($this->getid3);
280
+ if (!$flac->parseMETAdata()) {
281
+ $info['error'][] = 'Failed to parse FLAC headers';
282
+ return false;
283
+ }
284
+ unset($flac);
285
+ break;
286
+
287
+ case 'speex':
288
+ $this->fseek($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length'], SEEK_CUR);
289
+ $this->ParseVorbisComments();
290
+ break;
291
+ }
292
+
293
+
294
+ // Last Page - Number of Samples
295
+ if (!getid3_lib::intValueSupported($info['avdataend'])) {
296
+
297
+ $info['warning'][] = 'Unable to parse Ogg end chunk file (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)';
298
+
299
+ } else {
300
+
301
+ $this->fseek(max($info['avdataend'] - $this->getid3->fread_buffer_size(), 0));
302
+ $LastChunkOfOgg = strrev($this->fread($this->getid3->fread_buffer_size()));
303
+ if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) {
304
+ $this->fseek($info['avdataend'] - ($LastOggSpostion + strlen('SggO')));
305
+ $info['avdataend'] = $this->ftell();
306
+ $info['ogg']['pageheader']['eos'] = $this->ParseOggPageHeader();
307
+ $info['ogg']['samples'] = $info['ogg']['pageheader']['eos']['pcm_abs_position'];
308
+ if ($info['ogg']['samples'] == 0) {
309
+ $info['error'][] = 'Corrupt Ogg file: eos.number of samples == zero';
310
+ return false;
311
+ }
312
+ if (!empty($info['audio']['sample_rate'])) {
313
+ $info['ogg']['bitrate_average'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['ogg']['samples'] / $info['audio']['sample_rate']);
314
+ }
315
+ }
316
+
317
+ }
318
+
319
+ if (!empty($info['ogg']['bitrate_average'])) {
320
+ $info['audio']['bitrate'] = $info['ogg']['bitrate_average'];
321
+ } elseif (!empty($info['ogg']['bitrate_nominal'])) {
322
+ $info['audio']['bitrate'] = $info['ogg']['bitrate_nominal'];
323
+ } elseif (!empty($info['ogg']['bitrate_min']) && !empty($info['ogg']['bitrate_max'])) {
324
+ $info['audio']['bitrate'] = ($info['ogg']['bitrate_min'] + $info['ogg']['bitrate_max']) / 2;
325
+ }
326
+ if (isset($info['audio']['bitrate']) && !isset($info['playtime_seconds'])) {
327
+ if ($info['audio']['bitrate'] == 0) {
328
+ $info['error'][] = 'Corrupt Ogg file: bitrate_audio == zero';
329
+ return false;
330
+ }
331
+ $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']);
332
+ }
333
+
334
+ if (isset($info['ogg']['vendor'])) {
335
+ $info['audio']['encoder'] = preg_replace('/^Encoded with /', '', $info['ogg']['vendor']);
336
+
337
+ // Vorbis only
338
+ if ($info['audio']['dataformat'] == 'vorbis') {
339
+
340
+ // Vorbis 1.0 starts with Xiph.Org
341
+ if (preg_match('/^Xiph.Org/', $info['audio']['encoder'])) {
342
+
343
+ if ($info['audio']['bitrate_mode'] == 'abr') {
344
+
345
+ // Set -b 128 on abr files
346
+ $info['audio']['encoder_options'] = '-b '.round($info['ogg']['bitrate_nominal'] / 1000);
347
+
348
+ } elseif (($info['audio']['bitrate_mode'] == 'vbr') && ($info['audio']['channels'] == 2) && ($info['audio']['sample_rate'] >= 44100) && ($info['audio']['sample_rate'] <= 48000)) {
349
+ // Set -q N on vbr files
350
+ $info['audio']['encoder_options'] = '-q '.$this->get_quality_from_nominal_bitrate($info['ogg']['bitrate_nominal']);
351
+
352
+ }
353
+ }
354
+
355
+ if (empty($info['audio']['encoder_options']) && !empty($info['ogg']['bitrate_nominal'])) {
356
+ $info['audio']['encoder_options'] = 'Nominal bitrate: '.intval(round($info['ogg']['bitrate_nominal'] / 1000)).'kbps';
357
+ }
358
+ }
359
+ }
360
+
361
+ return true;
362
+ }
363
+
364
+ public function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) {
365
+ $info = &$this->getid3->info;
366
+ $info['audio']['dataformat'] = 'vorbis';
367
+ $info['audio']['lossless'] = false;
368
+
369
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
370
+ $filedataoffset += 1;
371
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, $filedataoffset, 6); // hard-coded to 'vorbis'
372
+ $filedataoffset += 6;
373
+ $info['ogg']['bitstreamversion'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
374
+ $filedataoffset += 4;
375
+ $info['ogg']['numberofchannels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
376
+ $filedataoffset += 1;
377
+ $info['audio']['channels'] = $info['ogg']['numberofchannels'];
378
+ $info['ogg']['samplerate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
379
+ $filedataoffset += 4;
380
+ if ($info['ogg']['samplerate'] == 0) {
381
+ $info['error'][] = 'Corrupt Ogg file: sample rate == zero';
382
+ return false;
383
+ }
384
+ $info['audio']['sample_rate'] = $info['ogg']['samplerate'];
385
+ $info['ogg']['samples'] = 0; // filled in later
386
+ $info['ogg']['bitrate_average'] = 0; // filled in later
387
+ $info['ogg']['bitrate_max'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
388
+ $filedataoffset += 4;
389
+ $info['ogg']['bitrate_nominal'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
390
+ $filedataoffset += 4;
391
+ $info['ogg']['bitrate_min'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
392
+ $filedataoffset += 4;
393
+ $info['ogg']['blocksize_small'] = pow(2, getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0x0F);
394
+ $info['ogg']['blocksize_large'] = pow(2, (getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0xF0) >> 4);
395
+ $info['ogg']['stop_bit'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); // must be 1, marks end of packet
396
+
397
+ $info['audio']['bitrate_mode'] = 'vbr'; // overridden if actually abr
398
+ if ($info['ogg']['bitrate_max'] == 0xFFFFFFFF) {
399
+ unset($info['ogg']['bitrate_max']);
400
+ $info['audio']['bitrate_mode'] = 'abr';
401
+ }
402
+ if ($info['ogg']['bitrate_nominal'] == 0xFFFFFFFF) {
403
+ unset($info['ogg']['bitrate_nominal']);
404
+ }
405
+ if ($info['ogg']['bitrate_min'] == 0xFFFFFFFF) {
406
+ unset($info['ogg']['bitrate_min']);
407
+ $info['audio']['bitrate_mode'] = 'abr';
408
+ }
409
+ return true;
410
+ }
411
+
412
+ public function ParseOggPageHeader() {
413
+ // http://xiph.org/ogg/vorbis/doc/framing.html
414
+ $oggheader['page_start_offset'] = $this->ftell(); // where we started from in the file
415
+
416
+ $filedata = $this->fread($this->getid3->fread_buffer_size());
417
+ $filedataoffset = 0;
418
+ while ((substr($filedata, $filedataoffset++, 4) != 'OggS')) {
419
+ if (($this->ftell() - $oggheader['page_start_offset']) >= $this->getid3->fread_buffer_size()) {
420
+ // should be found before here
421
+ return false;
422
+ }
423
+ if ((($filedataoffset + 28) > strlen($filedata)) || (strlen($filedata) < 28)) {
424
+ if ($this->feof() || (($filedata .= $this->fread($this->getid3->fread_buffer_size())) === false)) {
425
+ // get some more data, unless eof, in which case fail
426
+ return false;
427
+ }
428
+ }
429
+ }
430
+ $filedataoffset += strlen('OggS') - 1; // page, delimited by 'OggS'
431
+
432
+ $oggheader['stream_structver'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
433
+ $filedataoffset += 1;
434
+ $oggheader['flags_raw'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
435
+ $filedataoffset += 1;
436
+ $oggheader['flags']['fresh'] = (bool) ($oggheader['flags_raw'] & 0x01); // fresh packet
437
+ $oggheader['flags']['bos'] = (bool) ($oggheader['flags_raw'] & 0x02); // first page of logical bitstream (bos)
438
+ $oggheader['flags']['eos'] = (bool) ($oggheader['flags_raw'] & 0x04); // last page of logical bitstream (eos)
439
+
440
+ $oggheader['pcm_abs_position'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8));
441
+ $filedataoffset += 8;
442
+ $oggheader['stream_serialno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
443
+ $filedataoffset += 4;
444
+ $oggheader['page_seqno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
445
+ $filedataoffset += 4;
446
+ $oggheader['page_checksum'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));
447
+ $filedataoffset += 4;
448
+ $oggheader['page_segments'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
449
+ $filedataoffset += 1;
450
+ $oggheader['page_length'] = 0;
451
+ for ($i = 0; $i < $oggheader['page_segments']; $i++) {
452
+ $oggheader['segment_table'][$i] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1));
453
+ $filedataoffset += 1;
454
+ $oggheader['page_length'] += $oggheader['segment_table'][$i];
455
+ }
456
+ $oggheader['header_end_offset'] = $oggheader['page_start_offset'] + $filedataoffset;
457
+ $oggheader['page_end_offset'] = $oggheader['header_end_offset'] + $oggheader['page_length'];
458
+ $this->fseek($oggheader['header_end_offset']);
459
+
460
+ return $oggheader;
461
+ }
462
+
463
+ // http://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810005
464
+ public function ParseVorbisComments() {
465
+ $info = &$this->getid3->info;
466
+
467
+ $OriginalOffset = $this->ftell();
468
+ $commentdataoffset = 0;
469
+ $VorbisCommentPage = 1;
470
+
471
+ switch ($info['audio']['dataformat']) {
472
+ case 'vorbis':
473
+ case 'speex':
474
+ $CommentStartOffset = $info['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset']; // Second Ogg page, after header block
475
+ $this->fseek($CommentStartOffset);
476
+ $commentdataoffset = 27 + $info['ogg']['pageheader'][$VorbisCommentPage]['page_segments'];
477
+ $commentdata = $this->fread(self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset);
478
+
479
+ if ($info['audio']['dataformat'] == 'vorbis') {
480
+ $commentdataoffset += (strlen('vorbis') + 1);
481
+ }
482
+ break;
483
+
484
+ case 'flac':
485
+ $CommentStartOffset = $info['flac']['VORBIS_COMMENT']['raw']['offset'] + 4;
486
+ $this->fseek($CommentStartOffset);
487
+ $commentdata = $this->fread($info['flac']['VORBIS_COMMENT']['raw']['block_length']);
488
+ break;
489
+
490
+ default:
491
+ return false;
492
+ }
493
+
494
+ $VendorSize = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
495
+ $commentdataoffset += 4;
496
+
497
+ $info['ogg']['vendor'] = substr($commentdata, $commentdataoffset, $VendorSize);
498
+ $commentdataoffset += $VendorSize;
499
+
500
+ $CommentsCount = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
501
+ $commentdataoffset += 4;
502
+ $info['avdataoffset'] = $CommentStartOffset + $commentdataoffset;
503
+
504
+ $basicfields = array('TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT');
505
+ $ThisFileInfo_ogg_comments_raw = &$info['ogg']['comments_raw'];
506
+ for ($i = 0; $i < $CommentsCount; $i++) {
507
+
508
+ $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset;
509
+
510
+ if ($this->ftell() < ($ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + 4)) {
511
+ if ($oggpageinfo = $this->ParseOggPageHeader()) {
512
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
513
+
514
+ $VorbisCommentPage++;
515
+
516
+ // First, save what we haven't read yet
517
+ $AsYetUnusedData = substr($commentdata, $commentdataoffset);
518
+
519
+ // Then take that data off the end
520
+ $commentdata = substr($commentdata, 0, $commentdataoffset);
521
+
522
+ // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
523
+ $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
524
+ $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
525
+
526
+ // Finally, stick the unused data back on the end
527
+ $commentdata .= $AsYetUnusedData;
528
+
529
+ //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
530
+ $commentdata .= $this->fread($this->OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1));
531
+ }
532
+
533
+ }
534
+ $ThisFileInfo_ogg_comments_raw[$i]['size'] = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
535
+
536
+ // replace avdataoffset with position just after the last vorbiscomment
537
+ $info['avdataoffset'] = $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + $ThisFileInfo_ogg_comments_raw[$i]['size'] + 4;
538
+
539
+ $commentdataoffset += 4;
540
+ while ((strlen($commentdata) - $commentdataoffset) < $ThisFileInfo_ogg_comments_raw[$i]['size']) {
541
+ if (($ThisFileInfo_ogg_comments_raw[$i]['size'] > $info['avdataend']) || ($ThisFileInfo_ogg_comments_raw[$i]['size'] < 0)) {
542
+ $info['warning'][] = 'Invalid Ogg comment size (comment #'.$i.', claims to be '.number_format($ThisFileInfo_ogg_comments_raw[$i]['size']).' bytes) - aborting reading comments';
543
+ break 2;
544
+ }
545
+
546
+ $VorbisCommentPage++;
547
+
548
+ $oggpageinfo = $this->ParseOggPageHeader();
549
+ $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
550
+
551
+ // First, save what we haven't read yet
552
+ $AsYetUnusedData = substr($commentdata, $commentdataoffset);
553
+
554
+ // Then take that data off the end
555
+ $commentdata = substr($commentdata, 0, $commentdataoffset);
556
+
557
+ // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
558
+ $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
559
+ $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
560
+
561
+ // Finally, stick the unused data back on the end
562
+ $commentdata .= $AsYetUnusedData;
563
+
564
+ //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
565
+ if (!isset($info['ogg']['pageheader'][$VorbisCommentPage])) {
566
+ $info['warning'][] = 'undefined Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell();
567
+ break;
568
+ }
569
+ $readlength = self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1);
570
+ if ($readlength <= 0) {
571
+ $info['warning'][] = 'invalid length Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell();
572
+ break;
573
+ }
574
+ $commentdata .= $this->fread($readlength);
575
+
576
+ //$filebaseoffset += $oggpageinfo['header_end_offset'] - $oggpageinfo['page_start_offset'];
577
+ }
578
+ $ThisFileInfo_ogg_comments_raw[$i]['offset'] = $commentdataoffset;
579
+ $commentstring = substr($commentdata, $commentdataoffset, $ThisFileInfo_ogg_comments_raw[$i]['size']);
580
+ $commentdataoffset += $ThisFileInfo_ogg_comments_raw[$i]['size'];
581
+
582
+ if (!$commentstring) {
583
+
584
+ // no comment?
585
+ $info['warning'][] = 'Blank Ogg comment ['.$i.']';
586
+
587
+ } elseif (strstr($commentstring, '=')) {
588
+
589
+ $commentexploded = explode('=', $commentstring, 2);
590
+ $ThisFileInfo_ogg_comments_raw[$i]['key'] = strtoupper($commentexploded[0]);
591
+ $ThisFileInfo_ogg_comments_raw[$i]['value'] = (isset($commentexploded[1]) ? $commentexploded[1] : '');
592
+
593
+ if ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'METADATA_BLOCK_PICTURE') {
594
+
595
+ // http://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE
596
+ // The unencoded format is that of the FLAC picture block. The fields are stored in big endian order as in FLAC, picture data is stored according to the relevant standard.
597
+ // http://flac.sourceforge.net/format.html#metadata_block_picture
598
+ $flac = new getid3_flac($this->getid3);
599
+ $flac->setStringMode(base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value']));
600
+ $flac->parsePICTURE();
601
+ $info['ogg']['comments']['picture'][] = $flac->getid3->info['flac']['PICTURE'][0];
602
+ unset($flac);
603
+
604
+ } elseif ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'COVERART') {
605
+
606
+ $data = base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value']);
607
+ $this->notice('Found deprecated COVERART tag, it should be replaced in honor of METADATA_BLOCK_PICTURE structure');
608
+ /** @todo use 'coverartmime' where available */
609
+ $imageinfo = getid3_lib::GetDataImageSize($data);
610
+ if ($imageinfo === false || !isset($imageinfo['mime'])) {
611
+ $this->warning('COVERART vorbiscomment tag contains invalid image');
612
+ continue;
613
+ }
614
+
615
+ $ogg = new self($this->getid3);
616
+ $ogg->setStringMode($data);
617
+ $info['ogg']['comments']['picture'][] = array(
618
+ 'image_mime' => $imageinfo['mime'],
619
+ 'data' => $ogg->saveAttachment('coverart', 0, strlen($data), $imageinfo['mime']),
620
+ );
621
+ unset($ogg);
622
+
623
+ } else {
624
+
625
+ $info['ogg']['comments'][strtolower($ThisFileInfo_ogg_comments_raw[$i]['key'])][] = $ThisFileInfo_ogg_comments_raw[$i]['value'];
626
+
627
+ }
628
+
629
+ } else {
630
+
631
+ $info['warning'][] = '[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair ['.$i.']: '.$commentstring;
632
+
633
+ }
634
+ unset($ThisFileInfo_ogg_comments_raw[$i]);
635
+ }
636
+ unset($ThisFileInfo_ogg_comments_raw);
637
+
638
+
639
+ // Replay Gain Adjustment
640
+ // http://privatewww.essex.ac.uk/~djmrob/replaygain/
641
+ if (isset($info['ogg']['comments']) && is_array($info['ogg']['comments'])) {
642
+ foreach ($info['ogg']['comments'] as $index => $commentvalue) {
643
+ switch ($index) {
644
+ case 'rg_audiophile':
645
+ case 'replaygain_album_gain':
646
+ $info['replay_gain']['album']['adjustment'] = (double) $commentvalue[0];
647
+ unset($info['ogg']['comments'][$index]);
648
+ break;
649
+
650
+ case 'rg_radio':
651
+ case 'replaygain_track_gain':
652
+ $info['replay_gain']['track']['adjustment'] = (double) $commentvalue[0];
653
+ unset($info['ogg']['comments'][$index]);
654
+ break;
655
+
656
+ case 'replaygain_album_peak':
657
+ $info['replay_gain']['album']['peak'] = (double) $commentvalue[0];
658
+ unset($info['ogg']['comments'][$index]);
659
+ break;
660
+
661
+ case 'rg_peak':
662
+ case 'replaygain_track_peak':
663
+ $info['replay_gain']['track']['peak'] = (double) $commentvalue[0];
664
+ unset($info['ogg']['comments'][$index]);
665
+ break;
666
+
667
+ case 'replaygain_reference_loudness':
668
+ $info['replay_gain']['reference_volume'] = (double) $commentvalue[0];
669
+ unset($info['ogg']['comments'][$index]);
670
+ break;
671
+
672
+ default:
673
+ // do nothing
674
+ break;
675
+ }
676
+ }
677
+ }
678
+
679
+ $this->fseek($OriginalOffset);
680
+
681
+ return true;
682
+ }
683
+
684
+ public static function SpeexBandModeLookup($mode) {
685
+ static $SpeexBandModeLookup = array();
686
+ if (empty($SpeexBandModeLookup)) {
687
+ $SpeexBandModeLookup[0] = 'narrow';
688
+ $SpeexBandModeLookup[1] = 'wide';
689
+ $SpeexBandModeLookup[2] = 'ultra-wide';
690
+ }
691
+ return (isset($SpeexBandModeLookup[$mode]) ? $SpeexBandModeLookup[$mode] : null);
692
+ }
693
+
694
+
695
+ public static function OggPageSegmentLength($OggInfoArray, $SegmentNumber=1) {
696
+ for ($i = 0; $i < $SegmentNumber; $i++) {
697
+ $segmentlength = 0;
698
+ foreach ($OggInfoArray['segment_table'] as $key => $value) {
699
+ $segmentlength += $value;
700
+ if ($value < 255) {
701
+ break;
702
+ }
703
+ }
704
+ }
705
+ return $segmentlength;
706
+ }
707
+
708
+
709
+ public static function get_quality_from_nominal_bitrate($nominal_bitrate) {
710
+
711
+ // decrease precision
712
+ $nominal_bitrate = $nominal_bitrate / 1000;
713
+
714
+ if ($nominal_bitrate < 128) {
715
+ // q-1 to q4
716
+ $qval = ($nominal_bitrate - 64) / 16;
717
+ } elseif ($nominal_bitrate < 256) {
718
+ // q4 to q8
719
+ $qval = $nominal_bitrate / 32;
720
+ } elseif ($nominal_bitrate < 320) {
721
+ // q8 to q9
722
+ $qval = ($nominal_bitrate + 256) / 64;
723
+ } else {
724
+ // q9 to q10
725
+ $qval = ($nominal_bitrate + 1300) / 180;
726
+ }
727
+ //return $qval; // 5.031324
728
+ //return intval($qval); // 5
729
+ return round($qval, 1); // 5 or 4.9
730
+ }
731
+
732
+ public static function TheoraColorSpace($colorspace_id) {
733
+ // http://www.theora.org/doc/Theora.pdf (table 6.3)
734
+ static $TheoraColorSpaceLookup = array();
735
+ if (empty($TheoraColorSpaceLookup)) {
736
+ $TheoraColorSpaceLookup[0] = 'Undefined';
737
+ $TheoraColorSpaceLookup[1] = 'Rec. 470M';
738
+ $TheoraColorSpaceLookup[2] = 'Rec. 470BG';
739
+ $TheoraColorSpaceLookup[3] = 'Reserved';
740
+ }
741
+ return (isset($TheoraColorSpaceLookup[$colorspace_id]) ? $TheoraColorSpaceLookup[$colorspace_id] : null);
742
+ }
743
+
744
+ public static function TheoraPixelFormat($pixelformat_id) {
745
+ // http://www.theora.org/doc/Theora.pdf (table 6.4)
746
+ static $TheoraPixelFormatLookup = array();
747
+ if (empty($TheoraPixelFormatLookup)) {
748
+ $TheoraPixelFormatLookup[0] = '4:2:0';
749
+ $TheoraPixelFormatLookup[1] = 'Reserved';
750
+ $TheoraPixelFormatLookup[2] = '4:2:2';
751
+ $TheoraPixelFormatLookup[3] = '4:4:4';
752
+ }
753
+ return (isset($TheoraPixelFormatLookup[$pixelformat_id]) ? $TheoraPixelFormatLookup[$pixelformat_id] : null);
754
+ }
755
+
756
+ }
getid3/module.tag.apetag.php CHANGED
@@ -1,372 +1,371 @@
1
- <?php
2
- /////////////////////////////////////////////////////////////////
3
- /// getID3() by James Heinrich <info@getid3.org> //
4
- // available at http://getid3.sourceforge.net //
5
- // or http://www.getid3.org //
6
- /////////////////////////////////////////////////////////////////
7
- // See readme.txt for more details //
8
- /////////////////////////////////////////////////////////////////
9
- // //
10
- // module.tag.apetag.php //
11
- // module for analyzing APE tags //
12
- // dependencies: NONE //
13
- // ///
14
- /////////////////////////////////////////////////////////////////
15
-
16
- class getid3_apetag extends getid3_handler
17
- {
18
- var $inline_attachments = true; // true: return full data for all attachments; false: return no data for all attachments; integer: return data for attachments <= than this; string: save as file to this directory
19
- var $overrideendoffset = 0;
20
-
21
- function Analyze() {
22
- $info = &$this->getid3->info;
23
-
24
- if (!getid3_lib::intValueSupported($info['filesize'])) {
25
- $info['warning'][] = 'Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
26
- return false;
27
- }
28
-
29
- $id3v1tagsize = 128;
30
- $apetagheadersize = 32;
31
- $lyrics3tagsize = 10;
32
-
33
- if ($this->overrideendoffset == 0) {
34
-
35
- fseek($this->getid3->fp, 0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
36
- $APEfooterID3v1 = fread($this->getid3->fp, $id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
37
-
38
- //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
39
- if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
40
-
41
- // APE tag found before ID3v1
42
- $info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize;
43
-
44
- //} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) {
45
- } elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') {
46
-
47
- // APE tag found, no ID3v1
48
- $info['ape']['tag_offset_end'] = $info['filesize'];
49
-
50
- }
51
-
52
- } else {
53
-
54
- fseek($this->getid3->fp, $this->overrideendoffset - $apetagheadersize, SEEK_SET);
55
- if (fread($this->getid3->fp, 8) == 'APETAGEX') {
56
- $info['ape']['tag_offset_end'] = $this->overrideendoffset;
57
- }
58
-
59
- }
60
- if (!isset($info['ape']['tag_offset_end'])) {
61
-
62
- // APE tag not found
63
- unset($info['ape']);
64
- return false;
65
-
66
- }
67
-
68
- // shortcut
69
- $thisfile_ape = &$info['ape'];
70
-
71
- fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $apetagheadersize, SEEK_SET);
72
- $APEfooterData = fread($this->getid3->fp, 32);
73
- if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
74
- $info['error'][] = 'Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end'];
75
- return false;
76
- }
77
-
78
- if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
79
- fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize, SEEK_SET);
80
- $thisfile_ape['tag_offset_start'] = ftell($this->getid3->fp);
81
- $APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
82
- } else {
83
- $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
84
- fseek($this->getid3->fp, $thisfile_ape['tag_offset_start'], SEEK_SET);
85
- $APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize']);
86
- }
87
- $info['avdataend'] = $thisfile_ape['tag_offset_start'];
88
-
89
- if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) {
90
- $info['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in APEtag data';
91
- unset($info['id3v1']);
92
- foreach ($info['warning'] as $key => $value) {
93
- if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
94
- unset($info['warning'][$key]);
95
- sort($info['warning']);
96
- break;
97
- }
98
- }
99
- }
100
-
101
- $offset = 0;
102
- if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
103
- if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) {
104
- $offset += $apetagheadersize;
105
- } else {
106
- $info['error'][] = 'Error parsing APE header at offset '.$thisfile_ape['tag_offset_start'];
107
- return false;
108
- }
109
- }
110
-
111
- // shortcut
112
- $info['replay_gain'] = array();
113
- $thisfile_replaygain = &$info['replay_gain'];
114
-
115
- for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) {
116
- $value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
117
- $offset += 4;
118
- $item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
119
- $offset += 4;
120
- if (strstr(substr($APEtagData, $offset), "\x00") === false) {
121
- $info['error'][] = 'Cannot find null-byte (0x00) seperator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset);
122
- return false;
123
- }
124
- $ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset;
125
- $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength));
126
-
127
- // shortcut
128
- $thisfile_ape['items'][$item_key] = array();
129
- $thisfile_ape_items_current = &$thisfile_ape['items'][$item_key];
130
-
131
- $thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset;
132
-
133
- $offset += ($ItemKeyLength + 1); // skip 0x00 terminator
134
- $thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size);
135
- $offset += $value_size;
136
-
137
- $thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags);
138
- switch ($thisfile_ape_items_current['flags']['item_contents_raw']) {
139
- case 0: // UTF-8
140
- case 3: // Locator (URL, filename, etc), UTF-8 encoded
141
- $thisfile_ape_items_current['data'] = explode("\x00", trim($thisfile_ape_items_current['data']));
142
- break;
143
-
144
- default: // binary data
145
- break;
146
- }
147
-
148
- switch (strtolower($item_key)) {
149
- case 'replaygain_track_gain':
150
- $thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
151
- $thisfile_replaygain['track']['originator'] = 'unspecified';
152
- break;
153
-
154
- case 'replaygain_track_peak':
155
- $thisfile_replaygain['track']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
156
- $thisfile_replaygain['track']['originator'] = 'unspecified';
157
- if ($thisfile_replaygain['track']['peak'] <= 0) {
158
- $info['warning'][] = 'ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")';
159
- }
160
- break;
161
-
162
- case 'replaygain_album_gain':
163
- $thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
164
- $thisfile_replaygain['album']['originator'] = 'unspecified';
165
- break;
166
-
167
- case 'replaygain_album_peak':
168
- $thisfile_replaygain['album']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
169
- $thisfile_replaygain['album']['originator'] = 'unspecified';
170
- if ($thisfile_replaygain['album']['peak'] <= 0) {
171
- $info['warning'][] = 'ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")';
172
- }
173
- break;
174
-
175
- case 'mp3gain_undo':
176
- list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]);
177
- $thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left);
178
- $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
179
- $thisfile_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false);
180
- break;
181
-
182
- case 'mp3gain_minmax':
183
- list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]);
184
- $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
185
- $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
186
- break;
187
-
188
- case 'mp3gain_album_minmax':
189
- list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]);
190
- $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
191
- $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
192
- break;
193
-
194
- case 'tracknumber':
195
- if (is_array($thisfile_ape_items_current['data'])) {
196
- foreach ($thisfile_ape_items_current['data'] as $comment) {
197
- $thisfile_ape['comments']['track'][] = $comment;
198
- }
199
- }
200
- break;
201
-
202
- case 'cover art (artist)':
203
- case 'cover art (back)':
204
- case 'cover art (band logo)':
205
- case 'cover art (band)':
206
- case 'cover art (colored fish)':
207
- case 'cover art (composer)':
208
- case 'cover art (conductor)':
209
- case 'cover art (front)':
210
- case 'cover art (icon)':
211
- case 'cover art (illustration)':
212
- case 'cover art (lead)':
213
- case 'cover art (leaflet)':
214
- case 'cover art (lyricist)':
215
- case 'cover art (media)':
216
- case 'cover art (movie scene)':
217
- case 'cover art (other icon)':
218
- case 'cover art (other)':
219
- case 'cover art (performance)':
220
- case 'cover art (publisher logo)':
221
- case 'cover art (recording)':
222
- case 'cover art (studio)':
223
- // list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html
224
- list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2);
225
- $thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00");
226
- $thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']);
227
-
228
- $thisfile_ape_items_current['image_mime'] = '';
229
- $imageinfo = array();
230
- $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo);
231
- $thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
232
-
233
- do {
234
- if ($this->inline_attachments === false) {
235
- // skip entirely
236
- unset($thisfile_ape_items_current['data']);
237
- break;
238
- }
239
- if ($this->inline_attachments === true) {
240
- // great
241
- } elseif (is_int($this->inline_attachments)) {
242
- if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) {
243
- // too big, skip
244
- $info['warning'][] = 'attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)';
245
- unset($thisfile_ape_items_current['data']);
246
- break;
247
- }
248
- } elseif (is_string($this->inline_attachments)) {
249
- $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
250
- if (!is_dir($this->inline_attachments) || !is_writable($this->inline_attachments)) {
251
- // cannot write, skip
252
- $info['warning'][] = 'attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)';
253
- unset($thisfile_ape_items_current['data']);
254
- break;
255
- }
256
- }
257
- // if we get this far, must be OK
258
- if (is_string($this->inline_attachments)) {
259
- $destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset'];
260
- if (!file_exists($destination_filename) || is_writable($destination_filename)) {
261
- file_put_contents($destination_filename, $thisfile_ape_items_current['data']);
262
- } else {
263
- $info['warning'][] = 'attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$destination_filename.'" (not writable)';
264
- }
265
- $thisfile_ape_items_current['data_filename'] = $destination_filename;
266
- unset($thisfile_ape_items_current['data']);
267
- } else {
268
- if (!isset($info['ape']['comments']['picture'])) {
269
- $info['ape']['comments']['picture'] = array();
270
- }
271
- $info['ape']['comments']['picture'][] = array('data'=>$thisfile_ape_items_current['data'], 'image_mime'=>$thisfile_ape_items_current['image_mime']);
272
- }
273
- } while (false);
274
- break;
275
-
276
- default:
277
- if (is_array($thisfile_ape_items_current['data'])) {
278
- foreach ($thisfile_ape_items_current['data'] as $comment) {
279
- $thisfile_ape['comments'][strtolower($item_key)][] = $comment;
280
- }
281
- }
282
- break;
283
- }
284
-
285
- }
286
- if (empty($thisfile_replaygain)) {
287
- unset($info['replay_gain']);
288
- }
289
- return true;
290
- }
291
-
292
- function parseAPEheaderFooter($APEheaderFooterData) {
293
- // http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html
294
-
295
- // shortcut
296
- $headerfooterinfo['raw'] = array();
297
- $headerfooterinfo_raw = &$headerfooterinfo['raw'];
298
-
299
- $headerfooterinfo_raw['footer_tag'] = substr($APEheaderFooterData, 0, 8);
300
- if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') {
301
- return false;
302
- }
303
- $headerfooterinfo_raw['version'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 8, 4));
304
- $headerfooterinfo_raw['tagsize'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4));
305
- $headerfooterinfo_raw['tag_items'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4));
306
- $headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4));
307
- $headerfooterinfo_raw['reserved'] = substr($APEheaderFooterData, 24, 8);
308
-
309
- $headerfooterinfo['tag_version'] = $headerfooterinfo_raw['version'] / 1000;
310
- if ($headerfooterinfo['tag_version'] >= 2) {
311
- $headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']);
312
- }
313
- return $headerfooterinfo;
314
- }
315
-
316
- function parseAPEtagFlags($rawflagint) {
317
- // "Note: APE Tags 1.0 do not use any of the APE Tag flags.
318
- // All are set to zero on creation and ignored on reading."
319
- // http://www.uni-jena.de/~pfk/mpp/sv8/apetagflags.html
320
- $flags['header'] = (bool) ($rawflagint & 0x80000000);
321
- $flags['footer'] = (bool) ($rawflagint & 0x40000000);
322
- $flags['this_is_header'] = (bool) ($rawflagint & 0x20000000);
323
- $flags['item_contents_raw'] = ($rawflagint & 0x00000006) >> 1;
324
- $flags['read_only'] = (bool) ($rawflagint & 0x00000001);
325
-
326
- $flags['item_contents'] = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']);
327
-
328
- return $flags;
329
- }
330
-
331
- function APEcontentTypeFlagLookup($contenttypeid) {
332
- static $APEcontentTypeFlagLookup = array(
333
- 0 => 'utf-8',
334
- 1 => 'binary',
335
- 2 => 'external',
336
- 3 => 'reserved'
337
- );
338
- return (isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid');
339
- }
340
-
341
- function APEtagItemIsUTF8Lookup($itemkey) {
342
- static $APEtagItemIsUTF8Lookup = array(
343
- 'title',
344
- 'subtitle',
345
- 'artist',
346
- 'album',
347
- 'debut album',
348
- 'publisher',
349
- 'conductor',
350
- 'track',
351
- 'composer',
352
- 'comment',
353
- 'copyright',
354
- 'publicationright',
355
- 'file',
356
- 'year',
357
- 'record date',
358
- 'record location',
359
- 'genre',
360
- 'media',
361
- 'related',
362
- 'isrc',
363
- 'abstract',
364
- 'language',
365
- 'bibliography'
366
- );
367
- return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup);
368
- }
369
-
370
- }
371
-
372
- ?>
1
+ <?php
2
+ /////////////////////////////////////////////////////////////////
3
+ /// getID3() by James Heinrich <info@getid3.org> //
4
+ // available at http://getid3.sourceforge.net //
5
+ // or http://www.getid3.org //
6
+ // also https://github.com/JamesHeinrich/getID3 //
7
+ /////////////////////////////////////////////////////////////////
8
+ // See readme.txt for more details //
9
+ /////////////////////////////////////////////////////////////////
10
+ // //
11
+ // module.tag.apetag.php //
12
+ // module for analyzing APE tags //
13
+ // dependencies: NONE //
14
+ // ///
15
+ /////////////////////////////////////////////////////////////////
16
+
17
+ class getid3_apetag extends getid3_handler
18
+ {
19
+ public $inline_attachments = true; // true: return full data for all attachments; false: return no data for all attachments; integer: return data for attachments <= than this; string: save as file to this directory
20
+ public $overrideendoffset = 0;
21
+
22
+ public function Analyze() {
23
+ $info = &$this->getid3->info;
24
+
25
+ if (!getid3_lib::intValueSupported($info['filesize'])) {
26
+ $info['warning'][] = 'Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
27
+ return false;
28
+ }
29
+
30
+ $id3v1tagsize = 128;
31
+ $apetagheadersize = 32;
32
+ $lyrics3tagsize = 10;
33
+
34
+ if ($this->overrideendoffset == 0) {
35
+
36
+ $this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
37
+ $APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
38
+
39
+ //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
40
+ if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
41
+
42
+ // APE tag found before ID3v1
43
+ $info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize;
44
+
45
+ //} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) {
46
+ } elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') {
47
+
48
+ // APE tag found, no ID3v1
49
+ $info['ape']['tag_offset_end'] = $info['filesize'];
50
+
51
+ }
52
+
53
+ } else {
54
+
55
+ $this->fseek($this->overrideendoffset - $apetagheadersize);
56
+ if ($this->fread(8) == 'APETAGEX') {
57
+ $info['ape']['tag_offset_en