23 $info = &$this->getid3->info;
25 $info[
'fileformat'] =
'real';
27 $info[
'playtime_seconds'] = 0;
32 $ChunkData = $this->
fread(8);
33 $ChunkName = substr($ChunkData, 0, 4);
36 if ($ChunkName ==
'.ra'.
"\xFD") {
37 $ChunkData .= $this->
fread($ChunkSize - 8);
39 $info[
'audio'][
'dataformat'] =
'real';
40 $info[
'audio'][
'lossless'] =
false;
41 $info[
'audio'][
'sample_rate'] =
$info[
'real'][
'old_ra_header'][
'sample_rate'];
42 $info[
'audio'][
'bits_per_sample'] =
$info[
'real'][
'old_ra_header'][
'bits_per_sample'];
43 $info[
'audio'][
'channels'] =
$info[
'real'][
'old_ra_header'][
'channels'];
45 $info[
'playtime_seconds'] = 60 * (
$info[
'real'][
'old_ra_header'][
'audio_bytes'] /
$info[
'real'][
'old_ra_header'][
'bytes_per_minute']);
46 $info[
'audio'][
'bitrate'] = 8 * (
$info[
'real'][
'old_ra_header'][
'audio_bytes'] /
$info[
'playtime_seconds']);
49 foreach (
$info[
'real'][
'old_ra_header'][
'comments'] as
$key => $valuearray) {
50 if (strlen(trim($valuearray[0])) > 0) {
51 $info[
'real'][
'comments'][
$key][] = trim($valuearray[0]);
56 $this->
error(
'There was a problem parsing this RealAudio file. Please submit it for analysis to info@getid3.org');
57 unset(
$info[
'bitrate']);
58 unset(
$info[
'playtime_seconds']);
63 $info[
'real'][
'chunks'][$ChunkCounter] =
array();
64 $thisfile_real_chunks_currentchunk = &
$info[
'real'][
'chunks'][$ChunkCounter];
66 $thisfile_real_chunks_currentchunk[
'name'] = $ChunkName;
67 $thisfile_real_chunks_currentchunk[
'offset'] = $this->
ftell() - 8;
68 $thisfile_real_chunks_currentchunk[
'length'] = $ChunkSize;
69 if (($thisfile_real_chunks_currentchunk[
'offset'] + $thisfile_real_chunks_currentchunk[
'length']) >
$info[
'avdataend']) {
70 $this->
warning(
'Chunk "'.$thisfile_real_chunks_currentchunk[
'name'].
'" at offset '.$thisfile_real_chunks_currentchunk[
'offset'].
' claims to be '.$thisfile_real_chunks_currentchunk[
'length'].
' bytes long, which is beyond end of file');
74 if ($ChunkSize > ($this->getid3->fread_buffer_size() + 8)) {
76 $ChunkData .= $this->
fread($this->getid3->fread_buffer_size() - 8);
77 $this->
fseek($thisfile_real_chunks_currentchunk[
'offset'] + $ChunkSize);
79 } elseif(($ChunkSize - 8) > 0) {
81 $ChunkData .= $this->
fread($ChunkSize - 8);
91 switch ($thisfile_real_chunks_currentchunk[
'object_version']) {
111 if ($thisfile_real_chunks_currentchunk[
'object_version'] == 0) {
134 $info[
'playtime_seconds'] = $thisfile_real_chunks_currentchunk[
'duration'] / 1000;
135 if ($thisfile_real_chunks_currentchunk[
'duration'] > 0) {
136 $info[
'bitrate'] += $thisfile_real_chunks_currentchunk[
'avg_bit_rate'];
138 $thisfile_real_chunks_currentchunk[
'flags'][
'save_enabled'] = (bool) ($thisfile_real_chunks_currentchunk[
'flags_raw'] & 0x0001);
139 $thisfile_real_chunks_currentchunk[
'flags'][
'perfect_play'] = (bool) ($thisfile_real_chunks_currentchunk[
'flags_raw'] & 0x0002);
140 $thisfile_real_chunks_currentchunk[
'flags'][
'live_broadcast'] = (bool) ($thisfile_real_chunks_currentchunk[
'flags_raw'] & 0x0004);
147 if ($thisfile_real_chunks_currentchunk[
'object_version'] == 0) {
166 $thisfile_real_chunks_currentchunk[
'stream_name'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk[
'stream_name_size']);
167 $offset += $thisfile_real_chunks_currentchunk[
'stream_name_size'];
170 $thisfile_real_chunks_currentchunk[
'mime_type'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk[
'mime_type_size']);
171 $offset += $thisfile_real_chunks_currentchunk[
'mime_type_size'];
174 $thisfile_real_chunks_currentchunk[
'type_specific_data'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk[
'type_specific_len']);
175 $offset += $thisfile_real_chunks_currentchunk[
'type_specific_len'];
178 $thisfile_real_chunks_currentchunk_typespecificdata = &$thisfile_real_chunks_currentchunk[
'type_specific_data'];
180 switch ($thisfile_real_chunks_currentchunk[
'mime_type']) {
181 case 'video/x-pn-realvideo':
182 case 'video/x-pn-multirate-realvideo':
186 $thisfile_real_chunks_currentchunk[
'video_info'] =
array();
187 $thisfile_real_chunks_currentchunk_videoinfo = &$thisfile_real_chunks_currentchunk[
'video_info'];
189 $thisfile_real_chunks_currentchunk_videoinfo[
'dwSize'] =
getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 0, 4));
190 $thisfile_real_chunks_currentchunk_videoinfo[
'fourcc1'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 4, 4);
191 $thisfile_real_chunks_currentchunk_videoinfo[
'fourcc2'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 8, 4);
192 $thisfile_real_chunks_currentchunk_videoinfo[
'width'] =
getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 12, 2));
193 $thisfile_real_chunks_currentchunk_videoinfo[
'height'] =
getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 14, 2));
194 $thisfile_real_chunks_currentchunk_videoinfo[
'bits_per_sample'] =
getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 16, 2));
197 $thisfile_real_chunks_currentchunk_videoinfo[
'frames_per_second'] =
getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 22, 2));
206 $thisfile_real_chunks_currentchunk_videoinfo[
'codec'] =
getid3_riff::fourccLookup($thisfile_real_chunks_currentchunk_videoinfo[
'fourcc2']);
208 $info[
'video'][
'resolution_x'] = $thisfile_real_chunks_currentchunk_videoinfo[
'width'];
209 $info[
'video'][
'resolution_y'] = $thisfile_real_chunks_currentchunk_videoinfo[
'height'];
210 $info[
'video'][
'frame_rate'] = (float) $thisfile_real_chunks_currentchunk_videoinfo[
'frames_per_second'];
211 $info[
'video'][
'codec'] = $thisfile_real_chunks_currentchunk_videoinfo[
'codec'];
212 $info[
'video'][
'bits_per_sample'] = $thisfile_real_chunks_currentchunk_videoinfo[
'bits_per_sample'];
215 case 'audio/x-pn-realaudio':
216 case 'audio/x-pn-multirate-realaudio':
217 $this->
ParseOldRAheader($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk[
'parsed_audio_data']);
219 $info[
'audio'][
'sample_rate'] = $thisfile_real_chunks_currentchunk[
'parsed_audio_data'][
'sample_rate'];
220 $info[
'audio'][
'bits_per_sample'] = $thisfile_real_chunks_currentchunk[
'parsed_audio_data'][
'bits_per_sample'];
221 $info[
'audio'][
'channels'] = $thisfile_real_chunks_currentchunk[
'parsed_audio_data'][
'channels'];
222 if (!empty(
$info[
'audio'][
'dataformat'])) {
223 foreach (
$info[
'audio'] as
$key => $value) {
224 if (
$key !=
'streams') {
225 $info[
'audio'][
'streams'][$thisfile_real_chunks_currentchunk[
'stream_number']][
$key] = $value;
231 case 'logical-fileinfo':
233 $thisfile_real_chunks_currentchunk[
'logical_fileinfo'] =
array();
234 $thisfile_real_chunks_currentchunk_logicalfileinfo = &$thisfile_real_chunks_currentchunk[
'logical_fileinfo'];
236 $thisfile_real_chunks_currentchunk_logicalfileinfo_offset = 0;
237 $thisfile_real_chunks_currentchunk_logicalfileinfo[
'logical_fileinfo_length'] =
getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4));
238 $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
241 $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
243 $thisfile_real_chunks_currentchunk_logicalfileinfo[
'num_tags'] =
getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4));
244 $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
247 $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4;
261 if (empty(
$info[
'playtime_seconds'])) {
262 $info[
'playtime_seconds'] = max(
$info[
'playtime_seconds'], ($thisfile_real_chunks_currentchunk[
'duration'] + $thisfile_real_chunks_currentchunk[
'start_time']) / 1000);
264 if ($thisfile_real_chunks_currentchunk[
'duration'] > 0) {
265 switch ($thisfile_real_chunks_currentchunk[
'mime_type']) {
266 case 'audio/x-pn-realaudio':
267 case 'audio/x-pn-multirate-realaudio':
268 $info[
'audio'][
'bitrate'] = (isset(
$info[
'audio'][
'bitrate']) ?
$info[
'audio'][
'bitrate'] : 0) + $thisfile_real_chunks_currentchunk[
'avg_bit_rate'];
270 $info[
'audio'][
'dataformat'] =
'real';
271 $info[
'audio'][
'lossless'] =
false;
274 case 'video/x-pn-realvideo':
275 case 'video/x-pn-multirate-realvideo':
276 $info[
'video'][
'bitrate'] = (isset(
$info[
'video'][
'bitrate']) ?
$info[
'video'][
'bitrate'] : 0) + $thisfile_real_chunks_currentchunk[
'avg_bit_rate'];
277 $info[
'video'][
'bitrate_mode'] =
'cbr';
278 $info[
'video'][
'dataformat'] =
'real';
279 $info[
'video'][
'lossless'] =
false;
280 $info[
'video'][
'pixel_aspect_ratio'] = (float) 1;
283 case 'audio/x-ralf-mpeg4-generic':
284 $info[
'audio'][
'bitrate'] = (isset(
$info[
'audio'][
'bitrate']) ?
$info[
'audio'][
'bitrate'] : 0) + $thisfile_real_chunks_currentchunk[
'avg_bit_rate'];
285 $info[
'audio'][
'codec'] =
'RealAudio Lossless';
286 $info[
'audio'][
'dataformat'] =
'real';
287 $info[
'audio'][
'lossless'] =
true;
290 $info[
'bitrate'] = (isset(
$info[
'video'][
'bitrate']) ?
$info[
'video'][
'bitrate'] : 0) + (isset(
$info[
'audio'][
'bitrate']) ?
$info[
'audio'][
'bitrate'] : 0);
298 if ($thisfile_real_chunks_currentchunk[
'object_version'] == 0) {
301 $thisfile_real_chunks_currentchunk[
'title'] = (
string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk[
'title_len']);
302 $offset += $thisfile_real_chunks_currentchunk[
'title_len'];
306 $thisfile_real_chunks_currentchunk[
'artist'] = (
string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk[
'artist_len']);
307 $offset += $thisfile_real_chunks_currentchunk[
'artist_len'];
311 $thisfile_real_chunks_currentchunk[
'copyright'] = (
string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk[
'copyright_len']);
312 $offset += $thisfile_real_chunks_currentchunk[
'copyright_len'];
316 $thisfile_real_chunks_currentchunk[
'comment'] = (
string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk[
'comment_len']);
317 $offset += $thisfile_real_chunks_currentchunk[
'comment_len'];
320 $commentkeystocopy =
array(
'title'=>
'title',
'artist'=>
'artist',
'copyright'=>
'copyright',
'comment'=>
'comment');
321 foreach ($commentkeystocopy as
$key => $val) {
322 if ($thisfile_real_chunks_currentchunk[
$key]) {
323 $info[
'real'][
'comments'][$val][] = trim($thisfile_real_chunks_currentchunk[$key]);
338 if ($thisfile_real_chunks_currentchunk[
'object_version'] == 0) {
346 if ($thisfile_real_chunks_currentchunk[
'next_index_header'] == 0) {
351 $this->
fseek($thisfile_real_chunks_currentchunk[
'next_index_header']);
357 $this->
warning(
'Unhandled RealMedia chunk "'.$ChunkName.
'" at offset '.$thisfile_real_chunks_currentchunk[
'offset']);
363 if (!empty(
$info[
'audio'][
'streams'])) {
364 $info[
'audio'][
'bitrate'] = 0;
365 foreach (
$info[
'audio'][
'streams'] as
$key => $valuearray) {
366 $info[
'audio'][
'bitrate'] += $valuearray[
'bitrate'];
377 $ParsedArray =
array();
378 $ParsedArray[
'magic'] = substr($OldRAheaderData, 0, 4);
379 if ($ParsedArray[
'magic'] !=
'.ra'.
"\xFD") {
384 if ($ParsedArray[
'version1'] < 3) {
388 } elseif ($ParsedArray[
'version1'] == 3) {
390 $ParsedArray[
'fourcc1'] =
'.ra3';
391 $ParsedArray[
'bits_per_sample'] = 16;
392 $ParsedArray[
'sample_rate'] = 8000;
401 $ParsedArray[
'comments_raw'] = substr($OldRAheaderData, 22, $ParsedArray[
'header_size'] - 22 + 1);
405 $ParsedArray[
'comments'][
'title'][] = substr($ParsedArray[
'comments_raw'], $commentoffset, $commentlength);
406 $commentoffset += $commentlength;
409 $ParsedArray[
'comments'][
'artist'][] = substr($ParsedArray[
'comments_raw'], $commentoffset, $commentlength);
410 $commentoffset += $commentlength;
413 $ParsedArray[
'comments'][
'copyright'][] = substr($ParsedArray[
'comments_raw'], $commentoffset, $commentlength);
414 $commentoffset += $commentlength;
418 $ParsedArray[
'fourcc'] = substr($OldRAheaderData, 23 + $commentoffset, 4);
420 } elseif ($ParsedArray[
'version1'] <= 5) {
423 $ParsedArray[
'fourcc1'] = substr($OldRAheaderData, 8, 4);
437 switch ($ParsedArray[
'version1']) {
445 $ParsedArray[
'fourcc2'] = substr($OldRAheaderData, 57, 4);
447 $ParsedArray[
'fourcc3'] = substr($OldRAheaderData, 62, 4);
450 $ParsedArray[
'comments_raw'] = substr($OldRAheaderData, 69, $ParsedArray[
'header_size'] - 69 + 16);
454 $ParsedArray[
'comments'][
'title'][] = substr($ParsedArray[
'comments_raw'], $commentoffset, $commentlength);
455 $commentoffset += $commentlength;
458 $ParsedArray[
'comments'][
'artist'][] = substr($ParsedArray[
'comments_raw'], $commentoffset, $commentlength);
459 $commentoffset += $commentlength;
462 $ParsedArray[
'comments'][
'copyright'][] = substr($ParsedArray[
'comments_raw'], $commentoffset, $commentlength);
463 $commentoffset += $commentlength;
471 $ParsedArray[
'genr'] = substr($OldRAheaderData, 62, 4);
472 $ParsedArray[
'fourcc3'] = substr($OldRAheaderData, 66, 4);
473 $ParsedArray[
'comments'] =
array();
476 $ParsedArray[
'fourcc'] = $ParsedArray[
'fourcc3'];
479 foreach ($ParsedArray[
'comments'] as
$key => $value) {
480 if ($ParsedArray[
'comments'][
$key][0] ===
false) {
481 $ParsedArray[
'comments'][
$key][0] =
'';
489 static $RealAudioCodecFourCClookup =
array();
490 if (empty($RealAudioCodecFourCClookup)) {
494 $RealAudioCodecFourCClookup[
'14_4'][8000] =
'RealAudio v2 (14.4kbps)';
495 $RealAudioCodecFourCClookup[
'14.4'][8000] =
'RealAudio v2 (14.4kbps)';
496 $RealAudioCodecFourCClookup[
'lpcJ'][8000] =
'RealAudio v2 (14.4kbps)';
497 $RealAudioCodecFourCClookup[
'28_8'][15200] =
'RealAudio v2 (28.8kbps)';
498 $RealAudioCodecFourCClookup[
'28.8'][15200] =
'RealAudio v2 (28.8kbps)';
499 $RealAudioCodecFourCClookup[
'sipr'][4933] =
'RealAudio v4 (5kbps Voice)';
500 $RealAudioCodecFourCClookup[
'sipr'][6444] =
'RealAudio v4 (6.5kbps Voice)';
501 $RealAudioCodecFourCClookup[
'sipr'][8444] =
'RealAudio v4 (8.5kbps Voice)';
502 $RealAudioCodecFourCClookup[
'sipr'][16000] =
'RealAudio v4 (16kbps Wideband)';
503 $RealAudioCodecFourCClookup[
'dnet'][8000] =
'RealAudio v3 (8kbps Music)';
504 $RealAudioCodecFourCClookup[
'dnet'][16000] =
'RealAudio v3 (16kbps Music Low Response)';
505 $RealAudioCodecFourCClookup[
'dnet'][15963] =
'RealAudio v3 (16kbps Music Mid/High Response)';
506 $RealAudioCodecFourCClookup[
'dnet'][20000] =
'RealAudio v3 (20kbps Music Stereo)';
507 $RealAudioCodecFourCClookup[
'dnet'][32000] =
'RealAudio v3 (32kbps Music Mono)';
508 $RealAudioCodecFourCClookup[
'dnet'][31951] =
'RealAudio v3 (32kbps Music Stereo)';
509 $RealAudioCodecFourCClookup[
'dnet'][39965] =
'RealAudio v3 (40kbps Music Mono)';
510 $RealAudioCodecFourCClookup[
'dnet'][40000] =
'RealAudio v3 (40kbps Music Stereo)';
511 $RealAudioCodecFourCClookup[
'dnet'][79947] =
'RealAudio v3 (80kbps Music Mono)';
512 $RealAudioCodecFourCClookup[
'dnet'][80000] =
'RealAudio v3 (80kbps Music Stereo)';
514 $RealAudioCodecFourCClookup[
'dnet'][0] =
'RealAudio v3';
515 $RealAudioCodecFourCClookup[
'sipr'][0] =
'RealAudio v4';
516 $RealAudioCodecFourCClookup[
'cook'][0] =
'RealAudio G2';
517 $RealAudioCodecFourCClookup[
'atrc'][0] =
'RealAudio 8';
519 $roundbitrate = intval(round($bitrate));
520 if (isset($RealAudioCodecFourCClookup[$fourcc][$roundbitrate])) {
521 return $RealAudioCodecFourCClookup[$fourcc][$roundbitrate];
522 } elseif (isset($RealAudioCodecFourCClookup[$fourcc][0])) {
523 return $RealAudioCodecFourCClookup[$fourcc][0];
RealAudioCodecFourCClookup($fourcc, $bitrate)
static IncludeDependency($filename, $sourcefile, $DieOnFailure=false)
static fourccLookup($fourcc)
Create styles array
The data for the language used.
fseek($bytes, $whence=SEEK_SET)
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
ParseOldRAheader($OldRAheaderData, &$ParsedArray)