24 {
25
26
27
28 $ThisFileInfo['riff'] = array('raw'=>array());
29
30
31 $thisfile_riff = &$ThisFileInfo['riff'];
32 $thisfile_riff_raw = &$thisfile_riff['raw'];
33 $thisfile_audio = &$ThisFileInfo['audio'];
34 $thisfile_video = &$ThisFileInfo['video'];
35 $thisfile_avdataoffset = &$ThisFileInfo['avdataoffset'];
36 $thisfile_avdataend = &$ThisFileInfo['avdataend'];
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'] = $thisfile_avdataoffset;
43 $Original['avdataend'] = $thisfile_avdataend;
44
45 fseek($fd, $thisfile_avdataoffset, SEEK_SET);
46 $RIFFheader = fread($fd, 12);
47 $RIFFsubtype = substr($RIFFheader, 8, 4);
48 switch (substr($RIFFheader, 0, 4)) {
49 case 'FORM':
50 $ThisFileInfo['fileformat'] = 'aiff';
52 $thisfile_riff[$RIFFsubtype] =
getid3_riff::ParseRIFF($fd, $thisfile_avdataoffset + 12, $thisfile_avdataoffset + $RIFFheaderSize, $ThisFileInfo);
53 $thisfile_riff['header_size'] = $RIFFheaderSize;
54 break;
55
56 case 'RIFF':
57 case 'SDSS':
58 case 'RMP3':
59 if ($RIFFsubtype == 'RMP3') {
60
61 $RIFFsubtype = 'WAVE';
62 }
63
64 $ThisFileInfo['fileformat'] = 'riff';
66 $thisfile_riff[$RIFFsubtype] =
getid3_riff::ParseRIFF($fd, $thisfile_avdataoffset + 12, $thisfile_avdataoffset + $RIFFheaderSize, $ThisFileInfo);
67 $thisfile_riff['header_size'] = $RIFFheaderSize;
68 if ($RIFFsubtype == 'WAVE') {
69 $thisfile_riff_WAVE = &$thisfile_riff['WAVE'];
70 }
71 break;
72
73 default:
74 $ThisFileInfo['error'][] = 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead';
75 unset($ThisFileInfo['fileformat']);
76 return false;
77 break;
78 }
79
80 $streamindex = 0;
81 switch ($RIFFsubtype) {
82 case 'WAVE':
83 if (empty($thisfile_audio['bitrate_mode'])) {
84 $thisfile_audio['bitrate_mode'] = 'cbr';
85 }
86 if (empty($thisfile_audio_dataformat)) {
87 $thisfile_audio_dataformat = 'wav';
88 }
89
90 if (isset($thisfile_riff_WAVE['data'][0]['offset'])) {
91 $thisfile_avdataoffset = $thisfile_riff_WAVE['data'][0]['offset'] + 8;
92 $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff_WAVE['data'][0]['size'];
93 }
94 if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) {
95
97 $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
98 if (@$thisfile_riff_audio[$streamindex]['bitrate'] == 0) {
99 $ThisFileInfo['error'][] = 'Corrupt RIFF file: bitrate_audio == zero';
100 return false;
101 }
102 $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw'];
103 unset($thisfile_riff_audio[$streamindex]['raw']);
104 $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
105
107 if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
108 $ThisFileInfo['warning'][] = 'Audio codec = '.$thisfile_audio['codec'];
109 }
110 $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
111
112 $ThisFileInfo['playtime_seconds'] = (float) ((($thisfile_avdataend - $thisfile_avdataoffset) * 8) / $thisfile_audio['bitrate']);
113
114 $thisfile_audio['lossless'] = false;
115 if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
116 switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
117
118 case 0x0001:
119 $thisfile_audio['lossless'] = true;
120 break;
121
122 case 0x2000:
123 $thisfile_audio_dataformat = 'ac3';
124 break;
125
126 default:
127
128 break;
129
130 }
131 }
132 $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag'];
133 $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
134 $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless'];
135 $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat;
136 }
137
138 if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) {
139
140
141 $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data'];
142 $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array());
143 $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad'];
144 $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track'];
145 $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album'];
146
150
151 $nRadioRgAdjustBitstring = str_pad(
getid3_lib::Dec2Bin($thisfile_riff_raw_rgad[
'nRadioRgAdjust']), 16,
'0', STR_PAD_LEFT);
152 $nAudiophileRgAdjustBitstring = str_pad(
getid3_lib::Dec2Bin($thisfile_riff_raw_rgad[
'nAudiophileRgAdjust']), 16,
'0', STR_PAD_LEFT);
153 $thisfile_riff_raw_rgad_track[
'name'] =
getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
154 $thisfile_riff_raw_rgad_track[
'originator'] =
getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
155 $thisfile_riff_raw_rgad_track[
'signbit'] =
getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
156 $thisfile_riff_raw_rgad_track[
'adjustment'] =
getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
157 $thisfile_riff_raw_rgad_album[
'name'] =
getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
158 $thisfile_riff_raw_rgad_album[
'originator'] =
getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
159 $thisfile_riff_raw_rgad_album[
'signbit'] =
getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
160 $thisfile_riff_raw_rgad_album[
'adjustment'] =
getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
161
162 $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude'];
163 if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) {
166 $thisfile_riff[
'rgad'][
'track'][
'adjustment'] =
getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track[
'adjustment'], $thisfile_riff_raw_rgad_track[
'signbit']);
167 }
168 if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) {
171 $thisfile_riff[
'rgad'][
'album'][
'adjustment'] =
getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album[
'adjustment'], $thisfile_riff_raw_rgad_album[
'signbit']);
172 }
173 }
174
175 if (isset($thisfile_riff_WAVE['fact'][0]['data'])) {
176 $thisfile_riff_raw[
'fact'][
'NumberOfSamples'] =
getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_WAVE[
'fact'][0][
'data'], 0, 4));
177
178
179
180
181
182
183
184
185 }
186 if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
187 $thisfile_audio[
'bitrate'] =
getid3_lib::CastAsInt($thisfile_riff_raw[
'fmt '][
'nAvgBytesPerSec'] * 8);
188 }
189
190 if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
191
192 $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
193
194 $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256));
195 $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32));
196 $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32));
197 $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10);
198 $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8);
202 $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601)));
203
204 $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime(
205 substr($thisfile_riff_WAVE_bext_0['origin_time'], 0, 2),
206 substr($thisfile_riff_WAVE_bext_0['origin_time'], 3, 2),
207 substr($thisfile_riff_WAVE_bext_0['origin_time'], 6, 2),
208 substr($thisfile_riff_WAVE_bext_0['origin_date'], 5, 2),
209 substr($thisfile_riff_WAVE_bext_0['origin_date'], 8, 2),
210 substr($thisfile_riff_WAVE_bext_0['origin_date'], 0, 4));
211
212 $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
213 $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title'];
214 }
215
216 if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) {
217
218 $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0];
219
220 $thisfile_riff_WAVE_MEXT_0[
'raw'][
'sound_information'] =
getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0[
'data'], 0, 2));
221 $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001);
222 if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) {
223 $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true;
224 $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004);
225 $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008);
226
228 }
230 $thisfile_riff_WAVE_MEXT_0[
'raw'][
'anciliary_data_def'] =
getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0[
'data'], 8, 2));
231 $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001);
232 $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002);
233 $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004);
234 }
235
236 if (isset($thisfile_riff_WAVE['cart'][0]['data'])) {
237
238 $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0];
239
240 $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4);
241 $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64));
242 $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64));
243 $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64));
244 $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64));
245 $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64));
246 $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64));
247 $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64));
248 $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10));
249 $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8));
250 $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10));
251 $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8));
252 $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64));
253 $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64));
254 $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64));
255 $thisfile_riff_WAVE_cart_0[
'zero_db_reference'] =
getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0[
'data'], 680, 4),
true);
256 for ($i = 0; $i < 8; $i++) {
257 $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4);
258 $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));
259 }
260 $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024));
261 $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772)));
262
263 $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist'];
264 $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title'];
265 }
266
267 if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
268 $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
269 $ThisFileInfo['playtime_seconds'] = (float) ((($thisfile_avdataend - $thisfile_avdataoffset) * 8) / $thisfile_audio['bitrate']);
270 }
271
272 if (!empty($ThisFileInfo['wavpack'])) {
273 $thisfile_audio_dataformat = 'wavpack';
274 $thisfile_audio['bitrate_mode'] = 'vbr';
275 $thisfile_audio['encoder'] = 'WavPack v'.$ThisFileInfo['wavpack']['version'];
276
277
278 $thisfile_avdataend = $Original['avdataend'];
279 $thisfile_audio['bitrate'] = (($thisfile_avdataend - $thisfile_avdataoffset) * 8) / $ThisFileInfo['playtime_seconds'];
280
281 fseek($fd, $thisfile_avdataoffset - 44, SEEK_SET);
282 $RIFFdata = fread($fd, 44);
285
286 if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
287 $thisfile_avdataend -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
288 fseek($fd, $thisfile_avdataend, SEEK_SET);
289 $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize);
290 }
291
292
293
294
295 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
297 }
298
299 if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
300 switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
301 case 0x08AE:
302 $thisfile_audio['bitrate_mode'] = 'vbr';
303 $thisfile_audio_dataformat = 'litewave';
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322 $thisfile_riff['litewave']['raw'] = array();
323 $thisfile_riff_litewave = &$thisfile_riff['litewave'];
324 $thisfile_riff_litewave_raw = &$thisfile_riff_litewave['raw'];
325
326 $thisfile_riff_litewave_raw[
'compression_method'] =
getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE[
'fmt '][0][
'data'], 18, 1));
336
337
338 $thisfile_riff_litewave['quality_factor'] = $thisfile_riff_litewave_raw['m_wQuality'];
339
340 $thisfile_riff_litewave['flags']['raw_source'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
341 $thisfile_riff_litewave['flags']['vbr_blocksize'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
342 $thisfile_riff_litewave['flags']['seekpoints'] = (bool) ($thisfile_riff_litewave_raw['compression_flags'] & 0x04);
343
344 $thisfile_audio['lossless'] = (($thisfile_riff_litewave_raw['m_wQuality'] == 100) ? true : false);
345 $thisfile_audio['encoder_options'] = '-q'.$thisfile_riff_litewave['quality_factor'];
346 break;
347
348 default:
349 break;
350 }
351 }
352 if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
353 switch (@$thisfile_audio_dataformat) {
354 case 'wavpack':
355 case 'lpac':
356 case 'ofr':
357 case 'ofs':
358
359 break;
360
361 case 'litewave':
362 if (($thisfile_avdataend - $ThisFileInfo['filesize']) == 1) {
363
364
365
366 } else {
367
368 $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
369 $thisfile_avdataend = $ThisFileInfo['filesize'];
370 }
371 break;
372
373 default:
374 if ((($thisfile_avdataend - $ThisFileInfo['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($ThisFileInfo['filesize'] - $thisfile_avdataoffset) % 2) == 1)) {
375
376
377 $ThisFileInfo['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 '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
378 $thisfile_avdataend = $ThisFileInfo['filesize'];
379 break;
380 }
381
382 $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
383 $thisfile_avdataend = $ThisFileInfo['filesize'];
384 break;
385 }
386 }
387 if (!empty($ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'])) {
388 if ((($thisfile_avdataend - $thisfile_avdataoffset) - $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
389 $thisfile_avdataend--;
390 $ThisFileInfo['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
391 }
392 }
393 if (@$thisfile_audio_dataformat == 'ac3') {
394 unset($thisfile_audio['bits_per_sample']);
395 if (!empty($ThisFileInfo['ac3']['bitrate']) && ($ThisFileInfo['ac3']['bitrate'] != $thisfile_audio['bitrate'])) {
396 $thisfile_audio['bitrate'] = $ThisFileInfo['ac3']['bitrate'];
397 }
398 }
399 break;
400
401 case 'AVI ':
402 $thisfile_video['bitrate_mode'] = 'vbr';
403 $thisfile_video['dataformat'] = 'avi';
404 $ThisFileInfo['mime_type'] = 'video/avi';
405
406 if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) {
407 $thisfile_avdataoffset = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8;
408 $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff[$RIFFsubtype]['movi']['size'];
409 if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
410 $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['movi']['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' (short by '.($thisfile_riff[$RIFFsubtype]['movi']['size'] - ($ThisFileInfo['filesize'] - $thisfile_avdataoffset)).' bytes)';
411 $thisfile_avdataend = $ThisFileInfo['filesize'];
412 }
413 }
414
415 if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
416 $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'];
417
418
419 $thisfile_riff_raw['avih'] = array();
420 $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih'];
421
423 if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) {
424 $ThisFileInfo['error'][] = 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
425 return false;
426 }
440
441 $thisfile_riff_raw_avih['flags']['hasindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000010);
442 $thisfile_riff_raw_avih['flags']['mustuseindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000020);
443 $thisfile_riff_raw_avih['flags']['interleaved'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000100);
444 $thisfile_riff_raw_avih['flags']['trustcktype'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000800);
445 $thisfile_riff_raw_avih['flags']['capturedfile'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00010000);
446 $thisfile_riff_raw_avih['flags']['copyrighted'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00020010);
447
448
449 $thisfile_riff_video[$streamindex] = array();
450 $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex];
451
452 if ($thisfile_riff_raw_avih['dwWidth'] > 0) {
453 $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth'];
454 $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width'];
455 }
456 if ($thisfile_riff_raw_avih['dwHeight'] > 0) {
457 $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight'];
458 $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height'];
459 }
460 if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) {
461 $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames'];
462 $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames'];
463 }
464
465 $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3);
466 $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate'];
467 }
468 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
469 if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) {
470 for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
471 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
472 $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
473 $strhfccType = substr($strhData, 0, 4);
474
475 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
476 $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
477
478
479 $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex];
480
481 switch ($strhfccType) {
482 case 'auds':
483 $thisfile_audio['bitrate_mode'] = 'cbr';
484 $thisfile_audio_dataformat = 'wav';
485 if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) {
486 $streamindex = count($thisfile_riff_audio);
487 }
488
490 $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
491
492
493 $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
494 $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex];
495
496 if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) {
497 unset($thisfile_audio_streams_currentstream['bits_per_sample']);
498 }
499 $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag'];
500 unset($thisfile_audio_streams_currentstream['raw']);
501
502
503 $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw'];
504
505 unset($thisfile_riff_audio[$streamindex]['raw']);
507
508 $thisfile_audio['lossless'] = false;
509 switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) {
510 case 0x0001:
511 $thisfile_audio_dataformat = 'wav';
512 $thisfile_audio['lossless'] = true;
513 break;
514
515 case 0x0050:
516 $thisfile_audio_dataformat = 'mp2';
517 break;
518
519 case 0x0055:
520 $thisfile_audio_dataformat = 'mp3';
521 break;
522
523 case 0x00FF:
524 $thisfile_audio_dataformat = 'aac';
525 break;
526
527 case 0x0161:
528 case 0x0162:
529 case 0x0163:
530 $thisfile_audio_dataformat = 'wma';
531 break;
532
533 case 0x2000:
534 $thisfile_audio_dataformat = 'ac3';
535 break;
536
537 case 0x2001:
538 $thisfile_audio_dataformat = 'dts';
539 break;
540
541 default:
542 $thisfile_audio_dataformat = 'wav';
543 break;
544 }
545 $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat;
546 $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless'];
547 $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
548 break;
549
550
551 case 'iavs':
552 case 'vids':
553
554 $thisfile_riff_raw['strh'][$i] = array();
555 $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i];
556
557 $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4);
558 $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4);
571
573 $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler'];
574 if (!$thisfile_riff_video_current[
'codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex[
'fourcc']) &&
getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex[
'fourcc'])) {
576 $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
577 }
578 $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
579 $thisfile_video['pixel_aspect_ratio'] = (float) 1;
580 switch ($thisfile_riff_raw_strh_current['fccHandler']) {
581 case 'HFYU':
582 case 'IRAW':
583 case 'YUY2':
584 $thisfile_video['lossless'] = true;
585 break;
586
587 default:
588 $thisfile_video['lossless'] = false;
589 break;
590 }
591
592 switch ($strhfccType) {
593 case 'vids':
599 $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'] = substr($strfData, 16, 4);
605
606 $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'];
607
608 if ($thisfile_riff_video_current['codec'] == 'DV') {
609 $thisfile_riff_video_current['dv_type'] = 2;
610 }
611 break;
612
613 case 'iavs':
614 $thisfile_riff_video_current['dv_type'] = 1;
615 break;
616 }
617 break;
618
619 default:
620 $ThisFileInfo['warning'][] = 'Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"';
621 break;
622
623 }
624 }
625 }
626
627 if (isset($thisfile_riff_raw_strf_strhfccType_streamindex[
'fourcc']) &&
getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex[
'fourcc'])) {
628
630 $thisfile_video['codec'] = $thisfile_riff_video_current['codec'];
631 $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
632
633 switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) {
634 case 'HFYU':
635 case 'IRAW':
636 case 'YUY2':
637 $thisfile_video['lossless'] = true;
638 $thisfile_video['bits_per_sample'] = 24;
639 break;
640
641 default:
642 $thisfile_video['lossless'] = false;
643 $thisfile_video['bits_per_sample'] = 24;
644 break;
645 }
646
647 }
648 }
649 }
650 }
651 break;
652
653 case 'CDDA':
654 $thisfile_audio['bitrate_mode'] = 'cbr';
655 $thisfile_audio_dataformat = 'cda';
656 $thisfile_audio['lossless'] = true;
657 unset($ThisFileInfo['mime_type']);
658
659 $thisfile_avdataoffset = 44;
660
661 if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) {
662
663 $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0];
664
668 $thisfile_riff_CDDA_fmt_0[
'start_offset_frame'] =
getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0[
'data'], 8, 4));
669 $thisfile_riff_CDDA_fmt_0[
'playtime_frames'] =
getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0[
'data'], 12, 4));
672
673 $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75;
674 $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75;
675 $ThisFileInfo['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num'];
676 $ThisFileInfo['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds'];
677
678
679 $thisfile_audio['sample_rate'] = 44100;
680 $thisfile_audio['channels'] = 2;
681 $thisfile_audio['bits_per_sample'] = 16;
682 $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample'];
683 $thisfile_audio['bitrate_mode'] = 'cbr';
684 }
685 break;
686
687
688 case 'AIFF':
689 case 'AIFC':
690 $thisfile_audio['bitrate_mode'] = 'cbr';
691 $thisfile_audio_dataformat = 'aiff';
692 $thisfile_audio['lossless'] = true;
693 $ThisFileInfo['mime_type'] = 'audio/x-aiff';
694
695 if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) {
696 $thisfile_avdataoffset = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8;
697 $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size'];
698 if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
699 if (($thisfile_avdataend == ($ThisFileInfo['filesize'] + 1)) && (($ThisFileInfo['filesize'] % 2) == 1)) {
700
701
702 } else {
703 $ThisFileInfo['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' bytes found';
704 }
705 $thisfile_avdataend = $ThisFileInfo['filesize'];
706 }
707 }
708
709 if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) {
710
711
712 $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data'];
713
714 $thisfile_riff_audio[
'channels'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2),
true);
715 $thisfile_riff_audio[
'total_samples'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4),
false);
716 $thisfile_riff_audio[
'bits_per_sample'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2),
true);
718
719 if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) {
720 $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4);
722 $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize);
723 switch ($thisfile_riff_audio['codec_name']) {
724 case 'NONE':
725 $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
726 $thisfile_audio['lossless'] = true;
727 break;
728
729 case '':
730 switch ($thisfile_riff_audio['codec_fourcc']) {
731
732 case 'sowt':
733 $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
734 $thisfile_audio['lossless'] = true;
735 break;
736
737 case 'twos':
738 $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
739 $thisfile_audio['lossless'] = true;
740 break;
741
742 default:
743 break;
744 }
745 break;
746
747 default:
748 $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name'];
749 $thisfile_audio['lossless'] = false;
750 break;
751 }
752 }
753
754 $thisfile_audio['channels'] = $thisfile_riff_audio['channels'];
755 if ($thisfile_riff_audio['bits_per_sample'] > 0) {
756 $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample'];
757 }
758 $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate'];
759 if ($thisfile_audio['sample_rate'] == 0) {
760 $ThisFileInfo['error'][] = 'Corrupted AIFF file: sample_rate == zero';
761 return false;
762 }
763 $ThisFileInfo['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate'];
764 }
765
766 if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) {
767 $offset = 0;
769 $offset += 2;
770 for ($i = 0; $i < $CommentCount; $i++) {
771 $ThisFileInfo[
'comments_raw'][$i][
'timestamp'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype][
'COMT'][0][
'data'], $offset, 4),
false);
772 $offset += 4;
773 $ThisFileInfo[
'comments_raw'][$i][
'marker_id'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype][
'COMT'][0][
'data'], $offset, 2),
true);
774 $offset += 2;
776 $offset += 2;
777 $ThisFileInfo['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength);
778 $offset += $CommentLength;
779
780 $ThisFileInfo[
'comments_raw'][$i][
'timestamp_unix'] =
getid3_lib::DateMac2Unix($ThisFileInfo[
'comments_raw'][$i][
'timestamp']);
781 $thisfile_riff['comments']['comment'][] = $ThisFileInfo['comments_raw'][$i]['comment'];
782 }
783 }
784
785 $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
786 foreach ($CommentsChunkNames as $key => $value) {
787 if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
788 $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
789 }
790 }
791 break;
792
793 case '8SVX':
794 $thisfile_audio['bitrate_mode'] = 'cbr';
795 $thisfile_audio_dataformat = '8svx';
796 $thisfile_audio['bits_per_sample'] = 8;
797 $thisfile_audio['channels'] = 1;
798 $ThisFileInfo['mime_type'] = 'audio/x-aiff';
799
800 if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) {
801 $thisfile_avdataoffset = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8;
802 $thisfile_avdataend = $thisfile_avdataoffset + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size'];
803 if ($thisfile_avdataend > $ThisFileInfo['filesize']) {
804 $ThisFileInfo['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($ThisFileInfo['filesize'] - $thisfile_avdataoffset).' bytes found';
805 }
806 }
807
808 if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) {
809
810 $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0];
811
812 $thisfile_riff_RIFFsubtype_VHDR_0[
'oneShotHiSamples'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0[
'data'], 0, 4));
813 $thisfile_riff_RIFFsubtype_VHDR_0[
'repeatHiSamples'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0[
'data'], 4, 4));
814 $thisfile_riff_RIFFsubtype_VHDR_0[
'samplesPerHiCycle'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0[
'data'], 8, 4));
815 $thisfile_riff_RIFFsubtype_VHDR_0[
'samplesPerSec'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0[
'data'], 12, 2));
816 $thisfile_riff_RIFFsubtype_VHDR_0[
'ctOctave'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0[
'data'], 14, 1));
817 $thisfile_riff_RIFFsubtype_VHDR_0[
'sCompression'] =
getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0[
'data'], 15, 1));
818 $thisfile_riff_RIFFsubtype_VHDR_0[
'Volume'] =
getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0[
'data'], 16, 4));
819
820 $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'];
821
822 switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) {
823 case 0:
824 $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)';
825 $thisfile_audio['lossless'] = true;
826 $ActualBitsPerSample = 8;
827 break;
828
829 case 1:
830 $thisfile_audio['codec'] = 'Fibonacci-delta encoding';
831 $thisfile_audio['lossless'] = false;
832 $ActualBitsPerSample = 4;
833 break;
834
835 default:
836 $ThisFileInfo['warning'][] = 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"';
837 break;
838 }
839 }
840
841 if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) {
843 switch ($ChannelsIndex) {
844 case 6:
845 $thisfile_audio['channels'] = 2;
846 break;
847
848 case 2:
849 case 4:
850 $thisfile_audio['channels'] = 1;
851 break;
852
853 default:
854 $ThisFileInfo['warning'][] = 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"';
855 break;
856 }
857
858 }
859
860 $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
861 foreach ($CommentsChunkNames as $key => $value) {
862 if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
863 $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
864 }
865 }
866
867 $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels'];
868 if (!empty($thisfile_audio['bitrate'])) {
869 $ThisFileInfo['playtime_seconds'] = ($thisfile_avdataend - $thisfile_avdataoffset) / ($thisfile_audio['bitrate'] / 8);
870 }
871 break;
872
873
874 case 'CDXA':
875 $ThisFileInfo['mime_type'] = 'video/mpeg';
876 if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) {
877 $GETID3_ERRORARRAY = &$ThisFileInfo['warning'];
879 $dummy = $ThisFileInfo;
880 $dummy['error'] = array();
882 if (empty($dummy['error'])) {
883 $ThisFileInfo['audio'] = $dummy['audio'];
884 $ThisFileInfo['video'] = $dummy['video'];
885 $ThisFileInfo['mpeg'] = $dummy['mpeg'];
886 $ThisFileInfo['warning'] = $dummy['warning'];
887 }
888 }
889 }
890 break;
891
892
893 default:
894 $ThisFileInfo['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$RIFFsubtype.'" instead';
895 unset($ThisFileInfo['fileformat']);
896 break;
897 }
898
899 if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) {
900 $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4));
901 }
902 if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) {
903 $this->
RIFFcommentsParse($thisfile_riff_WAVE[
'INFO'], $thisfile_riff[
'comments']);
904 }
905
906 if (empty($thisfile_audio['encoder']) && !empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version'])) {
907 $thisfile_audio['encoder'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version'];
908 }
909
910 if (!isset($ThisFileInfo['playtime_seconds'])) {
911 $ThisFileInfo['playtime_seconds'] = 0;
912 }
913 if (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
914 $ThisFileInfo['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
915 }
916
917 if ($ThisFileInfo['playtime_seconds'] > 0) {
918 if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
919
920 if (!isset($ThisFileInfo['bitrate'])) {
921 $ThisFileInfo['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
922 }
923
924 } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) {
925
926 if (!isset($thisfile_audio['bitrate'])) {
927 $thisfile_audio['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
928 }
929
930 } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
931
932 if (!isset($thisfile_video['bitrate'])) {
933 $thisfile_video['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
934 }
935
936 }
937 }
938
939
940 if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($ThisFileInfo['playtime_seconds'] > 0)) {
941
942 $ThisFileInfo['bitrate'] = ((($thisfile_avdataend - $thisfile_avdataoffset) / $ThisFileInfo['playtime_seconds']) * 8);
943 $thisfile_audio['bitrate'] = 0;
944 $thisfile_video['bitrate'] = $ThisFileInfo['bitrate'];
945 foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) {
946 $thisfile_video['bitrate'] -= $audioinfoarray['bitrate'];
947 $thisfile_audio['bitrate'] += $audioinfoarray['bitrate'];
948 }
949 if ($thisfile_video['bitrate'] <= 0) {
950 unset($thisfile_video['bitrate']);
951 }
952 if ($thisfile_audio['bitrate'] <= 0) {
953 unset($thisfile_audio['bitrate']);
954 }
955 }
956
957 if (isset($ThisFileInfo['mpeg']['audio'])) {
958 $thisfile_audio_dataformat = 'mp'.$ThisFileInfo['mpeg']['audio']['layer'];
959 $thisfile_audio['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate'];
960 $thisfile_audio['channels'] = $ThisFileInfo['mpeg']['audio']['channels'];
961 $thisfile_audio['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'];
962 $thisfile_audio['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']);
963 if (!empty($ThisFileInfo['mpeg']['audio']['codec'])) {
964 $thisfile_audio['codec'] = $ThisFileInfo['mpeg']['audio']['codec'].' '.$thisfile_audio['codec'];
965 }
966 if (!empty($thisfile_audio['streams'])) {
967 foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) {
968 if ($streamdata['dataformat'] == $thisfile_audio_dataformat) {
969 $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate'];
970 $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels'];
971 $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
972 $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
973 $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec'];
974 }
975 }
976 }
978 }
979
980
981 if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
982 switch ($thisfile_audio_dataformat) {
983 case 'ac3':
984
985 break;
986
987 default:
988 $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample'];
989 break;
990 }
991 }
992
993
994 if (empty($thisfile_riff_raw)) {
995 unset($thisfile_riff['raw']);
996 }
997 if (empty($thisfile_riff_audio)) {
998 unset($thisfile_riff['audio']);
999 }
1000 if (empty($thisfile_riff_video)) {
1001 unset($thisfile_riff['video']);
1002 }
1003
1004 return true;
1005 }
BigEndian2Float($byteword)
RGADadjustmentLookup($rawadjustment, $signbit)
RGADoriginatorLookup($originatorcode)
IncludeDependency($filename, $sourcefile, $DieOnFailure=false)
array_merge_noclobber($array1, $array2)
RGADnameLookup($namecode)
LittleEndian2Float($byteword)
FixedPoint16_16($rawdata)
Bin2Dec($binstring, $signed=false)
GuessEncoderOptions(&$ThisFileInfo)
RIFFparseWAVEFORMATex($WaveFormatExData)
RIFFcommentsParse(&$RIFFinfoArray, &$CommentsTargetArray)
RIFFfourccLookup($fourcc)
ParseRIFF(&$fd, $startoffset, $maxoffset, &$ThisFileInfo)
ParseRIFFdata(&$RIFFdata, &$ThisFileInfo)
EitherEndian2Int(&$ThisFileInfo, $byteword, $signed=false)