Пример #1
0
function getRIFFHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    $Original['avdataoffset'] = $ThisFileInfo['avdataoffset'];
    $Original['avdataend'] = $ThisFileInfo['avdataend'];
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $RIFFheader = fread($fd, 12);
    switch (substr($RIFFheader, 0, 4)) {
        case 'FORM':
            $ThisFileInfo['fileformat'] = 'aiff';
            $RIFFheaderSize = EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4));
            $ThisFileInfo['RIFF'][substr($RIFFheader, 8, 4)] = ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + $RIFFheaderSize, $ThisFileInfo);
            $ThisFileInfo['RIFF']['header_size'] = $RIFFheaderSize;
            break;
        case 'RIFF':
        case 'SDSS':
            // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
        // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
        case 'RMP3':
            // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
            $RIFFtype = substr($RIFFheader, 8, 4);
            if ($RIFFtype == 'RMP3') {
                $RIFFtype == 'WAVE';
            }
            $ThisFileInfo['fileformat'] = 'riff';
            $RIFFheaderSize = EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4));
            $ThisFileInfo['RIFF']["{$RIFFtype}"] = ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + $RIFFheaderSize, $ThisFileInfo);
            $ThisFileInfo['RIFF']['header_size'] = $RIFFheaderSize;
            break;
        default:
            $ThisFileInfo['error'] .= "\n" . 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?)';
            unset($ThisFileInfo['fileformat']);
            return false;
            break;
    }
    $streamindex = 0;
    $arraykeys = array_keys($ThisFileInfo['RIFF']);
    switch ($arraykeys[0]) {
        case 'WAVE':
        case 'RMP3':
            // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
            if (empty($ThisFileInfo['audio']['bitrate_mode'])) {
                $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            }
            if (empty($ThisFileInfo['audio']['dataformat'])) {
                $ThisFileInfo['audio']['dataformat'] = 'wav';
            }
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['data'][0]['offset'])) {
                $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['data'][0]['offset'] + 8;
                $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['data'][0]['size'];
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data'])) {
                $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data']);
                if ($ThisFileInfo['RIFF']['audio'][$streamindex] == 0) {
                    $ThisFileInfo['error'] .= 'Corrupt RIFF file: bitrate_audio == zero';
                    return false;
                }
                $ThisFileInfo['RIFF']['raw']['fmt '] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw'];
                unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']);
                $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]);
                if (substr($ThisFileInfo['audio']['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
                    $ThisFileInfo['warning'] .= "\n" . 'Audio codec = ' . $ThisFileInfo['audio']['codec'];
                }
                $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'];
                if ($ThisFileInfo['audio']['bits_per_sample'] == 0) {
                    unset($ThisFileInfo['audio']['bits_per_sample']);
                }
                $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']);
                if (isset($ThisFileInfo['RIFF']['WAVE']['data'][0]['offset']) && isset($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag'])) {
                    $ThisFileInfo['audio']['lossless'] = false;
                    switch ($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag']) {
                        case 1:
                            // PCM
                            $ThisFileInfo['audio']['lossless'] = true;
                            break;
                        default:
                            // do nothing
                            break;
                    }
                }
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data'])) {
                require_once GETID3_INCLUDEPATH . 'getid3.rgad.php';
                $rgadData = $ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data'];
                $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'] = LittleEndian2Float(substr($rgadData, 0, 4));
                $ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust'] = EitherEndian2Int($ThisFileInfo, substr($rgadData, 4, 2));
                $ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust'] = EitherEndian2Int($ThisFileInfo, substr($rgadData, 6, 2));
                $nRadioRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
                $nAudiophileRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
                $ThisFileInfo['RIFF']['rgad']['peakamplitude'] = $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'];
                if ($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] != 0) {
                    $ThisFileInfo['RIFF']['rgad']['radio']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name']);
                    $ThisFileInfo['RIFF']['rgad']['radio']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator']);
                    $ThisFileInfo['RIFF']['rgad']['radio']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit']);
                }
                if ($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] != 0) {
                    $ThisFileInfo['RIFF']['rgad']['audiophile']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name']);
                    $ThisFileInfo['RIFF']['rgad']['audiophile']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator']);
                    $ThisFileInfo['RIFF']['rgad']['audiophile']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit']);
                }
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'])) {
                $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] = EitherEndian2Int($ThisFileInfo, substr($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'], 0, 4));
                if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'] > 0) {
                    $ThisFileInfo['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] / $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'];
                }
                if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) {
                    $ThisFileInfo['audio']['bitrate'] = CastAsInt($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec'] * 8);
                }
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'])) {
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['title'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 0, 256));
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['author'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 256, 32));
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['reference'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 288, 32));
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'] = substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 320, 10);
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'] = substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 330, 8);
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['time_reference'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 338, 8));
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['bwf_version'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 346, 1));
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['reserved'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 347, 254));
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['coding_history'] = explode("\r\n", trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 601)));
                $ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date_unix'] = mktime(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'], 0, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'], 3, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'], 6, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'], 5, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'], 8, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'], 0, 4));
                $ThisFileInfo['RIFF']['comments']['author'][] = $ThisFileInfo['RIFF']['WAVE']['bext'][0]['author'];
                $ThisFileInfo['RIFF']['comments']['title'][] = $ThisFileInfo['RIFF']['WAVE']['bext'][0]['title'];
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'])) {
                $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 0, 2));
                $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['homogenous'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x1);
                if ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['homogenous']) {
                    $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['padding'] = InverseBoolean($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x2);
                    $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['22_or_44'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x4);
                    $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['free_format'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x8);
                    $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['nominal_frame_size'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 2, 2));
                }
                $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['anciliary_data_length'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 6, 2));
                $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 8, 2));
                $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['anciliary_data_left'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] & 0x1);
                $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['anciliary_data_free'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] & 0x2);
                $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['anciliary_data_right'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] & 0x4);
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'])) {
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['version'] = substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 0, 4);
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['title'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 4, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['artist'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 68, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['cut_id'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 132, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['client_id'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 196, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['category'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 260, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['classification'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 324, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['out_cue'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 388, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['start_date'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 452, 10));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['start_time'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 462, 8));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['end_date'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 470, 10));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['end_time'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 480, 8));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['producer_app_id'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 488, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['producer_app_version'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 552, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['user_defined_text'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 616, 64));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['zero_db_reference'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 680, 4), true);
                for ($i = 0; $i < 8; $i++) {
                    $ThisFileInfo['RIFF']['WAVE']['cart'][0]['post_time'][$i]['usage_fourcc'] = substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 684 + $i * 8, 4);
                    $ThisFileInfo['RIFF']['WAVE']['cart'][0]['post_time'][$i]['timer_value'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 684 + $i * 8 + 4, 4));
                }
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['url'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 748, 1024));
                $ThisFileInfo['RIFF']['WAVE']['cart'][0]['tag_text'] = explode("\r\n", trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 1772)));
                $ThisFileInfo['RIFF']['comments']['artist'][] = $ThisFileInfo['RIFF']['WAVE']['cart'][0]['artist'];
                $ThisFileInfo['RIFF']['comments']['title'][] = $ThisFileInfo['RIFF']['WAVE']['cart'][0]['title'];
            }
            if (!isset($ThisFileInfo['audio']['bitrate']) && isset($ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'])) {
                $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'];
                $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']);
            }
            if (!empty($ThisFileInfo['wavpack'])) {
                $ThisFileInfo['audio']['dataformat'] = 'wavpack';
                $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
                $ThisFileInfo['audio']['encoder'] = 'WavPack v' . $ThisFileInfo['wavpack']['version'];
                // Reset to the way it was - RIFF parsing will have messed this up
                $ThisFileInfo['avdataend'] = $Original['avdataend'];
                $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
                fseek($fd, $ThisFileInfo['avdataoffset'] - 44, SEEK_SET);
                $RIFFdata = fread($fd, 44);
                $OrignalRIFFheaderSize = LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
                $OrignalRIFFdataSize = LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
                if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
                    $ThisFileInfo['avdataend'] -= $OrignalRIFFheaderSize - $OrignalRIFFdataSize;
                    fseek($fd, $ThisFileInfo['avdataend'], SEEK_SET);
                    $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize);
                }
                // move the data chunk after all other chunks (if any)
                // so that the RIFF parser doesn't see EOF when trying
                // to skip over the data chunk
                $RIFFdata = substr($RIFFdata, 0, 36) . substr($RIFFdata, 44) . substr($RIFFdata, 36, 8);
                ParseRIFFdata($RIFFdata, $ThisFileInfo);
            }
            break;
        case 'AVI ':
            $ThisFileInfo['video']['bitrate_mode'] = 'cbr';
            $ThisFileInfo['video']['dataformat'] = 'avi';
            $ThisFileInfo['mime_type'] = 'video/avi';
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['movi']['offset'])) {
                $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['movi']['offset'] + 8;
                $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['movi']['size'];
            }
            if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
                $avihData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data'];
                $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 0, 4));
                // frame display rate (or 0L)
                if ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] == 0) {
                    $ThisFileInfo['error'] .= 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
                    return false;
                }
                $ThisFileInfo['RIFF']['raw']['avih']['dwMaxBytesPerSec'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 4, 4));
                // max. transfer rate
                $ThisFileInfo['RIFF']['raw']['avih']['dwPaddingGranularity'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 8, 4));
                // pad to multiples of this size; normally 2K.
                $ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 12, 4));
                // the ever-present flags
                $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 16, 4));
                // # frames in file
                $ThisFileInfo['RIFF']['raw']['avih']['dwInitialFrames'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 20, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwStreams'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 24, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwSuggestedBufferSize'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 28, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwWidth'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 32, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwHeight'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 36, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwScale'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 40, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwRate'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 44, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwStart'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 48, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwLength'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 52, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['hasindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['mustuseindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['interleaved'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x100);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['trustcktype'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x800);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['capturedfile'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10000);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['copyrighted'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20010);
                if ($ThisFileInfo['RIFF']['raw']['avih']['dwWidth'] > 0) {
                    $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width'] = $ThisFileInfo['RIFF']['raw']['avih']['dwWidth'];
                    $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width'];
                }
                if ($ThisFileInfo['RIFF']['raw']['avih']['dwHeight'] > 0) {
                    $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height'] = $ThisFileInfo['RIFF']['raw']['avih']['dwHeight'];
                    $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height'];
                }
                $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate'] = round(1000000 / $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'], 3);
                $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate'];
            }
            if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
                if (is_array($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'])) {
                    for ($i = 0; $i < count($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh']); $i++) {
                        if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
                            $strhData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data'];
                            $strhfccType = substr($strhData, 0, 4);
                            if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
                                $strfData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data'];
                                switch ($strhfccType) {
                                    case 'auds':
                                        $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
                                        $ThisFileInfo['audio']['dataformat'] = 'wav';
                                        if (isset($ThisFileInfo['RIFF']['audio']) && is_array($ThisFileInfo['RIFF']['audio'])) {
                                            $streamindex = count($ThisFileInfo['RIFF']['audio']);
                                        }
                                        $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($strfData);
                                        $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw'];
                                        unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']);
                                        $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]);
                                        $ThisFileInfo['audio']['lossless'] = false;
                                        switch ($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['wFormatTag']) {
                                            case 1:
                                                // PCM
                                                $ThisFileInfo['audio']['lossless'] = true;
                                                break;
                                            case 85:
                                                // MPEG Layer 3
                                                $ThisFileInfo['audio']['dataformat'] = 'mp3';
                                                break;
                                            case 8192:
                                                // AC-3
                                                $ThisFileInfo['audio']['dataformat'] = 'ac3';
                                                break;
                                            default:
                                                $ThisFileInfo['audio']['dataformat'] = 'wav';
                                                break;
                                        }
                                        break;
                                    case 'iavs':
                                    case 'vids':
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccType'] = substr($strhData, 0, 4);
                                        // same as $strhfccType;
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler'] = substr($strhData, 4, 4);
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwFlags'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 8, 4));
                                        // Contains AVITF_* flags
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['wPriority'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 12, 2));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['wLanguage'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 14, 2));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwInitialFrames'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 16, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwScale'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 20, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwRate'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 24, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwStart'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 28, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwLength'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 32, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSuggestedBufferSize'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 36, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwQuality'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 40, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSampleSize'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 44, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['rcFrame'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 48, 4));
                                        $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler']);
                                        if (!$ThisFileInfo['RIFF']['video'][$streamindex]['codec'] && isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) {
                                            $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']);
                                        }
                                        $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec'];
                                        switch ($ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler']) {
                                            case 'HFYU':
                                                // Huffman Lossless Codec
                                            // Huffman Lossless Codec
                                            case 'IRAW':
                                                // Intel YUV Uncompressed
                                            // Intel YUV Uncompressed
                                            case 'YUY2':
                                                // Uncompressed YUV 4:2:2
                                                $ThisFileInfo['video']['lossless'] = true;
                                                break;
                                            default:
                                                $ThisFileInfo['video']['lossless'] = false;
                                                break;
                                        }
                                        switch ($strhfccType) {
                                            case 'vids':
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSize'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 0, 4));
                                                // number of bytes required by the BITMAPINFOHEADER structure
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biWidth'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 4, 4));
                                                // width of the bitmap in pixels
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biHeight'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 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
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biPlanes'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 12, 2));
                                                // number of color planes on the target device. In most cases this value must be set to 1
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biBitCount'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 14, 2));
                                                // Specifies the number of bits per pixels
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'] = substr($strfData, 16, 4);
                                                //
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSizeImage'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 20, 4));
                                                // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biXPelsPerMeter'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 24, 4));
                                                // horizontal resolution, in pixels per metre, of the target device
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biYPelsPerMeter'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 28, 4));
                                                // vertical resolution, in pixels per metre, of the target device
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrUsed'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 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
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrImportant'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 36, 4));
                                                // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
                                                $ThisFileInfo['video']['bits_per_sample'] = $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biBitCount'];
                                                if ($ThisFileInfo['RIFF']['video'][$streamindex]['codec'] == 'DV') {
                                                    $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 2;
                                                }
                                                break;
                                            case 'iavs':
                                                $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 1;
                                                break;
                                        }
                                        break;
                                    default:
                                        $ThisFileInfo['warning'] .= "\n" . 'Unhandled fccType for stream (' . $i . '): "' . $strhfccType . '"';
                                        break;
                                }
                            }
                        }
                        if (isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) {
                            $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']);
                            $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec'];
                            switch ($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) {
                                case 'HFYU':
                                    // Huffman Lossless Codec
                                // Huffman Lossless Codec
                                case 'IRAW':
                                    // Intel YUV Uncompressed
                                // Intel YUV Uncompressed
                                case 'YUY2':
                                    // Uncompressed YUV 4:2:2
                                    $ThisFileInfo['video']['lossless'] = true;
                                    $ThisFileInfo['video']['bits_per_sample'] = 24;
                                    break;
                                default:
                                    $ThisFileInfo['video']['lossless'] = false;
                                    $ThisFileInfo['video']['bits_per_sample'] = 24;
                                    break;
                            }
                        }
                    }
                }
            }
            break;
        case 'CDDA':
            $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            $ThisFileInfo['audio']['dataformat'] = 'cda';
            $ThisFileInfo['audio']['lossless'] = true;
            unset($ThisFileInfo['mime_type']);
            $ThisFileInfo['avdataoffset'] = 44;
            if (isset($ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data'])) {
                $fmtData = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data'];
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown1'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 0, 2));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 2, 2));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['disc_id'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 4, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 8, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 12, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown6'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 16, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown7'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 20, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] / 75;
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] / 75;
                $ThisFileInfo['comments']['track'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num'];
                $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds'];
                // hardcoded data for CD-audio
                $ThisFileInfo['audio']['sample_rate'] = 44100;
                $ThisFileInfo['audio']['channels'] = 2;
                $ThisFileInfo['audio']['bits_per_sample'] = 16;
                $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['audio']['sample_rate'] * $ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['bits_per_sample'];
                $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            }
            break;
        case 'AIFF':
        case 'AIFC':
            $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            $ThisFileInfo['audio']['dataformat'] = 'aiff';
            $ThisFileInfo['audio']['lossless'] = true;
            $ThisFileInfo['mime_type'] = 'audio/x-aiff';
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['offset'])) {
                $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['offset'] + 8;
                $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['size'];
                if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) {
                    if ($ThisFileInfo['avdataend'] == $ThisFileInfo['filesize'] + 1 && $ThisFileInfo['filesize'] % 2 == 1) {
                        // structures rounded to 2-byte boundary, but dumb encoders
                        // forget to pad end of file to make this actually work
                    } else {
                        $ThisFileInfo['warning'] .= "\n" . 'Probable truncated AIFF file: expecting ' . $ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['size'] . ' bytes of audio data, only ' . ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) . ' bytes found';
                    }
                    $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize'];
                }
            }
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'])) {
                $ThisFileInfo['RIFF']['audio']['channels'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 0, 2), true);
                $ThisFileInfo['RIFF']['audio']['total_samples'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 2, 4), false);
                $ThisFileInfo['RIFF']['audio']['bits_per_sample'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 6, 2), true);
                $ThisFileInfo['RIFF']['audio']['sample_rate'] = (int) BigEndian2Float(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 8, 10));
                if ($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['size'] > 18) {
                    $ThisFileInfo['RIFF']['audio']['codec_fourcc'] = substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 18, 4);
                    $CodecNameSize = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 22, 1), false);
                    $ThisFileInfo['RIFF']['audio']['codec_name'] = substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 23, $CodecNameSize);
                    if ($ThisFileInfo['RIFF']['audio']['codec_name'] == 'NONE') {
                        $ThisFileInfo['audio']['codec'] = 'Pulse Code Modulation (PCM)';
                        $ThisFileInfo['audio']['lossless'] = true;
                    } else {
                        $ThisFileInfo['audio']['codec'] = $ThisFileInfo['RIFF']['audio']['codec_name'];
                        $ThisFileInfo['audio']['lossless'] = false;
                    }
                }
                $ThisFileInfo['audio']['channels'] = $ThisFileInfo['RIFF']['audio']['channels'];
                if ($ThisFileInfo['RIFF']['audio']['bits_per_sample'] > 0) {
                    $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['RIFF']['audio']['bits_per_sample'];
                }
                $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['RIFF']['audio']['sample_rate'];
                if ($ThisFileInfo['audio']['sample_rate'] == 0) {
                    $ThisFileInfo['error'] .= "\n" . 'Corrupted AIFF file: sample_rate == zero';
                    return false;
                }
                $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['audio']['total_samples'] / $ThisFileInfo['audio']['sample_rate'];
            }
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'])) {
                $offset = 0;
                $CommentCount = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 2), false);
                $offset += 2;
                for ($i = 0; $i < $CommentCount; $i++) {
                    $ThisFileInfo['comments_raw'][$i]['timestamp'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 4), false);
                    $offset += 4;
                    $ThisFileInfo['comments_raw'][$i]['marker_id'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 2), true);
                    $offset += 2;
                    $CommentLength = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 2), false);
                    $offset += 2;
                    $ThisFileInfo['comments_raw'][$i]['comment'] = substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, $CommentLength);
                    $offset += $CommentLength;
                    $ThisFileInfo['comments_raw'][$i]['timestamp_unix'] = DateMac2Unix($ThisFileInfo['comments_raw'][$i]['timestamp']);
                    $ThisFileInfo['RIFF']['comments']['comment'][] = $ThisFileInfo['comments_raw'][$i]['comment'];
                }
            }
            $CommentsChunkNames = array('NAME' => 'title', 'author' => 'artist', '(c) ' => 'copyright', 'ANNO' => 'comment');
            foreach ($CommentsChunkNames as $key => $value) {
                if (isset($ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data'])) {
                    $ThisFileInfo['RIFF']['comments'][$value][] = $ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data'];
                }
            }
            if (isset($ThisFileInfo['RIFF']['comments'])) {
                CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, true, true);
            }
            break;
        case '8SVX':
            $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            $ThisFileInfo['audio']['dataformat'] = '8svx';
            $ThisFileInfo['audio']['bits_per_sample'] = 8;
            $ThisFileInfo['audio']['channels'] = 1;
            // overridden below, if need be
            $ThisFileInfo['mime_type'] = 'audio/x-aiff';
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['offset'])) {
                $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['offset'] + 8;
                $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['size'];
                if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) {
                    $ThisFileInfo['warning'] .= "\n" . 'Probable truncated AIFF file: expecting ' . $ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['size'] . ' bytes of audio data, only ' . ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) . ' bytes found';
                }
            }
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['offset'])) {
                $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['oneShotHiSamples'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 0, 4));
                $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['repeatHiSamples'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 4, 4));
                $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['samplesPerHiCycle'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 8, 4));
                $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['samplesPerSec'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 12, 2));
                $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['ctOctave'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 14, 1));
                $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['sCompression'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 15, 1));
                $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['Volume'] = FixedPoint16_16(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 16, 4));
                $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['samplesPerSec'];
                switch ($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['sCompression']) {
                    case 0:
                        $ThisFileInfo['audio']['codec'] = 'Pulse Code Modulation (PCM)';
                        $ThisFileInfo['audio']['lossless'] = true;
                        $ActualBitsPerSample = 8;
                        break;
                    case 1:
                        $ThisFileInfo['audio']['codec'] = 'Fibonacci-delta encoding';
                        $ThisFileInfo['audio']['lossless'] = false;
                        $ActualBitsPerSample = 4;
                        break;
                    default:
                        $ThisFileInfo['warning'] .= "\n" . 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "' . sCompression . '"';
                        break;
                }
            }
            if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['CHAN'][0]['data'])) {
                $ChannelsIndex = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['CHAN'][0]['data'], 0, 4));
                switch ($ChannelsIndex) {
                    case 6:
                        // Stereo
                        $ThisFileInfo['audio']['channels'] = 2;
                        break;
                    case 2:
                        // Left channel only
                    // Left channel only
                    case 4:
                        // Right channel only
                        $ThisFileInfo['audio']['channels'] = 1;
                        break;
                    default:
                        $ThisFileInfo['warning'] .= "\n" . 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "' . $ChannelsIndex . '"';
                        break;
                }
            }
            $CommentsChunkNames = array('NAME' => 'title', 'author' => 'artist', '(c) ' => 'copyright', 'ANNO' => 'comment');
            foreach ($CommentsChunkNames as $key => $value) {
                if (isset($ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data'])) {
                    $ThisFileInfo['RIFF']['comments'][$value][] = $ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data'];
                }
            }
            if (isset($ThisFileInfo['RIFF']['comments'])) {
                CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, true, true);
            }
            $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['audio']['sample_rate'] * $ActualBitsPerSample * $ThisFileInfo['audio']['channels'];
            if (!empty($ThisFileInfo['audio']['bitrate'])) {
                $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['audio']['bitrate'] / 8);
            }
            break;
        default:
            $ThisFileInfo['error'] .= "\n" . 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|), found "' . $arraykeys[0] . '" instead';
            unset($ThisFileInfo['fileformat']);
            break;
    }
    if (isset($ThisFileInfo['RIFF']['WAVE']['DISP']) && is_array($ThisFileInfo['RIFF']['WAVE']['DISP'])) {
        $ThisFileInfo['tags'][] = 'riff';
        $ThisFileInfo['RIFF']['comments']['title'][] = trim(substr($ThisFileInfo['RIFF']['WAVE']['DISP'][count($ThisFileInfo['RIFF']['WAVE']['DISP']) - 1]['data'], 4));
    }
    if (isset($ThisFileInfo['RIFF']['WAVE']['INFO']) && is_array($ThisFileInfo['RIFF']['WAVE']['INFO'])) {
        $ThisFileInfo['tags'][] = 'riff';
        $RIFFinfoKeyLookup = array('IART' => 'artist', 'IGNR' => 'genre', 'ICMT' => 'comment', 'ICOP' => 'copyright', 'IENG' => 'engineers', 'IKEY' => 'keywords', 'IMED' => 'orignalmedium', 'INAM' => 'name', 'ISRC' => 'sourcesupplier', 'ITCH' => 'digitizer', 'ISBJ' => 'subject', 'ISRF' => 'digitizationsource', 'ISFT' => 'encoded_by');
        foreach ($RIFFinfoKeyLookup as $key => $value) {
            if (isset($ThisFileInfo['RIFF']['WAVE']['INFO']["{$key}"])) {
                foreach ($ThisFileInfo['RIFF']['WAVE']['INFO']["{$key}"] as $commentid => $commentdata) {
                    if (trim($commentdata['data']) != '') {
                        $ThisFileInfo['RIFF']['comments']["{$value}"][] = trim($commentdata['data']);
                    }
                }
            }
        }
    }
    if (!empty($ThisFileInfo['RIFF']['comments'])) {
        CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, false, true);
    }
    if (empty($ThisFileInfo['audio']['encoder']) && !empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version'])) {
        $ThisFileInfo['audio']['encoder'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version'];
    }
    if (!isset($ThisFileInfo['playtime_seconds'])) {
        $ThisFileInfo['playtime_seconds'] = 0;
    }
    if (isset($ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames']) && isset($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'])) {
        $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] * ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] / 1000000);
    }
    if ($ThisFileInfo['playtime_seconds'] > 0) {
        if (isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) {
            if (!isset($ThisFileInfo['bitrate'])) {
                $ThisFileInfo['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
            }
        } elseif (isset($ThisFileInfo['RIFF']['audio']) && !isset($ThisFileInfo['RIFF']['video'])) {
            if (!isset($ThisFileInfo['audio']['bitrate'])) {
                $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
            }
        } elseif (!isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) {
            if (!isset($ThisFileInfo['video']['bitrate'])) {
                $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
            }
        }
    }
    if (isset($ThisFileInfo['RIFF']['video']) && isset($ThisFileInfo['audio']['bitrate']) && $ThisFileInfo['audio']['bitrate'] > 0 && $ThisFileInfo['playtime_seconds'] > 0) {
        $ThisFileInfo['audio']['bitrate'] = 0;
        $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
        foreach ($ThisFileInfo['RIFF']['audio'] as $channelnumber => $audioinfoarray) {
            $ThisFileInfo['video']['bitrate'] -= $audioinfoarray['bitrate'];
            $ThisFileInfo['audio']['bitrate'] += $audioinfoarray['bitrate'];
        }
        if ($ThisFileInfo['video']['bitrate'] <= 0) {
            unset($ThisFileInfo['video']['bitrate']);
        }
        if ($ThisFileInfo['audio']['bitrate'] <= 0) {
            unset($ThisFileInfo['audio']['bitrate']);
        }
    }
    if (!empty($ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'] > 0) {
        $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'];
    }
    return true;
}
Пример #2
0
function getASFHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    // ASF structure:
    // * Header Object [required]
    //   * File Properties Object [required]   (global file attributes)
    //   * Stream Properties Object [required] (defines media stream & characteristics)
    //   * Header Extension Object [required]  (additional functionality)
    //   * Content Description Object          (bibliographic information)
    //   * Script Command Object               (commands for during playback)
    //   * Marker Object                       (named jumped points within the file)
    // * Data Object [required]
    //   * Data Packets
    // * Index Object
    // Header Object: (mandatory, one only)
    // Field Name                   Field Type   Size (bits)
    // Object ID                    GUID         128             // GUID for header object - ASF_Header_Object
    // Object Size                  QWORD        64              // size of header object, including 30 bytes of Header Object header
    // Number of Header Objects     DWORD        32              // number of objects in header object
    // Reserved1                    BYTE         8               // hardcoded: 0x01
    // Reserved2                    BYTE         8               // hardcoded: 0x02
    $ThisFileInfo['fileformat'] = 'asf';
    $ThisFileInfo['audio']['lossless'] = false;
    $ThisFileInfo['video']['lossless'] = false;
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $HeaderObjectData = fread($fd, 30);
    $ThisFileInfo['asf']['header_object']['objectid'] = substr($HeaderObjectData, 0, 16);
    $ThisFileInfo['asf']['header_object']['objectid_guid'] = BytestringToGUID($ThisFileInfo['asf']['header_object']['objectid']);
    if ($ThisFileInfo['asf']['header_object']['objectid'] != ASF_Header_Object) {
        $ThisFileInfo['warning'] .= "\n" . 'ASF header GUID {' . BytestringToGUID($ThisFileInfo['asf']['header_object']['objectid']) . '} does not match expected "ASF_Header_Object" GUID {' . BytestringToGUID(ASF_Header_Object) . '}';
        //return false;
        break;
    }
    $ThisFileInfo['asf']['header_object']['objectsize'] = LittleEndian2Int(substr($HeaderObjectData, 16, 8));
    $ThisFileInfo['asf']['header_object']['headerobjects'] = LittleEndian2Int(substr($HeaderObjectData, 24, 4));
    $ThisFileInfo['asf']['header_object']['reserved1'] = LittleEndian2Int(substr($HeaderObjectData, 28, 1));
    $ThisFileInfo['asf']['header_object']['reserved2'] = LittleEndian2Int(substr($HeaderObjectData, 29, 1));
    //$ASFHeaderData  = $HeaderObjectData;
    $ASFHeaderData = fread($fd, $ThisFileInfo['asf']['header_object']['objectsize'] - 30);
    //$offset = 30;
    $offset = 0;
    for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $ThisFileInfo['asf']['header_object']['headerobjects']; $HeaderObjectsCounter++) {
        $NextObjectGUID = substr($ASFHeaderData, $offset, 16);
        $offset += 16;
        $NextObjectGUIDtext = BytestringToGUID($NextObjectGUID);
        $NextObjectSize = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
        $offset += 8;
        switch ($NextObjectGUID) {
            case ASF_File_Properties_Object:
                // File Properties Object: (mandatory, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for file properties object - ASF_File_Properties_Object
                // Object Size                  QWORD        64              // size of file properties object, including 104 bytes of File Properties Object header
                // File ID                      GUID         128             // unique ID - identical to File ID in Data Object
                // File Size                    QWORD        64              // entire file in bytes. Invalid if Broadcast Flag == 1
                // Creation Date                QWORD        64              // date & time of file creation. Maybe invalid if Broadcast Flag == 1
                // Data Packets Count           QWORD        64              // number of data packets in Data Object. Invalid if Broadcast Flag == 1
                // Play Duration                QWORD        64              // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
                // Send Duration                QWORD        64              // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
                // Preroll                      QWORD        64              // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount
                // Flags                        DWORD        32              //
                // * Broadcast Flag             bits         1  (0x01)       // file is currently being written, some header values are invalid
                // * Seekable Flag              bits         1  (0x02)       // is file seekable
                // * Reserved                   bits         30 (0xFFFFFFFC) // reserved - set to zero
                // Minimum Data Packet Size     DWORD        32              // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
                // Maximum Data Packet Size     DWORD        32              // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
                // Maximum Bitrate              DWORD        32              // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
                $ThisFileInfo['asf']['file_properties_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['file_properties_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['file_properties_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['file_properties_object']['fileid'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['file_properties_object']['fileid_guid'] = BytestringToGUID($ThisFileInfo['asf']['file_properties_object']['fileid']);
                $ThisFileInfo['asf']['file_properties_object']['filesize'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                $offset += 8;
                $ThisFileInfo['asf']['file_properties_object']['creation_date'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                $ThisFileInfo['asf']['file_properties_object']['creation_date_unix'] = FILETIMEtoUNIXtime($ThisFileInfo['asf']['file_properties_object']['creation_date']);
                $offset += 8;
                $ThisFileInfo['asf']['file_properties_object']['data_packets'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                $offset += 8;
                $ThisFileInfo['asf']['file_properties_object']['play_duration'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                $offset += 8;
                $ThisFileInfo['asf']['file_properties_object']['send_duration'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                $offset += 8;
                $ThisFileInfo['asf']['file_properties_object']['preroll'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                $offset += 8;
                $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['asf']['file_properties_object']['play_duration'] / 10000000 - $ThisFileInfo['asf']['file_properties_object']['preroll'] / 1000;
                $ThisFileInfo['asf']['file_properties_object']['flags_raw'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['asf']['file_properties_object']['flags']['broadcast'] = (bool) ($ThisFileInfo['asf']['file_properties_object']['flags_raw'] & 0x1);
                $ThisFileInfo['asf']['file_properties_object']['flags']['seekable'] = (bool) ($ThisFileInfo['asf']['file_properties_object']['flags_raw'] & 0x2);
                $ThisFileInfo['asf']['file_properties_object']['min_packet_size'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['asf']['file_properties_object']['max_packet_size'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['asf']['file_properties_object']['max_bitrate'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['bitrate'] = $ThisFileInfo['asf']['file_properties_object']['max_bitrate'];
                break;
            case ASF_Stream_Properties_Object:
                // Stream Properties Object: (mandatory, one per media stream)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for stream properties object - ASF_Stream_Properties_Object
                // Object Size                  QWORD        64              // size of stream properties object, including 78 bytes of Stream Properties Object header
                // Stream Type                  GUID         128             // ASF_Audio_Media, ASF_Video_Media or ASF_Command_Media
                // Error Correction Type        GUID         128             // ASF_Audio_Spread for audio-only streams, ASF_No_Error_Correction for other stream types
                // Time Offset                  QWORD        64              // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
                // Type-Specific Data Length    DWORD        32              // number of bytes for Type-Specific Data field
                // Error Correction Data Length DWORD        32              // number of bytes for Error Correction Data field
                // Flags                        WORD         16              //
                // * Stream Number              bits         7 (0x007F)      // number of this stream.  1 <= valid <= 127
                // * Reserved                   bits         8 (0x7F80)      // reserved - set to zero
                // * Encrypted Content Flag     bits         1 (0x8000)      // stream contents encrypted if set
                // Reserved                     DWORD        32              // reserved - set to zero
                // Type-Specific Data           BYTESTREAM   variable        // type-specific format data, depending on value of Stream Type
                // Error Correction Data        BYTESTREAM   variable        // error-correction-specific format data, depending on value of Error Correct Type
                // There is one ASF_Stream_Properties_Object for each stream (audio, video) but the
                // stream number isn't known until halfway through decoding the structure, hence it
                // it is decoded to a temporary variable and then stuck in the appropriate index later
                $StreamPropertiesObjectData['objectid'] = $NextObjectGUID;
                $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext;
                $StreamPropertiesObjectData['objectsize'] = $NextObjectSize;
                $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $StreamPropertiesObjectData['stream_type_guid'] = BytestringToGUID($StreamPropertiesObjectData['stream_type']);
                $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $StreamPropertiesObjectData['error_correct_guid'] = BytestringToGUID($StreamPropertiesObjectData['error_correct_type']);
                $StreamPropertiesObjectData['time_offset'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                $offset += 8;
                $StreamPropertiesObjectData['type_data_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $StreamPropertiesObjectData['error_data_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $StreamPropertiesObjectData['flags_raw'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x7f;
                $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000);
                $offset += 4;
                // reserved - DWORD
                $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']);
                $offset += $StreamPropertiesObjectData['type_data_length'];
                $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']);
                $offset += $StreamPropertiesObjectData['error_data_length'];
                switch ($StreamPropertiesObjectData['stream_type']) {
                    case ASF_Audio_Media:
                        if (empty($ThisFileInfo['audio']['bitrate_mode'])) {
                            $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
                        }
                        require_once GETID3_INCLUDEPATH . 'getid3.riff.php';
                        $audiodata = RIFFparseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16));
                        unset($audiodata['raw']);
                        $ThisFileInfo['audio'] = array_merge_noclobber($audiodata, $ThisFileInfo['audio']);
                        break;
                    case ASF_Video_Media:
                        if (empty($ThisFileInfo['video']['bitrate_mode'])) {
                            $ThisFileInfo['video']['bitrate_mode'] = 'cbr';
                        }
                        break;
                    case ASF_Command_Media:
                    default:
                        // do nothing
                        break;
                }
                $ThisFileInfo['asf']['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData;
                unset($StreamPropertiesObjectData);
                // clear for next stream, if any
                break;
            case ASF_Header_Extension_Object:
                // Header Extension Object: (mandatory, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Header Extension object - ASF_Header_Extension_Object
                // Object Size                  QWORD        64              // size of Header Extension object, including 46 bytes of Header Extension Object header
                // Reserved Field 1             GUID         128             // hardcoded: ASF_Reserved_1
                // Reserved Field 2             WORD         16              // hardcoded: 0x00000006
                // Header Extension Data Size   DWORD        32              // in bytes. valid: 0, or > 24. equals object size minus 46
                // Header Extension Data        BYTESTREAM   variable        // array of zero or more extended header objects
                $ThisFileInfo['asf']['header_extension_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['header_extension_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['header_extension_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['header_extension_object']['reserved_1'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['header_extension_object']['reserved_1_guid'] = BytestringToGUID($ThisFileInfo['asf']['header_extension_object']['reserved_1']);
                if ($ThisFileInfo['asf']['header_extension_object']['reserved_1'] != ASF_Reserved_1) {
                    $ThisFileInfo['warning'] .= "\n" . 'header_extension_object.reserved_1 GUID (' . BytestringToGUID($ThisFileInfo['asf']['header_extension_object']['reserved_1']) . ') does not match expected "ASF_Reserved_1" GUID (' . BytestringToGUID(ASF_Reserved_1) . ')';
                    //return false;
                    break;
                }
                $ThisFileInfo['asf']['header_extension_object']['reserved_2'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                if ($ThisFileInfo['asf']['header_extension_object']['reserved_2'] != 6) {
                    $ThisFileInfo['warning'] .= "\n" . 'header_extension_object.reserved_2 (' . PrintHexBytes($ThisFileInfo['asf']['header_extension_object']['reserved_2']) . ') does not match expected value of "6"';
                    //return false;
                    break;
                }
                $ThisFileInfo['asf']['header_extension_object']['extension_data_size'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['asf']['header_extension_object']['extension_data'] = LittleEndian2Int(substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['header_extension_object']['extension_data_size']));
                $offset += $ThisFileInfo['asf']['header_extension_object']['extension_data_size'];
                break;
            case ASF_Codec_List_Object:
                // Codec List Object: (optional, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Codec List object - ASF_Codec_List_Object
                // Object Size                  QWORD        64              // size of Codec List object, including 44 bytes of Codec List Object header
                // Reserved                     GUID         128             // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
                // Codec Entries Count          DWORD        32              // number of entries in Codec Entries array
                // Codec Entries                array of:    variable        //
                // * Type                       WORD         16              // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
                // * Codec Name Length          WORD         16              // number of Unicode characters stored in the Codec Name field
                // * Codec Name                 WCHAR        variable        // array of Unicode characters - name of codec used to create the content
                // * Codec Description Length   WORD         16              // number of Unicode characters stored in the Codec Description field
                // * Codec Description          WCHAR        variable        // array of Unicode characters - description of format used to create the content
                // * Codec Information Length   WORD         16              // number of Unicode characters stored in the Codec Information field
                // * Codec Information          BYTESTREAM   variable        // opaque array of information bytes about the codec used to create the content
                $ThisFileInfo['asf']['codec_list']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['codec_list']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['codec_list']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['codec_list']['reserved'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['codec_list']['reserved_guid'] = BytestringToGUID($ThisFileInfo['asf']['codec_list']['reserved']);
                if ($ThisFileInfo['asf']['codec_list']['reserved'] != GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) {
                    $ThisFileInfo['warning'] .= "\n" . 'codec_list_object.reserved GUID {' . BytestringToGUID($ThisFileInfo['asf']['codec_list']['reserved']) . '} does not match expected "ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}';
                    //return false;
                    break;
                }
                $ThisFileInfo['asf']['codec_list']['codec_entries_count'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                for ($CodecEntryCounter = 0; $CodecEntryCounter < $ThisFileInfo['asf']['codec_list']['codec_entries_count']; $CodecEntryCounter++) {
                    $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['type_raw'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['type'] = ASFCodecListObjectTypeLookup($ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['type_raw']);
                    $CodecNameLength = LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                    // 2 bytes per character
                    $offset += 2;
                    $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['name'] = substr($ASFHeaderData, $offset, $CodecNameLength);
                    $offset += $CodecNameLength;
                    $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['name_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['name'], 2);
                    $CodecDescriptionLength = LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                    // 2 bytes per character
                    $offset += 2;
                    $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength);
                    $offset += $CodecDescriptionLength;
                    $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['description_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['description'], 2);
                    $CodecInformationLength = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength);
                    $offset += $CodecInformationLength;
                    if ($ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['type_raw'] == 2) {
                        // audio codec
                        $ThisFileInfo['audio']['codec'] = $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['name_ascii'];
                        list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['description_ascii']);
                        if (!isset($ThisFileInfo['audio']['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) {
                            $ThisFileInfo['audio']['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000);
                        }
                        if (!isset($ThisFileInfo['video']['bitrate']) && isset($ThisFileInfo['audio']['bitrate']) && isset($ThisFileInfo['asf']['file_properties_object']['max_bitrate']) && $ThisFileInfo['asf']['codec_list']['codec_entries_count'] > 1) {
                            $ThisFileInfo['video']['bitrate'] = $ThisFileInfo['asf']['file_properties_object']['max_bitrate'] - $ThisFileInfo['audio']['bitrate'];
                        }
                        $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency));
                        switch ($AudioCodecFrequency) {
                            case 8:
                                $ThisFileInfo['audio']['sample_rate'] = 8000;
                                break;
                            case 11:
                                $ThisFileInfo['audio']['sample_rate'] = 11025;
                                break;
                            case 12:
                                $ThisFileInfo['audio']['sample_rate'] = 12000;
                                break;
                            case 16:
                                $ThisFileInfo['audio']['sample_rate'] = 16000;
                                break;
                            case 22:
                                $ThisFileInfo['audio']['sample_rate'] = 22050;
                                break;
                            case 24:
                                $ThisFileInfo['audio']['sample_rate'] = 24000;
                                break;
                            case 32:
                                $ThisFileInfo['audio']['sample_rate'] = 32000;
                                break;
                            case 44:
                                $ThisFileInfo['audio']['sample_rate'] = 44100;
                                break;
                            case 48:
                                $ThisFileInfo['audio']['sample_rate'] = 48000;
                                break;
                            default:
                                $ThisFileInfo['warning'] .= "\n" . 'unknown frequency: "' . $AudioCodecFrequency . '" (' . $ThisFileInfo['asf']['codec_list']['codec_entries'][$CodecEntryCounter]['description_ascii'] . ')';
                                //								return false;
                                break;
                        }
                        if (!isset($ThisFileInfo['audio']['channels'])) {
                            if (strstr($AudioCodecChannels, 'stereo')) {
                                $ThisFileInfo['audio']['channels'] = 2;
                            } elseif (strstr($AudioCodecChannels, 'mono')) {
                                $ThisFileInfo['audio']['channels'] = 1;
                            }
                        }
                    }
                }
                break;
            case ASF_Script_Command_Object:
                // Script Command Object: (optional, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Script Command object - ASF_Script_Command_Object
                // Object Size                  QWORD        64              // size of Script Command object, including 44 bytes of Script Command Object header
                // Reserved                     GUID         128             // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
                // Commands Count               WORD         16              // number of Commands structures in the Script Commands Objects
                // Command Types Count          WORD         16              // number of Command Types structures in the Script Commands Objects
                // Command Types                array of:    variable        //
                // * Command Type Name Length   WORD         16              // number of Unicode characters for Command Type Name
                // * Command Type Name          WCHAR        variable        // array of Unicode characters - name of a type of command
                // Commands                     array of:    variable        //
                // * Presentation Time          DWORD        32              // presentation time of that command, in milliseconds
                // * Type Index                 WORD         16              // type of this command, as a zero-based index into the array of Command Types of this object
                // * Command Name Length        WORD         16              // number of Unicode characters for Command Name
                // * Command Name               WCHAR        variable        // array of Unicode characters - name of this command
                $ThisFileInfo['asf']['script_command_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['script_command_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['script_command_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['script_command_object']['reserved'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['script_command_object']['reserved_guid'] = BytestringToGUID($ThisFileInfo['asf']['script_command_object']['reserved']);
                if ($ThisFileInfo['asf']['script_command_object']['reserved'] != GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) {
                    $ThisFileInfo['warning'] .= "\n" . 'script_command_object.reserved GUID {' . BytestringToGUID($ThisFileInfo['asf']['script_command_object']['reserved']) . '} does not match expected "ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}';
                    //return false;
                    break;
                }
                $ThisFileInfo['asf']['script_command_object']['commands_count'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['script_command_object']['command_types_count'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                for ($CommandTypesCounter = 0; $CommandTypesCounter < $ThisFileInfo['asf']['script_command_object']['command_types_count']; $CommandTypesCounter++) {
                    $CommandTypeNameLength = LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                    // 2 bytes per character
                    $offset += 2;
                    $ThisFileInfo['asf']['script_command_object']['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
                    $offset += $CommandTypeNameLength;
                    $ThisFileInfo['asf']['script_command_object']['command_types'][$CommandTypesCounter]['name_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['script_command_object']['command_types'][$CommandTypesCounter]['name'], 2);
                }
                for ($CommandsCounter = 0; $CommandsCounter < $ThisFileInfo['asf']['script_command_object']['commands_count']; $CommandsCounter++) {
                    $ThisFileInfo['asf']['script_command_object']['commands'][$CommandsCounter]['presentation_time'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                    $offset += 4;
                    $ThisFileInfo['asf']['script_command_object']['commands'][$CommandsCounter]['type_index'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $CommandTypeNameLength = LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                    // 2 bytes per character
                    $offset += 2;
                    $ThisFileInfo['asf']['script_command_object']['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
                    $offset += $CommandTypeNameLength;
                    $ThisFileInfo['asf']['script_command_object']['commands'][$CommandsCounter]['name_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['script_command_object']['commands'][$CommandsCounter]['name'], 2);
                }
                break;
            case ASF_Marker_Object:
                // Marker Object: (optional, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Marker object - ASF_Marker_Object
                // Object Size                  QWORD        64              // size of Marker object, including 48 bytes of Marker Object header
                // Reserved                     GUID         128             // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
                // Markers Count                DWORD        32              // number of Marker structures in Marker Object
                // Reserved                     WORD         16              // hardcoded: 0x0000
                // Name Length                  WORD         16              // number of bytes in the Name field
                // Name                         WCHAR        variable        // name of the Marker Object
                // Markers                      array of:    variable        //
                // * Offset                     QWORD        64              // byte offset into Data Object
                // * Presentation Time          QWORD        64              // in 100-nanosecond units
                // * Entry Length               WORD         16              // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
                // * Send Time                  DWORD        32              // in milliseconds
                // * Flags                      DWORD        32              // hardcoded: 0x00000000
                // * Marker Description Length  DWORD        32              // number of bytes in Marker Description field
                // * Marker Description         WCHAR        variable        // array of Unicode characters - description of marker entry
                // * Padding                    BYTESTREAM   variable        // optional padding bytes
                $ThisFileInfo['asf']['marker_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['marker_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['marker_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['marker_object']['reserved'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['marker_object']['reserved_guid'] = BytestringToGUID($ThisFileInfo['asf']['marker_object']['reserved']);
                if ($ThisFileInfo['asf']['marker_object']['reserved'] != GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) {
                    $ThisFileInfo['warning'] .= "\n" . 'marker_object.reserved GUID {' . BytestringToGUID($ThisFileInfo['asf']['marker_object']['reserved_1']) . '} does not match expected "ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}';
                    //return false;
                    break;
                }
                $ThisFileInfo['asf']['marker_object']['markers_count'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['asf']['marker_object']['reserved_2'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                if ($ThisFileInfo['asf']['marker_object']['reserved_2'] != 0) {
                    $ThisFileInfo['warning'] .= "\n" . 'marker_object.reserved_2 (' . PrintHexBytes($ThisFileInfo['asf']['marker_object']['reserved_2']) . ') does not match expected value of "0"';
                    //return false;
                    break;
                }
                $ThisFileInfo['asf']['marker_object']['name_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['marker_object']['name'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['marker_object']['name_length']);
                $offset += $ThisFileInfo['asf']['marker_object']['name_length'];
                $ThisFileInfo['asf']['marker_object']['name_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['marker_object']['name'], 2);
                for ($MarkersCounter = 0; $MarkersCounter < $ThisFileInfo['asf']['marker_object']['markers_count']; $MarkersCounter++) {
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['offset'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                    $offset += 8;
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['presentation_time'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                    $offset += 8;
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['entry_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['send_time'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                    $offset += 4;
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['flags'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                    $offset += 4;
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['marker_description_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                    $offset += 4;
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['marker_description_length']);
                    $offset += $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['marker_description_length'];
                    $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['marker_description_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['marker_description'], 2);
                    $PaddingLength = $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['marker_description_length'];
                    if ($PaddingLength > 0) {
                        $ThisFileInfo['asf']['marker_object']['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength);
                        $offset += $PaddingLength;
                    }
                }
                break;
            case ASF_Bitrate_Mutual_Exclusion_Object:
                // Bitrate Mutual Exclusion Object: (optional)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Bitrate Mutual Exclusion object - ASF_Bitrate_Mutual_Exclusion_Object
                // Object Size                  QWORD        64              // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
                // Exlusion Type                GUID         128             // nature of mutual exclusion relationship. one of: (ASF_Mutex_Bitrate, ASF_Mutex_Unknown)
                // Stream Numbers Count         WORD         16              // number of video streams
                // Stream Numbers               WORD         variable        // array of mutually exclusive video stream numbers. 1 <= valid <= 127
                $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['reserved'] = substr($ASFHeaderData, $offset, 16);
                $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['reserved_guid'] = BytestringToGUID($ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['reserved']);
                $offset += 16;
                if ($ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['reserved'] != ASF_Mutex_Bitrate && $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['reserved'] != ASF_Mutex_Unknown) {
                    $ThisFileInfo['warning'] .= "\n" . 'bitrate_mutual_exclusion_object.reserved GUID {' . BytestringToGUID($ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['reserved']) . '} does not match expected "ASF_Mutex_Bitrate" GUID {' . BytestringToGUID(ASF_Mutex_Bitrate) . '} or  "ASF_Mutex_Unknown" GUID {' . BytestringToGUID(ASF_Mutex_Unknown) . '}';
                    //return false;
                    break;
                }
                $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['stream_numbers_count'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                for ($StreamNumberCounter = 0; $StreamNumberCounter < $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['stream_numbers_count']; $StreamNumberCounter++) {
                    $ThisFileInfo['asf']['bitrate_mutual_exclusion_object']['stream_numbers'][$StreamNumberCounter] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                }
                break;
            case ASF_Error_Correction_Object:
                // Error Correction Object: (optional, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Error Correction object - ASF_Error_Correction_Object
                // Object Size                  QWORD        64              // size of Error Correction object, including 44 bytes of Error Correction Object header
                // Error Correction Type        GUID         128             // type of error correction. one of: (ASF_No_Error_Correction, ASF_Audio_Spread)
                // Error Correction Data Length DWORD        32              // number of bytes in Error Correction Data field
                // Error Correction Data        BYTESTREAM   variable        // structure depends on value of Error Correction Type field
                $ThisFileInfo['asf']['error_correction_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['error_correction_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['error_correction_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['error_correction_object']['error_correction_type'] = substr($ASFHeaderData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['error_correction_object']['error_correction_guid'] = BytestringToGUID($ThisFileInfo['asf']['error_correction_object']['error_correction_type']);
                $ThisFileInfo['asf']['error_correction_object']['error_correction_data_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                $offset += 4;
                switch ($ThisFileInfo['asf']['error_correction_object']['error_correction_type']) {
                    case ASF_No_Error_Correction:
                        // should be no data, but just in case there is, skip to the end of the field
                        $offset += $ThisFileInfo['asf']['error_correction_object']['error_correction_data_length'];
                        break;
                    case ASF_Audio_Spread:
                        // Field Name                   Field Type   Size (bits)
                        // Span                         BYTE         8               // number of packets over which audio will be spread.
                        // Virtual Packet Length        WORD         16              // size of largest audio payload found in audio stream
                        // Virtual Chunk Length         WORD         16              // size of largest audio payload found in audio stream
                        // Silence Data Length          WORD         16              // number of bytes in Silence Data field
                        // Silence Data                 BYTESTREAM   variable        // hardcoded: 0x00 * (Silence Data Length) bytes
                        $ThisFileInfo['asf']['error_correction_object']['span'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 1));
                        $offset += 1;
                        $ThisFileInfo['asf']['error_correction_object']['virtual_packet_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                        $offset += 2;
                        $ThisFileInfo['asf']['error_correction_object']['virtual_chunk_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                        $offset += 2;
                        $ThisFileInfo['asf']['error_correction_object']['silence_data_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                        $offset += 2;
                        $ThisFileInfo['asf']['error_correction_object']['silence_data'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['error_correction_object']['silence_data_length']);
                        $offset += $ThisFileInfo['asf']['error_correction_object']['silence_data_length'];
                        break;
                    default:
                        $ThisFileInfo['warning'] .= "\n" . 'error_correction_object.error_correction_type GUID {' . BytestringToGUID($ThisFileInfo['asf']['error_correction_object']['reserved']) . '} does not match expected "ASF_No_Error_Correction" GUID {' . BytestringToGUID(ASF_No_Error_Correction) . '} or  "ASF_Audio_Spread" GUID {' . BytestringToGUID(ASF_Audio_Spread) . '}';
                        //return false;
                        break;
                }
                break;
            case ASF_Content_Description_Object:
                // Content Description Object: (optional, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Content Description object - ASF_Content_Description_Object
                // Object Size                  QWORD        64              // size of Content Description object, including 34 bytes of Content Description Object header
                // Title Length                 WORD         16              // number of bytes in Title field
                // Author Length                WORD         16              // number of bytes in Author field
                // Copyright Length             WORD         16              // number of bytes in Copyright field
                // Description Length           WORD         16              // number of bytes in Description field
                // Rating Length                WORD         16              // number of bytes in Rating field
                // Title                        WCHAR        16              // array of Unicode characters - Title
                // Author                       WCHAR        16              // array of Unicode characters - Author
                // Copyright                    WCHAR        16              // array of Unicode characters - Copyright
                // Description                  WCHAR        16              // array of Unicode characters - Description
                // Rating                       WCHAR        16              // array of Unicode characters - Rating
                $ThisFileInfo['asf']['content_description']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['content_description']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['content_description']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['content_description']['title_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['content_description']['author_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['content_description']['copyright_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['content_description']['description_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['content_description']['rating_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['content_description']['title'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['content_description']['title_length']);
                $offset += $ThisFileInfo['asf']['content_description']['title_length'];
                $ThisFileInfo['asf']['content_description']['title_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['content_description']['title'], 2);
                $ThisFileInfo['asf']['content_description']['author'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['content_description']['author_length']);
                $offset += $ThisFileInfo['asf']['content_description']['author_length'];
                $ThisFileInfo['asf']['content_description']['author_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['content_description']['author'], 2);
                $ThisFileInfo['asf']['content_description']['copyright'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['content_description']['copyright_length']);
                $offset += $ThisFileInfo['asf']['content_description']['copyright_length'];
                $ThisFileInfo['asf']['content_description']['copyright_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['content_description']['copyright'], 2);
                $ThisFileInfo['asf']['content_description']['description'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['content_description']['description_length']);
                $offset += $ThisFileInfo['asf']['content_description']['description_length'];
                $ThisFileInfo['asf']['content_description']['description_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['content_description']['description'], 2);
                $ThisFileInfo['asf']['content_description']['rating'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['content_description']['rating_length']);
                $offset += $ThisFileInfo['asf']['content_description']['rating_length'];
                $ThisFileInfo['asf']['content_description']['rating_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['content_description']['rating'], 2);
                foreach (array('title', 'author', 'copyright', 'description', 'rating') as $keytocopy) {
                    if (!empty($ThisFileInfo['asf']['content_description'][$keytocopy . '_ascii'])) {
                        $ThisFileInfo['asf']['comments']["{$keytocopy}"] = $ThisFileInfo['asf']['content_description'][$keytocopy . '_ascii'];
                    }
                }
                // ASF tags have highest priority
                if (!empty($ThisFileInfo['asf']['comments'])) {
                    CopyFormatCommentsToRootComments($ThisFileInfo['asf']['comments'], $ThisFileInfo, true, true, true);
                    // add tag to array of tags
                    $ThisFileInfo['tags'][] = 'asf';
                }
                break;
            case ASF_Extended_Content_Description_Object:
                // Extended Content Description Object: (optional, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Extended Content Description object - ASF_Extended_Content_Description_Object
                // Object Size                  QWORD        64              // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
                // Content Descriptors Count    WORD         16              // number of entries in Content Descriptors list
                // Content Descriptors          array of:    variable        //
                // * Descriptor Name Length     WORD         16              // size in bytes of Descriptor Name field
                // * Descriptor Name            WCHAR        variable        // array of Unicode characters - Descriptor Name
                // * Descriptor Value Data Type WORD         16              // Lookup array:
                // 0x0000 = Unicode String (variable length)
                // 0x0001 = BYTE array     (variable length)
                // 0x0002 = BOOL           (DWORD, 32 bits)
                // 0x0003 = DWORD          (DWORD, 32 bits)
                // 0x0004 = QWORD          (QWORD, 64 bits)
                // 0x0005 = WORD           (WORD,  16 bits)
                // * Descriptor Value Length    WORD         16              // number of bytes stored in Descriptor Value field
                // * Descriptor Value           variable     variable        // value for Content Descriptor
                $ThisFileInfo['asf']['extended_content_description']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['extended_content_description']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['extended_content_description']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['extended_content_description']['content_descriptors_count'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $ThisFileInfo['asf']['extended_content_description']['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) {
                    $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['name_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['name'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['name_length']);
                    $offset += $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['name_length'];
                    $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['name_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['name'], 2);
                    $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_type'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_length'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_length']);
                    $offset += $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_length'];
                    switch ($ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_type']) {
                        case 0x0:
                            // Unicode string
                            $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value'], 2);
                            break;
                        case 0x1:
                            // BYTE array
                            // do nothing
                            break;
                        case 0x2:
                            // BOOL
                            $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value'] = (bool) LittleEndian2Int($ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value']);
                            break;
                        case 0x3:
                            // DWORD
                        // DWORD
                        case 0x4:
                            // QWORD
                        // QWORD
                        case 0x5:
                            // WORD
                            $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value'] = LittleEndian2Int($ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value']);
                            break;
                        default:
                            $ThisFileInfo['warning'] .= "\n" . 'extended_content_description.content_descriptors.' . $ExtendedContentDescriptorsCounter . '.value_type is invalid (' . $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_type'] . ')';
                            //return false;
                            break;
                    }
                    switch ($ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['name_ascii']) {
                        case 'WM/AlbumTitle':
                            $ThisFileInfo['asf']['comments']['album'] = $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_ascii'];
                            break;
                        case 'WM/Genre':
                            $ThisFileInfo['asf']['comments']['genre'] = $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_ascii'];
                            require_once GETID3_INCLUDEPATH . 'getid3.id3.php';
                            $CleanedGenre = LookupGenre(LookupGenre($ThisFileInfo['asf']['comments']['genre'], true));
                            // convert to standard GenreID and back to standard spelling/capitalization
                            if ($CleanedGenre != $ThisFileInfo['asf']['comments']['genre']) {
                                $ThisFileInfo['asf']['comments']['genre'] = $CleanedGenre;
                            }
                            break;
                        case 'WM/TrackNumber':
                            $ThisFileInfo['asf']['comments']['track'] = $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value'];
                            break;
                        case 'WM/Track':
                            if (empty($ThisFileInfo['asf']['comments']['track'])) {
                                $ThisFileInfo['asf']['comments']['track'] = 1 + $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value'];
                            }
                            break;
                        case 'WM/Year':
                            $ThisFileInfo['asf']['comments']['year'] = $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value_ascii'];
                            break;
                        case 'IsVBR':
                            if ($ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value']) {
                                $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
                                $ThisFileInfo['video']['bitrate_mode'] = 'vbr';
                            }
                            break;
                        case 'ID3':
                            if ($tempfilehandle = tmpfile()) {
                                require_once GETID3_INCLUDEPATH . 'getid3.id3v2.php';
                                $tempThisfileInfo = array();
                                fwrite($tempfilehandle, $ThisFileInfo['asf']['extended_content_description']['content_descriptors'][$ExtendedContentDescriptorsCounter]['value']);
                                getID3v2Filepointer($tempfilehandle, $tempThisfileInfo);
                                fclose($tempfilehandle);
                                $ThisFileInfo['id3v2'] = $tempThisfileInfo['id3v2'];
                            }
                            break;
                        default:
                            // do nothing
                            break;
                    }
                    // ASF tags have highest priority
                    if (!empty($ThisFileInfo['asf']['comments'])) {
                        CopyFormatCommentsToRootComments($ThisFileInfo['asf']['comments'], $ThisFileInfo, true, true, true);
                    }
                }
                break;
            case ASF_Stream_Bitrate_Properties_Object:
                // Stream Bitrate Properties Object: (optional, one only)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Stream Bitrate Properties object - ASF_Stream_Bitrate_Properties_Object
                // Object Size                  QWORD        64              // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
                // Bitrate Records Count        WORD         16              // number of records in Bitrate Records
                // Bitrate Records              array of:    variable        //
                // * Flags                      WORD         16              //
                // * * Stream Number            bits         7  (0x007F)     // number of this stream
                // * * Reserved                 bits         9  (0xFF80)     // hardcoded: 0
                // * Average Bitrate            DWORD        32              // in bits per second
                $ThisFileInfo['asf']['stream_bitrate_properties']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['stream_bitrate_properties']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['stream_bitrate_properties']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records_count'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                $offset += 2;
                for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records_count']; $BitrateRecordsCounter++) {
                    $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x7f;
                    $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                    $offset += 4;
                }
                break;
            case ASF_Padding_Object:
                // Padding Object: (optional)
                // Field Name                   Field Type   Size (bits)
                // Object ID                    GUID         128             // GUID for Padding object - ASF_Padding_Object
                // Object Size                  QWORD        64              // size of Padding object, including 24 bytes of ASF Padding Object header
                // Padding Data                 BYTESTREAM   variable        // ignore
                $ThisFileInfo['asf']['padding_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['padding_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['padding_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['padding_object']['padding_length'] = $ThisFileInfo['asf']['padding_object']['objectsize'] - 16 - 8;
                $ThisFileInfo['asf']['padding_object']['padding'] = substr($ASFHeaderData, $offset, $ThisFileInfo['asf']['padding_object']['padding_length']);
                break;
            default:
                // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
                if (GUIDname($NextObjectGUIDtext)) {
                    $ThisFileInfo['warning'] .= "\n" . 'unhandled GUID "' . GUIDname($NextObjectGUIDtext) . '" {' . $NextObjectGUIDtext . '} in ASF header at offset ' . ($offset - 16 - 8);
                } else {
                    $ThisFileInfo['warning'] .= "\n" . 'unknown GUID {' . $NextObjectGUIDtext . '} in ASF header at offset ' . ($offset - 16 - 8);
                }
                $offset += $NextObjectSize - 16 - 8;
                break;
        }
    }
    if (isset($ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records_count'])) {
        $ASFbitrateAudio = 0;
        $ASFbitrateVideo = 0;
        for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records_count']; $BitrateRecordsCounter++) {
            if (isset($ThisFileInfo['asf']['codec_list']['codec_entries'][$BitrateRecordsCounter])) {
                switch ($ThisFileInfo['asf']['codec_list']['codec_entries'][$BitrateRecordsCounter]['type_raw']) {
                    case 1:
                        $ASFbitrateVideo += $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
                        break;
                    case 2:
                        $ASFbitrateAudio += $ThisFileInfo['asf']['stream_bitrate_properties']['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
                        break;
                    default:
                        // do nothing
                        break;
                }
            }
        }
        if ($ASFbitrateAudio > 0) {
            $ThisFileInfo['audio']['bitrate'] = $ASFbitrateAudio;
        }
        if ($ASFbitrateVideo > 0) {
            $ThisFileInfo['video']['bitrate'] = $ASFbitrateVideo;
        }
    }
    if (isset($ThisFileInfo['asf']['stream_properties_object']) && is_array($ThisFileInfo['asf']['stream_properties_object'])) {
        require_once GETID3_INCLUDEPATH . 'getid3.riff.php';
        foreach ($ThisFileInfo['asf']['stream_properties_object'] as $streamnumber => $streamdata) {
            switch ($streamdata['stream_type']) {
                case ASF_Audio_Media:
                    // Field Name                   Field Type   Size (bits)
                    // Codec ID / Format Tag        WORD         16              // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
                    // Number of Channels           WORD         16              // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
                    // Samples Per Second           DWORD        32              // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
                    // Average number of Bytes/sec  DWORD        32              // bytes/sec of audio stream  - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
                    // Block Alignment              WORD         16              // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
                    // Bits per sample              WORD         16              // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure
                    // Codec Specific Data Size     WORD         16              // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
                    // Codec Specific Data          BYTESTREAM   variable        // array of codec-specific data bytes
                    $audiomediaoffset = 0;
                    require_once GETID3_INCLUDEPATH . 'getid3.riff.php';
                    $ThisFileInfo['asf']['audio_media'][$streamnumber] = RIFFparseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16));
                    $audiomediaoffset += 16;
                    if (!isset($ThisFileInfo['audio']['bitrate'])) {
                        $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['asf']['audio_media'][$streamnumber]['bytes_sec'] * 8;
                    }
                    $ThisFileInfo['asf']['audio_media'][$streamnumber]['codec_data_size'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2));
                    $audiomediaoffset += 2;
                    $ThisFileInfo['asf']['audio_media'][$streamnumber]['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $ThisFileInfo['asf']['audio_media'][$streamnumber]['codec_data_size']);
                    $audiomediaoffset += $ThisFileInfo['asf']['audio_media'][$streamnumber]['codec_data_size'];
                    break;
                case ASF_Video_Media:
                    // Field Name                   Field Type   Size (bits)
                    // Encoded Image Width          DWORD        32              // width of image in pixels
                    // Encoded Image Height         DWORD        32              // height of image in pixels
                    // Reserved Flags               BYTE         8               // hardcoded: 0x02
                    // Format Data Size             WORD         16              // size of Format Data field in bytes
                    // Format Data                  array of:    variable        //
                    // * Format Data Size           DWORD        32              // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
                    // * Image Width                LONG         32              // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
                    // * Image Height               LONG         32              // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
                    // * Reserved                   WORD         16              // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
                    // * Bits Per Pixel Count       WORD         16              // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
                    // * Compression ID             FOURCC       32              // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
                    // * Image Size                 DWORD        32              // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
                    // * Horizontal Pixels / Meter  DWORD        32              // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
                    // * Vertical Pixels / Meter    DWORD        32              // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
                    // * Colors Used Count          DWORD        32              // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
                    // * Important Colors Count     DWORD        32              // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure
                    // * Codec Specific Data        BYTESTREAM   variable        // array of codec-specific data bytes
                    $videomediaoffset = 0;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['image_width'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['image_height'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['flags'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1));
                    $videomediaoffset += 1;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data_size'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
                    $videomediaoffset += 2;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['format_data_size'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['image_width'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['image_height'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['reserved'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
                    $videomediaoffset += 2;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['bits_per_pixel'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
                    $videomediaoffset += 2;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4);
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['image_size'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['horizontal_pels'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['vertical_pels'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['colors_used'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['colors_important'] = LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                    $videomediaoffset += 4;
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset);
                    $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['codec'] = RIFFfourccLookup($ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['codec_fourcc']);
                    $ThisFileInfo['video']['codec'] = $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['codec'];
                    $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['asf']['video_media'][$streamnumber]['image_width'];
                    $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['asf']['video_media'][$streamnumber]['image_height'];
                    $ThisFileInfo['video']['bits_per_sample'] = $ThisFileInfo['asf']['video_media'][$streamnumber]['format_data']['bits_per_pixel'];
                    break;
                default:
                    break;
            }
        }
    }
    while (ftell($fd) < $ThisFileInfo['avdataend']) {
        $NextObjectDataHeader = fread($fd, 24);
        $offset = 0;
        $NextObjectGUID = substr($NextObjectDataHeader, 0, 16);
        $offset += 16;
        $NextObjectGUIDtext = BytestringToGUID($NextObjectGUID);
        $NextObjectSize = LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8));
        $offset += 8;
        switch ($NextObjectGUID) {
            case ASF_Data_Object:
                // Data Object: (mandatory, one only)
                // Field Name                       Field Type   Size (bits)
                // Object ID                        GUID         128             // GUID for Data object - ASF_Data_Object
                // Object Size                      QWORD        64              // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
                // File ID                          GUID         128             // unique identifier. identical to File ID field in Header Object
                // Total Data Packets               QWORD        64              // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
                // Reserved                         WORD         16              // hardcoded: 0x0101
                $DataObjectData = $NextObjectDataHeader . fread($fd, 50 - 24);
                $offset = 24;
                $ThisFileInfo['asf']['data_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['data_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['data_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['data_object']['fileid'] = substr($DataObjectData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['data_object']['fileid_guid'] = BytestringToGUID($ThisFileInfo['asf']['data_object']['fileid']);
                $ThisFileInfo['asf']['data_object']['total_data_packets'] = LittleEndian2Int(substr($DataObjectData, $offset, 8));
                $offset += 8;
                $ThisFileInfo['asf']['data_object']['reserved'] = LittleEndian2Int(substr($DataObjectData, $offset, 2));
                $offset += 2;
                if ($ThisFileInfo['asf']['data_object']['reserved'] != 0x101) {
                    $ThisFileInfo['warning'] .= "\n" . 'data_object.reserved (' . PrintHexBytes($ThisFileInfo['asf']['data_object']['reserved']) . ') does not match expected value of "0x0101"';
                    //return false;
                    break;
                }
                // Data Packets                     array of:    variable        //
                // * Error Correction Flags         BYTE         8               //
                // * * Error Correction Data Length bits         4               // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
                // * * Opaque Data Present          bits         1               //
                // * * Error Correction Length Type bits         2               // number of bits for size of the error correction data. hardcoded: 00
                // * * Error Correction Present     bits         1               // If set, use Opaque Data Packet structure, else use Payload structure
                // * Error Correction Data
                $ThisFileInfo['avdataoffset'] = ftell($fd);
                fseek($fd, $ThisFileInfo['asf']['data_object']['objectsize'] - 50, SEEK_CUR);
                // skip actual audio/video data
                $ThisFileInfo['avdataend'] = ftell($fd);
                break;
            case ASF_Simple_Index_Object:
                // Simple Index Object: (optional, recommended, one per video stream)
                // Field Name                       Field Type   Size (bits)
                // Object ID                        GUID         128             // GUID for Simple Index object - ASF_Data_Object
                // Object Size                      QWORD        64              // size of Simple Index object, including 56 bytes of Simple Index Object header
                // File ID                          GUID         128             // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
                // Index Entry Time Interval        QWORD        64              // interval between index entries in 100-nanosecond units
                // Maximum Packet Count             DWORD        32              // maximum packet count for all index entries
                // Index Entries Count              DWORD        32              // number of Index Entries structures
                // Index Entries                    array of:    variable        //
                // * Packet Number                  DWORD        32              // number of the Data Packet associated with this index entry
                // * Packet Count                   WORD         16              // number of Data Packets to sent at this index entry
                $SimpleIndexObjectData = $NextObjectDataHeader . fread($fd, 56 - 24);
                $offset = 24;
                $ThisFileInfo['asf']['simple_index_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['simple_index_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['simple_index_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['simple_index_object']['fileid'] = substr($SimpleIndexObjectData, $offset, 16);
                $offset += 16;
                $ThisFileInfo['asf']['simple_index_object']['fileid_guid'] = BytestringToGUID($ThisFileInfo['asf']['simple_index_object']['fileid']);
                $ThisFileInfo['asf']['simple_index_object']['index_entry_time_interval'] = LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8));
                $offset += 8;
                $ThisFileInfo['asf']['simple_index_object']['maximum_packet_count'] = LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['asf']['simple_index_object']['index_entries_count'] = LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
                $offset += 4;
                $IndexEntriesData = $SimpleIndexObjectData . fread($fd, 6 * $ThisFileInfo['asf']['simple_index_object']['index_entries_count']);
                for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $ThisFileInfo['asf']['simple_index_object']['index_entries_count']; $IndexEntriesCounter++) {
                    $ThisFileInfo['asf']['simple_index_object']['index_entries'][$IndexEntriesCounter]['packet_number'] = LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
                    $offset += 4;
                    $ThisFileInfo['asf']['simple_index_object']['index_entries'][$IndexEntriesCounter]['packet_count'] = LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
                    $offset += 2;
                }
                break;
            case ASF_Index_Object:
                // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
                // Field Name                       Field Type   Size (bits)
                // Object ID                        GUID         128             // GUID for the Index Object - ASF_Index_Object
                // Object Size                      QWORD        64              // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
                // Index Entry Time Interval        DWORD        32              // Specifies the time interval between each index entry in ms.
                // Index Specifiers Count           WORD         16              // Specifies the number of Index Specifiers structures in this Index Object.
                // Index Blocks Count               DWORD        32              // Specifies the number of Index Blocks structures in this Index Object.
                // Index Entry Time Interval        DWORD        32              // Specifies the time interval between index entries in milliseconds.  This value cannot be 0.
                // Index Specifiers Count           WORD         16              // Specifies the number of entries in the Index Specifiers list.  Valid values are 1 and greater.
                // Index Specifiers                 array of:    varies          //
                // * Stream Number                  WORD         16              // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127.
                // * Index Type                     WORD         16              // Specifies Index Type values as follows:
                //   1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
                //   2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
                //   3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set.
                //   Nearest Past Cleanpoint is the most common type of index.
                // Index Entry Count                DWORD        32              // Specifies the number of Index Entries in the block.
                // * Block Positions                QWORD        varies          // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed.
                // * Index Entries                  array of:    varies          //
                // * * Offsets                      DWORD        varies          // An offset value of 0xffffffff indicates an invalid offset value
                $ASFIndexObjectData = $NextObjectDataHeader . fread($fd, 34 - 24);
                $offset = 24;
                $ThisFileInfo['asf']['asf_index_object']['objectid'] = $NextObjectGUID;
                $ThisFileInfo['asf']['asf_index_object']['objectid_guid'] = $NextObjectGUIDtext;
                $ThisFileInfo['asf']['asf_index_object']['objectsize'] = $NextObjectSize;
                $ThisFileInfo['asf']['asf_index_object']['entry_time_interval'] = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                $offset += 4;
                $ThisFileInfo['asf']['asf_index_object']['index_specifiers_count'] = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
                $offset += 2;
                $ThisFileInfo['asf']['asf_index_object']['index_blocks_count'] = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                $offset += 4;
                $ASFIndexObjectData .= fread($fd, 4 * $ThisFileInfo['asf']['asf_index_object']['index_specifiers_count']);
                for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $ThisFileInfo['asf']['asf_index_object']['index_specifiers_count']; $IndexSpecifiersCounter++) {
                    $IndexSpecifierStreamNumber = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['asf_index_object']['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber;
                    $ThisFileInfo['asf']['asf_index_object']['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
                    $offset += 2;
                    $ThisFileInfo['asf']['asf_index_object']['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = ASFIndexObjectIndexTypeLookup($ThisFileInfo['asf']['asf_index_object']['index_specifiers'][$IndexSpecifiersCounter]['index_type']);
                }
                $ASFIndexObjectData .= fread($fd, 4);
                $ThisFileInfo['asf']['asf_index_object']['index_entry_count'] = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                $offset += 4;
                $ASFIndexObjectData .= fread($fd, 8 * $ThisFileInfo['asf']['asf_index_object']['index_specifiers_count']);
                for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $ThisFileInfo['asf']['asf_index_object']['index_specifiers_count']; $IndexSpecifiersCounter++) {
                    $ThisFileInfo['asf']['asf_index_object']['block_positions'][$IndexSpecifiersCounter] = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8));
                    $offset += 8;
                }
                $ASFIndexObjectData .= fread($fd, 4 * $ThisFileInfo['asf']['asf_index_object']['index_specifiers_count'] * $ThisFileInfo['asf']['asf_index_object']['index_entry_count']);
                for ($IndexEntryCounter = 0; $IndexEntryCounter < $ThisFileInfo['asf']['asf_index_object']['index_entry_count']; $IndexEntryCounter++) {
                    for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $ThisFileInfo['asf']['asf_index_object']['index_specifiers_count']; $IndexSpecifiersCounter++) {
                        $ThisFileInfo['asf']['asf_index_object']['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                        $offset += 4;
                    }
                }
                break;
            default:
                // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
                if (GUIDname($NextObjectGUIDtext)) {
                    $ThisFileInfo['warning'] .= "\n" . 'unhandled GUID "' . GUIDname($NextObjectGUIDtext) . '" {' . $NextObjectGUIDtext . '} in ASF body at offset ' . ($offset - 16 - 8);
                } else {
                    $ThisFileInfo['warning'] .= "\n" . 'unknown GUID {' . $NextObjectGUIDtext . '} in ASF body at offset ' . (ftell($fd) - 16 - 8);
                }
                fseek($fd, $NextObjectSize - 16 - 8, SEEK_CUR);
                break;
        }
    }
    if (isset($ThisFileInfo['asf']['codec_list']['codec_entries']) && is_array($ThisFileInfo['asf']['codec_list']['codec_entries'])) {
        foreach ($ThisFileInfo['asf']['codec_list']['codec_entries'] as $streamnumber => $streamdata) {
            switch ($streamdata['information']) {
                case 'WMV1':
                case 'WMV2':
                case 'WMV3':
                    $ThisFileInfo['video']['dataformat'] = 'wmv';
                    $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
                    break;
                case 'MP42':
                case 'MP43':
                case 'MP4S':
                case 'mp4s':
                    $ThisFileInfo['video']['dataformat'] = 'asf';
                    $ThisFileInfo['mime_type'] = 'video/x-ms-asf';
                    break;
                default:
                    switch ($streamdata['type_raw']) {
                        case 1:
                            if (strstr($streamdata['name_ascii'], 'Windows Media')) {
                                $ThisFileInfo['video']['dataformat'] = 'wmv';
                                if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
                                    $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
                                }
                            }
                            break;
                        case 2:
                            if (strstr($streamdata['name_ascii'], 'Windows Media')) {
                                $ThisFileInfo['audio']['dataformat'] = 'wma';
                                if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
                                    $ThisFileInfo['mime_type'] = 'audio/x-ms-wma';
                                }
                            }
                            break;
                    }
                    break;
            }
        }
    }
    if (!empty($ThisFileInfo['audio']) && empty($ThisFileInfo['audio']['dataformat'])) {
        $ThisFileInfo['audio']['dataformat'] = 'asf';
    }
    if (!empty($ThisFileInfo['video']) && empty($ThisFileInfo['video']['dataformat'])) {
        $ThisFileInfo['video']['dataformat'] = 'asf';
    }
    switch ($ThisFileInfo['audio']['codec']) {
        case 'MPEG Layer-3':
            $ThisFileInfo['audio']['dataformat'] = 'mp3';
            $ThisFileInfo['audio']['bits_per_sample'] = 16;
            break;
        default:
            break;
    }
    if (isset($ThisFileInfo['asf']['codec_list']['codec_entries'])) {
        foreach ($ThisFileInfo['asf']['codec_list']['codec_entries'] as $streamnumber => $streamdata) {
            switch ($streamdata['type_raw']) {
                case 1:
                    // video
                    $ThisFileInfo['video']['encoder'] = $ThisFileInfo['asf']['codec_list']['codec_entries'][$streamnumber]['name_ascii'];
                    break;
                case 2:
                    // audio
                    $ThisFileInfo['audio']['encoder'] = $ThisFileInfo['asf']['codec_list']['codec_entries'][$streamnumber]['name_ascii'];
                    $ThisFileInfo['audio']['codec'] = $ThisFileInfo['audio']['encoder'];
                    break;
                default:
                    $ThisFileInfo['warning'] .= "\n" . 'Unknown streamtype: [codec_list][codec_entries][' . $streamnumber . '][type_raw] == ' . $streamdata['type_raw'];
                    break;
            }
        }
    }
    return true;
}
Пример #3
0
function getRIFFHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $RIFFheader = fread($fd, 12);
    switch (substr($RIFFheader, 0, 4)) {
        case 'RIFF':
        case 'SDSS':
            // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
            $ThisFileInfo['fileformat'] = 'riff';
            $ThisFileInfo['RIFF'][substr($RIFFheader, 8, 4)] = ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + LittleEndian2Int(substr($RIFFheader, 4, 4)), $ThisFileInfo);
            break;
        default:
            $ThisFileInfo['error'] .= "\n" . 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?)';
            unset($ThisFileInfo['fileformat']);
            return false;
            break;
    }
    $streamindex = 0;
    $arraykeys = array_keys($ThisFileInfo['RIFF']);
    switch ($arraykeys[0]) {
        case 'WAVE':
            $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            $ThisFileInfo['audio']['dataformat'] = 'wav';
            if (isset($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data'])) {
                $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data']);
                if ($ThisFileInfo['RIFF']['audio'][$streamindex] == 0) {
                    $ThisFileInfo['error'] .= 'Corrupt RIFF file: bitrate_audio == zero';
                    return false;
                }
                $ThisFileInfo['RIFF']['raw']['fmt '] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw'];
                unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']);
                $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]);
                $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'];
                $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']);
                if (isset($ThisFileInfo['RIFF']['WAVE']['data'][0]['offset']) && isset($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag'])) {
                    switch ($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag']) {
                        case 85:
                            // LAME ACM
                            require_once GETID3_INCLUDEPATH . 'getid3.mp3.php';
                            getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['RIFF']['WAVE']['data'][0]['offset'], false);
                            $ThisFileInfo['audio']['dataformat'] = 'mp3';
                            if (isset($ThisFileInfo['mpeg']['audio'])) {
                                $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate'];
                                $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels'];
                                $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'] * 1000;
                                $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate'];
                                $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitratemode']);
                            }
                            break;
                        default:
                            // do nothing
                            break;
                    }
                }
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data'])) {
                require_once GETID3_INCLUDEPATH . 'getid3.rgad.php';
                $rgadData = $ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data'];
                $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'] = LittleEndian2Float(substr($rgadData, 0, 4));
                $ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust'] = LittleEndian2Int(substr($rgadData, 4, 2));
                $ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust'] = LittleEndian2Int(substr($rgadData, 6, 2));
                $nRadioRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
                $nAudiophileRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
                $ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
                $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
                $ThisFileInfo['RIFF']['rgad']['peakamplitude'] = $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'];
                if ($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] != 0) {
                    $ThisFileInfo['RIFF']['rgad']['radio']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name']);
                    $ThisFileInfo['RIFF']['rgad']['radio']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator']);
                    $ThisFileInfo['RIFF']['rgad']['radio']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit']);
                }
                if ($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] != 0) {
                    $ThisFileInfo['RIFF']['rgad']['audiophile']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name']);
                    $ThisFileInfo['RIFF']['rgad']['audiophile']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator']);
                    $ThisFileInfo['RIFF']['rgad']['audiophile']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit']);
                }
            }
            if (isset($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'])) {
                $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'], 0, 4));
                if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'] > 0) {
                    $ThisFileInfo['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] / $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'];
                }
                if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) {
                    $ThisFileInfo['audio']['bitrate'] = CastAsInt($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec'] * 8);
                }
            }
            if (!isset($ThisFileInfo['audio']['bitrate']) && isset($ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'])) {
                $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'];
                $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']);
            }
            break;
        case 'AVI ':
            $ThisFileInfo['video']['bitrate_mode'] = 'cbr';
            $ThisFileInfo['video']['dataformat'] = 'avi';
            $ThisFileInfo['mime_type'] = 'video/avi';
            if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
                $avihData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data'];
                $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] = LittleEndian2Int(substr($avihData, 0, 4));
                // frame display rate (or 0L)
                if ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] == 0) {
                    $ThisFileInfo['error'] .= 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
                    return false;
                }
                $ThisFileInfo['RIFF']['raw']['avih']['dwMaxBytesPerSec'] = LittleEndian2Int(substr($avihData, 4, 4));
                // max. transfer rate
                $ThisFileInfo['RIFF']['raw']['avih']['dwPaddingGranularity'] = LittleEndian2Int(substr($avihData, 8, 4));
                // pad to multiples of this size; normally 2K.
                $ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] = LittleEndian2Int(substr($avihData, 12, 4));
                // the ever-present flags
                $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] = LittleEndian2Int(substr($avihData, 16, 4));
                // # frames in file
                $ThisFileInfo['RIFF']['raw']['avih']['dwInitialFrames'] = LittleEndian2Int(substr($avihData, 20, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwStreams'] = LittleEndian2Int(substr($avihData, 24, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwSuggestedBufferSize'] = LittleEndian2Int(substr($avihData, 28, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwWidth'] = LittleEndian2Int(substr($avihData, 32, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwHeight'] = LittleEndian2Int(substr($avihData, 36, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwScale'] = LittleEndian2Int(substr($avihData, 40, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwRate'] = LittleEndian2Int(substr($avihData, 44, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwStart'] = LittleEndian2Int(substr($avihData, 48, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['dwLength'] = LittleEndian2Int(substr($avihData, 52, 4));
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['hasindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['mustuseindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['interleaved'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x100);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['trustcktype'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x800);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['capturedfile'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10000);
                $ThisFileInfo['RIFF']['raw']['avih']['flags']['copyrighted'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20010);
                $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width'] = $ThisFileInfo['RIFF']['raw']['avih']['dwWidth'];
                $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height'] = $ThisFileInfo['RIFF']['raw']['avih']['dwHeight'];
                $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate'] = round(1000000 / $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'], 3);
                if (!isset($ThisFileInfo['video']['resolution_x'])) {
                    $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width'];
                }
                if (!isset($ThisFileInfo['video']['resolution_y'])) {
                    $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height'];
                }
                $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate'];
            }
            if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
                if (is_array($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'])) {
                    for ($i = 0; $i < count($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh']); $i++) {
                        if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
                            $strhData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data'];
                            $strhfccType = substr($strhData, 0, 4);
                            if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
                                $strfData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data'];
                                switch ($strhfccType) {
                                    case 'auds':
                                        $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
                                        $ThisFileInfo['audio']['dataformat'] = 'wav';
                                        if (isset($ThisFileInfo['RIFF']['audio']) && is_array($ThisFileInfo['RIFF']['audio'])) {
                                            $streamindex = count($ThisFileInfo['RIFF']['audio']);
                                        }
                                        $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($strfData);
                                        $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw'];
                                        unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']);
                                        $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]);
                                        switch ($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['wFormatTag']) {
                                            case 85:
                                                $ThisFileInfo['audio']['dataformat'] = 'mp3';
                                                break;
                                            case 8192:
                                                $ThisFileInfo['audio']['dataformat'] = 'ac3';
                                                break;
                                            default:
                                                $ThisFileInfo['audio']['dataformat'] = 'wav';
                                                break;
                                        }
                                        break;
                                    case 'iavs':
                                    case 'vids':
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccType'] = substr($strhData, 0, 4);
                                        // same as $strhfccType;
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler'] = substr($strhData, 4, 4);
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwFlags'] = LittleEndian2Int(substr($strhData, 8, 4));
                                        // Contains AVITF_* flags
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['wPriority'] = LittleEndian2Int(substr($strhData, 12, 2));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['wLanguage'] = LittleEndian2Int(substr($strhData, 14, 2));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwInitialFrames'] = LittleEndian2Int(substr($strhData, 16, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwScale'] = LittleEndian2Int(substr($strhData, 20, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwRate'] = LittleEndian2Int(substr($strhData, 24, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwStart'] = LittleEndian2Int(substr($strhData, 28, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwLength'] = LittleEndian2Int(substr($strhData, 32, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSuggestedBufferSize'] = LittleEndian2Int(substr($strhData, 36, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwQuality'] = LittleEndian2Int(substr($strhData, 40, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSampleSize'] = LittleEndian2Int(substr($strhData, 44, 4));
                                        $ThisFileInfo['RIFF']['raw']['strh'][$i]['rcFrame'] = LittleEndian2Int(substr($strhData, 48, 4));
                                        $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler']);
                                        if (!$ThisFileInfo['RIFF']['video'][$streamindex]['codec'] && isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) {
                                            $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']);
                                        }
                                        $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec'];
                                        switch ($strhfccType) {
                                            case 'vids':
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSize'] = LittleEndian2Int(substr($strfData, 0, 4));
                                                // number of bytes required by the BITMAPINFOHEADER structure
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biWidth'] = LittleEndian2Int(substr($strfData, 4, 4));
                                                // width of the bitmap in pixels
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biHeight'] = LittleEndian2Int(substr($strfData, 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
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biPlanes'] = LittleEndian2Int(substr($strfData, 12, 2));
                                                // number of color planes on the target device. In most cases this value must be set to 1
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biBitCount'] = LittleEndian2Int(substr($strfData, 14, 2));
                                                // Specifies the number of bits per pixels
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'] = substr($strfData, 16, 4);
                                                //
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSizeImage'] = LittleEndian2Int(substr($strfData, 20, 4));
                                                // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biXPelsPerMeter'] = LittleEndian2Int(substr($strfData, 24, 4));
                                                // horizontal resolution, in pixels per metre, of the target device
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biYPelsPerMeter'] = LittleEndian2Int(substr($strfData, 28, 4));
                                                // vertical resolution, in pixels per metre, of the target device
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrUsed'] = LittleEndian2Int(substr($strfData, 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
                                                $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrImportant'] = LittleEndian2Int(substr($strfData, 36, 4));
                                                // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
                                                if ($ThisFileInfo['RIFF']['video'][$streamindex]['codec'] == 'DV') {
                                                    $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 2;
                                                }
                                                break;
                                            case 'iavs':
                                                $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 1;
                                                break;
                                        }
                                        break;
                                    default:
                                        $ThisFileInfo['warning'] .= "\n" . 'Unhandled fccType for stream (' . $i . '): "' . $strhfccType . '"';
                                        break;
                                }
                            }
                        }
                        if (isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) {
                            $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']);
                            $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec'];
                        }
                    }
                }
            }
            break;
        case 'CDDA':
            $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            $ThisFileInfo['audio']['dataformat'] = 'cda';
            unset($ThisFileInfo['mime_type']);
            if (isset($ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data'])) {
                $fmtData = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data'];
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown1'] = LittleEndian2Int(substr($fmtData, 0, 2));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num'] = LittleEndian2Int(substr($fmtData, 2, 2));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['disc_id'] = LittleEndian2Int(substr($fmtData, 4, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] = LittleEndian2Int(substr($fmtData, 8, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] = LittleEndian2Int(substr($fmtData, 12, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown6'] = LittleEndian2Int(substr($fmtData, 16, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown7'] = LittleEndian2Int(substr($fmtData, 20, 4));
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] / 75;
                $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] / 75;
                $ThisFileInfo['comments']['track'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num'];
                $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds'];
                // hardcoded data for CD-audio
                $ThisFileInfo['audio']['sample_rate'] = 44100;
                $ThisFileInfo['audio']['channels'] = 2;
                $ThisFileInfo['audio']['bits_per_sample'] = 16;
                $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['audio']['sample_rate'] * $ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['bits_per_sample'];
                $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
            }
            break;
        default:
            unset($ThisFileInfo['fileformat']);
            break;
    }
    if (isset($ThisFileInfo['RIFF']['WAVE']['DISP']) && is_array($ThisFileInfo['RIFF']['WAVE']['DISP'])) {
        $ThisFileInfo['tags'][] = 'riff';
        $ThisFileInfo['RIFF']['comments']['title'][] = trim(substr($ThisFileInfo['RIFF']['WAVE']['DISP'][count($ThisFileInfo['RIFF']['WAVE']['DISP']) - 1]['data'], 4));
    }
    if (isset($ThisFileInfo['RIFF']['WAVE']['INFO']) && is_array($ThisFileInfo['RIFF']['WAVE']['INFO'])) {
        $ThisFileInfo['tags'][] = 'riff';
        $RIFFinfoKeyLookup = array('IART' => 'artist', 'IGNR' => 'genre', 'ICMT' => 'comment', 'ICOP' => 'copyright', 'IENG' => 'engineers', 'IKEY' => 'keywords', 'IMED' => 'orignalmedium', 'INAM' => 'name', 'ISRC' => 'sourcesupplier', 'ITCH' => 'digitizer', 'ISBJ' => 'subject', 'ISRF' => 'digitizationsource');
        foreach ($RIFFinfoKeyLookup as $key => $value) {
            foreach ($ThisFileInfo['RIFF']['WAVE']['INFO']["{$key}"] as $commentid => $commentdata) {
                if (trim($commentdata['data']) != '') {
                    $ThisFileInfo['RIFF']['comments']["{$value}"][] = trim($commentdata['data']);
                }
            }
        }
    }
    if (!empty($ThisFileInfo['RIFF']['comments'])) {
        CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, true, true);
    }
    if (!isset($ThisFileInfo['playtime_seconds'])) {
        $ThisFileInfo['playtime_seconds'] = 0;
    }
    if (isset($ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames']) && isset($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'])) {
        $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] * ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] / 1000000);
    }
    if ($ThisFileInfo['playtime_seconds'] > 0) {
        if (isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) {
            if (!isset($ThisFileInfo['bitrate'])) {
                $ThisFileInfo['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
            }
        } elseif (isset($ThisFileInfo['RIFF']['audio']) && !isset($ThisFileInfo['RIFF']['video'])) {
            if (!isset($ThisFileInfo['audio']['bitrate'])) {
                $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
            }
        } elseif (!isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) {
            if (!isset($ThisFileInfo['video']['bitrate'])) {
                $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
            }
        }
    }
    if (isset($ThisFileInfo['RIFF']['video']) && isset($ThisFileInfo['audio']['bitrate']) && $ThisFileInfo['audio']['bitrate'] > 0 && $ThisFileInfo['playtime_seconds'] > 0) {
        $ThisFileInfo['audio']['bitrate'] = 0;
        $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
        foreach ($ThisFileInfo['RIFF']['audio'] as $channelnumber => $audioinfoarray) {
            $ThisFileInfo['video']['bitrate'] -= $audioinfoarray['bitrate'];
            $ThisFileInfo['audio']['bitrate'] += $audioinfoarray['bitrate'];
        }
        if ($ThisFileInfo['video']['bitrate'] <= 0) {
            unset($ThisFileInfo['video']['bitrate']);
        }
        if ($ThisFileInfo['audio']['bitrate'] <= 0) {
            unset($ThisFileInfo['audio']['bitrate']);
        }
    }
    if (!empty($ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'])) {
        $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'];
    }
    // Skip RIFF header
    $ThisFileInfo['avdataoffset'] += 44;
    return true;
}