Example #1
0
function getGIFHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    $ThisFileInfo['fileformat'] = 'gif';
    $ThisFileInfo['video']['dataformat'] = 'gif';
    $ThisFileInfo['video']['lossless'] = true;
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $GIFheader = fread($fd, 13);
    $offset = 0;
    $ThisFileInfo['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3);
    $offset += 3;
    $ThisFileInfo['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3);
    $offset += 3;
    $ThisFileInfo['gif']['header']['raw']['width'] = LittleEndian2Int(substr($GIFheader, $offset, 2));
    $offset += 2;
    $ThisFileInfo['gif']['header']['raw']['height'] = LittleEndian2Int(substr($GIFheader, $offset, 2));
    $offset += 2;
    $ThisFileInfo['gif']['header']['raw']['flags'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
    $offset += 1;
    $ThisFileInfo['gif']['header']['raw']['bg_color_index'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
    $offset += 1;
    $ThisFileInfo['gif']['header']['raw']['aspect_ratio'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
    $offset += 1;
    $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['gif']['header']['raw']['width'];
    $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['gif']['header']['raw']['height'];
    $ThisFileInfo['gif']['version'] = $ThisFileInfo['gif']['header']['raw']['version'];
    $ThisFileInfo['gif']['header']['flags']['global_color_table'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80);
    if ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80) {
        // Number of bits per primary color available to the original image, minus 1
        $ThisFileInfo['gif']['header']['bits_per_pixel'] = 3 * ((($ThisFileInfo['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
    } else {
        $ThisFileInfo['gif']['header']['bits_per_pixel'] = 0;
    }
    $ThisFileInfo['gif']['header']['flags']['global_color_sorted'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x40);
    if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
        // the number of bytes contained in the Global Color Table. To determine that
        // actual size of the color table, raise 2 to [the value of the field + 1]
        $ThisFileInfo['gif']['header']['global_color_size'] = pow(2, ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x7) + 1);
        $ThisFileInfo['video']['bits_per_sample'] = ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x7) + 1;
    } else {
        $ThisFileInfo['gif']['header']['global_color_size'] = 0;
    }
    if ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] != 0) {
        // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64
        $ThisFileInfo['gif']['header']['aspect_ratio'] = ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
    }
    if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
        $GIFcolorTable = fread($fd, 3 * $ThisFileInfo['gif']['header']['global_color_size']);
        $offset = 0;
        for ($i = 0; $i < $ThisFileInfo['gif']['header']['global_color_size']; $i++) {
            //$ThisFileInfo['gif']['global_color_table']['red'][$i]   = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            //$ThisFileInfo['gif']['global_color_table']['green'][$i] = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            //$ThisFileInfo['gif']['global_color_table']['blue'][$i]  = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $red = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $green = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $blue = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $ThisFileInfo['gif']['global_color_table'][$i] = $red << 16 | $green << 8 | $blue;
        }
    }
    return true;
}
Example #2
0
function getSWFHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    $ThisFileInfo['fileformat'] = 'swf';
    $ThisFileInfo['video']['dataformat'] = 'swf';
    // http://www.openswf.org/spec/SWFfileformat.html
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $SWFheaderData = fread($fd, 12);
    // 12 bytes NOT including Frame_Size RECT data
    $ThisFileInfo['swf']['header']['signature'] = substr($SWFheaderData, 0, 3);
    if ($ThisFileInfo['swf']['header']['signature'] != 'FWS') {
        $ThisFileInfo['error'] .= "\n" . '"FWS" expected at offset ' . $ThisFileInfo['avdataoffset'] . ', "' . $ThisFileInfo['swf']['header']['signature'] . '" found instead.';
        return false;
    }
    $ThisFileInfo['swf']['header']['version'] = LittleEndian2Int(substr($SWFheaderData, 3, 1));
    $ThisFileInfo['swf']['header']['length'] = LittleEndian2Int(substr($SWFheaderData, 4, 4));
    $FrameSizeBitsPerValue = (ord(substr($SWFheaderData, 8, 1)) & 0xf8) >> 3;
    $FrameSizeDataLength = ceil((5 + 4 * $FrameSizeBitsPerValue) / 8);
    $SWFheaderData .= fread($fd, $FrameSizeDataLength);
    $FrameSizeDataString = str_pad(decbin(ord(substr($SWFheaderData, 8, 1)) & 0x7), 3, '0', STR_PAD_LEFT);
    for ($i = 1; $i < $FrameSizeDataLength; $i++) {
        $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFheaderData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
    }
    list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1));
    $ThisFileInfo['swf']['header']['frame_width'] = Bin2Dec($X2);
    $ThisFileInfo['swf']['header']['frame_height'] = Bin2Dec($Y2);
    $ThisFileInfo['swf']['header']['frame_delay'] = FixedPoint8_8(substr($SWFheaderData, 8 + $FrameSizeDataLength, 2));
    $ThisFileInfo['swf']['header']['frame_count'] = LittleEndian2Int(substr($SWFheaderData, 10 + $FrameSizeDataLength, 2));
    $ThisFileInfo['video']['resolution_x'] = round($ThisFileInfo['swf']['header']['frame_width'] / 20);
    $ThisFileInfo['video']['resolution_y'] = round($ThisFileInfo['swf']['header']['frame_height'] / 20);
    switch ($ThisFileInfo['swf']['header']['frame_delay']) {
        case 0:
        case 128:
            // invalid / ignore
            break;
        default:
            $ThisFileInfo['video']['frame_rate'] = 1 / $ThisFileInfo['swf']['header']['frame_delay'];
            break;
    }
    return true;
}
Example #3
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;
}
Example #4
0
function getNSVfHeaderFilepointer(&$fd, &$ThisFileInfo, $fileoffset, $getTOCoffsets = false)
{
    fseek($fd, $fileoffset, SEEK_SET);
    $NSVfheader = fread($fd, 28);
    $offset = 0;
    $ThisFileInfo['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4);
    $offset += 4;
    if ($ThisFileInfo['nsv']['NSVf']['identifier'] != 'NSVf') {
        $ThisFileInfo['error'] .= "\n" . 'expected "NSVf" at offset (' . $fileoffset . '), found "' . $ThisFileInfo['nsv']['NSVf']['identifier'] . '" instead';
        unset($ThisFileInfo['nsv']['NSVf']);
        return false;
    }
    $ThisFileInfo['nsv']['NSVs']['offset'] = $fileoffset;
    $ThisFileInfo['nsv']['NSVf']['header_length'] = LittleEndian2Int(substr($NSVfheader, $offset, 4));
    $offset += 4;
    $ThisFileInfo['nsv']['NSVf']['file_size'] = LittleEndian2Int(substr($NSVfheader, $offset, 4));
    $offset += 4;
    if ($ThisFileInfo['nsv']['NSVf']['file_size'] > $ThisFileInfo['avdataend']) {
        $ThisFileInfo['warning'] .= "\n" . 'truncated file - NSVf header indicates ' . $ThisFileInfo['nsv']['NSVf']['file_size'] . ' bytes, file actually ' . $ThisFileInfo['avdataend'] . ' bytes';
    }
    $ThisFileInfo['nsv']['NSVf']['playtime_ms'] = LittleEndian2Int(substr($NSVfheader, $offset, 4));
    $offset += 4;
    $ThisFileInfo['nsv']['NSVf']['meta_size'] = LittleEndian2Int(substr($NSVfheader, $offset, 4));
    $offset += 4;
    $ThisFileInfo['nsv']['NSVf']['TOC_entries_1'] = LittleEndian2Int(substr($NSVfheader, $offset, 4));
    $offset += 4;
    $ThisFileInfo['nsv']['NSVf']['TOC_entries_2'] = LittleEndian2Int(substr($NSVfheader, $offset, 4));
    $offset += 4;
    if ($ThisFileInfo['nsv']['NSVf']['playtime_ms'] == 0) {
        $ThisFileInfo['error'] .= "\n" . 'Corrupt NSV file: NSVf.playtime_ms == zero';
        return false;
    }
    $NSVfheader .= fread($fd, $ThisFileInfo['nsv']['NSVf']['meta_size'] + 4 * $ThisFileInfo['nsv']['NSVf']['TOC_entries_1'] + 4 * $ThisFileInfo['nsv']['NSVf']['TOC_entries_2']);
    $NSVfheaderlength = strlen($NSVfheader);
    $ThisFileInfo['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $ThisFileInfo['nsv']['NSVf']['meta_size']);
    $offset += $ThisFileInfo['nsv']['NSVf']['meta_size'];
    if ($getTOCoffsets) {
        $TOCcounter = 0;
        while ($TOCcounter < $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) {
            if ($TOCcounter < $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) {
                $ThisFileInfo['nsv']['NSVf']['TOC_1'][$TOCcounter] = LittleEndian2Int(substr($NSVfheader, $offset, 4));
                $offset += 4;
                $TOCcounter++;
            }
        }
    }
    if (trim($ThisFileInfo['nsv']['NSVf']['metadata']) != '') {
        $CommentPairArray = explode('` ', $ThisFileInfo['nsv']['NSVf']['metadata']);
        foreach ($CommentPairArray as $CommentPair) {
            if (strstr($CommentPair, '=`')) {
                list($key, $value) = explode('=`', $CommentPair, 2);
                $ThisFileInfo['nsv']['comments'][strtolower($key)] = str_replace('`', '', $value);
            } elseif (strstr($CommentPair, '=' . chr(1))) {
                list($key, $value) = explode('=' . chr(1), $CommentPair, 2);
                $ThisFileInfo['nsv']['comments'][strtolower($key)] = str_replace(chr(1), '', $value);
            }
        }
    }
    // NSV tags have highest priority
    if (!empty($ThisFileInfo['nsv']['comments'])) {
        CopyFormatCommentsToRootComments($ThisFileInfo['nsv']['comments'], $ThisFileInfo, true, true, true);
    }
    // add tag to array of tags
    $ThisFileInfo['tags'][] = 'nsv';
    $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['nsv']['NSVf']['playtime_ms'] / 1000;
    $ThisFileInfo['bitrate'] = $ThisFileInfo['nsv']['NSVf']['file_size'] * 8 / $ThisFileInfo['playtime_seconds'];
    return true;
}
Example #5
0
function getLAHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    $offset = 0;
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $rawdata = fread($fd, FREAD_BUFFER_SIZE);
    switch (substr($rawdata, $offset, 4)) {
        case 'LA02':
        case 'LA03':
            $ThisFileInfo['fileformat'] = 'la';
            $ThisFileInfo['audio']['dataformat'] = 'la';
            $ThisFileInfo['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1);
            $ThisFileInfo['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1);
            $ThisFileInfo['la']['version'] = (double) $ThisFileInfo['la']['version_major'] + $ThisFileInfo['la']['version_minor'] / 10;
            $offset += 4;
            $ThisFileInfo['la']['uncompressed_size'] = LittleEndian2Int(substr($rawdata, $offset, 4));
            $offset += 4;
            if ($ThisFileInfo['la']['uncompressed_size'] == 0) {
                $ThisFileInfo['error'] .= "\n" . 'Corrupt LA file: uncompressed_size == zero';
                return false;
            }
            $WAVEchunk = substr($rawdata, $offset, 4);
            if ($WAVEchunk !== 'WAVE') {
                $ThisFileInfo['error'] .= "\n" . 'Expected "WAVE" (' . PrintHexBytes('WAVE') . ') at offset ' . $offset . ', found "' . $WAVEchunk . '" (' . PrintHexBytes($WAVEchunk) . ') instead.';
                return false;
            }
            $offset += 4;
            $ThisFileInfo['la']['format_size'] = 24;
            if ($ThisFileInfo['la']['version'] > 0.2) {
                $ThisFileInfo['la']['format_size'] = LittleEndian2Int(substr($rawdata, $offset, 4));
                $ThisFileInfo['la']['header_size'] = 49 + $ThisFileInfo['la']['format_size'] - 24;
                $offset += 4;
            } else {
                // version two didn't support additional data blocks
                $ThisFileInfo['la']['header_size'] = 41;
            }
            $fmt_chunk = substr($rawdata, $offset, 4);
            if ($fmt_chunk !== 'fmt ') {
                $ThisFileInfo['error'] .= "\n" . 'Expected "fmt " (' . PrintHexBytes('fmt ') . ') at offset ' . $offset . ', found "' . $fmt_chunk . '" (' . PrintHexBytes($fmt_chunk) . ') instead.';
                return false;
            }
            $offset += 4;
            $fmt_size = LittleEndian2Int(substr($rawdata, $offset, 4));
            $offset += 4;
            $ThisFileInfo['la']['format_raw'] = LittleEndian2Int(substr($rawdata, $offset, 2));
            $offset += 2;
            $ThisFileInfo['la']['channels'] = LittleEndian2Int(substr($rawdata, $offset, 2));
            $offset += 2;
            if ($ThisFileInfo['la']['channels'] == 0) {
                $ThisFileInfo['error'] .= "\n" . 'Corrupt LA file: channels == zero';
                return false;
            }
            $ThisFileInfo['la']['sample_rate'] = LittleEndian2Int(substr($rawdata, $offset, 4));
            $offset += 4;
            if ($ThisFileInfo['la']['sample_rate'] == 0) {
                $ThisFileInfo['error'] .= "\n" . 'Corrupt LA file: sample_rate == zero';
                return false;
            }
            $ThisFileInfo['la']['bytes_per_second'] = LittleEndian2Int(substr($rawdata, $offset, 4));
            $offset += 4;
            $ThisFileInfo['la']['bytes_per_sample'] = LittleEndian2Int(substr($rawdata, $offset, 2));
            $offset += 2;
            $ThisFileInfo['la']['bits_per_sample'] = LittleEndian2Int(substr($rawdata, $offset, 2));
            $offset += 2;
            $ThisFileInfo['la']['samples'] = LittleEndian2Int(substr($rawdata, $offset, 4));
            $offset += 4;
            $ThisFileInfo['la']['seekable'] = (bool) LittleEndian2Int(substr($rawdata, $offset, 1));
            $offset += 1;
            $ThisFileInfo['la']['original_crc'] = LittleEndian2Int(substr($rawdata, $offset, 4));
            $offset += 4;
            require_once GETID3_INCLUDEPATH . 'getid3.riff.php';
            $ThisFileInfo['la']['codec'] = RIFFwFormatTagLookup($ThisFileInfo['la']['format_raw']);
            $ThisFileInfo['la']['compression_ratio'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['la']['uncompressed_size']);
            $ThisFileInfo['playtime_seconds'] = (double) ($ThisFileInfo['la']['samples'] / $ThisFileInfo['la']['sample_rate']) / $ThisFileInfo['la']['channels'];
            if ($ThisFileInfo['playtime_seconds'] == 0) {
                $ThisFileInfo['error'] .= "\n" . 'Corrupt LA file: playtime_seconds == zero';
                return false;
            }
            // add size of file header to avdataoffset - calc bitrate correctly + MD5 data
            $ThisFileInfo['avdataoffset'] += $ThisFileInfo['la']['header_size'];
            $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
            $ThisFileInfo['audio']['codec'] = $ThisFileInfo['la']['codec'];
            $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['la']['bits_per_sample'];
            break;
        default:
            if (substr($rawdata, $offset, 2) == 'LA') {
                $ThisFileInfo['error'] .= "\n" . 'This version of getID3() (v' . GETID3VERSION . ') doesn\'t support LA version ' . substr($rawdata, $offset + 2, 1) . '.' . substr($rawdata, $offset + 3, 1) . ' which this appears to be - check http://getid3.sourceforge.net for updates.';
            } else {
                $ThisFileInfo['error'] .= "\n" . 'Not a LA (Lossless-Audio) file';
            }
            return false;
            break;
    }
    $ThisFileInfo['audio']['channels'] = $ThisFileInfo['la']['channels'];
    $ThisFileInfo['audio']['sample_rate'] = (int) $ThisFileInfo['la']['sample_rate'];
    $ThisFileInfo['audio']['encoder'] = (string) $ThisFileInfo['la']['version'];
    return true;
}
Example #6
0
function getVOCheaderFilepointer(&$fd, &$ThisFileInfo)
{
    $OriginalAVdataOffset = $ThisFileInfo['avdataoffset'];
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $VOCheader = fread($fd, 26);
    if (substr($VOCheader, 0, 19) != 'Creative Voice File') {
        $ThisFileInfo['error'] .= "\n" . 'Expecting "Creative Voice File" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . substr($VOCheader, 0, 19) . '"';
        return false;
    }
    $ThisFileInfo['fileformat'] = 'voc';
    $ThisFileInfo['audio']['dataformat'] = 'voc';
    $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
    $ThisFileInfo['audio']['channels'] = 1;
    // might be overriden below
    $ThisFileInfo['audio']['bits_per_sample'] = 8;
    // might be overriden below
    // byte #     Description
    // ------     ------------------------------------------
    // 00-12      'Creative Voice File'
    // 13         1A (eof to abort printing of file)
    // 14-15      Offset of first datablock in .voc file (std 1A 00 in Intel Notation)
    // 16-17      Version number (minor,major) (VOC-HDR puts 0A 01)
    // 18-19      2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
    $ThisFileInfo['voc']['header']['datablock_offset'] = LittleEndian2Int(substr($VOCheader, 20, 2));
    $ThisFileInfo['voc']['header']['minor_version'] = LittleEndian2Int(substr($VOCheader, 22, 1));
    $ThisFileInfo['voc']['header']['major_version'] = LittleEndian2Int(substr($VOCheader, 23, 1));
    do {
        $BlockOffset = ftell($fd);
        $BlockData = fread($fd, 4);
        $BlockType = LittleEndian2Int(substr($BlockData, 0, 1));
        $BlockSize = LittleEndian2Int(substr($BlockData, 1, 3));
        $ThisBlock = array();
        switch ($BlockType) {
            case 0:
                // Terminator
                // do nothing, we'll break out of the loop down below
                break;
            case 1:
                // Sound data
                $BlockData .= fread($fd, 2);
                if ($ThisFileInfo['avdataoffset'] <= $OriginalAVdataOffset) {
                    $ThisFileInfo['avdataoffset'] = ftell($fd);
                }
                fseek($fd, $BlockSize - 2, SEEK_CUR);
                $ThisBlock['sample_rate_id'] = LittleEndian2Int(substr($BlockData, 4, 1));
                $ThisBlock['compression_type'] = LittleEndian2Int(substr($BlockData, 5, 1));
                $ThisBlock['compression_name'] = VOCcompressionTypeLookup($ThisBlock['compression_type']);
                if ($ThisBlock['compression_type'] <= 3) {
                    $ThisFileInfo['voc']['compressed_bits_per_sample'] = CastAsInt(str_replace('-bit', '', $ThisBlock['compression_name']));
                }
                if (empty($ThisFileInfo['audio']['sample_rate'])) {
                    // Less accurate than the Extended block (#8) data
                    // SR byte = 256-(1000000/sample_rate)
                    $ThisFileInfo['audio']['sample_rate'] = trunc(1000000 / (256 - $ThisBlock['sample_rate_id']) / $ThisFileInfo['audio']['channels']);
                }
                break;
            case 2:
                // Sound continue
            // Sound continue
            case 3:
                // Silence
            // Silence
            case 4:
                // Marker
            // Marker
            case 6:
                // Repeat
            // Repeat
            case 7:
                // End repeat
                // nothing useful, just skip
                fseek($fd, $BlockSize, SEEK_CUR);
                break;
            case 8:
                // Extended
                $BlockData .= fread($fd, 4);
                //00-01  Time Constant:
                //   Mono: 65536 - (256000000 / sample_rate)
                // Stereo: 65536 - (256000000 / (sample_rate * 2))
                $ThisBlock['time_constant'] = LittleEndian2Int(substr($BlockData, 4, 2));
                $ThisBlock['pack_method'] = LittleEndian2Int(substr($BlockData, 6, 1));
                $ThisBlock['stereo'] = (bool) LittleEndian2Int(substr($BlockData, 7, 1));
                $ThisFileInfo['audio']['channels'] = $ThisBlock['stereo'] ? 2 : 1;
                $ThisFileInfo['audio']['sample_rate'] = trunc(256000000 / (65536 - $ThisBlock['time_constant']) / $ThisFileInfo['audio']['channels']);
                break;
            case 9:
                // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit
                $BlockData .= fread($fd, 12);
                if ($ThisFileInfo['avdataoffset'] <= $OriginalAVdataOffset) {
                    $ThisFileInfo['avdataoffset'] = ftell($fd);
                }
                fseek($fd, $BlockSize - 12, SEEK_CUR);
                $ThisBlock['sample_rate'] = LittleEndian2Int(substr($BlockData, 4, 4));
                $ThisBlock['bits_per_sample'] = LittleEndian2Int(substr($BlockData, 8, 1));
                $ThisBlock['channels'] = LittleEndian2Int(substr($BlockData, 9, 1));
                $ThisBlock['wFormat'] = LittleEndian2Int(substr($BlockData, 10, 2));
                $ThisBlock['compression_name'] = VOCwFormatLookup($ThisBlock['wFormat']);
                if (VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat'])) {
                    $ThisFileInfo['voc']['compressed_bits_per_sample'] = VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat']);
                }
                $ThisFileInfo['audio']['sample_rate'] = $ThisBlock['sample_rate'];
                $ThisFileInfo['audio']['bits_per_sample'] = $ThisBlock['bits_per_sample'];
                $ThisFileInfo['audio']['channels'] = $ThisBlock['channels'];
                break;
            default:
                $ThisFileInfo['warning'] .= "\n" . 'Unhandled block type "' . $BlockType . '" at offset ' . $BlockOffset;
                fseek($fd, $BlockSize, SEEK_CUR);
                break;
        }
        if (!empty($ThisBlock)) {
            $ThisBlock['block_offset'] = $BlockOffset;
            $ThisBlock['block_size'] = $BlockSize;
            $ThisBlock['block_type_id'] = $BlockType;
            $ThisFileInfo['voc']['blocks'][] = $ThisBlock;
        }
    } while (!feof($fd) && $BlockType != 0);
    // Terminator block doesn't have size field, so seek back 3 spaces
    fseek($fd, -3, SEEK_CUR);
    if (!empty($ThisFileInfo['voc']['compressed_bits_per_sample'])) {
        $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / ($ThisFileInfo['voc']['compressed_bits_per_sample'] * $ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate']);
        $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
    }
    return true;
}
Example #7
0
function getMPCHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    // http://www.uni-jena.de/~pfk/mpp/sv8/header.html
    $ThisFileInfo['fileformat'] = 'mpc';
    $ThisFileInfo['audio']['dataformat'] = 'mpc';
    $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
    $ThisFileInfo['audio']['channels'] = 2;
    // the format appears to be hardcoded for stereo only
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $ThisFileInfo['mpc']['header']['size'] = 30;
    $MPCheaderData = fread($fd, $ThisFileInfo['mpc']['header']['size']);
    $offset = 0;
    $ThisFileInfo['mpc']['header']['raw']['preamble'] = substr($MPCheaderData, $offset, 3);
    // should be 'MP+'
    $offset += 3;
    $StreamVersionByte = LittleEndian2Int(substr($MPCheaderData, $offset, 1));
    $offset += 1;
    $ThisFileInfo['mpc']['header']['stream_major_version'] = $StreamVersionByte & 0xf;
    $ThisFileInfo['mpc']['header']['stream_minor_version'] = ($StreamVersionByte & 0xf0) >> 4;
    $ThisFileInfo['mpc']['header']['frame_count'] = LittleEndian2Int(substr($MPCheaderData, $offset, 4));
    $offset += 4;
    switch ($ThisFileInfo['mpc']['header']['stream_major_version']) {
        case 7:
            //$ThisFileInfo['fileformat'] = 'SV7';
            break;
        default:
            $ThisFileInfo['error'] .= "\n" . 'Only MPEGplus/Musepack SV7 supported';
            return false;
    }
    $FlagsByte1 = LittleEndian2Int(substr($MPCheaderData, $offset, 4));
    $offset += 4;
    $ThisFileInfo['mpc']['header']['intensity_stereo'] = (bool) (($FlagsByte1 & 2147483648.0) >> 31);
    $ThisFileInfo['mpc']['header']['mid_side_stereo'] = (bool) (($FlagsByte1 & 0x40000000) >> 30);
    $ThisFileInfo['mpc']['header']['max_subband'] = ($FlagsByte1 & 0x3f000000) >> 24;
    $ThisFileInfo['mpc']['header']['raw']['profile'] = ($FlagsByte1 & 0xf00000) >> 20;
    $ThisFileInfo['mpc']['header']['begin_loud'] = (bool) (($FlagsByte1 & 0x80000) >> 19);
    $ThisFileInfo['mpc']['header']['end_loud'] = (bool) (($FlagsByte1 & 0x40000) >> 18);
    $ThisFileInfo['mpc']['header']['raw']['sample_rate'] = ($FlagsByte1 & 0x30000) >> 16;
    $ThisFileInfo['mpc']['header']['max_level'] = $FlagsByte1 & 0xffff;
    $ThisFileInfo['mpc']['header']['raw']['title_peak'] = LittleEndian2Int(substr($MPCheaderData, $offset, 2));
    $offset += 2;
    $ThisFileInfo['mpc']['header']['raw']['title_gain'] = LittleEndian2Int(substr($MPCheaderData, $offset, 2), true);
    $offset += 2;
    $ThisFileInfo['mpc']['header']['raw']['album_peak'] = LittleEndian2Int(substr($MPCheaderData, $offset, 2));
    $offset += 2;
    $ThisFileInfo['mpc']['header']['raw']['album_gain'] = LittleEndian2Int(substr($MPCheaderData, $offset, 2), true);
    $offset += 2;
    $FlagsByte2 = LittleEndian2Int(substr($MPCheaderData, $offset, 4));
    $offset += 4;
    $ThisFileInfo['mpc']['header']['true_gapless'] = (bool) (($FlagsByte2 & 2147483648.0) >> 31);
    $ThisFileInfo['mpc']['header']['last_frame_length'] = ($FlagsByte2 & 0x7ff00000) >> 20;
    $offset += 3;
    // unused?
    $ThisFileInfo['mpc']['header']['raw']['encoder_version'] = LittleEndian2Int(substr($MPCheaderData, $offset, 1));
    $offset += 1;
    $ThisFileInfo['mpc']['header']['profile'] = MPCprofileNameLookup($ThisFileInfo['mpc']['header']['raw']['profile']);
    $ThisFileInfo['mpc']['header']['sample_rate'] = MPCfrequencyLookup($ThisFileInfo['mpc']['header']['raw']['sample_rate']);
    if ($ThisFileInfo['mpc']['header']['sample_rate'] == 0) {
        $ThisFileInfo['error'] .= "\n" . 'Corrupt MPC file: frequency == zero';
        return false;
    }
    $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpc']['header']['sample_rate'];
    $ThisFileInfo['mpc']['header']['samples'] = (($ThisFileInfo['mpc']['header']['frame_count'] - 1) * 1152 + $ThisFileInfo['mpc']['header']['last_frame_length']) * $ThisFileInfo['audio']['channels'];
    $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['mpc']['header']['samples'] / $ThisFileInfo['audio']['channels'] / $ThisFileInfo['audio']['sample_rate'];
    if ($ThisFileInfo['playtime_seconds'] == 0) {
        $ThisFileInfo['error'] .= "\n" . 'Corrupt MPC file: playtime_seconds == zero';
        return false;
    }
    // add size of file header to avdataoffset - calc bitrate correctly + MD5 data
    $ThisFileInfo['avdataoffset'] += $ThisFileInfo['mpc']['header']['size'];
    $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
    $ThisFileInfo['mpc']['header']['title_peak'] = $ThisFileInfo['mpc']['header']['raw']['title_peak'];
    $ThisFileInfo['mpc']['header']['title_peak_db'] = MPCpeakDBLookup($ThisFileInfo['mpc']['header']['title_peak']);
    $ThisFileInfo['mpc']['header']['title_gain_db'] = $ThisFileInfo['mpc']['header']['raw']['title_gain'] / 100;
    $ThisFileInfo['mpc']['header']['album_peak'] = $ThisFileInfo['mpc']['header']['raw']['album_peak'];
    $ThisFileInfo['mpc']['header']['album_peak_db'] = MPCpeakDBLookup($ThisFileInfo['mpc']['header']['album_peak']);
    $ThisFileInfo['mpc']['header']['album_gain_db'] = $ThisFileInfo['mpc']['header']['raw']['album_gain'] / 100;
    $ThisFileInfo['mpc']['header']['encoder_version'] = MPCencoderVersionLookup($ThisFileInfo['mpc']['header']['raw']['encoder_version']);
    if ($ThisFileInfo['mpc']['header']['title_peak_db']) {
        $ThisFileInfo['replay_gain']['radio']['peak'] = $ThisFileInfo['mpc']['header']['title_peak'];
        $ThisFileInfo['replay_gain']['radio']['adjustment'] = $ThisFileInfo['mpc']['header']['title_gain_db'];
    } else {
        $ThisFileInfo['replay_gain']['radio']['peak'] = CastAsInt(round($ThisFileInfo['mpc']['header']['max_level'] * 1.18));
        // why? I don't know - see mppdec.c
        $ThisFileInfo['replay_gain']['radio']['adjustment'] = 0;
    }
    if ($ThisFileInfo['mpc']['header']['album_peak_db']) {
        $ThisFileInfo['replay_gain']['audiophile']['peak'] = $ThisFileInfo['mpc']['header']['album_peak'];
        $ThisFileInfo['replay_gain']['audiophile']['adjustment'] = $ThisFileInfo['mpc']['header']['album_gain_db'];
    }
    $ThisFileInfo['audio']['encoder'] = $ThisFileInfo['mpc']['header']['encoder_version'] . ', SV' . $ThisFileInfo['mpc']['header']['stream_major_version'] . '.' . $ThisFileInfo['mpc']['header']['stream_minor_version'];
    return true;
}
Example #8
0
function parseAPEheaderFooter($APEheaderFooterData)
{
    // http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html
    $headerfooterinfo['raw']['footer_tag'] = substr($APEheaderFooterData, 0, 8);
    $headerfooterinfo['raw']['version'] = LittleEndian2Int(substr($APEheaderFooterData, 8, 4));
    $headerfooterinfo['raw']['tagsize'] = LittleEndian2Int(substr($APEheaderFooterData, 12, 4));
    $headerfooterinfo['raw']['tag_items'] = LittleEndian2Int(substr($APEheaderFooterData, 16, 4));
    $headerfooterinfo['raw']['global_flags'] = LittleEndian2Int(substr($APEheaderFooterData, 20, 4));
    $headerfooterinfo['raw']['reserved'] = substr($APEheaderFooterData, 24, 8);
    $headerfooterinfo['tag_version'] = $headerfooterinfo['raw']['version'] / 1000;
    if ($headerfooterinfo['tag_version'] >= 2) {
        $headerfooterinfo['flags'] = parseAPEtagFlags($headerfooterinfo['raw']['global_flags']);
    }
    return $headerfooterinfo;
}
Example #9
0
function ZIPparseEndOfCentralDirectory(&$fd)
{
    $EndOfCentralDirectory['offset'] = ftell($fd);
    $ZIPendOfCentralDirectory = fread($fd, 22);
    $EndOfCentralDirectory['signature'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
    if ($EndOfCentralDirectory['signature'] != 0x6054b50) {
        // invalid End Of Central Directory Signature
        fseek($fd, $EndOfCentralDirectory['offset'], SEEK_SET);
        // seek back to where filepointer originally was so it can be handled properly
        return false;
    }
    $EndOfCentralDirectory['disk_number_current'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
    $EndOfCentralDirectory['disk_number_start_directory'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
    $EndOfCentralDirectory['directory_entries_this_disk'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
    $EndOfCentralDirectory['directory_entries_total'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
    $EndOfCentralDirectory['directory_size'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
    $EndOfCentralDirectory['directory_offset'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
    $EndOfCentralDirectory['comment_length'] = LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
    if ($EndOfCentralDirectory['comment_length'] > 0) {
        $EndOfCentralDirectory['comment'] = fread($fd, $EndOfCentralDirectory['comment_length']);
    }
    return $EndOfCentralDirectory;
}
function getOggHeaderFilepointer(&$fd, &$MP3fileInfo)
{
    if (!$fd) {
        $MP3fileInfo['error'] = "\n" . 'Could not open file';
        return FALSE;
    } else {
        // Page 1 - Stream Header
        rewind($fd);
        $MP3fileInfo['ogg']['pageheader'][0] = ParseOggPageHeader($fd);
        if (ftell($fd) >= 10000) {
            $MP3fileInfo['error'] = "\n" . 'Could not find start of Ogg page in the first 10,000 bytes (this might not be an Ogg-Vorbis file?)';
            unset($MP3fileInfo['fileformat']);
            unset($MP3fileInfo['ogg']);
            return FALSE;
        }
        $filedata = fread($fd, 23);
        $filedataoffset = 0;
        $MP3fileInfo['ogg']['bitstreamversion'] = LittleEndian2Int(substr($filedata, 0, 4));
        $MP3fileInfo['ogg']['numberofchannels'] = LittleEndian2Int(substr($filedata, 4, 1));
        $MP3fileInfo['ogg']['samplerate'] = LittleEndian2Int(substr($filedata, 5, 4));
        $MP3fileInfo['ogg']['samples'] = 0;
        // filled in later
        $MP3fileInfo['ogg']['bitrate_average'] = 0;
        // filled in later
        if (substr($filedata, 9, 4) !== chr(0xff) . chr(0xff) . chr(0xff) . chr(0xff)) {
            $MP3fileInfo['ogg']['bitrate_max'] = LittleEndian2Int(substr($filedata, 9, 4));
        }
        if (substr($filedata, 13, 4) !== chr(0xff) . chr(0xff) . chr(0xff) . chr(0xff)) {
            $MP3fileInfo['ogg']['bitrate_nominal'] = LittleEndian2Int(substr($filedata, 13, 4));
        }
        if (substr($filedata, 17, 4) !== chr(0xff) . chr(0xff) . chr(0xff) . chr(0xff)) {
            $MP3fileInfo['ogg']['bitrate_min'] = LittleEndian2Int(substr($filedata, 17, 4));
        }
        $MP3fileInfo['ogg']['blocksize_small'] = pow(2, LittleEndian2Int(substr($filedata, 21, 1)) & 0xf);
        $MP3fileInfo['ogg']['blocksize_large'] = pow(2, (LittleEndian2Int(substr($filedata, 21, 1)) & 0xf0) >> 4);
        $MP3fileInfo['ogg']['stop_bit'] = ord(substr($filedata, 22, 1));
        // must be 1, marks end of packet
        // Page 2 - Comment Header
        $MP3fileInfo['ogg']['pageheader'][1] = ParseOggPageHeader($fd);
        $filedata = fread($fd, FREAD_BUFFER_SIZE);
        $filedataoffset = 0;
        $vendorsize = LittleEndian2Int(substr($filedata, $filedataoffset, 4));
        $filedataoffset += 4;
        $MP3fileInfo['ogg']['vendor'] = substr($filedata, $filedataoffset, $vendorsize);
        $filedataoffset += $vendorsize;
        $basicfields = array('TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT');
        $totalcomments = LittleEndian2Int(substr($filedata, $filedataoffset, 4));
        $filedataoffset += 4;
        for ($i = 0; $i < $totalcomments; $i++) {
            $commentsize = LittleEndian2Int(substr($filedata, $filedataoffset, 4));
            $filedataoffset += 4;
            $commentstring = substr($filedata, $filedataoffset, $commentsize);
            $filedataoffset += $commentsize;
            $commentexploded = explode('=', $commentstring, 2);
            $MP3fileInfo['ogg']['comments']["{$i}"]['key'] = strtoupper($commentexploded[0]);
            $MP3fileInfo['ogg']['comments']["{$i}"]['value'] = $commentexploded[1] ? $commentexploded[1] : '';
            if (in_array($MP3fileInfo['ogg']['comments']["{$i}"]['key'], $basicfields)) {
                $MP3fileInfo['ogg'][strtolower($MP3fileInfo['ogg']['comments']["{$i}"]['key'])] = $MP3fileInfo['ogg']['comments']["{$i}"]['value'];
            }
        }
        $MP3fileInfo['ogg']['comments_offset_end'] = $filedataoffset;
        // Last Page - Number of Samples
        fseek($fd, max($MP3fileInfo['filesize'] - FREAD_BUFFER_SIZE, 0), SEEK_SET);
        $LastChunkOfOgg = strrev(fread($fd, FREAD_BUFFER_SIZE));
        if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) {
            fseek($fd, 0 - ($LastOggSpostion + strlen('SggO')), SEEK_END);
            $MP3fileInfo['ogg']['pageheader']['eos'] = ParseOggPageHeader($fd);
            $MP3fileInfo['ogg']['samples'] = $MP3fileInfo['ogg']['pageheader']['eos']['pcm_abs_position'];
            $MP3fileInfo['ogg']['bitrate_average'] = $MP3fileInfo['filesize'] * 8 / ($MP3fileInfo['ogg']['samples'] / $MP3fileInfo['ogg']['samplerate']);
        }
        if (isset($MP3fileInfo['ogg']['bitrate_average']) && $MP3fileInfo['ogg']['bitrate_average'] > 0) {
            $MP3fileInfo['bitrate'] = $MP3fileInfo['ogg']['bitrate_average'];
        } else {
            if (isset($MP3fileInfo['ogg']['bitrate_nominal']) && $MP3fileInfo['ogg']['bitrate_nominal'] > 0) {
                $MP3fileInfo['bitrate'] = $MP3fileInfo['ogg']['bitrate_nominal'];
            } else {
                if (isset($MP3fileInfo['ogg']['bitrate_min']) && isset($MP3fileInfo['ogg']['bitrate_max'])) {
                    $MP3fileInfo['bitrate'] = ($MP3fileInfo['ogg']['bitrate_min'] + $MP3fileInfo['ogg']['bitrate_max']) / 2;
                }
            }
        }
        if (isset($MP3fileInfo['bitrate']) && !isset($MP3fileInfo['playtime_seconds'])) {
            $MP3fileInfo['playtime_seconds'] = (double) ($MP3fileInfo['filesize'] * 8 / $MP3fileInfo['bitrate']);
        }
    }
    return TRUE;
}
function ParseOptimFROGheader45(&$fd, &$ThisFileInfo)
{
    // for fileformat of v4.50a and higher
    $RIFFdata = '';
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    while (!feof($fd) && ftell($fd) < $ThisFileInfo['avdataend']) {
        $BlockOffset = ftell($fd);
        $BlockData = fread($fd, 8);
        $offset = 8;
        $BlockName = substr($BlockData, 0, 4);
        $BlockSize = LittleEndian2Int(substr($BlockData, 4, 4));
        switch ($BlockName) {
            case 'OFR ':
                $ThisFileInfo['OFR']["{$BlockName}"]['offset'] = $BlockOffset;
                $ThisFileInfo['OFR']["{$BlockName}"]['size'] = $BlockSize;
                $ThisFileInfo['audio']['encoder'] = 'OptimFROG 4.50 alpha';
                switch ($BlockSize) {
                    case 12:
                    case 15:
                        // good
                        break;
                    default:
                        $ThisFileInfo['warning'] .= "\n" . '"' . $BlockName . '" contains more data than expected (expected 12 or 15 bytes, found ' . $BlockSize . ' bytes)';
                        break;
                }
                $BlockData .= fread($fd, $BlockSize);
                $ThisFileInfo['OFR']["{$BlockName}"]['total_samples'] = LittleEndian2Int(substr($BlockData, $offset, 6));
                $offset += 6;
                $ThisFileInfo['OFR']["{$BlockName}"]['raw']['sample_type'] = LittleEndian2Int(substr($BlockData, $offset, 1));
                $ThisFileInfo['OFR']["{$BlockName}"]['sample_type'] = OptimFROGsampleTypeLookup($ThisFileInfo['OFR']["{$BlockName}"]['raw']['sample_type']);
                $offset += 1;
                $ThisFileInfo['OFR']["{$BlockName}"]['channel_config'] = LittleEndian2Int(substr($BlockData, $offset, 1));
                $ThisFileInfo['OFR']["{$BlockName}"]['channels'] = $ThisFileInfo['OFR']["{$BlockName}"]['channel_config'];
                $offset += 1;
                $ThisFileInfo['OFR']["{$BlockName}"]['sample_rate'] = LittleEndian2Int(substr($BlockData, $offset, 4));
                $offset += 4;
                if ($BlockSize > 12) {
                    // OFR 4.504b or higher
                    $ThisFileInfo['OFR']["{$BlockName}"]['channels'] = OptimFROGchannelConfigNumChannelsLookup($ThisFileInfo['OFR']["{$BlockName}"]['channel_config']);
                    $ThisFileInfo['OFR']["{$BlockName}"]['raw']['encoder_id'] = LittleEndian2Int(substr($BlockData, $offset, 2));
                    $ThisFileInfo['OFR']["{$BlockName}"]['encoder'] = OptimFROGencoderNameLookup($ThisFileInfo['OFR']["{$BlockName}"]['raw']['encoder_id']);
                    $offset += 2;
                    $ThisFileInfo['OFR']["{$BlockName}"]['raw']['compression'] = LittleEndian2Int(substr($BlockData, $offset, 1));
                    $ThisFileInfo['OFR']["{$BlockName}"]['compression'] = OptimFROGcompressionLookup($ThisFileInfo['OFR']["{$BlockName}"]['raw']['compression']);
                    $offset += 1;
                    $ThisFileInfo['audio']['encoder'] = 'OptimFROG ' . $ThisFileInfo['OFR']["{$BlockName}"]['encoder'];
                }
                $ThisFileInfo['audio']['channels'] = $ThisFileInfo['OFR']["{$BlockName}"]['channels'];
                $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['OFR']["{$BlockName}"]['sample_rate'];
                $ThisFileInfo['audio']['bits_per_sample'] = OptimFROGbitsPerSampleTypeLookup($ThisFileInfo['OFR']["{$BlockName}"]['raw']['sample_type']);
                break;
            case 'COMP':
                // unlike other block types, there CAN be multiple COMP blocks
                $COMPdata['offset'] = $BlockOffset;
                $COMPdata['size'] = $BlockSize;
                if ($ThisFileInfo['avdataoffset'] == 0) {
                    $ThisFileInfo['avdataoffset'] = $BlockOffset;
                }
                // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data
                $BlockData .= fread($fd, 14);
                fseek($fd, $BlockSize - 14, SEEK_CUR);
                $COMPdata['crc_32'] = LittleEndian2Int(substr($BlockData, $offset, 4));
                $offset += 4;
                $COMPdata['sample_count'] = LittleEndian2Int(substr($BlockData, $offset, 4));
                $offset += 4;
                $COMPdata['raw']['sample_type'] = LittleEndian2Int(substr($BlockData, $offset, 1));
                $COMPdata['sample_type'] = OptimFROGsampleTypeLookup($COMPdata['raw']['sample_type']);
                $offset += 1;
                $COMPdata['raw']['channel_configuration'] = LittleEndian2Int(substr($BlockData, $offset, 1));
                $COMPdata['channel_configuration'] = OptimFROGchannelConfigurationLookup($COMPdata['raw']['channel_configuration']);
                $offset += 1;
                $COMPdata['raw']['algorithm_id'] = LittleEndian2Int(substr($BlockData, $offset, 2));
                //$COMPdata['algorithm']                    = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']);
                $offset += 2;
                if ($ThisFileInfo['OFR']['OFR ']['size'] > 12) {
                    // OFR 4.504b or higher
                    $COMPdata['raw']['encoder_id'] = LittleEndian2Int(substr($BlockData, $offset, 2));
                    $COMPdata['encoder'] = OptimFROGencoderNameLookup($COMPdata['raw']['encoder_id']);
                    $offset += 2;
                }
                if ($COMPdata['crc_32'] == 0x454e4f4e) {
                    // ASCII value of 'NONE' - placeholder value in v4.50a
                    $COMPdata['crc_32'] = false;
                }
                $ThisFileInfo['OFR']["{$BlockName}"][] = $COMPdata;
                break;
            case 'HEAD':
                $ThisFileInfo['OFR']["{$BlockName}"]['offset'] = $BlockOffset;
                $ThisFileInfo['OFR']["{$BlockName}"]['size'] = $BlockSize;
                $RIFFdata .= fread($fd, $BlockSize);
                break;
            case 'TAIL':
                $ThisFileInfo['OFR']["{$BlockName}"]['offset'] = $BlockOffset;
                $ThisFileInfo['OFR']["{$BlockName}"]['size'] = $BlockSize;
                $ThisFileInfo['avdataend'] = $BlockOffset;
                $RIFFdata .= fread($fd, $BlockSize);
                break;
            case 'RECV':
                // block contains no useful meta data - simply note and skip
                $ThisFileInfo['OFR']["{$BlockName}"]['offset'] = $BlockOffset;
                $ThisFileInfo['OFR']["{$BlockName}"]['size'] = $BlockSize;
                fseek($fd, $BlockSize, SEEK_CUR);
                break;
            default:
                $ThisFileInfo['OFR']["{$BlockName}"]['offset'] = $BlockOffset;
                $ThisFileInfo['OFR']["{$BlockName}"]['size'] = $BlockSize;
                $ThisFileInfo['warning'] .= "\n" . 'Unhandled OptimFROG block type "' . $BlockName . '" at offset ' . $ThisFileInfo['OFR']["{$BlockName}"]['offset'];
                fseek($fd, $BlockSize, SEEK_CUR);
                break;
        }
    }
    $ThisFileInfo['playtime_seconds'] = (double) $ThisFileInfo['OFR']['OFR ']['total_samples'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate']);
    $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
    require_once GETID3_INCLUDEPATH . 'getid3.riff.php';
    // 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);
    return true;
}
Example #12
0
function ParseDirectoryRecord(&$fd, $directorydata, &$ThisFileInfo)
{
    if (isset($ThisFileInfo['iso']['supplementary_volume_descriptor'])) {
        $TextEncoding = 255;
        // Big-Endian Unicode
    } else {
        $TextEncoding = 0;
        // ASCII
    }
    fseek($fd, $directorydata['location_bytes'], SEEK_SET);
    $DirectoryRecordData = fread($fd, 1);
    while (ord($DirectoryRecordData[0]) > 33) {
        $DirectoryRecordData .= fread($fd, ord($DirectoryRecordData[0]) - 1);
        $ThisDirectoryRecord['raw']['length'] = LittleEndian2Int(substr($DirectoryRecordData, 0, 1));
        $ThisDirectoryRecord['raw']['extended_attribute_length'] = LittleEndian2Int(substr($DirectoryRecordData, 1, 1));
        $ThisDirectoryRecord['raw']['offset_logical'] = LittleEndian2Int(substr($DirectoryRecordData, 2, 4));
        $ThisDirectoryRecord['raw']['filesize'] = LittleEndian2Int(substr($DirectoryRecordData, 10, 4));
        $ThisDirectoryRecord['raw']['recording_date_time'] = substr($DirectoryRecordData, 18, 7);
        $ThisDirectoryRecord['raw']['file_flags'] = LittleEndian2Int(substr($DirectoryRecordData, 25, 1));
        $ThisDirectoryRecord['raw']['file_unit_size'] = LittleEndian2Int(substr($DirectoryRecordData, 26, 1));
        $ThisDirectoryRecord['raw']['interleave_gap_size'] = LittleEndian2Int(substr($DirectoryRecordData, 27, 1));
        $ThisDirectoryRecord['raw']['volume_sequence_number'] = LittleEndian2Int(substr($DirectoryRecordData, 28, 2));
        $ThisDirectoryRecord['raw']['file_identifier_length'] = LittleEndian2Int(substr($DirectoryRecordData, 32, 1));
        $ThisDirectoryRecord['raw']['file_identifier'] = substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']);
        $ThisDirectoryRecord['file_identifier_ascii'] = RoughTranslateUnicodeToASCII($ThisDirectoryRecord['raw']['file_identifier'], $TextEncoding);
        $ThisDirectoryRecord['filesize'] = $ThisDirectoryRecord['raw']['filesize'];
        $ThisDirectoryRecord['offset_bytes'] = $ThisDirectoryRecord['raw']['offset_logical'] * 2048;
        $ThisDirectoryRecord['file_flags']['hidden'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x1);
        $ThisDirectoryRecord['file_flags']['directory'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x2);
        $ThisDirectoryRecord['file_flags']['associated'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x4);
        $ThisDirectoryRecord['file_flags']['extended'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x8);
        $ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10);
        $ThisDirectoryRecord['file_flags']['multiple'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80);
        $ThisDirectoryRecord['recording_timestamp'] = ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']);
        if ($ThisDirectoryRecord['file_flags']['directory']) {
            $ThisDirectoryRecord['filename'] = $directorydata['full_path'];
        } else {
            $ThisDirectoryRecord['filename'] = $directorydata['full_path'] . ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']);
            $ThisFileInfo['iso']['files'] = array_merge_clobber($ThisFileInfo['iso']['files'], CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize']));
        }
        $DirectoryRecord[] = $ThisDirectoryRecord;
        $DirectoryRecordData = fread($fd, 1);
    }
    return $DirectoryRecord;
}
function getMonkeysAudioHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    // based loosely on code from TMonkey by Jurgen Faul
    // jfaul@gmx.de     http://jfaul.de/atl
    $ThisFileInfo['fileformat'] = 'mac';
    $ThisFileInfo['audio']['dataformat'] = 'mac';
    $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $MACheaderData = fread($fd, 40);
    $ThisFileInfo['monkeys_audio']['raw']['header_tag'] = substr($MACheaderData, 0, 4);
    $ThisFileInfo['monkeys_audio']['raw']['nVersion'] = LittleEndian2Int(substr($MACheaderData, 4, 2));
    $ThisFileInfo['monkeys_audio']['raw']['nCompressionLevel'] = LittleEndian2Int(substr($MACheaderData, 6, 2));
    $ThisFileInfo['monkeys_audio']['raw']['nFormatFlags'] = LittleEndian2Int(substr($MACheaderData, 8, 2));
    $ThisFileInfo['monkeys_audio']['raw']['nChannels'] = LittleEndian2Int(substr($MACheaderData, 10, 2));
    $ThisFileInfo['monkeys_audio']['raw']['nSampleRate'] = LittleEndian2Int(substr($MACheaderData, 12, 4));
    $ThisFileInfo['monkeys_audio']['raw']['nWAVHeaderBytes'] = LittleEndian2Int(substr($MACheaderData, 16, 4));
    $ThisFileInfo['monkeys_audio']['raw']['nWAVTerminatingBytes'] = LittleEndian2Int(substr($MACheaderData, 20, 4));
    $ThisFileInfo['monkeys_audio']['raw']['nTotalFrames'] = LittleEndian2Int(substr($MACheaderData, 24, 4));
    $ThisFileInfo['monkeys_audio']['raw']['nFinalFrameSamples'] = LittleEndian2Int(substr($MACheaderData, 28, 4));
    $ThisFileInfo['monkeys_audio']['raw']['nPeakLevel'] = LittleEndian2Int(substr($MACheaderData, 32, 4));
    $ThisFileInfo['monkeys_audio']['raw']['nSeekElements'] = LittleEndian2Int(substr($MACheaderData, 38, 2));
    $ThisFileInfo['monkeys_audio']['flags']['8-bit'] = (bool) ($ThisFileInfo['monkeys_audio']['raw']['nFormatFlags'] & 0x1);
    $ThisFileInfo['monkeys_audio']['flags']['crc-32'] = (bool) ($ThisFileInfo['monkeys_audio']['raw']['nFormatFlags'] & 0x2);
    $ThisFileInfo['monkeys_audio']['flags']['peak_level'] = (bool) ($ThisFileInfo['monkeys_audio']['raw']['nFormatFlags'] & 0x4);
    $ThisFileInfo['monkeys_audio']['flags']['24-bit'] = (bool) ($ThisFileInfo['monkeys_audio']['raw']['nFormatFlags'] & 0x8);
    $ThisFileInfo['monkeys_audio']['flags']['seek_elements'] = (bool) ($ThisFileInfo['monkeys_audio']['raw']['nFormatFlags'] & 0x10);
    $ThisFileInfo['monkeys_audio']['flags']['no_wav_header'] = (bool) ($ThisFileInfo['monkeys_audio']['raw']['nFormatFlags'] & 0x20);
    $ThisFileInfo['monkeys_audio']['version'] = $ThisFileInfo['monkeys_audio']['raw']['nVersion'] / 1000;
    $ThisFileInfo['monkeys_audio']['compression'] = MonkeyCompressionLevelNameLookup($ThisFileInfo['monkeys_audio']['raw']['nCompressionLevel']);
    $ThisFileInfo['monkeys_audio']['samples_per_frame'] = MonkeySamplesPerFrame($ThisFileInfo['monkeys_audio']['raw']['nVersion'], $ThisFileInfo['monkeys_audio']['raw']['nCompressionLevel']);
    $ThisFileInfo['monkeys_audio']['bits_per_sample'] = $ThisFileInfo['monkeys_audio']['flags']['24-bit'] ? 24 : ($ThisFileInfo['monkeys_audio']['flags']['8-bit'] ? 8 : 16);
    if ($ThisFileInfo['monkeys_audio']['bits_per_sample'] == 0) {
        $ThisFileInfo['error'] .= "\n" . 'Corrupt MAC file: bits_per_sample == zero';
        return false;
    }
    $ThisFileInfo['monkeys_audio']['channels'] = $ThisFileInfo['monkeys_audio']['raw']['nChannels'];
    $ThisFileInfo['audio']['channels'] = $ThisFileInfo['monkeys_audio']['channels'];
    $ThisFileInfo['monkeys_audio']['sample_rate'] = $ThisFileInfo['monkeys_audio']['raw']['nSampleRate'];
    if ($ThisFileInfo['monkeys_audio']['sample_rate'] == 0) {
        $ThisFileInfo['error'] .= "\n" . 'Corrupt MAC file: frequency == zero';
        return false;
    }
    $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['monkeys_audio']['sample_rate'];
    $ThisFileInfo['monkeys_audio']['peak_level'] = $ThisFileInfo['monkeys_audio']['raw']['nPeakLevel'];
    $ThisFileInfo['monkeys_audio']['peak_ratio'] = $ThisFileInfo['monkeys_audio']['peak_level'] / pow(2, $ThisFileInfo['monkeys_audio']['bits_per_sample'] - 1);
    $ThisFileInfo['monkeys_audio']['frames'] = $ThisFileInfo['monkeys_audio']['raw']['nTotalFrames'];
    $ThisFileInfo['monkeys_audio']['samples'] = ($ThisFileInfo['monkeys_audio']['frames'] - 1) * $ThisFileInfo['monkeys_audio']['samples_per_frame'] + $ThisFileInfo['monkeys_audio']['raw']['nFinalFrameSamples'];
    $ThisFileInfo['monkeys_audio']['playtime'] = $ThisFileInfo['monkeys_audio']['samples'] / $ThisFileInfo['monkeys_audio']['sample_rate'];
    if ($ThisFileInfo['monkeys_audio']['playtime'] == 0) {
        $ThisFileInfo['error'] .= "\n" . 'Corrupt MAC file: playtime == zero';
        return false;
    }
    $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['monkeys_audio']['playtime'];
    $ThisFileInfo['monkeys_audio']['compressed_size'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'];
    $ThisFileInfo['monkeys_audio']['uncompressed_size'] = $ThisFileInfo['monkeys_audio']['samples'] * $ThisFileInfo['monkeys_audio']['channels'] * ($ThisFileInfo['monkeys_audio']['bits_per_sample'] / 8);
    if ($ThisFileInfo['monkeys_audio']['uncompressed_size'] == 0) {
        $ThisFileInfo['error'] .= "\n" . 'Corrupt MAC file: uncompressed_size == zero';
        return false;
    }
    $ThisFileInfo['monkeys_audio']['compression_ratio'] = $ThisFileInfo['monkeys_audio']['compressed_size'] / ($ThisFileInfo['monkeys_audio']['uncompressed_size'] + $ThisFileInfo['monkeys_audio']['raw']['nWAVHeaderBytes']);
    $ThisFileInfo['monkeys_audio']['bitrate'] = $ThisFileInfo['monkeys_audio']['samples'] * $ThisFileInfo['monkeys_audio']['channels'] * $ThisFileInfo['monkeys_audio']['bits_per_sample'] / $ThisFileInfo['monkeys_audio']['playtime'] * $ThisFileInfo['monkeys_audio']['compression_ratio'];
    $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['monkeys_audio']['bitrate'];
    // add size of MAC header to avdataoffset - MD5data
    $ThisFileInfo['avdataoffset'] += 40;
    $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['monkeys_audio']['bits_per_sample'];
    $ThisFileInfo['audio']['encoder'] = 'MAC v' . number_format($ThisFileInfo['monkeys_audio']['version'], 2);
    return true;
}
function getRIFFHeaderFilepointer(&$fd, &$MP3fileInfo)
{
    $offset = 0;
    rewind($fd);
    $MP3fileInfo['RIFF'] = ParseRIFF($fd, $offset, $MP3fileInfo['filesize']);
    $streamindex = 0;
    if (!is_array($MP3fileInfo['RIFF'])) {
        $MP3fileInfo['error'] .= "\n" . 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?)';
        unset($MP3fileInfo['RIFF']);
        unset($MP3fileInfo['fileformat']);
        return FALSE;
    }
    $arraykeys = array_keys($MP3fileInfo['RIFF']);
    switch ($arraykeys[0]) {
        case 'WAVE':
            $MP3fileInfo['fileformat'] = 'wav';
            if (isset($MP3fileInfo['RIFF']['WAVE']['fmt '][0]['data'])) {
                $fmtData = $MP3fileInfo['RIFF']['WAVE']['fmt '][0]['data'];
                $MP3fileInfo['RIFF']['raw']['fmt ']['wFormatTag'] = LittleEndian2Int(substr($fmtData, 0, 2));
                $MP3fileInfo['RIFF']['raw']['fmt ']['nChannels'] = LittleEndian2Int(substr($fmtData, 2, 2));
                $MP3fileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'] = LittleEndian2Int(substr($fmtData, 4, 4));
                $MP3fileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec'] = LittleEndian2Int(substr($fmtData, 8, 4));
                $MP3fileInfo['RIFF']['raw']['fmt ']['nBlockAlign'] = LittleEndian2Int(substr($fmtData, 12, 2));
                $MP3fileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'] = LittleEndian2Int(substr($fmtData, 14, 2));
                $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['format'] = RIFFwFormatTagLookup($MP3fileInfo['RIFF']['raw']['fmt ']['wFormatTag']);
                $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['channels'] = $MP3fileInfo['RIFF']['raw']['fmt ']['nChannels'];
                $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['channelmode'] = $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['channels'] == 1 ? 'mono' : 'stereo';
                $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['frequency'] = $MP3fileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'];
                $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['bitrate'] = $MP3fileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec'] * 8;
                $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['bitspersample'] = $MP3fileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'];
            }
            if (isset($MP3fileInfo['RIFF']['WAVE']['rgad'][0]['data'])) {
                $rgadData = $MP3fileInfo['RIFF']['WAVE']['rgad'][0]['data'];
                $MP3fileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'] = LittleEndian2Float(substr($rgadData, 0, 4));
                $MP3fileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust'] = LittleEndian2Int(substr($rgadData, 4, 2));
                $MP3fileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust'] = LittleEndian2Int(substr($rgadData, 6, 2));
                $nRadioRgAdjustBitstring = str_pad(Dec2Bin($MP3fileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
                $nAudiophileRgAdjustBitstring = str_pad(Dec2Bin($MP3fileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
                $MP3fileInfo['RIFF']['raw']['rgad']['radio']['name'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
                $MP3fileInfo['RIFF']['raw']['rgad']['radio']['originator'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
                $MP3fileInfo['RIFF']['raw']['rgad']['radio']['signbit'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
                $MP3fileInfo['RIFF']['raw']['rgad']['radio']['adjustment'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
                $MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['name'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
                $MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
                $MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['signbit'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
                $MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
                $MP3fileInfo['RIFF']['rgad']['peakamplitude'] = $MP3fileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'];
                if ($MP3fileInfo['RIFF']['raw']['rgad']['radio']['name'] != 0 && $MP3fileInfo['RIFF']['raw']['rgad']['radio']['originator'] != 0) {
                    $MP3fileInfo['RIFF']['rgad']['radio']['name'] = RGADnameLookup($MP3fileInfo['RIFF']['raw']['rgad']['radio']['name']);
                    $MP3fileInfo['RIFF']['rgad']['radio']['originator'] = RGADoriginatorLookup($MP3fileInfo['RIFF']['raw']['rgad']['radio']['originator']);
                    $MP3fileInfo['RIFF']['rgad']['radio']['adjustment'] = RGADadjustmentLookup($MP3fileInfo['RIFF']['raw']['rgad']['radio']['adjustment'], $MP3fileInfo['RIFF']['raw']['rgad']['radio']['signbit']);
                }
                if ($MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['name'] != 0 && $MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] != 0) {
                    $MP3fileInfo['RIFF']['rgad']['audiophile']['name'] = RGADnameLookup($MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['name']);
                    $MP3fileInfo['RIFF']['rgad']['audiophile']['originator'] = RGADoriginatorLookup($MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['originator']);
                    $MP3fileInfo['RIFF']['rgad']['audiophile']['adjustment'] = RGADadjustmentLookup($MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'], $MP3fileInfo['RIFF']['raw']['rgad']['audiophile']['signbit']);
                }
            }
            if (isset($MP3fileInfo['RIFF']['WAVE']['fact'][0]['data'])) {
                $MP3fileInfo['RIFF']['raw']['fact']['NumberOfSamples'] = LittleEndian2Int(substr($MP3fileInfo['RIFF']['WAVE']['fact'][0]['data'], 0, 4));
                if (isset($MP3fileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']) && $MP3fileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']) {
                    $MP3fileInfo['playtime_seconds'] = (double) $MP3fileInfo['RIFF']['raw']['fact']['NumberOfSamples'] / $MP3fileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'];
                }
                if (isset($MP3fileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) && $MP3fileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) {
                    $MP3fileInfo['audiobytes'] = CastAsInt(round($MP3fileInfo['playtime_seconds'] * $MP3fileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']));
                    $MP3fileInfo['bitrate'] = CastAsInt($MP3fileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec'] * 8);
                }
            }
            if (!isset($MP3fileInfo['audiobytes']) && isset($MP3fileInfo['RIFF']['WAVE']['data'][0]['size'])) {
                $MP3fileInfo['audiobytes'] = $MP3fileInfo['RIFF']['WAVE']['data'][0]['size'];
            }
            if (!isset($MP3fileInfo['bitrate']) && isset($MP3fileInfo['RIFF']['audio']["{$streamindex}"]['bitrate']) && isset($MP3fileInfo['audiobytes'])) {
                $MP3fileInfo['bitrate'] = $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['bitrate'];
                $MP3fileInfo['playtime_seconds'] = (double) ($MP3fileInfo['audiobytes'] * 8 / $MP3fileInfo['bitrate']);
            }
            break;
        case 'AVI ':
            $MP3fileInfo['fileformat'] = 'avi';
            if (isset($MP3fileInfo['RIFF']['AVI ']['hdrl']['avih']["{$streamindex}"]['data'])) {
                $avihData = $MP3fileInfo['RIFF']['AVI ']['hdrl']['avih']["{$streamindex}"]['data'];
                $MP3fileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] = LittleEndian2Int(substr($avihData, 0, 4));
                // frame display rate (or 0L)
                $MP3fileInfo['RIFF']['raw']['avih']['dwMaxBytesPerSec'] = LittleEndian2Int(substr($avihData, 4, 4));
                // max. transfer rate
                $MP3fileInfo['RIFF']['raw']['avih']['dwPaddingGranularity'] = LittleEndian2Int(substr($avihData, 8, 4));
                // pad to multiples of this size; normally 2K.
                $MP3fileInfo['RIFF']['raw']['avih']['dwFlags'] = LittleEndian2Int(substr($avihData, 12, 4));
                // the ever-present flags
                $MP3fileInfo['RIFF']['raw']['avih']['dwTotalFrames'] = LittleEndian2Int(substr($avihData, 16, 4));
                // # frames in file
                $MP3fileInfo['RIFF']['raw']['avih']['dwInitialFrames'] = LittleEndian2Int(substr($avihData, 20, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwStreams'] = LittleEndian2Int(substr($avihData, 24, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwSuggestedBufferSize'] = LittleEndian2Int(substr($avihData, 28, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwWidth'] = LittleEndian2Int(substr($avihData, 32, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwHeight'] = LittleEndian2Int(substr($avihData, 36, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwScale'] = LittleEndian2Int(substr($avihData, 40, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwRate'] = LittleEndian2Int(substr($avihData, 44, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwStart'] = LittleEndian2Int(substr($avihData, 48, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['dwLength'] = LittleEndian2Int(substr($avihData, 52, 4));
                $MP3fileInfo['RIFF']['raw']['avih']['flags']['hasindex'] = (bool) ($MP3fileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10);
                $MP3fileInfo['RIFF']['raw']['avih']['flags']['mustuseindex'] = (bool) ($MP3fileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20);
                $MP3fileInfo['RIFF']['raw']['avih']['flags']['interleaved'] = (bool) ($MP3fileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x100);
                $MP3fileInfo['RIFF']['raw']['avih']['flags']['trustcktype'] = (bool) ($MP3fileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x800);
                $MP3fileInfo['RIFF']['raw']['avih']['flags']['capturedfile'] = (bool) ($MP3fileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10000);
                $MP3fileInfo['RIFF']['raw']['avih']['flags']['copyrighted'] = (bool) ($MP3fileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20010);
                $MP3fileInfo['RIFF']['video']["{$streamindex}"]['frame_width'] = $MP3fileInfo['RIFF']['raw']['avih']['dwWidth'];
                $MP3fileInfo['RIFF']['video']["{$streamindex}"]['frame_height'] = $MP3fileInfo['RIFF']['raw']['avih']['dwHeight'];
                $MP3fileInfo['RIFF']['video']["{$streamindex}"]['frame_rate'] = round(1000000 / $MP3fileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'], 3);
                $MP3fileInfo['playtime_seconds'] = $MP3fileInfo['RIFF']['raw']['avih']['dwTotalFrames'] * ($MP3fileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] / 1000000);
                $MP3fileInfo['bitrate'] = $MP3fileInfo['filesize'] / $MP3fileInfo['playtime_seconds'] * 8;
            }
            if (isset($MP3fileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
                if (is_array($MP3fileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'])) {
                    for ($i = 0; $i < count($MP3fileInfo['RIFF']['AVI ']['hdrl']['strl']['strh']); $i++) {
                        if (isset($MP3fileInfo['RIFF']['AVI ']['hdrl']['strl']['strh']["{$i}"]['data'])) {
                            $strhData = $MP3fileInfo['RIFF']['AVI ']['hdrl']['strl']['strh']["{$i}"]['data'];
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['fccType'] = substr($strhData, 0, 4);
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['fccHandler'] = substr($strhData, 4, 4);
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwFlags'] = LittleEndian2Int(substr($strhData, 8, 4));
                            // Contains AVITF_* flags
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['wPriority'] = LittleEndian2Int(substr($strhData, 12, 2));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['wLanguage'] = LittleEndian2Int(substr($strhData, 14, 2));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwInitialFrames'] = LittleEndian2Int(substr($strhData, 16, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwScale'] = LittleEndian2Int(substr($strhData, 20, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwRate'] = LittleEndian2Int(substr($strhData, 24, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwStart'] = LittleEndian2Int(substr($strhData, 28, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwLength'] = LittleEndian2Int(substr($strhData, 32, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwSuggestedBufferSize'] = LittleEndian2Int(substr($strhData, 36, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwQuality'] = LittleEndian2Int(substr($strhData, 40, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['dwSampleSize'] = LittleEndian2Int(substr($strhData, 44, 4));
                            $MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['rcFrame'] = LittleEndian2Int(substr($strhData, 48, 4));
                            if (isset($MP3fileInfo['RIFF']['AVI ']['hdrl']['strl']['strf']["{$i}"]['data'])) {
                                $strfData = $MP3fileInfo['RIFF']['AVI ']['hdrl']['strl']['strf']["{$i}"]['data'];
                                switch ($MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['fccType']) {
                                    case 'auds':
                                        if (isset($MP3fileInfo['RIFF']['audio']) && is_array($MP3fileInfo['RIFF']['audio'])) {
                                            $streamindex = count($MP3fileInfo['RIFF']['audio']);
                                        }
                                        $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['wFormatTag'] = LittleEndian2Int(substr($strfData, 0, 2));
                                        $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nChannels'] = LittleEndian2Int(substr($strfData, 2, 2));
                                        $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nSamplesPerSec'] = LittleEndian2Int(substr($strfData, 4, 4));
                                        $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nAvgBytesPerSec'] = LittleEndian2Int(substr($strfData, 8, 4));
                                        $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nBlockAlign'] = LittleEndian2Int(substr($strfData, 12, 2));
                                        $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nBitsPerSample'] = LittleEndian2Int(substr($strfData, 14, 2));
                                        $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['format'] = RIFFwFormatTagLookup($MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['wFormatTag']);
                                        $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['channels'] = $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nChannels'];
                                        $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['channelmode'] = $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['channels'] == 1 ? 'mono' : 'stereo';
                                        $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['frequency'] = $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nSamplesPerSec'];
                                        $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['bitrate'] = $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nAvgBytesPerSec'] * 8;
                                        $MP3fileInfo['RIFF']['audio']["{$streamindex}"]['bitspersample'] = $MP3fileInfo['RIFF']['raw']['strf']['auds']["{$streamindex}"]['nBitsPerSample'];
                                        break;
                                    case 'vids':
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['biSize'] = LittleEndian2Int(substr($strfData, 0, 4));
                                        // number of bytes required by the BITMAPINFOHEADER structure
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['biWidth'] = LittleEndian2Int(substr($strfData, 4, 4));
                                        // width of the bitmap in pixels
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$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
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$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
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['biBitCount'] = LittleEndian2Int(substr($strfData, 14, 2));
                                        // Specifies the number of bits per pixels
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['fourcc'] = substr($strfData, 16, 4);
                                        //
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$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)
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['biXPelsPerMeter'] = LittleEndian2Int(substr($strfData, 24, 4));
                                        // horizontal resolution, in pixels per metre, of the target device
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['biYPelsPerMeter'] = LittleEndian2Int(substr($strfData, 28, 4));
                                        // vertical resolution, in pixels per metre, of the target device
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$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
                                        $MP3fileInfo['RIFF']['raw']['strf']['vids']["{$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
                                        $MP3fileInfo['RIFF']['video']["{$streamindex}"]['codec'] = RIFFfourccLookup($MP3fileInfo['RIFF']['raw']['strh']["{$i}"]['fccHandler']);
                                        if (!$MP3fileInfo['RIFF']['video']["{$streamindex}"]['codec'] && RIFFfourccLookup($MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['fourcc'])) {
                                            RIFFfourccLookup($MP3fileInfo['RIFF']['raw']['strf']['vids']["{$streamindex}"]['fourcc']);
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            break;
        default:
            unset($MP3fileInfo['fileformat']);
            break;
    }
    if (isset($MP3fileInfo['RIFF']['WAVE']['INFO']) && is_array($MP3fileInfo['RIFF']['WAVE']['INFO'])) {
        $MP3fileInfo['RIFF']['title'] = trim(substr($MP3fileInfo['RIFF']['WAVE']['INFO']['DISP'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['DISP']) - 1]['data'], 4));
        $MP3fileInfo['RIFF']['artist'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['IART'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['IART']) - 1]['data']);
        $MP3fileInfo['RIFF']['genre'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['IGNR'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['IGNR']) - 1]['data']);
        $MP3fileInfo['RIFF']['comment'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['ICMT'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['ICMT']) - 1]['data']);
        $MP3fileInfo['RIFF']['copyright'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['ICOP'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['ICOP']) - 1]['data']);
        $MP3fileInfo['RIFF']['engineers'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['IENG'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['IENG']) - 1]['data']);
        $MP3fileInfo['RIFF']['keywords'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['IKEY'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['IKEY']) - 1]['data']);
        $MP3fileInfo['RIFF']['originalmedium'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['IMED'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['IMED']) - 1]['data']);
        $MP3fileInfo['RIFF']['name'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['INAM'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['INAM']) - 1]['data']);
        $MP3fileInfo['RIFF']['sourcesupplier'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['ISRC'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['ISRC']) - 1]['data']);
        $MP3fileInfo['RIFF']['digitizer'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['ITCH'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['ITCH']) - 1]['data']);
        $MP3fileInfo['RIFF']['subject'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['ISBJ'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['ISBJ']) - 1]['data']);
        $MP3fileInfo['RIFF']['digitizationsource'] = trim($MP3fileInfo['RIFF']['WAVE']['INFO']['ISRF'][count($MP3fileInfo['RIFF']['WAVE']['INFO']['ISRF']) - 1]['data']);
    }
    foreach ($MP3fileInfo['RIFF'] as $key => $value) {
        if (!is_array($value) && !$value) {
            unset($MP3fileInfo['RIFF']["{$key}"]);
        }
    }
    return TRUE;
}
Example #15
0
function ParseVorbisCommentsFilepointer(&$fd, &$ThisFileInfo)
{
    $OriginalOffset = ftell($fd);
    $CommentStartOffset = $OriginalOffset;
    $commentdataoffset = 0;
    $VorbisCommentPage = 1;
    switch ($ThisFileInfo['audio']['dataformat']) {
        case 'vorbis':
            $CommentStartOffset = $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset'];
            // Second Ogg page, after header block
            fseek($fd, $CommentStartOffset, SEEK_SET);
            $commentdataoffset = 27 + $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_segments'];
            $commentdata = fread($fd, OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset);
            $commentdataoffset += strlen('vorbis') + 1;
            break;
        case 'flac':
            fseek($fd, $ThisFileInfo['flac']['VORBIS_COMMENT']['raw']['offset'] + 4, SEEK_SET);
            $commentdata = fread($fd, $ThisFileInfo['flac']['VORBIS_COMMENT']['raw']['block_length']);
            break;
        case 'speex':
            $CommentStartOffset = $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset'];
            // Second Ogg page, after header block
            fseek($fd, $CommentStartOffset, SEEK_SET);
            $commentdataoffset = 27 + $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_segments'];
            $commentdata = fread($fd, OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset);
            break;
        default:
            return false;
            break;
    }
    $VendorSize = LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
    $commentdataoffset += 4;
    $ThisFileInfo['ogg']['vendor'] = substr($commentdata, $commentdataoffset, $VendorSize);
    $commentdataoffset += $VendorSize;
    $CommentsCount = LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
    $commentdataoffset += 4;
    $ThisFileInfo['avdataoffset'] = $CommentStartOffset + $commentdataoffset;
    $basicfields = array('TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT');
    for ($i = 0; $i < $CommentsCount; $i++) {
        $ThisFileInfo['ogg']['comments_raw'][$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset;
        if (ftell($fd) < $ThisFileInfo['ogg']['comments_raw'][$i]['dataoffset'] + 4) {
            $VorbisCommentPage++;
            $oggpageinfo = ParseOggPageHeader($fd);
            $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
            // First, save what we haven't read yet
            $AsYetUnusedData = substr($commentdata, $commentdataoffset);
            // Then take that data off the end
            $commentdata = substr($commentdata, 0, $commentdataoffset);
            // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
            $commentdata .= str_repeat(chr(0), 27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
            $commentdataoffset += 27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments'];
            // Finally, stick the unused data back on the end
            $commentdata .= $AsYetUnusedData;
            //$commentdata .= fread($fd, $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
            $commentdata .= fread($fd, OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1));
        }
        $ThisFileInfo['ogg']['comments_raw'][$i]['size'] = LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
        // replace avdataoffset with position just after the last vorbiscomment
        $ThisFileInfo['avdataoffset'] = $ThisFileInfo['ogg']['comments_raw'][$i]['dataoffset'] + $ThisFileInfo['ogg']['comments_raw'][$i]['size'] + 4;
        $commentdataoffset += 4;
        while (strlen($commentdata) - $commentdataoffset < $ThisFileInfo['ogg']['comments_raw'][$i]['size']) {
            if ($ThisFileInfo['ogg']['comments_raw'][$i]['size'] > $ThisFileInfo['avdataend'] || $ThisFileInfo['ogg']['comments_raw'][$i]['size'] < 0) {
                $ThisFileInfo['error'] .= "\n" . 'Invalid Ogg comment size (comment #' . $i . ', claims to be ' . number_format($ThisFileInfo['ogg']['comments_raw'][$i]['size']) . ' bytes) - aborting reading comments';
                break 2;
            }
            $VorbisCommentPage++;
            $oggpageinfo = ParseOggPageHeader($fd);
            $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
            // First, save what we haven't read yet
            $AsYetUnusedData = substr($commentdata, $commentdataoffset);
            // Then take that data off the end
            $commentdata = substr($commentdata, 0, $commentdataoffset);
            // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
            $commentdata .= str_repeat(chr(0), 27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
            $commentdataoffset += 27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments'];
            // Finally, stick the unused data back on the end
            $commentdata .= $AsYetUnusedData;
            //$commentdata .= fread($fd, $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
            $commentdata .= fread($fd, OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1));
            //$filebaseoffset += $oggpageinfo['header_end_offset'] - $oggpageinfo['page_start_offset'];
        }
        $commentstring = substr($commentdata, $commentdataoffset, $ThisFileInfo['ogg']['comments_raw'][$i]['size']);
        $commentdataoffset += $ThisFileInfo['ogg']['comments_raw'][$i]['size'];
        if (!$commentstring) {
            // no comment?
            $ThisFileInfo['warning'] .= "\n" . 'Blank Ogg comment [' . $i . ']';
        } elseif (strstr($commentstring, '=')) {
            $commentexploded = explode('=', $commentstring, 2);
            $ThisFileInfo['ogg']['comments_raw'][$i]['key'] = strtoupper($commentexploded[0]);
            $ThisFileInfo['ogg']['comments_raw'][$i]['value'] = $commentexploded[1] ? utf8_decode($commentexploded[1]) : '';
            $ThisFileInfo['ogg']['comments_raw'][$i]['data'] = base64_decode($ThisFileInfo['ogg']['comments_raw'][$i]['value']);
            $ThisFileInfo['ogg']['comments'][strtolower($ThisFileInfo['ogg']['comments_raw'][$i]['key'])][] = $ThisFileInfo['ogg']['comments_raw'][$i]['value'];
            require_once GETID3_INCLUDEPATH . 'getid3.getimagesize.php';
            $imagechunkcheck = GetDataImageSize($ThisFileInfo['ogg']['comments_raw'][$i]['data']);
            $ThisFileInfo['ogg']['comments_raw'][$i]['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
            if (!$ThisFileInfo['ogg']['comments_raw'][$i]['image_mime'] || $ThisFileInfo['ogg']['comments_raw'][$i]['image_mime'] == 'application/octet-stream') {
                unset($ThisFileInfo['ogg']['comments_raw'][$i]['image_mime']);
                unset($ThisFileInfo['ogg']['comments_raw'][$i]['data']);
            }
        } else {
            $ThisFileInfo['warning'] .= "\n" . '[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair [' . $i . ']: ' . $commentstring;
        }
    }
    // Check for presence of vorbiscomments
    if (isset($ThisFileInfo['ogg']['comments'])) {
        $ThisFileInfo['tags'][] = 'vorbiscomment';
        // Yank other comments - vorbiscomments has highest preference
        if (isset($ThisFileInfo['ogg']['comments'])) {
            CopyFormatCommentsToRootComments($ThisFileInfo['ogg']['comments'], $ThisFileInfo, true, true, true);
        }
    }
    // Replay Gain Adjustment
    // http://privatewww.essex.ac.uk/~djmrob/replaygain/
    if (isset($ThisFileInfo['ogg']['comments']) && is_array($ThisFileInfo['ogg']['comments'])) {
        foreach ($ThisFileInfo['ogg']['comments'] as $index => $keyvaluepair) {
            if (isset($keyvaluepair['key'])) {
                switch ($keyvaluepair['key']) {
                    case 'RG_AUDIOPHILE':
                    case 'REPLAYGAIN_ALBUM_GAIN':
                        $ThisFileInfo['replay_gain']['audiophile']['adjustment'] = (double) $keyvaluepair['value'];
                        break;
                    case 'RG_RADIO':
                    case 'REPLAYGAIN_TRACK_GAIN':
                        $ThisFileInfo['replay_gain']['radio']['adjustment'] = (double) $keyvaluepair['value'];
                        break;
                    case 'REPLAYGAIN_ALBUM_PEAK':
                        $ThisFileInfo['replay_gain']['audiophile']['peak'] = (double) $keyvaluepair['value'];
                        break;
                    case 'RG_PEAK':
                    case 'REPLAYGAIN_TRACK_PEAK':
                        $ThisFileInfo['replay_gain']['radio']['peak'] = (double) $keyvaluepair['value'];
                        break;
                    default:
                        // do nothing
                        break;
                }
            }
        }
    }
    fseek($fd, $OriginalOffset, SEEK_SET);
    return true;
}
Example #16
0
function DeleteAPEtag($filename)
{
    if ($fp = @fopen($filename, 'a+b')) {
        $oldignoreuserabort = ignore_user_abort(true);
        flock($fp, LOCK_EX);
        $APEwritingOffset = 0;
        fseek($fp, -128, SEEK_END);
        $ID3v1 = fread($fp, 128);
        if (substr($ID3v1, 0, 3) == 'TAG') {
            // existing ID3v1 tag
            $APEwritingOffset -= 128;
        } else {
            // no ID3v1 tag found
            if ($writeid3v1) {
                $ID3v1 = 'TAG' . str_repeat(chr(0), 124) . chr(255);
            } else {
                unset($ID3v1);
            }
        }
        fseek($fp, $APEwritingOffset - 32, SEEK_END);
        $APEfooterTest = fread($fp, 32);
        if (substr($APEfooterTest, 0, 8) == 'APETAGEX') {
            // existing APE tag found
            $OldAPEversion = LittleEndian2Int(substr($APEfooterTest, 8, 4)) / 1000;
            $OldAPEsize = LittleEndian2Int(substr($APEfooterTest, 12, 4));
            switch ($OldAPEversion) {
                case 1:
                    $APEwritingOffset -= $OldAPEsize;
                    break;
                case 2:
                    fseek($fp, $APEwritingOffset - $OldAPEsize - 32, SEEK_END);
                    $APEheaderTest = fread($fp, 32);
                    if (substr($APEheaderTest, 0, 8) == 'APETAGEX') {
                        // APE header present
                        $APEwritingOffset -= $OldAPEsize + 32;
                    } else {
                        // no APE header present
                        $APEwritingOffset -= $OldAPEsize;
                    }
                    break;
                default:
                    flock($fp, LOCK_UN);
                    fclose($fp);
                    ignore_user_abort($oldignoreuserabort);
                    return false;
                    break;
            }
        } else {
            // no existing APE tag found
            // nothing further to do
        }
        fseek($fp, $APEwritingOffset, SEEK_END);
        ftruncate($fp, ftell($fp));
        if (!empty($ID3v1)) {
            fwrite($fp, $ID3v1, 128);
        }
        flock($fp, LOCK_UN);
        fclose($fp);
        ignore_user_abort($oldignoreuserabort);
        return true;
    }
    return false;
}
Example #17
0
function EitherEndian2Int(&$ThisFileInfo, $byteword, $signed = false)
{
    if ($ThisFileInfo['fileformat'] == 'riff') {
        return LittleEndian2Int($byteword, $signed);
    }
    return BigEndian2Int($byteword, false, $signed);
}
Example #18
0
function getBMPHeaderFilepointer(&$fd, &$ThisFileInfo, $ExtractPalette = false, $ExtractData = false)
{
    $ThisFileInfo['fileformat'] = 'bmp';
    $ThisFileInfo['video']['dataformat'] = 'bmp';
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $offset = 0;
    $BMPheader = fread($fd, 14 + 40);
    // check if the hardcoded-to-1 "planes" is at offset 22 or 26
    $planes22 = LittleEndian2Int(substr($BMPheader, 22, 2));
    $planes26 = LittleEndian2Int(substr($BMPheader, 26, 2));
    if ($planes22 == 1 && $planes26 != 1) {
        $ThisFileInfo['bmp']['type_os'] = 'OS/2';
        $ThisFileInfo['bmp']['type_version'] = 1;
    } elseif ($planes26 == 1 && $planes22 != 1) {
        $ThisFileInfo['bmp']['type_os'] = 'Windows';
        $ThisFileInfo['bmp']['type_version'] = 1;
    } elseif ($ThisFileInfo['bmp']['header']['raw']['header_size'] == 12) {
        $ThisFileInfo['bmp']['type_os'] = 'OS/2';
        $ThisFileInfo['bmp']['type_version'] = 1;
    } elseif ($ThisFileInfo['bmp']['header']['raw']['header_size'] == 40) {
        $ThisFileInfo['bmp']['type_os'] = 'Windows';
        $ThisFileInfo['bmp']['type_version'] = 1;
    } elseif ($ThisFileInfo['bmp']['header']['raw']['header_size'] == 84) {
        $ThisFileInfo['bmp']['type_os'] = 'Windows';
        $ThisFileInfo['bmp']['type_version'] = 4;
    } elseif ($ThisFileInfo['bmp']['header']['raw']['header_size'] == 100) {
        $ThisFileInfo['bmp']['type_os'] = 'Windows';
        $ThisFileInfo['bmp']['type_version'] = 5;
    }
    // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
    // all versions
    // WORD    bfType;
    // DWORD   bfSize;
    // WORD    bfReserved1;
    // WORD    bfReserved2;
    // DWORD   bfOffBits;
    $ThisFileInfo['bmp']['header']['raw']['identifier'] = substr($BMPheader, $offset, 2);
    $offset += 2;
    $ThisFileInfo['bmp']['header']['raw']['filesize'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
    $offset += 4;
    $ThisFileInfo['bmp']['header']['raw']['reserved1'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
    $offset += 2;
    $ThisFileInfo['bmp']['header']['raw']['reserved2'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
    $offset += 2;
    $ThisFileInfo['bmp']['header']['raw']['data_offset'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
    $offset += 4;
    if ($ThisFileInfo['bmp']['type_os'] == 'OS/2') {
        // OS/2-format BMP
        // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm
        // DWORD  Size;             /* Size of this structure in bytes */
        // DWORD  Width;            /* Bitmap width in pixels */
        // DWORD  Height;           /* Bitmap height in pixel */
        // WORD   NumPlanes;        /* Number of bit planes (color depth) */
        // WORD   BitsPerPixel;     /* Number of bits per pixel per plane */
        $ThisFileInfo['bmp']['header']['raw']['header_size'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['width'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
        $offset += 2;
        $ThisFileInfo['bmp']['header']['raw']['height'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
        $offset += 2;
        $ThisFileInfo['bmp']['header']['raw']['planes'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
        $offset += 2;
        $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
        $offset += 2;
        $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['bmp']['header']['raw']['width'];
        $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['bmp']['header']['raw']['height'];
        $ThisFileInfo['video']['codec'] = 'BI_RGB ' . $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] . '-bit';
        if ($ThisFileInfo['bmp']['type_version'] >= 2) {
            // DWORD  Compression;      /* Bitmap compression scheme */
            // DWORD  ImageDataSize;    /* Size of bitmap data in bytes */
            // DWORD  XResolution;      /* X resolution of display device */
            // DWORD  YResolution;      /* Y resolution of display device */
            // DWORD  ColorsUsed;       /* Number of color table indices used */
            // DWORD  ColorsImportant;  /* Number of important color indices */
            // WORD   Units;            /* Type of units used to measure resolution */
            // WORD   Reserved;         /* Pad structure to 4-byte boundary */
            // WORD   Recording;        /* Recording algorithm */
            // WORD   Rendering;        /* Halftoning algorithm used */
            // DWORD  Size1;            /* Reserved for halftoning algorithm use */
            // DWORD  Size2;            /* Reserved for halftoning algorithm use */
            // DWORD  ColorEncoding;    /* Color model used in bitmap */
            // DWORD  Identifier;       /* Reserved for application use */
            $ThisFileInfo['bmp']['header']['raw']['compression'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['bmp_data_size'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['resolution_h'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['resolution_v'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['colors_used'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['colors_important'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['resolution_units'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
            $offset += 2;
            $ThisFileInfo['bmp']['header']['raw']['reserved1'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
            $offset += 2;
            $ThisFileInfo['bmp']['header']['raw']['recording'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
            $offset += 2;
            $ThisFileInfo['bmp']['header']['raw']['rendering'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
            $offset += 2;
            $ThisFileInfo['bmp']['header']['raw']['size1'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['size2'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['color_encoding'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['identifier'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['compression'] = BMPcompressionOS2Lookup($ThisFileInfo['bmp']['header']['raw']['compression']);
            $ThisFileInfo['video']['codec'] = $ThisFileInfo['bmp']['header']['compression'] . ' ' . $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] . '-bit';
        }
    } elseif ($ThisFileInfo['bmp']['type_os'] == 'Windows') {
        // Windows-format BMP
        // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
        // all versions
        // DWORD  biSize;
        // LONG   biWidth;
        // LONG   biHeight;
        // WORD   biPlanes;
        // WORD   biBitCount;
        // DWORD  biCompression;
        // DWORD  biSizeImage;
        // LONG   biXPelsPerMeter;
        // LONG   biYPelsPerMeter;
        // DWORD  biClrUsed;
        // DWORD  biClrImportant;
        $ThisFileInfo['bmp']['header']['raw']['header_size'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['width'] = LittleEndian2Int(substr($BMPheader, $offset, 4), true);
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['height'] = LittleEndian2Int(substr($BMPheader, $offset, 4), true);
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['planes'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
        $offset += 2;
        $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] = LittleEndian2Int(substr($BMPheader, $offset, 2));
        $offset += 2;
        $ThisFileInfo['bmp']['header']['raw']['compression'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['bmp_data_size'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['resolution_h'] = LittleEndian2Int(substr($BMPheader, $offset, 4), true);
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['resolution_v'] = LittleEndian2Int(substr($BMPheader, $offset, 4), true);
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['colors_used'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
        $offset += 4;
        $ThisFileInfo['bmp']['header']['raw']['colors_important'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
        $offset += 4;
        $ThisFileInfo['bmp']['header']['compression'] = BMPcompressionWindowsLookup($ThisFileInfo['bmp']['header']['raw']['compression']);
        $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['bmp']['header']['raw']['width'];
        $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['bmp']['header']['raw']['height'];
        $ThisFileInfo['video']['codec'] = $ThisFileInfo['bmp']['header']['compression'] . ' ' . $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] . '-bit';
        if ($ThisFileInfo['bmp']['type_version'] >= 4) {
            $BMPheader .= fread($fd, 44);
            // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp
            // Win95+, WinNT4.0+
            // DWORD        bV4RedMask;
            // DWORD        bV4GreenMask;
            // DWORD        bV4BlueMask;
            // DWORD        bV4AlphaMask;
            // DWORD        bV4CSType;
            // CIEXYZTRIPLE bV4Endpoints;
            // DWORD        bV4GammaRed;
            // DWORD        bV4GammaGreen;
            // DWORD        bV4GammaBlue;
            $ThisFileInfo['bmp']['header']['raw']['red_mask'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['green_mask'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['blue_mask'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['alpha_mask'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['cs_type'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['ciexyz_red'] = substr($BMPheader, $offset, 4);
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['ciexyz_green'] = substr($BMPheader, $offset, 4);
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['ciexyz_blue'] = substr($BMPheader, $offset, 4);
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['gamma_red'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['gamma_green'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['gamma_blue'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['ciexyz_red'] = FixedPoint2_30(strrev($ThisFileInfo['bmp']['header']['raw']['ciexyz_red']));
            $ThisFileInfo['bmp']['header']['ciexyz_green'] = FixedPoint2_30(strrev($ThisFileInfo['bmp']['header']['raw']['ciexyz_green']));
            $ThisFileInfo['bmp']['header']['ciexyz_blue'] = FixedPoint2_30(strrev($ThisFileInfo['bmp']['header']['raw']['ciexyz_blue']));
        }
        if ($ThisFileInfo['bmp']['type_version'] >= 5) {
            $BMPheader .= fread($fd, 16);
            // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp
            // Win98+, Win2000+
            // DWORD        bV5Intent;
            // DWORD        bV5ProfileData;
            // DWORD        bV5ProfileSize;
            // DWORD        bV5Reserved;
            $ThisFileInfo['bmp']['header']['raw']['intent'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['profile_data_offset'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['profile_data_size'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
            $ThisFileInfo['bmp']['header']['raw']['reserved3'] = LittleEndian2Int(substr($BMPheader, $offset, 4));
            $offset += 4;
        }
    } else {
        $ThisFileInfo['error'] .= "\n" . 'Unknown BMP format in header.';
        return false;
    }
    if ($ExtractPalette || $ExtractData) {
        $PaletteEntries = 0;
        if ($ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] < 16) {
            $PaletteEntries = pow(2, $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel']);
        } elseif (isset($ThisFileInfo['bmp']['header']['raw']['colors_used']) && $ThisFileInfo['bmp']['header']['raw']['colors_used'] > 0 && $ThisFileInfo['bmp']['header']['raw']['colors_used'] <= 256) {
            $PaletteEntries = $ThisFileInfo['bmp']['header']['raw']['colors_used'];
        }
        if ($PaletteEntries > 0) {
            $BMPpalette = fread($fd, 4 * $PaletteEntries);
            $paletteoffset = 0;
            for ($i = 0; $i < $PaletteEntries; $i++) {
                // RGBQUAD          - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_5f8y.asp
                // BYTE    rgbBlue;
                // BYTE    rgbGreen;
                // BYTE    rgbRed;
                // BYTE    rgbReserved;
                //$ThisFileInfo['bmp']['palette']['blue'][$i]   = LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
                //$ThisFileInfo['bmp']['palette']['green'][$i] = LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
                //$ThisFileInfo['bmp']['palette']['red'][$i]  = LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
                $blue = LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
                $green = LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
                $red = LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
                if ($ThisFileInfo['bmp']['type_os'] == 'OS/2' && $ThisFileInfo['bmp']['type_version'] == 1) {
                    // no padding byte
                } else {
                    $paletteoffset++;
                    // padding byte
                }
                $ThisFileInfo['bmp']['palette'][$i] = $red << 16 | $green << 8 | $blue;
            }
        }
    }
    if ($ExtractData) {
        fseek($fd, $ThisFileInfo['bmp']['header']['raw']['data_offset'], SEEK_SET);
        $RowByteLength = ceil($ThisFileInfo['bmp']['header']['raw']['width'] * ($ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] / 8) / 4) * 4;
        // round up to nearest DWORD boundry
        $BMPpixelData = fread($fd, $ThisFileInfo['bmp']['header']['raw']['height'] * $RowByteLength);
        $pixeldataoffset = 0;
        switch ($ThisFileInfo['bmp']['header']['raw']['compression']) {
            case 0:
                // BI_RGB
                switch ($ThisFileInfo['bmp']['header']['raw']['bits_per_pixel']) {
                    case 1:
                        for ($row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1; $row >= 0; $row--) {
                            for ($col = 0; $col < $ThisFileInfo['bmp']['header']['raw']['width']; $col = $col) {
                                $paletteindexbyte = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                for ($i = 7; $i >= 0; $i--) {
                                    $paletteindex = ($paletteindexbyte & 0x1 << $i) >> $i;
                                    $ThisFileInfo['bmp']['data'][$row][$col] = $ThisFileInfo['bmp']['palette'][$paletteindex];
                                    $col++;
                                }
                            }
                            while ($pixeldataoffset % 4 != 0) {
                                // lines are padded to nearest DWORD
                                $pixeldataoffset++;
                            }
                        }
                        break;
                    case 4:
                        for ($row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1; $row >= 0; $row--) {
                            for ($col = 0; $col < $ThisFileInfo['bmp']['header']['raw']['width']; $col = $col) {
                                $paletteindexbyte = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                for ($i = 1; $i >= 0; $i--) {
                                    $paletteindex = ($paletteindexbyte & 0xf << 4 * $i) >> 4 * $i;
                                    $ThisFileInfo['bmp']['data'][$row][$col] = $ThisFileInfo['bmp']['palette'][$paletteindex];
                                    $col++;
                                }
                            }
                            while ($pixeldataoffset % 4 != 0) {
                                // lines are padded to nearest DWORD
                                $pixeldataoffset++;
                            }
                        }
                        break;
                    case 8:
                        for ($row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1; $row >= 0; $row--) {
                            for ($col = 0; $col < $ThisFileInfo['bmp']['header']['raw']['width']; $col++) {
                                $paletteindex = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                $ThisFileInfo['bmp']['data'][$row][$col] = $ThisFileInfo['bmp']['palette'][$paletteindex];
                            }
                            while ($pixeldataoffset % 4 != 0) {
                                // lines are padded to nearest DWORD
                                $pixeldataoffset++;
                            }
                        }
                        break;
                    case 24:
                    case 32:
                        for ($row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1; $row >= 0; $row--) {
                            for ($col = 0; $col < $ThisFileInfo['bmp']['header']['raw']['width']; $col++) {
                                $blue = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                $green = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                $red = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                if ($ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] == 32) {
                                    $paletteoffset++;
                                    // filler byte
                                }
                                $ThisFileInfo['bmp']['data'][$row][$col] = $red << 16 | $green << 8 | $blue;
                            }
                            while ($pixeldataoffset % 4 != 0) {
                                // lines are padded to nearest DWORD
                                $pixeldataoffset++;
                            }
                        }
                        break;
                    case 16:
                    default:
                        $ThisFileInfo['error'] .= "\n" . 'Unknown bits-per-pixel value (' . $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] . ') - cannot read pixel data';
                        break;
                }
                break;
            case 1:
                // BI_RLE8 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp
                switch ($ThisFileInfo['bmp']['header']['raw']['bits_per_pixel']) {
                    case 8:
                        $pixelcounter = 0;
                        while ($pixeldataoffset < strlen($BMPpixelData)) {
                            $firstbyte = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                            $secondbyte = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                            if ($firstbyte == 0) {
                                // escaped/absolute mode - the first byte of the pair can be set to zero to
                                // indicate an escape character that denotes the end of a line, the end of
                                // a bitmap, or a delta, depending on the value of the second byte.
                                switch ($secondbyte) {
                                    case 0:
                                        // end of line
                                        // no need for special processing, just ignore
                                        break;
                                    case 1:
                                        // end of bitmap
                                        $pixeldataoffset = strlen($BMPpixelData);
                                        // force to exit loop just in case
                                        break;
                                    case 2:
                                        // delta - The 2 bytes following the escape contain unsigned values
                                        // indicating the horizontal and vertical offsets of the next pixel
                                        // from the current position.
                                        $colincrement = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                        $rowincrement = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                        $col = $pixelcounter % $ThisFileInfo['bmp']['header']['raw']['width'] + $colincrement;
                                        $row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1 - ($pixelcounter - $col) / $ThisFileInfo['bmp']['header']['raw']['width'] - $rowincrement;
                                        $pixelcounter = $row * $ThisFileInfo['bmp']['header']['raw']['width'] + $col;
                                        break;
                                    default:
                                        // In absolute mode, the first byte is zero and the second byte is a
                                        // value in the range 03H through FFH. The second byte represents the
                                        // number of bytes that follow, each of which contains the color index
                                        // of a single pixel. Each run must be aligned on a word boundary.
                                        for ($i = 0; $i < $secondbyte; $i++) {
                                            $paletteindex = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                            $col = $pixelcounter % $ThisFileInfo['bmp']['header']['raw']['width'];
                                            $row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1 - ($pixelcounter - $col) / $ThisFileInfo['bmp']['header']['raw']['width'];
                                            $ThisFileInfo['bmp']['data'][$row][$col] = $ThisFileInfo['bmp']['palette'][$paletteindex];
                                            $pixelcounter++;
                                        }
                                        while ($pixeldataoffset % 2 != 0) {
                                            // Each run must be aligned on a word boundary.
                                            $pixeldataoffset++;
                                        }
                                        break;
                                }
                            } else {
                                // encoded mode - the first byte specifies the number of consecutive pixels
                                // to be drawn using the color index contained in the second byte.
                                for ($i = 0; $i < $firstbyte; $i++) {
                                    $col = $pixelcounter % $ThisFileInfo['bmp']['header']['raw']['width'];
                                    $row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1 - ($pixelcounter - $col) / $ThisFileInfo['bmp']['header']['raw']['width'];
                                    $ThisFileInfo['bmp']['data'][$row][$col] = $ThisFileInfo['bmp']['palette'][$secondbyte];
                                    $pixelcounter++;
                                }
                            }
                        }
                        break;
                    default:
                        $ThisFileInfo['error'] .= "\n" . 'Unknown bits-per-pixel value (' . $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] . ') - cannot read pixel data';
                        break;
                }
                break;
            case 2:
                // BI_RLE4 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp
                switch ($ThisFileInfo['bmp']['header']['raw']['bits_per_pixel']) {
                    case 4:
                        $pixelcounter = 0;
                        while ($pixeldataoffset < strlen($BMPpixelData)) {
                            $firstbyte = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                            $secondbyte = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                            if ($firstbyte == 0) {
                                // escaped/absolute mode - the first byte of the pair can be set to zero to
                                // indicate an escape character that denotes the end of a line, the end of
                                // a bitmap, or a delta, depending on the value of the second byte.
                                switch ($secondbyte) {
                                    case 0:
                                        // end of line
                                        // no need for special processing, just ignore
                                        break;
                                    case 1:
                                        // end of bitmap
                                        $pixeldataoffset = strlen($BMPpixelData);
                                        // force to exit loop just in case
                                        break;
                                    case 2:
                                        // delta - The 2 bytes following the escape contain unsigned values
                                        // indicating the horizontal and vertical offsets of the next pixel
                                        // from the current position.
                                        $colincrement = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                        $rowincrement = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                        $col = $pixelcounter % $ThisFileInfo['bmp']['header']['raw']['width'] + $colincrement;
                                        $row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1 - ($pixelcounter - $col) / $ThisFileInfo['bmp']['header']['raw']['width'] - $rowincrement;
                                        $pixelcounter = $row * $ThisFileInfo['bmp']['header']['raw']['width'] + $col;
                                        break;
                                    default:
                                        // In absolute mode, the first byte is zero. The second byte contains the number
                                        // of color indexes that follow. Subsequent bytes contain color indexes in their
                                        // high- and low-order 4 bits, one color index for each pixel. In absolute mode,
                                        // each run must be aligned on a word boundary.
                                        unset($paletteindexes);
                                        for ($i = 0; $i < ceil($secondbyte / 2); $i++) {
                                            $paletteindexbyte = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
                                            $paletteindexes[] = ($paletteindexbyte & 0xf0) >> 4;
                                            $paletteindexes[] = $paletteindexbyte & 0xf;
                                        }
                                        while ($pixeldataoffset % 2 != 0) {
                                            // Each run must be aligned on a word boundary.
                                            $pixeldataoffset++;
                                        }
                                        foreach ($paletteindexes as $paletteindex) {
                                            $col = $pixelcounter % $ThisFileInfo['bmp']['header']['raw']['width'];
                                            $row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1 - ($pixelcounter - $col) / $ThisFileInfo['bmp']['header']['raw']['width'];
                                            $ThisFileInfo['bmp']['data'][$row][$col] = $ThisFileInfo['bmp']['palette'][$paletteindex];
                                            $pixelcounter++;
                                        }
                                        break;
                                }
                            } else {
                                // encoded mode - the first byte of the pair contains the number of pixels to be
                                // drawn using the color indexes in the second byte. The second byte contains two
                                // color indexes, one in its high-order 4 bits and one in its low-order 4 bits.
                                // The first of the pixels is drawn using the color specified by the high-order
                                // 4 bits, the second is drawn using the color in the low-order 4 bits, the third
                                // is drawn using the color in the high-order 4 bits, and so on, until all the
                                // pixels specified by the first byte have been drawn.
                                $paletteindexes[0] = ($secondbyte & 0xf0) >> 4;
                                $paletteindexes[1] = $secondbyte & 0xf;
                                for ($i = 0; $i < $firstbyte; $i++) {
                                    $col = $pixelcounter % $ThisFileInfo['bmp']['header']['raw']['width'];
                                    $row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1 - ($pixelcounter - $col) / $ThisFileInfo['bmp']['header']['raw']['width'];
                                    $ThisFileInfo['bmp']['data'][$row][$col] = $ThisFileInfo['bmp']['palette'][$paletteindexes[$i % 2]];
                                    $pixelcounter++;
                                }
                            }
                        }
                        break;
                    default:
                        $ThisFileInfo['error'] .= "\n" . 'Unknown bits-per-pixel value (' . $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] . ') - cannot read pixel data';
                        break;
                }
                break;
            case 3:
                // BI_BITFIELDS
                switch ($ThisFileInfo['bmp']['header']['raw']['bits_per_pixel']) {
                    case 16:
                    case 32:
                        $redshift = 0;
                        $greenshift = 0;
                        $blueshift = 0;
                        while (($ThisFileInfo['bmp']['header']['raw']['red_mask'] >> $redshift & 0x1) == 0) {
                            $redshift++;
                        }
                        while (($ThisFileInfo['bmp']['header']['raw']['green_mask'] >> $greenshift & 0x1) == 0) {
                            $greenshift++;
                        }
                        while (($ThisFileInfo['bmp']['header']['raw']['blue_mask'] >> $blueshift & 0x1) == 0) {
                            $blueshift++;
                        }
                        for ($row = $ThisFileInfo['bmp']['header']['raw']['height'] - 1; $row >= 0; $row--) {
                            for ($col = 0; $col < $ThisFileInfo['bmp']['header']['raw']['width']; $col++) {
                                $pixelvalue = LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset, $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] / 8));
                                $pixeldataoffset += $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] / 8;
                                $red = round((($pixelvalue & $ThisFileInfo['bmp']['header']['raw']['red_mask']) >> $redshift) / ($ThisFileInfo['bmp']['header']['raw']['red_mask'] >> $redshift) * 255);
                                $green = round((($pixelvalue & $ThisFileInfo['bmp']['header']['raw']['green_mask']) >> $greenshift) / ($ThisFileInfo['bmp']['header']['raw']['green_mask'] >> $greenshift) * 255);
                                $blue = round((($pixelvalue & $ThisFileInfo['bmp']['header']['raw']['blue_mask']) >> $blueshift) / ($ThisFileInfo['bmp']['header']['raw']['blue_mask'] >> $blueshift) * 255);
                                $ThisFileInfo['bmp']['data'][$row][$col] = $red << 16 | $green << 8 | $blue;
                            }
                            while ($pixeldataoffset % 4 != 0) {
                                // lines are padded to nearest DWORD
                                $pixeldataoffset++;
                            }
                        }
                        break;
                    default:
                        $ThisFileInfo['error'] .= "\n" . 'Unknown bits-per-pixel value (' . $ThisFileInfo['bmp']['header']['raw']['bits_per_pixel'] . ') - cannot read pixel data';
                        break;
                }
                break;
            default:
                // unhandled compression type
                $ThisFileInfo['error'] .= "\n" . 'Unknown/unhandled compression type value (' . $ThisFileInfo['bmp']['header']['raw']['compression'] . ') - cannot decompress pixel data';
                break;
        }
    }
    return true;
}
Example #19
0
function RIFFparseWAVEFORMATex($WaveFormatExData)
{
    $WaveFormatEx['raw']['wFormatTag'] = LittleEndian2Int(substr($WaveFormatExData, 0, 2));
    $WaveFormatEx['raw']['nChannels'] = LittleEndian2Int(substr($WaveFormatExData, 2, 2));
    $WaveFormatEx['raw']['nSamplesPerSec'] = LittleEndian2Int(substr($WaveFormatExData, 4, 4));
    $WaveFormatEx['raw']['nAvgBytesPerSec'] = LittleEndian2Int(substr($WaveFormatExData, 8, 4));
    $WaveFormatEx['raw']['nBlockAlign'] = LittleEndian2Int(substr($WaveFormatExData, 12, 2));
    $WaveFormatEx['raw']['nBitsPerSample'] = LittleEndian2Int(substr($WaveFormatExData, 14, 2));
    $WaveFormatEx['codec'] = RIFFwFormatTagLookup($WaveFormatEx['raw']['wFormatTag']);
    $WaveFormatEx['channels'] = $WaveFormatEx['raw']['nChannels'];
    $WaveFormatEx['sample_rate'] = $WaveFormatEx['raw']['nSamplesPerSec'];
    $WaveFormatEx['bitrate'] = $WaveFormatEx['raw']['nAvgBytesPerSec'] * 8;
    $WaveFormatEx['bits_per_sample'] = $WaveFormatEx['raw']['nBitsPerSample'];
    return $WaveFormatEx;
}