function getID3v1Filepointer(&$fd, &$ThisFileInfo) { fseek($fd, -128, SEEK_END); $id3v1tag = fread($fd, 128); if (substr($id3v1tag, 0, 3) == 'TAG') { $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize'] - 128; require_once GETID3_INCLUDEPATH . 'getid3.id3.php'; $ThisFileInfo['id3v1']['title'] = trim(substr($id3v1tag, 3, 30)); $ThisFileInfo['id3v1']['artist'] = trim(substr($id3v1tag, 33, 30)); $ThisFileInfo['id3v1']['album'] = trim(substr($id3v1tag, 63, 30)); $ThisFileInfo['id3v1']['year'] = trim(substr($id3v1tag, 93, 4)); $ThisFileInfo['id3v1']['comment'] = substr($id3v1tag, 97, 30); // can't remove nulls yet, track detection depends on them $ThisFileInfo['id3v1']['genreid'] = ord(substr($id3v1tag, 127, 1)); if (substr($ThisFileInfo['id3v1']['comment'], 28, 1) === chr(0) && substr($ThisFileInfo['id3v1']['comment'], 29, 1) !== chr(0)) { $ThisFileInfo['id3v1']['track'] = ord(substr($ThisFileInfo['id3v1']['comment'], 29, 1)); $ThisFileInfo['id3v1']['comment'] = substr($ThisFileInfo['id3v1']['comment'], 0, 28); } $ThisFileInfo['id3v1']['comment'] = trim($ThisFileInfo['id3v1']['comment']); $ThisFileInfo['id3v1']['genre'] = LookupGenre($ThisFileInfo['id3v1']['genreid']); $ThisFileInfo['tags'][] = 'id3v1'; // Do not change fileformat if already set if (empty($ThisFileInfo['fileformat'])) { $ThisFileInfo['fileformat'] = 'id3'; } // ID3v1 has lowest preference. We add if $ThisFileInfo[comments] is empty - this will override empty tags of higher preference, or add comments to root if not already present if (isset($ThisFileInfo['id3v1'])) { CopyFormatCommentsToRootComments($ThisFileInfo['id3v1'], $ThisFileInfo, true, false, false); } } return true; }
function getZIPHeaderFilepointerTopDown(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'zip'; $ThisFileInfo['zip']['compressed_size'] = 0; $ThisFileInfo['zip']['uncompressed_size'] = 0; $ThisFileInfo['zip']['entries_count'] = 0; rewind($fd); while ($fileentry = ZIPparseLocalFileHeader($fd)) { $ThisFileInfo['zip']['entries'][] = $fileentry; $ThisFileInfo['zip']['entries_count']++; } if ($ThisFileInfo['zip']['entries_count'] == 0) { $ThisFileInfo['error'] .= "\n" . 'No Local File Header entries found'; return false; } $ThisFileInfo['zip']['entries_count'] = 0; while ($centraldirectoryentry = ZIPparseCentralDirectory($fd)) { $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry; $ThisFileInfo['zip']['entries_count']++; $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; } if ($ThisFileInfo['zip']['entries_count'] == 0) { $ThisFileInfo['error'] .= "\n" . 'No Central Directory entries found (truncated file?)'; return false; } if ($EOCD = ZIPparseEndOfCentralDirectory($fd)) { $ThisFileInfo['zip']['end_central_directory'] = $EOCD; } else { $ThisFileInfo['error'] .= "\n" . 'No End Of Central Directory entry found (truncated file?)'; return false; } if (isset($ThisFileInfo['zip']['end_central_directory']['comment'])) { $ThisFileInfo['zip']['comments']['comment'] = $ThisFileInfo['zip']['end_central_directory']['comment']; // ZIP tags have highest priority if (!empty($ThisFileInfo['zip']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['zip']['comments'], $ThisFileInfo, true, true, true); } // add tag to array of tags $ThisFileInfo['tags'][] = 'zip'; } return true; }
function getQuicktimeHeaderFilepointer(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'quicktime'; $ThisFileInfo['audio']['dataformat'] = 'quicktime'; $ThisFileInfo['video']['dataformat'] = 'quicktime'; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $offset = 0; $atomcounter = 0; while ($offset < $ThisFileInfo['avdataend']) { fseek($fd, $offset, SEEK_SET); $AtomHeader = fread($fd, 8); $atomsize = BigEndian2Int(substr($AtomHeader, 0, 4)); $atomname = substr($AtomHeader, 4, 4); $ThisFileInfo['quicktime']["{$atomname}"]['name'] = $atomname; $ThisFileInfo['quicktime']["{$atomname}"]['size'] = $atomsize; $ThisFileInfo['quicktime']["{$atomname}"]['offset'] = $offset; if ($offset + $atomsize > $ThisFileInfo['avdataend']) { $ThisFileInfo['error'] .= "\n" . 'Atom at offset ' . $offset . ' claims to go beyond end-of-file (length: ' . $atomsize . ' bytes)'; return false; } switch ($atomname) { case 'mdat': // Media DATa atom // 'mdat' contains the actual data for the audio/video if (!isset($ThisFileInfo['avdataend_tmp']) || $ThisFileInfo['quicktime']["{$atomname}"]['size'] > $ThisFileInfo['avdataend_tmp'] - $ThisFileInfo['avdataoffset']) { $ThisFileInfo['avdataoffset'] = $ThisFileInfo['quicktime']["{$atomname}"]['offset'] + 8; $OldAVDataEnd = $ThisFileInfo['avdataend']; $ThisFileInfo['avdataend'] = $ThisFileInfo['quicktime']["{$atomname}"]['offset'] + $ThisFileInfo['quicktime']["{$atomname}"]['size']; require_once GETID3_INCLUDEPATH . 'getid3.mp3.php'; if (MPEGaudioHeaderValid(MPEGaudioHeaderDecode(fread($fd, 4)))) { getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset'], false); if (isset($ThisFileInfo['mpeg']['audio'])) { $ThisFileInfo['audio']['dataformat'] = 'mp3'; $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'] * 1000; $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitratemode']); $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate']; } } $ThisFileInfo['avdataend'] = $OldAVDataEnd; unset($OldAVDataEnd); } break; case 'free': // FREE space atom // FREE space atom case 'skip': // SKIP atom // SKIP atom case 'wide': // 64-bit expansion placeholder atom // 'free', 'skip' and 'wide' are just padding, contains no useful data at all break; default: $atomHierarchy = array(); $ThisFileInfo['quicktime']["{$atomname}"] = QuicktimeParseAtom($atomname, $atomsize, fread($fd, $atomsize), $ThisFileInfo, $offset, $atomHierarchy); break; } $offset += $atomsize; $atomcounter++; } if (!empty($ThisFileInfo['avdataend_tmp'])) { // this value is assigned to a temp value and then erased because // otherwise any atoms beyond the 'mdat' atom would not get parsed $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataend_tmp']; unset($ThisFileInfo['avdataend_tmp']); } // Quicktime tags have highest priority if (isset($ThisFileInfo['quicktime']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['quicktime']['comments'], $ThisFileInfo, true, true, true); // add tag to array of tags $ThisFileInfo['tags'][] = 'quicktime'; } if (!isset($ThisFileInfo['bitrate']) && isset($ThisFileInfo['playtime_seconds'])) { $ThisFileInfo['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds']; } if (isset($ThisFileInfo['bitrate']) && !isset($ThisFileInfo['audio']['bitrate']) && !isset($ThisFileInfo['quicktime']['video'])) { $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['bitrate']; } return true; }
function HandleID3v2Tag(&$fd, &$ThisFileInfo) { require_once GETID3_INCLUDEPATH . 'getid3.id3v2.php'; getID3v2Filepointer($fd, $ThisFileInfo); // Tag present if (isset($ThisFileInfo['id3v2']['header'])) { // Do not change fileformat if already set if (empty($ThisFileInfo['fileformat'])) { $ThisFileInfo['fileformat'] = 'id3'; } // Set avdataoffset $ThisFileInfo['avdataoffset'] = $ThisFileInfo['id3v2']['headerlength']; if (isset($ThisFileInfo['id3v2']['footer'])) { $ThisFileInfo['avdataoffset'] += 10; } $ThisFileInfo['tags'][] = 'id3v2'; if (isset($ThisFileInfo['id3v2']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['id3v2']['comments'], $ThisFileInfo, true, true, false); } } return true; }
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; }
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; }
function getLyrics3Data(&$ThisFileInfo, &$fd, $endoffset, $version, $length) { // http://www.volweb.cz/str/tags.htm fseek($fd, $endoffset, SEEK_SET); $rawdata = fread($fd, $length); if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') { if (strpos($rawdata, 'LYRICSBEGIN') !== false) { $ThisFileInfo['warning'] .= "\n" . '"LYRICSBEGIN" expected at ' . $endoffset . ' but actually found at ' . ($endoffset + strpos($rawdata, 'LYRICSBEGIN')) . ' - this is invalid for Lyrics3 v' . $version; $rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN')); $length = strlen($rawdata); } else { $ThisFileInfo['error'] .= "\n" . '"LYRICSBEGIN" expected at ' . $endoffset . ' but found "' . substr($rawdata, 0, 11) . '" instead'; return false; } } switch ($version) { case 1: if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') { $ThisFileInfo['lyrics3']['raw']['lyrics3version'] = $version; $ThisFileInfo['lyrics3']['raw']['lyrics3tagsize'] = $length; $ThisFileInfo['lyrics3']['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9)); Lyrics3LyricsTimestampParse($ThisFileInfo); } else { $ThisFileInfo['error'] .= "\n" . '"LYRICSEND" expected at ' . (ftell($fd) - 11 + $length - 9) . ' but found "' . substr($rawdata, strlen($rawdata) - 9, 9) . '" instead'; } break; case 2: if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICS200') { $ThisFileInfo['lyrics3']['raw']['lyrics3version'] = $version; $ThisFileInfo['lyrics3']['raw']['lyrics3tagsize'] = $length; $ThisFileInfo['lyrics3']['raw']['unparsed'] = substr($rawdata, 11, strlen($rawdata) - 11 - 9 - 6); // LYRICSBEGIN + LYRICS200 + LSZ $rawdata = $ThisFileInfo['lyrics3']['raw']['unparsed']; while (strlen($rawdata) > 0) { $fieldname = substr($rawdata, 0, 3); $fieldsize = (int) substr($rawdata, 3, 5); $ThisFileInfo['lyrics3']['raw']["{$fieldname}"] = substr($rawdata, 8, $fieldsize); $rawdata = substr($rawdata, 3 + 5 + $fieldsize); } if (isset($ThisFileInfo['lyrics3']['raw']['IND'])) { $i = 0; $flagnames = array('lyrics', 'timestamps', 'inhibitrandom'); foreach ($flagnames as $flagname) { if (strlen($ThisFileInfo['lyrics3']['raw']['IND']) > ++$i) { $ThisFileInfo['lyrics3']['flags']["{$flagname}"] = IntString2Bool(substr($ThisFileInfo['lyrics3']['raw']['IND'], $i, 1)); } } } $fieldnametranslation = array('ETT' => 'title', 'EAR' => 'artist', 'EAL' => 'album', 'INF' => 'comment', 'AUT' => 'author'); foreach ($fieldnametranslation as $key => $value) { if (isset($ThisFileInfo['lyrics3']['raw']["{$key}"])) { $ThisFileInfo['lyrics3']['comments']["{$value}"] = $ThisFileInfo['lyrics3']['raw']["{$key}"]; } } if (!empty($ThisFileInfo['lyrics3']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['lyrics3']['comments'], $ThisFileInfo, true, false, false); } if (isset($ThisFileInfo['lyrics3']['raw']['IMG'])) { $imagestrings = explode("\r\n", $ThisFileInfo['lyrics3']['raw']['IMG']); foreach ($imagestrings as $key => $imagestring) { if (strpos($imagestring, '||') !== false) { $imagearray = explode('||', $imagestring); $ThisFileInfo['lyrics3']['images']["{$key}"]['filename'] = $imagearray[0]; $ThisFileInfo['lyrics3']['images']["{$key}"]['description'] = $imagearray[1]; $ThisFileInfo['lyrics3']['images']["{$key}"]['timestamp'] = Lyrics3Timestamp2Seconds($imagearray[2]); } } } if (isset($ThisFileInfo['lyrics3']['raw']['LYR'])) { Lyrics3LyricsTimestampParse($ThisFileInfo); } } else { $ThisFileInfo['error'] .= "\n" . '"LYRICS200" expected at ' . (ftell($fd) - 11 + $length - 9) . ' but found "' . substr($rawdata, strlen($rawdata) - 9, 9) . '" instead'; } break; default: $ThisFileInfo['error'] .= "\n" . 'Cannot process Lyrics3 version ' . $version . ' (only v1 and v2)'; break; } if (isset($ThisFileInfo['lyrics3'])) { $ThisFileInfo['tags'][] = 'lyrics3'; } return true; }
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; }
function getMIDIHeaderFilepointer(&$fd, &$ThisFileInfo, $scanwholefile = true) { $ThisFileInfo['fileformat'] = 'midi'; $ThisFileInfo['audio']['dataformat'] = 'midi'; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $MIDIdata = fread($fd, FREAD_BUFFER_SIZE); $offset = 0; $MIDIheaderID = substr($MIDIdata, $offset, 4); // 'MThd' $offset += 4; $ThisFileInfo['midi']['raw']['headersize'] = BigEndian2Int(substr($MIDIdata, $offset, 4)); $offset += 4; $ThisFileInfo['midi']['raw']['fileformat'] = BigEndian2Int(substr($MIDIdata, $offset, 2)); $offset += 2; $ThisFileInfo['midi']['raw']['tracks'] = BigEndian2Int(substr($MIDIdata, $offset, 2)); $offset += 2; $ThisFileInfo['midi']['raw']['ticksperqnote'] = BigEndian2Int(substr($MIDIdata, $offset, 2)); $offset += 2; for ($i = 0; $i < $ThisFileInfo['midi']['raw']['tracks']; $i++) { if (strlen($MIDIdata) - $offset < 8) { $MIDIdata .= fread($fd, FREAD_BUFFER_SIZE); } $trackID = substr($MIDIdata, $offset, 4); $offset += 4; if ($trackID == 'MTrk') { $tracksize = BigEndian2Int(substr($MIDIdata, $offset, 4)); $offset += 4; // $ThisFileInfo['midi']['tracks'][$i]['size'] = $tracksize; $trackdataarray[$i] = substr($MIDIdata, $offset, $tracksize); $offset += $tracksize; } else { $ThisFileInfo['error'] .= "\n" . 'Expecting "MTrk" at ' . $offset . ', found ' . $trackID . ' instead'; return false; } } if (!isset($trackdataarray) || !is_array($trackdataarray)) { $ThisFileInfo['error'] .= "\n" . 'Cannot find MIDI track information'; unset($ThisFileInfo['midi']); unset($ThisFileInfo['fileformat']); return false; } if ($scanwholefile) { // this can take quite a long time, so have the option to bypass it if speed is very important $ThisFileInfo['midi']['totalticks'] = 0; $ThisFileInfo['playtime_seconds'] = 0; $CurrentMicroSecondsPerBeat = 500000; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat $CurrentBeatsPerMinute = 120; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat foreach ($trackdataarray as $tracknumber => $trackdata) { $eventsoffset = 0; $LastIssuedMIDIcommand = 0; $LastIssuedMIDIchannel = 0; $CumulativeDeltaTime = 0; $TicksAtCurrentBPM = 0; while ($eventsoffset < strlen($trackdata)) { $eventid = 0; if (isset($MIDIevents[$tracknumber]) && is_array($MIDIevents[$tracknumber])) { $eventid = count($MIDIevents[$tracknumber]); } $deltatime = 0; for ($i = 0; $i < 4; $i++) { $deltatimebyte = ord(substr($trackdata, $eventsoffset++, 1)); $deltatime = ($deltatime << 7) + ($deltatimebyte & 0x7f); if ($deltatimebyte & 0x80) { // another byte follows } else { break; } } $CumulativeDeltaTime += $deltatime; $TicksAtCurrentBPM += $deltatime; $MIDIevents[$tracknumber][$eventid]['deltatime'] = $deltatime; $MIDI_event_channel = ord(substr($trackdata, $eventsoffset++, 1)); if ($MIDI_event_channel & 0x80) { // OK, normal event - MIDI command has MSB set $LastIssuedMIDIcommand = $MIDI_event_channel >> 4; $LastIssuedMIDIchannel = $MIDI_event_channel & 0xf; } else { // running event - assume last command $eventsoffset--; } $MIDIevents[$tracknumber][$eventid]['eventid'] = $LastIssuedMIDIcommand; $MIDIevents[$tracknumber][$eventid]['channel'] = $LastIssuedMIDIchannel; if ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x8) { // Note off (key is released) $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); $velocity = ord(substr($trackdata, $eventsoffset++, 1)); } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x9) { // Note on (key is pressed) $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); $velocity = ord(substr($trackdata, $eventsoffset++, 1)); } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0xa) { // Key after-touch $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); $velocity = ord(substr($trackdata, $eventsoffset++, 1)); } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0xb) { // Control Change $controllernum = ord(substr($trackdata, $eventsoffset++, 1)); $newvalue = ord(substr($trackdata, $eventsoffset++, 1)); } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0xc) { // Program (patch) change $newprogramnum = ord(substr($trackdata, $eventsoffset++, 1)); $ThisFileInfo['midi']['raw']['track'][$tracknumber]['instrumentid'] = $newprogramnum; if ($tracknumber == 10) { $ThisFileInfo['midi']['raw']['track'][$tracknumber]['instrument'] = GeneralMIDIpercussionLookup($newprogramnum); } else { $ThisFileInfo['midi']['raw']['track'][$tracknumber]['instrument'] = GeneralMIDIinstrumentLookup($newprogramnum); } } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0xd) { // Channel after-touch $channelnumber = ord(substr($trackdata, $eventsoffset++, 1)); } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0xe) { // Pitch wheel change (2000H is normal or no change) $changeLSB = ord(substr($trackdata, $eventsoffset++, 1)); $changeMSB = ord(substr($trackdata, $eventsoffset++, 1)); $pitchwheelchange = ($changeMSB & 0x7f) << 7 & ($changeLSB & 0x7f); } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0xf && $MIDIevents[$tracknumber][$eventid]['channel'] == 0xf) { $METAeventCommand = ord(substr($trackdata, $eventsoffset++, 1)); $METAeventLength = ord(substr($trackdata, $eventsoffset++, 1)); $METAeventData = substr($trackdata, $eventsoffset, $METAeventLength); $eventsoffset += $METAeventLength; switch ($METAeventCommand) { case 0x0: // Set track sequence number $track_sequence_number = BigEndian2Int(substr($METAeventData, 0, $METAeventLength)); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['seqno'] = $track_sequence_number; break; case 0x1: // Text: generic $text_generic = substr($METAeventData, 0, $METAeventLength); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['text'] = $text_generic; if (empty($ThisFileInfo['midi']['comments']['comment'])) { $ThisFileInfo['midi']['comments']['comment'] = ''; } $ThisFileInfo['midi']['comments']['comment'] .= $text_generic . "\n"; break; case 0x2: // Text: copyright $text_copyright = substr($METAeventData, 0, $METAeventLength); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['copyright'] = $text_copyright; if (empty($ThisFileInfo['midi']['comments']['copyright'])) { $ThisFileInfo['midi']['comments']['copyright'] = ''; } $ThisFileInfo['midi']['comments']['copyright'] = $text_copyright . "\n"; break; case 0x3: // Text: track name $text_trackname = substr($METAeventData, 0, $METAeventLength); $ThisFileInfo['midi']['raw']['track'][$tracknumber]['name'] = $text_trackname; break; case 0x4: // Text: track instrument name $text_instrument = substr($METAeventData, 0, $METAeventLength); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['instrument'] = $text_instrument; break; case 0x5: // Text: lyric $text_lyric = substr($METAeventData, 0, $METAeventLength); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['lyric'] = $text_lyric; if (!isset($ThisFileInfo['midi']['lyric'])) { $ThisFileInfo['midi']['lyric'] = ''; } $ThisFileInfo['midi']['lyric'] .= $text_lyric . "\n"; break; case 0x6: // Text: marker $text_marker = substr($METAeventData, 0, $METAeventLength); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['marker'] = $text_marker; break; case 0x7: // Text: cue point $text_cuepoint = substr($METAeventData, 0, $METAeventLength); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['cuepoint'] = $text_cuepoint; break; case 0x2f: // End Of Track //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['EOT'] = $CumulativeDeltaTime; break; case 0x51: // Tempo: microseconds / quarter note $CurrentMicroSecondsPerBeat = BigEndian2Int(substr($METAeventData, 0, $METAeventLength)); if ($CurrentMicroSecondsPerBeat == 0) { $ThisFileInfo['error'] .= "\n" . 'Corrupt MIDI file: CurrentMicroSecondsPerBeat == zero'; return false; } $ThisFileInfo['midi']['raw']['events'][$tracknumber][$CumulativeDeltaTime]['us_qnote'] = $CurrentMicroSecondsPerBeat; $CurrentBeatsPerMinute = 1000000 / $CurrentMicroSecondsPerBeat * 60; $MicroSecondsPerQuarterNoteAfter[$CumulativeDeltaTime] = $CurrentMicroSecondsPerBeat; $TicksAtCurrentBPM = 0; break; case 0x58: // Time signature $timesig_numerator = BigEndian2Int($METAeventData[0]); $timesig_denominator = pow(2, BigEndian2Int($METAeventData[1])); // $02 -> x/4, $03 -> x/8, etc $timesig_32inqnote = BigEndian2Int($METAeventData[2]); // number of 32nd notes to the quarter note //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['timesig_32inqnote'] = $timesig_32inqnote; //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['timesig_numerator'] = $timesig_numerator; //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['timesig_denominator'] = $timesig_denominator; //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['timesig_text'] = $timesig_numerator.'/'.$timesig_denominator; $ThisFileInfo['midi']['timesignature'][] = $timesig_numerator . '/' . $timesig_denominator; break; case 0x59: // Keysignature $keysig_sharpsflats = BigEndian2Int($METAeventData[0]); if ($keysig_sharpsflats & 0x80) { // (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps) $keysig_sharpsflats -= 256; } $keysig_majorminor = BigEndian2Int($METAeventData[1]); // 0 -> major, 1 -> minor $keysigs = array(-7 => 'Cb', -6 => 'Gb', -5 => 'Db', -4 => 'Ab', -3 => 'Eb', -2 => 'Bb', -1 => 'F', 0 => 'C', 1 => 'G', 2 => 'D', 3 => 'A', 4 => 'E', 5 => 'B', 6 => 'F#', 7 => 'C#'); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['keysig_flats'] = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0); //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['keysig_minor'] = (bool) $keysig_majorminor; //$ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['keysig_text'] = $keysigs[$keysig_sharpsflats].' '.($ThisFileInfo['midi']['raw']['events'][$tracknumber][$eventid]['keysig_minor'] ? 'minor' : 'major'); // $keysigs[$keysig_sharpsflats] gets an int key (correct) - $keysigs["$keysig_sharpsflats"] gets a string key (incorrect) $ThisFileInfo['midi']['keysignature'][] = $keysigs[$keysig_sharpsflats] . ' ' . ((bool) $keysig_majorminor ? 'minor' : 'major'); break; case 0x7f: // Sequencer specific information $custom_data = substr($METAeventData, 0, $METAeventLength); break; default: $ThisFileInfo['warning'] .= "\n" . 'Unhandled META Event Command: ' . $METAeventCommand; break; } } else { $ThisFileInfo['warning'] .= "\n" . 'Unhandled MIDI Event ID: ' . $MIDIevents[$tracknumber][$eventid]['eventid']; } } if ($tracknumber > 0) { $ThisFileInfo['midi']['totalticks'] = max($ThisFileInfo['midi']['totalticks'], $CumulativeDeltaTime); } } $previoustickoffset = 0; foreach ($MicroSecondsPerQuarterNoteAfter as $tickoffset => $microsecondsperbeat) { if ($ThisFileInfo['midi']['totalticks'] > $tickoffset) { if ($ThisFileInfo['midi']['raw']['ticksperqnote'] == 0) { $ThisFileInfo['error'] .= "\n" . 'Corrupt MIDI file: ticksperqnote == zero'; return false; } $ThisFileInfo['playtime_seconds'] += ($tickoffset - $previoustickoffset) / $ThisFileInfo['midi']['raw']['ticksperqnote'] * ($microsecondsperbeat / 1000000); $previoustickoffset = $tickoffset; } } if ($ThisFileInfo['midi']['totalticks'] > $previoustickoffset) { if ($ThisFileInfo['midi']['raw']['ticksperqnote'] == 0) { $ThisFileInfo['error'] .= "\n" . 'Corrupt MIDI file: ticksperqnote == zero'; return false; } $ThisFileInfo['playtime_seconds'] += ($ThisFileInfo['midi']['totalticks'] - $previoustickoffset) / $ThisFileInfo['midi']['raw']['ticksperqnote'] * ($microsecondsperbeat / 1000000); } } // MIDI tags have highest priority if (!empty($ThisFileInfo['midi']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['midi']['comments'], $ThisFileInfo, true, true, true); // add tag to array of tags $ThisFileInfo['tags'][] = 'midi'; } return true; }
function getPNGHeaderFilepointer(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'png'; $ThisFileInfo['video']['dataformat'] = 'png'; $ThisFileInfo['video']['lossless'] = false; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $PNGfiledata = fread($fd, FREAD_BUFFER_SIZE); $offset = 0; $PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A $offset += 8; if ($PNGidentifier != chr(0x89) . chr(0x50) . chr(0x4e) . chr(0x47) . chr(0xd) . chr(0xa) . chr(0x1a) . chr(0xa)) { $ThisFileInfo['error'] .= "\n" . 'First 8 bytes of file (' . PrintHexBytes($PNGidentifier) . ') did not match expected PNG identifier'; unset($ThisFileInfo['fileformat']); return false; } while (ftell($fd) - (strlen($PNGfiledata) - $offset) < $ThisFileInfo['filesize']) { $chunk['data_length'] = BigEndian2Int(substr($PNGfiledata, $offset, 4)); $offset += 4; while (strlen($PNGfiledata) - $offset < $chunk['data_length'] + 4 && ftell($fd) < $ThisFileInfo['filesize']) { $PNGfiledata .= fread($fd, FREAD_BUFFER_SIZE); } $chunk['type_text'] = substr($PNGfiledata, $offset, 4); $offset += 4; $chunk['type_raw'] = BigEndian2Int($chunk['type_text']); $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']); $offset += $chunk['data_length']; $chunk['crc'] = BigEndian2Int(substr($PNGfiledata, $offset, 4)); $offset += 4; $chunk['flags']['ancilliary'] = (bool) ($chunk['type_raw'] & 0x20000000); $chunk['flags']['private'] = (bool) ($chunk['type_raw'] & 0x200000); $chunk['flags']['reserved'] = (bool) ($chunk['type_raw'] & 0x2000); $chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x20); switch ($chunk['type_text']) { case 'IHDR': // Image Header $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['width'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 4)); $ThisFileInfo['png'][$chunk['type_text']]['height'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 4, 4)); $ThisFileInfo['png'][$chunk['type_text']]['raw']['bit_depth'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 8, 1)); $ThisFileInfo['png'][$chunk['type_text']]['raw']['color_type'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 9, 1)); $ThisFileInfo['png'][$chunk['type_text']]['raw']['compression_method'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 10, 1)); $ThisFileInfo['png'][$chunk['type_text']]['raw']['filter_method'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 11, 1)); $ThisFileInfo['png'][$chunk['type_text']]['raw']['interlace_method'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 12, 1)); $ThisFileInfo['png'][$chunk['type_text']]['compression_method_text'] = PNGcompressionMethodLookup($ThisFileInfo['png'][$chunk['type_text']]['raw']['compression_method']); $ThisFileInfo['png'][$chunk['type_text']]['color_type']['palette'] = (bool) ($ThisFileInfo['png'][$chunk['type_text']]['raw']['color_type'] & 0x1); $ThisFileInfo['png'][$chunk['type_text']]['color_type']['true_color'] = (bool) ($ThisFileInfo['png'][$chunk['type_text']]['raw']['color_type'] & 0x2); $ThisFileInfo['png'][$chunk['type_text']]['color_type']['alpha'] = (bool) ($ThisFileInfo['png'][$chunk['type_text']]['raw']['color_type'] & 0x4); $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['png'][$chunk['type_text']]['width']; $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['png'][$chunk['type_text']]['height']; $ThisFileInfo['video']['bits_per_sample'] = IHDRcalculateBitsPerSample($ThisFileInfo['png'][$chunk['type_text']]['raw']['color_type'], $ThisFileInfo['png'][$chunk['type_text']]['raw']['bit_depth']); break; case 'PLTE': // Palette $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $paletteoffset = 0; for ($i = 0; $i <= 255; $i++) { //$ThisFileInfo['png'][$chunk['type_text']]['red'][$i] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $paletteoffset++, 1)); //$ThisFileInfo['png'][$chunk['type_text']]['green'][$i] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $paletteoffset++, 1)); //$ThisFileInfo['png'][$chunk['type_text']]['blue'][$i] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $paletteoffset++, 1)); $red = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $paletteoffset++, 1)); $green = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $paletteoffset++, 1)); $blue = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $paletteoffset++, 1)); $ThisFileInfo['png'][$chunk['type_text']][$i] = $red << 16 | $green << 8 | $blue; } break; case 'tRNS': // Transparency $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; switch ($ThisFileInfo['png']['IHDR']['raw']['color_type']) { case 0: $ThisFileInfo['png'][$chunk['type_text']]['transparent_color_gray'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 2)); break; case 2: $ThisFileInfo['png'][$chunk['type_text']]['transparent_color_red'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 2)); $ThisFileInfo['png'][$chunk['type_text']]['transparent_color_green'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 2)); $ThisFileInfo['png'][$chunk['type_text']]['transparent_color_blue'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 2)); break; case 3: for ($i = 0; $i < strlen($ThisFileInfo['png'][$chunk['type_text']]['header']['data']); $i++) { $ThisFileInfo['png'][$chunk['type_text']]['palette_opacity'][$i] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $i, 1)); } break; case 4: case 6: $ThisFileInfo['error'] .= "\n" . 'Invalid color_type in tRNS chunk: ' . $ThisFileInfo['png']['IHDR']['raw']['color_type']; default: $ThisFileInfo['warning'] .= "\n" . 'Unhandled color_type in tRNS chunk: ' . $ThisFileInfo['png']['IHDR']['raw']['color_type']; break; } break; case 'gAMA': // Image Gamma $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['gamma'] = BigEndian2Int($ThisFileInfo['png'][$chunk['type_text']]['header']['data']) / 100000; break; case 'cHRM': // Primary Chromaticities $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['white_x'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 4)) / 100000; $ThisFileInfo['png'][$chunk['type_text']]['white_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 4, 4)) / 100000; $ThisFileInfo['png'][$chunk['type_text']]['red_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 8, 4)) / 100000; $ThisFileInfo['png'][$chunk['type_text']]['red_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 12, 4)) / 100000; $ThisFileInfo['png'][$chunk['type_text']]['green_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 16, 4)) / 100000; $ThisFileInfo['png'][$chunk['type_text']]['green_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 20, 4)) / 100000; $ThisFileInfo['png'][$chunk['type_text']]['blue_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 24, 4)) / 100000; $ThisFileInfo['png'][$chunk['type_text']]['blue_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 28, 4)) / 100000; break; case 'sRGB': // Standard RGB Color Space $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['reindering_intent'] = BigEndian2Int($ThisFileInfo['png'][$chunk['type_text']]['header']['data']); $ThisFileInfo['png'][$chunk['type_text']]['reindering_intent_text'] = PNGsRGBintentLookup($ThisFileInfo['png'][$chunk['type_text']]['reindering_intent']); break; case 'iCCP': // Embedded ICC Profile $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; list($profilename, $compressiondata) = explode(chr(0x0), $ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2); $ThisFileInfo['png'][$chunk['type_text']]['profile_name'] = $profilename; $ThisFileInfo['png'][$chunk['type_text']]['compression_method'] = BigEndian2Int(substr($compressiondata, 0, 1)); $ThisFileInfo['png'][$chunk['type_text']]['compression_profile'] = substr($compressiondata, 1); $ThisFileInfo['png'][$chunk['type_text']]['compression_method_text'] = PNGcompressionMethodLookup($ThisFileInfo['png'][$chunk['type_text']]['compression_method']); break; case 'tEXt': // Textual Data $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; list($keyword, $text) = explode(chr(0x0), $ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2); $ThisFileInfo['png'][$chunk['type_text']]['keyword'] = $keyword; $ThisFileInfo['png'][$chunk['type_text']]['text'] = $text; $ThisFileInfo['png']['comments'][$ThisFileInfo['png'][$chunk['type_text']]['keyword']][] = $ThisFileInfo['png'][$chunk['type_text']]['text']; break; case 'zTXt': // Compressed Textual Data $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; list($keyword, $otherdata) = explode(chr(0x0), $ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2); $ThisFileInfo['png'][$chunk['type_text']]['keyword'] = $keyword; $ThisFileInfo['png'][$chunk['type_text']]['compression_method'] = BigEndian2Int(substr($otherdata, 0, 1)); $ThisFileInfo['png'][$chunk['type_text']]['compressed_text'] = substr($otherdata, 1); $ThisFileInfo['png'][$chunk['type_text']]['compression_method_text'] = PNGcompressionMethodLookup($ThisFileInfo['png'][$chunk['type_text']]['compression_method']); switch ($ThisFileInfo['png'][$chunk['type_text']]['compression_method']) { case 0: $ThisFileInfo['png'][$chunk['type_text']]['text'] = gzuncompress($ThisFileInfo['png'][$chunk['type_text']]['compressed_text']); break; default: // unknown compression method break; } if (isset($ThisFileInfo['png'][$chunk['type_text']]['text'])) { $ThisFileInfo['png']['comments'][$ThisFileInfo['png'][$chunk['type_text']]['keyword']][] = $ThisFileInfo['png'][$chunk['type_text']]['text']; } break; case 'iTXt': // International Textual Data $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; list($keyword, $otherdata) = explode(chr(0x0), $ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2); $ThisFileInfo['png'][$chunk['type_text']]['keyword'] = $keyword; $ThisFileInfo['png'][$chunk['type_text']]['compression'] = (bool) BigEndian2Int(substr($otherdata, 0, 1)); $ThisFileInfo['png'][$chunk['type_text']]['compression_method'] = BigEndian2Int(substr($otherdata, 1, 1)); $ThisFileInfo['png'][$chunk['type_text']]['compression_method_text'] = PNGcompressionMethodLookup($ThisFileInfo['png'][$chunk['type_text']]['compression_method']); list($languagetag, $translatedkeyword, $text) = explode(chr(0x0), substr($otherdata, 2), 3); $ThisFileInfo['png'][$chunk['type_text']]['language_tag'] = $languagetag; $ThisFileInfo['png'][$chunk['type_text']]['translated_keyword'] = utf8_decode($translatedkeyword); if ($ThisFileInfo['png'][$chunk['type_text']]['compression']) { switch ($ThisFileInfo['png'][$chunk['type_text']]['compression_method']) { case 0: $ThisFileInfo['png'][$chunk['type_text']]['text'] = utf8_decode(gzuncompress($text)); break; default: // unknown compression method break; } } else { $ThisFileInfo['png'][$chunk['type_text']]['text'] = utf8_decode($text); } if (isset($ThisFileInfo['png'][$chunk['type_text']]['text'])) { $ThisFileInfo['png']['comments'][$ThisFileInfo['png'][$chunk['type_text']]['keyword']][] = $ThisFileInfo['png'][$chunk['type_text']]['text']; } break; case 'bKGD': // Background Color $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; switch ($ThisFileInfo['png']['IHDR']['raw']['color_type']) { case 0: case 4: $ThisFileInfo['png'][$chunk['type_text']]['background_gray'] = BigEndian2Int($ThisFileInfo['png'][$chunk['type_text']]['header']['data']); break; case 2: case 6: $ThisFileInfo['png'][$chunk['type_text']]['background_red'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0 * $ThisFileInfo['png']['IHDR']['raw']['bit_depth'], $ThisFileInfo['png']['IHDR']['raw']['bit_depth'])); $ThisFileInfo['png'][$chunk['type_text']]['background_green'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 1 * $ThisFileInfo['png']['IHDR']['raw']['bit_depth'], $ThisFileInfo['png']['IHDR']['raw']['bit_depth'])); $ThisFileInfo['png'][$chunk['type_text']]['background_blue'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2 * $ThisFileInfo['png']['IHDR']['raw']['bit_depth'], $ThisFileInfo['png']['IHDR']['raw']['bit_depth'])); break; case 3: $ThisFileInfo['png'][$chunk['type_text']]['background_index'] = BigEndian2Int($ThisFileInfo['png'][$chunk['type_text']]['header']['data']); break; default: break; } break; case 'pHYs': // Physical Pixel Dimensions $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['pixels_per_unit_x'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 4)); $ThisFileInfo['png'][$chunk['type_text']]['pixels_per_unit_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 4, 4)); $ThisFileInfo['png'][$chunk['type_text']]['unit_specifier'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 8, 1)); $ThisFileInfo['png'][$chunk['type_text']]['unit'] = PNGpHYsUnitLookup($ThisFileInfo['png'][$chunk['type_text']]['unit_specifier']); break; case 'sBIT': // Significant Bits $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; switch ($ThisFileInfo['png']['IHDR']['raw']['color_type']) { case 0: $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_gray'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 1)); break; case 2: case 3: $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_red'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 1)); $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_green'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 1, 1)); $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_blue'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2, 1)); break; case 4: $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_gray'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 1)); $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_alpha'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 1, 1)); break; case 6: $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_red'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 1)); $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_green'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 1, 1)); $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_blue'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2, 1)); $ThisFileInfo['png'][$chunk['type_text']]['significant_bits_alpha'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 3, 1)); break; default: break; } break; case 'sPLT': // Suggested Palette $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; list($palettename, $otherdata) = explode(chr(0x0), $ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2); $ThisFileInfo['png'][$chunk['type_text']]['palette_name'] = $palettename; $sPLToffset = 0; $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bits'] = BigEndian2Int(substr($otherdata, $sPLToffset, 1)); $sPLToffset += 1; $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes'] = $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bits'] / 8; $paletteCounter = 0; while ($sPLToffset < strlen($otherdata)) { $ThisFileInfo['png'][$chunk['type_text']]['red'][$paletteCounter] = BigEndian2Int(substr($otherdata, $sPLToffset, $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes'])); $sPLToffset += $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes']; $ThisFileInfo['png'][$chunk['type_text']]['green'][$paletteCounter] = BigEndian2Int(substr($otherdata, $sPLToffset, $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes'])); $sPLToffset += $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes']; $ThisFileInfo['png'][$chunk['type_text']]['blue'][$paletteCounter] = BigEndian2Int(substr($otherdata, $sPLToffset, $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes'])); $sPLToffset += $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes']; $ThisFileInfo['png'][$chunk['type_text']]['alpha'][$paletteCounter] = BigEndian2Int(substr($otherdata, $sPLToffset, $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes'])); $sPLToffset += $ThisFileInfo['png'][$chunk['type_text']]['sample_depth_bytes']; $ThisFileInfo['png'][$chunk['type_text']]['frequency'][$paletteCounter] = BigEndian2Int(substr($otherdata, $sPLToffset, 2)); $sPLToffset += 2; $paletteCounter++; } break; case 'hIST': // Palette Histogram $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $hISTcounter = 0; while ($hISTcounter < strlen($ThisFileInfo['png'][$chunk['type_text']]['header']['data'])) { $ThisFileInfo['png'][$chunk['type_text']][$hISTcounter] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $hISTcounter / 2, 2)); $hISTcounter += 2; } break; case 'tIME': // Image Last-Modification Time $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['year'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 2)); $ThisFileInfo['png'][$chunk['type_text']]['month'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2, 1)); $ThisFileInfo['png'][$chunk['type_text']]['day'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 3, 1)); $ThisFileInfo['png'][$chunk['type_text']]['hour'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 4, 1)); $ThisFileInfo['png'][$chunk['type_text']]['minute'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 5, 1)); $ThisFileInfo['png'][$chunk['type_text']]['second'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 6, 1)); $ThisFileInfo['png'][$chunk['type_text']]['unix'] = gmmktime($ThisFileInfo['png'][$chunk['type_text']]['hour'], $ThisFileInfo['png'][$chunk['type_text']]['minute'], $ThisFileInfo['png'][$chunk['type_text']]['second'], $ThisFileInfo['png'][$chunk['type_text']]['month'], $ThisFileInfo['png'][$chunk['type_text']]['day'], $ThisFileInfo['png'][$chunk['type_text']]['year']); break; case 'oFFs': // Image Offset $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['position_x'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 4), false, true); $ThisFileInfo['png'][$chunk['type_text']]['position_y'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 4, 4), false, true); $ThisFileInfo['png'][$chunk['type_text']]['unit_specifier'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 8, 1)); $ThisFileInfo['png'][$chunk['type_text']]['unit'] = PNGoFFsUnitLookup($ThisFileInfo['png'][$chunk['type_text']]['unit_specifier']); break; case 'pCAL': // Calibration Of Pixel Values $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; list($calibrationname, $otherdata) = explode(chr(0x0), $ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2); $ThisFileInfo['png'][$chunk['type_text']]['calibration_name'] = $calibrationname; $pCALoffset = 0; $ThisFileInfo['png'][$chunk['type_text']]['original_zero'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $pCALoffset, 4), false, true); $pCALoffset += 4; $ThisFileInfo['png'][$chunk['type_text']]['original_max'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $pCALoffset, 4), false, true); $pCALoffset += 4; $ThisFileInfo['png'][$chunk['type_text']]['equation_type'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $pCALoffset, 1)); $pCALoffset += 1; $ThisFileInfo['png'][$chunk['type_text']]['equation_type_text'] = PNGpCALequationTypeLookup($ThisFileInfo['png'][$chunk['type_text']]['equation_type']); $ThisFileInfo['png'][$chunk['type_text']]['parameter_count'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $pCALoffset, 1)); $pCALoffset += 1; $ThisFileInfo['png'][$chunk['type_text']]['parameters'] = explode(chr(0x0), substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], $pCALoffset)); break; case 'sCAL': // Physical Scale Of Image Subject $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']]['unit_specifier'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 1)); $ThisFileInfo['png'][$chunk['type_text']]['unit'] = PNGsCALUnitLookup($ThisFileInfo['png'][$chunk['type_text']]['unit_specifier']); list($pixelwidth, $pixelheight) = explode(chr(0x0), substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 1)); $ThisFileInfo['png'][$chunk['type_text']]['pixel_width'] = $pixelwidth; $ThisFileInfo['png'][$chunk['type_text']]['pixel_height'] = $pixelheight; break; case 'gIFg': // GIF Graphic Control Extension $gIFgCounter = 0; if (isset($ThisFileInfo['png'][$chunk['type_text']]) && is_array($ThisFileInfo['png'][$chunk['type_text']])) { $gIFgCounter = count($ThisFileInfo['png'][$chunk['type_text']]); } $ThisFileInfo['png'][$chunk['type_text']][$gIFgCounter]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']][$gIFgCounter]['disposal_method'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 1)); $ThisFileInfo['png'][$chunk['type_text']][$gIFgCounter]['user_input_flag'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 1, 1)); $ThisFileInfo['png'][$chunk['type_text']][$gIFgCounter]['delay_time'] = BigEndian2Int(substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 2, 2)); break; case 'gIFx': // GIF Application Extension $gIFxCounter = 0; if (isset($ThisFileInfo['png'][$chunk['type_text']]) && is_array($ThisFileInfo['png'][$chunk['type_text']])) { $gIFxCounter = count($ThisFileInfo['png'][$chunk['type_text']]); } $ThisFileInfo['png'][$chunk['type_text']][$gIFxCounter]['header'] = $chunk; $ThisFileInfo['png'][$chunk['type_text']][$gIFxCounter]['application_identifier'] = substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 0, 8); $ThisFileInfo['png'][$chunk['type_text']][$gIFxCounter]['authentication_code'] = substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 8, 3); $ThisFileInfo['png'][$chunk['type_text']][$gIFxCounter]['application_data'] = substr($ThisFileInfo['png'][$chunk['type_text']]['header']['data'], 11); break; case 'IDAT': // Image Data $idatinformationfieldindex = 0; if (isset($ThisFileInfo['png']['IDAT']) && is_array($ThisFileInfo['png']['IDAT'])) { $idatinformationfieldindex = count($ThisFileInfo['png']['IDAT']); } unset($chunk['data']); $ThisFileInfo['png'][$chunk['type_text']][$idatinformationfieldindex]['header'] = $chunk; break; case 'IEND': // Image Trailer $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; break; default: //unset($chunk['data']); $ThisFileInfo['png'][$chunk['type_text']]['header'] = $chunk; $ThisFileInfo['warning'] .= "\n" . 'Unhandled chunk type: ' . $chunk['type_text']; break; } } // PNG tags have highest priority if (!empty($ThisFileInfo['png']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['png']['comments'], $ThisFileInfo, true, true, true); // add tag to array of tags $ThisFileInfo['tags'][] = 'png'; } return true; }
function getRIFFHeaderFilepointer(&$fd, &$ThisFileInfo) { $Original['avdataoffset'] = $ThisFileInfo['avdataoffset']; $Original['avdataend'] = $ThisFileInfo['avdataend']; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $RIFFheader = fread($fd, 12); switch (substr($RIFFheader, 0, 4)) { case 'FORM': $ThisFileInfo['fileformat'] = 'aiff'; $RIFFheaderSize = EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4)); $ThisFileInfo['RIFF'][substr($RIFFheader, 8, 4)] = ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + $RIFFheaderSize, $ThisFileInfo); $ThisFileInfo['RIFF']['header_size'] = $RIFFheaderSize; break; case 'RIFF': case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s $RIFFtype = substr($RIFFheader, 8, 4); if ($RIFFtype == 'RMP3') { $RIFFtype == 'WAVE'; } $ThisFileInfo['fileformat'] = 'riff'; $RIFFheaderSize = EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4)); $ThisFileInfo['RIFF']["{$RIFFtype}"] = ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + $RIFFheaderSize, $ThisFileInfo); $ThisFileInfo['RIFF']['header_size'] = $RIFFheaderSize; break; default: $ThisFileInfo['error'] .= "\n" . 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?)'; unset($ThisFileInfo['fileformat']); return false; break; } $streamindex = 0; $arraykeys = array_keys($ThisFileInfo['RIFF']); switch ($arraykeys[0]) { case 'WAVE': case 'RMP3': // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s if (empty($ThisFileInfo['audio']['bitrate_mode'])) { $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; } if (empty($ThisFileInfo['audio']['dataformat'])) { $ThisFileInfo['audio']['dataformat'] = 'wav'; } if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['data'][0]['offset'])) { $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['data'][0]['offset'] + 8; $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['data'][0]['size']; } if (isset($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data'])) { $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data']); if ($ThisFileInfo['RIFF']['audio'][$streamindex] == 0) { $ThisFileInfo['error'] .= 'Corrupt RIFF file: bitrate_audio == zero'; return false; } $ThisFileInfo['RIFF']['raw']['fmt '] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw']; unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']); $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]); if (substr($ThisFileInfo['audio']['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') { $ThisFileInfo['warning'] .= "\n" . 'Audio codec = ' . $ThisFileInfo['audio']['codec']; } $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate']; if ($ThisFileInfo['audio']['bits_per_sample'] == 0) { unset($ThisFileInfo['audio']['bits_per_sample']); } $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']); if (isset($ThisFileInfo['RIFF']['WAVE']['data'][0]['offset']) && isset($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag'])) { $ThisFileInfo['audio']['lossless'] = false; switch ($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag']) { case 1: // PCM $ThisFileInfo['audio']['lossless'] = true; break; default: // do nothing break; } } } if (isset($ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data'])) { require_once GETID3_INCLUDEPATH . 'getid3.rgad.php'; $rgadData = $ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data']; $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'] = LittleEndian2Float(substr($rgadData, 0, 4)); $ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust'] = EitherEndian2Int($ThisFileInfo, substr($rgadData, 4, 2)); $ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust'] = EitherEndian2Int($ThisFileInfo, substr($rgadData, 6, 2)); $nRadioRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); $nAudiophileRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1)); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9)); $ThisFileInfo['RIFF']['rgad']['peakamplitude'] = $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude']; if ($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] != 0) { $ThisFileInfo['RIFF']['rgad']['radio']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name']); $ThisFileInfo['RIFF']['rgad']['radio']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator']); $ThisFileInfo['RIFF']['rgad']['radio']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit']); } if ($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] != 0) { $ThisFileInfo['RIFF']['rgad']['audiophile']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name']); $ThisFileInfo['RIFF']['rgad']['audiophile']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator']); $ThisFileInfo['RIFF']['rgad']['audiophile']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit']); } } if (isset($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'])) { $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] = EitherEndian2Int($ThisFileInfo, substr($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'], 0, 4)); if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'] > 0) { $ThisFileInfo['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] / $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']; } if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) { $ThisFileInfo['audio']['bitrate'] = CastAsInt($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec'] * 8); } } if (isset($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'])) { $ThisFileInfo['RIFF']['WAVE']['bext'][0]['title'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 0, 256)); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['author'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 256, 32)); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['reference'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 288, 32)); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'] = substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 320, 10); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'] = substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 330, 8); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['time_reference'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 338, 8)); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['bwf_version'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 346, 1)); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['reserved'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 347, 254)); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['coding_history'] = explode("\r\n", trim(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['data'], 601))); $ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date_unix'] = mktime(substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'], 0, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'], 3, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_time'], 6, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'], 5, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'], 8, 2), substr($ThisFileInfo['RIFF']['WAVE']['bext'][0]['origin_date'], 0, 4)); $ThisFileInfo['RIFF']['comments']['author'][] = $ThisFileInfo['RIFF']['WAVE']['bext'][0]['author']; $ThisFileInfo['RIFF']['comments']['title'][] = $ThisFileInfo['RIFF']['WAVE']['bext'][0]['title']; } if (isset($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'])) { $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 0, 2)); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['homogenous'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x1); if ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['homogenous']) { $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['padding'] = InverseBoolean($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x2); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['22_or_44'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x4); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['free_format'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['sound_information'] & 0x8); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['nominal_frame_size'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 2, 2)); } $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['anciliary_data_length'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 6, 2)); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['data'], 8, 2)); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['anciliary_data_left'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] & 0x1); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['anciliary_data_free'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] & 0x2); $ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['flags']['anciliary_data_right'] = (bool) ($ThisFileInfo['RIFF']['WAVE']['MEXT'][0]['raw']['anciliary_data_def'] & 0x4); } if (isset($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'])) { $ThisFileInfo['RIFF']['WAVE']['cart'][0]['version'] = substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 0, 4); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['title'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 4, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['artist'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 68, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['cut_id'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 132, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['client_id'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 196, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['category'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 260, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['classification'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 324, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['out_cue'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 388, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['start_date'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 452, 10)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['start_time'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 462, 8)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['end_date'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 470, 10)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['end_time'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 480, 8)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['producer_app_id'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 488, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['producer_app_version'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 552, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['user_defined_text'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 616, 64)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['zero_db_reference'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 680, 4), true); for ($i = 0; $i < 8; $i++) { $ThisFileInfo['RIFF']['WAVE']['cart'][0]['post_time'][$i]['usage_fourcc'] = substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 684 + $i * 8, 4); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['post_time'][$i]['timer_value'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 684 + $i * 8 + 4, 4)); } $ThisFileInfo['RIFF']['WAVE']['cart'][0]['url'] = trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 748, 1024)); $ThisFileInfo['RIFF']['WAVE']['cart'][0]['tag_text'] = explode("\r\n", trim(substr($ThisFileInfo['RIFF']['WAVE']['cart'][0]['data'], 1772))); $ThisFileInfo['RIFF']['comments']['artist'][] = $ThisFileInfo['RIFF']['WAVE']['cart'][0]['artist']; $ThisFileInfo['RIFF']['comments']['title'][] = $ThisFileInfo['RIFF']['WAVE']['cart'][0]['title']; } if (!isset($ThisFileInfo['audio']['bitrate']) && isset($ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'])) { $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate']; $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']); } if (!empty($ThisFileInfo['wavpack'])) { $ThisFileInfo['audio']['dataformat'] = 'wavpack'; $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; $ThisFileInfo['audio']['encoder'] = 'WavPack v' . $ThisFileInfo['wavpack']['version']; // Reset to the way it was - RIFF parsing will have messed this up $ThisFileInfo['avdataend'] = $Original['avdataend']; $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds']; fseek($fd, $ThisFileInfo['avdataoffset'] - 44, SEEK_SET); $RIFFdata = fread($fd, 44); $OrignalRIFFheaderSize = LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8; $OrignalRIFFdataSize = LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { $ThisFileInfo['avdataend'] -= $OrignalRIFFheaderSize - $OrignalRIFFdataSize; fseek($fd, $ThisFileInfo['avdataend'], SEEK_SET); $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize); } // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk $RIFFdata = substr($RIFFdata, 0, 36) . substr($RIFFdata, 44) . substr($RIFFdata, 36, 8); ParseRIFFdata($RIFFdata, $ThisFileInfo); } break; case 'AVI ': $ThisFileInfo['video']['bitrate_mode'] = 'cbr'; $ThisFileInfo['video']['dataformat'] = 'avi'; $ThisFileInfo['mime_type'] = 'video/avi'; if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['movi']['offset'])) { $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['movi']['offset'] + 8; $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['movi']['size']; } if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data'])) { $avihData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data']; $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 0, 4)); // frame display rate (or 0L) if ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] == 0) { $ThisFileInfo['error'] .= 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero'; return false; } $ThisFileInfo['RIFF']['raw']['avih']['dwMaxBytesPerSec'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 4, 4)); // max. transfer rate $ThisFileInfo['RIFF']['raw']['avih']['dwPaddingGranularity'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 8, 4)); // pad to multiples of this size; normally 2K. $ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 12, 4)); // the ever-present flags $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 16, 4)); // # frames in file $ThisFileInfo['RIFF']['raw']['avih']['dwInitialFrames'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 20, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwStreams'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 24, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwSuggestedBufferSize'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 28, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwWidth'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 32, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwHeight'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 36, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwScale'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 40, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwRate'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 44, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwStart'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 48, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwLength'] = EitherEndian2Int($ThisFileInfo, substr($avihData, 52, 4)); $ThisFileInfo['RIFF']['raw']['avih']['flags']['hasindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10); $ThisFileInfo['RIFF']['raw']['avih']['flags']['mustuseindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20); $ThisFileInfo['RIFF']['raw']['avih']['flags']['interleaved'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x100); $ThisFileInfo['RIFF']['raw']['avih']['flags']['trustcktype'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x800); $ThisFileInfo['RIFF']['raw']['avih']['flags']['capturedfile'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10000); $ThisFileInfo['RIFF']['raw']['avih']['flags']['copyrighted'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20010); if ($ThisFileInfo['RIFF']['raw']['avih']['dwWidth'] > 0) { $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width'] = $ThisFileInfo['RIFF']['raw']['avih']['dwWidth']; $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width']; } if ($ThisFileInfo['RIFF']['raw']['avih']['dwHeight'] > 0) { $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height'] = $ThisFileInfo['RIFF']['raw']['avih']['dwHeight']; $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height']; } $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate'] = round(1000000 / $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'], 3); $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate']; } if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][0]['data'])) { if (is_array($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'])) { for ($i = 0; $i < count($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh']); $i++) { if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { $strhData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data']; $strhfccType = substr($strhData, 0, 4); if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data'])) { $strfData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data']; switch ($strhfccType) { case 'auds': $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['dataformat'] = 'wav'; if (isset($ThisFileInfo['RIFF']['audio']) && is_array($ThisFileInfo['RIFF']['audio'])) { $streamindex = count($ThisFileInfo['RIFF']['audio']); } $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($strfData); $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw']; unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']); $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]); $ThisFileInfo['audio']['lossless'] = false; switch ($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['wFormatTag']) { case 1: // PCM $ThisFileInfo['audio']['lossless'] = true; break; case 85: // MPEG Layer 3 $ThisFileInfo['audio']['dataformat'] = 'mp3'; break; case 8192: // AC-3 $ThisFileInfo['audio']['dataformat'] = 'ac3'; break; default: $ThisFileInfo['audio']['dataformat'] = 'wav'; break; } break; case 'iavs': case 'vids': $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccType'] = substr($strhData, 0, 4); // same as $strhfccType; $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler'] = substr($strhData, 4, 4); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwFlags'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 8, 4)); // Contains AVITF_* flags $ThisFileInfo['RIFF']['raw']['strh'][$i]['wPriority'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 12, 2)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['wLanguage'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 14, 2)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwInitialFrames'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 16, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwScale'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 20, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwRate'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 24, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwStart'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 28, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwLength'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 32, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSuggestedBufferSize'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 36, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwQuality'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 40, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSampleSize'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 44, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['rcFrame'] = EitherEndian2Int($ThisFileInfo, substr($strhData, 48, 4)); $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler']); if (!$ThisFileInfo['RIFF']['video'][$streamindex]['codec'] && isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) { $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']); } $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec']; switch ($ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler']) { case 'HFYU': // Huffman Lossless Codec // Huffman Lossless Codec case 'IRAW': // Intel YUV Uncompressed // Intel YUV Uncompressed case 'YUY2': // Uncompressed YUV 4:2:2 $ThisFileInfo['video']['lossless'] = true; break; default: $ThisFileInfo['video']['lossless'] = false; break; } switch ($strhfccType) { case 'vids': $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSize'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 0, 4)); // number of bytes required by the BITMAPINFOHEADER structure $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biWidth'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 4, 4)); // width of the bitmap in pixels $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biHeight'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 8, 4)); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biPlanes'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 12, 2)); // number of color planes on the target device. In most cases this value must be set to 1 $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biBitCount'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 14, 2)); // Specifies the number of bits per pixels $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'] = substr($strfData, 16, 4); // $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSizeImage'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 20, 4)); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures) $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biXPelsPerMeter'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 24, 4)); // horizontal resolution, in pixels per metre, of the target device $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biYPelsPerMeter'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 28, 4)); // vertical resolution, in pixels per metre, of the target device $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrUsed'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 32, 4)); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrImportant'] = EitherEndian2Int($ThisFileInfo, substr($strfData, 36, 4)); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important $ThisFileInfo['video']['bits_per_sample'] = $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biBitCount']; if ($ThisFileInfo['RIFF']['video'][$streamindex]['codec'] == 'DV') { $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 2; } break; case 'iavs': $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 1; break; } break; default: $ThisFileInfo['warning'] .= "\n" . 'Unhandled fccType for stream (' . $i . '): "' . $strhfccType . '"'; break; } } } if (isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) { $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']); $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec']; switch ($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) { case 'HFYU': // Huffman Lossless Codec // Huffman Lossless Codec case 'IRAW': // Intel YUV Uncompressed // Intel YUV Uncompressed case 'YUY2': // Uncompressed YUV 4:2:2 $ThisFileInfo['video']['lossless'] = true; $ThisFileInfo['video']['bits_per_sample'] = 24; break; default: $ThisFileInfo['video']['lossless'] = false; $ThisFileInfo['video']['bits_per_sample'] = 24; break; } } } } } break; case 'CDDA': $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['dataformat'] = 'cda'; $ThisFileInfo['audio']['lossless'] = true; unset($ThisFileInfo['mime_type']); $ThisFileInfo['avdataoffset'] = 44; if (isset($ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data'])) { $fmtData = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data']; $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown1'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 0, 2)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 2, 2)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['disc_id'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 4, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 8, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 12, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown6'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 16, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown7'] = EitherEndian2Int($ThisFileInfo, substr($fmtData, 20, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] / 75; $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] / 75; $ThisFileInfo['comments']['track'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num']; $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds']; // hardcoded data for CD-audio $ThisFileInfo['audio']['sample_rate'] = 44100; $ThisFileInfo['audio']['channels'] = 2; $ThisFileInfo['audio']['bits_per_sample'] = 16; $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['audio']['sample_rate'] * $ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['bits_per_sample']; $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; } break; case 'AIFF': case 'AIFC': $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['dataformat'] = 'aiff'; $ThisFileInfo['audio']['lossless'] = true; $ThisFileInfo['mime_type'] = 'audio/x-aiff'; if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['offset'])) { $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['offset'] + 8; $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['size']; if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) { if ($ThisFileInfo['avdataend'] == $ThisFileInfo['filesize'] + 1 && $ThisFileInfo['filesize'] % 2 == 1) { // structures rounded to 2-byte boundary, but dumb encoders // forget to pad end of file to make this actually work } else { $ThisFileInfo['warning'] .= "\n" . 'Probable truncated AIFF file: expecting ' . $ThisFileInfo['RIFF'][$arraykeys[0]]['SSND'][0]['size'] . ' bytes of audio data, only ' . ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) . ' bytes found'; } $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize']; } } if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'])) { $ThisFileInfo['RIFF']['audio']['channels'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 0, 2), true); $ThisFileInfo['RIFF']['audio']['total_samples'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 2, 4), false); $ThisFileInfo['RIFF']['audio']['bits_per_sample'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 6, 2), true); $ThisFileInfo['RIFF']['audio']['sample_rate'] = (int) BigEndian2Float(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 8, 10)); if ($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['size'] > 18) { $ThisFileInfo['RIFF']['audio']['codec_fourcc'] = substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 18, 4); $CodecNameSize = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 22, 1), false); $ThisFileInfo['RIFF']['audio']['codec_name'] = substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMM'][0]['data'], 23, $CodecNameSize); if ($ThisFileInfo['RIFF']['audio']['codec_name'] == 'NONE') { $ThisFileInfo['audio']['codec'] = 'Pulse Code Modulation (PCM)'; $ThisFileInfo['audio']['lossless'] = true; } else { $ThisFileInfo['audio']['codec'] = $ThisFileInfo['RIFF']['audio']['codec_name']; $ThisFileInfo['audio']['lossless'] = false; } } $ThisFileInfo['audio']['channels'] = $ThisFileInfo['RIFF']['audio']['channels']; if ($ThisFileInfo['RIFF']['audio']['bits_per_sample'] > 0) { $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['RIFF']['audio']['bits_per_sample']; } $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['RIFF']['audio']['sample_rate']; if ($ThisFileInfo['audio']['sample_rate'] == 0) { $ThisFileInfo['error'] .= "\n" . 'Corrupted AIFF file: sample_rate == zero'; return false; } $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['audio']['total_samples'] / $ThisFileInfo['audio']['sample_rate']; } if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'])) { $offset = 0; $CommentCount = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 2), false); $offset += 2; for ($i = 0; $i < $CommentCount; $i++) { $ThisFileInfo['comments_raw'][$i]['timestamp'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 4), false); $offset += 4; $ThisFileInfo['comments_raw'][$i]['marker_id'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 2), true); $offset += 2; $CommentLength = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, 2), false); $offset += 2; $ThisFileInfo['comments_raw'][$i]['comment'] = substr($ThisFileInfo['RIFF'][$arraykeys[0]]['COMT'][0]['data'], $offset, $CommentLength); $offset += $CommentLength; $ThisFileInfo['comments_raw'][$i]['timestamp_unix'] = DateMac2Unix($ThisFileInfo['comments_raw'][$i]['timestamp']); $ThisFileInfo['RIFF']['comments']['comment'][] = $ThisFileInfo['comments_raw'][$i]['comment']; } } $CommentsChunkNames = array('NAME' => 'title', 'author' => 'artist', '(c) ' => 'copyright', 'ANNO' => 'comment'); foreach ($CommentsChunkNames as $key => $value) { if (isset($ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data'])) { $ThisFileInfo['RIFF']['comments'][$value][] = $ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data']; } } if (isset($ThisFileInfo['RIFF']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, true, true); } break; case '8SVX': $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['dataformat'] = '8svx'; $ThisFileInfo['audio']['bits_per_sample'] = 8; $ThisFileInfo['audio']['channels'] = 1; // overridden below, if need be $ThisFileInfo['mime_type'] = 'audio/x-aiff'; if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['offset'])) { $ThisFileInfo['avdataoffset'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['offset'] + 8; $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['size']; if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) { $ThisFileInfo['warning'] .= "\n" . 'Probable truncated AIFF file: expecting ' . $ThisFileInfo['RIFF'][$arraykeys[0]]['BODY'][0]['size'] . ' bytes of audio data, only ' . ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) . ' bytes found'; } } if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['offset'])) { $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['oneShotHiSamples'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 0, 4)); $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['repeatHiSamples'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 4, 4)); $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['samplesPerHiCycle'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 8, 4)); $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['samplesPerSec'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 12, 2)); $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['ctOctave'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 14, 1)); $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['sCompression'] = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 15, 1)); $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['Volume'] = FixedPoint16_16(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['data'], 16, 4)); $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['samplesPerSec']; switch ($ThisFileInfo['RIFF'][$arraykeys[0]]['VHDR'][0]['sCompression']) { case 0: $ThisFileInfo['audio']['codec'] = 'Pulse Code Modulation (PCM)'; $ThisFileInfo['audio']['lossless'] = true; $ActualBitsPerSample = 8; break; case 1: $ThisFileInfo['audio']['codec'] = 'Fibonacci-delta encoding'; $ThisFileInfo['audio']['lossless'] = false; $ActualBitsPerSample = 4; break; default: $ThisFileInfo['warning'] .= "\n" . 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "' . sCompression . '"'; break; } } if (isset($ThisFileInfo['RIFF'][$arraykeys[0]]['CHAN'][0]['data'])) { $ChannelsIndex = BigEndian2Int(substr($ThisFileInfo['RIFF'][$arraykeys[0]]['CHAN'][0]['data'], 0, 4)); switch ($ChannelsIndex) { case 6: // Stereo $ThisFileInfo['audio']['channels'] = 2; break; case 2: // Left channel only // Left channel only case 4: // Right channel only $ThisFileInfo['audio']['channels'] = 1; break; default: $ThisFileInfo['warning'] .= "\n" . 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "' . $ChannelsIndex . '"'; break; } } $CommentsChunkNames = array('NAME' => 'title', 'author' => 'artist', '(c) ' => 'copyright', 'ANNO' => 'comment'); foreach ($CommentsChunkNames as $key => $value) { if (isset($ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data'])) { $ThisFileInfo['RIFF']['comments'][$value][] = $ThisFileInfo['RIFF'][$arraykeys[0]][$key][0]['data']; } } if (isset($ThisFileInfo['RIFF']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, true, true); } $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['audio']['sample_rate'] * $ActualBitsPerSample * $ThisFileInfo['audio']['channels']; if (!empty($ThisFileInfo['audio']['bitrate'])) { $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['audio']['bitrate'] / 8); } break; default: $ThisFileInfo['error'] .= "\n" . 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|), found "' . $arraykeys[0] . '" instead'; unset($ThisFileInfo['fileformat']); break; } if (isset($ThisFileInfo['RIFF']['WAVE']['DISP']) && is_array($ThisFileInfo['RIFF']['WAVE']['DISP'])) { $ThisFileInfo['tags'][] = 'riff'; $ThisFileInfo['RIFF']['comments']['title'][] = trim(substr($ThisFileInfo['RIFF']['WAVE']['DISP'][count($ThisFileInfo['RIFF']['WAVE']['DISP']) - 1]['data'], 4)); } if (isset($ThisFileInfo['RIFF']['WAVE']['INFO']) && is_array($ThisFileInfo['RIFF']['WAVE']['INFO'])) { $ThisFileInfo['tags'][] = 'riff'; $RIFFinfoKeyLookup = array('IART' => 'artist', 'IGNR' => 'genre', 'ICMT' => 'comment', 'ICOP' => 'copyright', 'IENG' => 'engineers', 'IKEY' => 'keywords', 'IMED' => 'orignalmedium', 'INAM' => 'name', 'ISRC' => 'sourcesupplier', 'ITCH' => 'digitizer', 'ISBJ' => 'subject', 'ISRF' => 'digitizationsource', 'ISFT' => 'encoded_by'); foreach ($RIFFinfoKeyLookup as $key => $value) { if (isset($ThisFileInfo['RIFF']['WAVE']['INFO']["{$key}"])) { foreach ($ThisFileInfo['RIFF']['WAVE']['INFO']["{$key}"] as $commentid => $commentdata) { if (trim($commentdata['data']) != '') { $ThisFileInfo['RIFF']['comments']["{$value}"][] = trim($commentdata['data']); } } } } } if (!empty($ThisFileInfo['RIFF']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, false, true); } if (empty($ThisFileInfo['audio']['encoder']) && !empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version'])) { $ThisFileInfo['audio']['encoder'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version']; } if (!isset($ThisFileInfo['playtime_seconds'])) { $ThisFileInfo['playtime_seconds'] = 0; } if (isset($ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames']) && isset($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'])) { $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] * ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] / 1000000); } if ($ThisFileInfo['playtime_seconds'] > 0) { if (isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) { if (!isset($ThisFileInfo['bitrate'])) { $ThisFileInfo['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; } } elseif (isset($ThisFileInfo['RIFF']['audio']) && !isset($ThisFileInfo['RIFF']['video'])) { if (!isset($ThisFileInfo['audio']['bitrate'])) { $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; } } elseif (!isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) { if (!isset($ThisFileInfo['video']['bitrate'])) { $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; } } } if (isset($ThisFileInfo['RIFF']['video']) && isset($ThisFileInfo['audio']['bitrate']) && $ThisFileInfo['audio']['bitrate'] > 0 && $ThisFileInfo['playtime_seconds'] > 0) { $ThisFileInfo['audio']['bitrate'] = 0; $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; foreach ($ThisFileInfo['RIFF']['audio'] as $channelnumber => $audioinfoarray) { $ThisFileInfo['video']['bitrate'] -= $audioinfoarray['bitrate']; $ThisFileInfo['audio']['bitrate'] += $audioinfoarray['bitrate']; } if ($ThisFileInfo['video']['bitrate'] <= 0) { unset($ThisFileInfo['video']['bitrate']); } if ($ThisFileInfo['audio']['bitrate'] <= 0) { unset($ThisFileInfo['audio']['bitrate']); } } if (!empty($ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'] > 0) { $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample']; } return true; }
function getAPEtagFilepointer(&$fd, &$ThisFileInfo) { $id3v1tagsize = 128; $apetagheadersize = 32; fseek($fd, 0 - $id3v1tagsize - $apetagheadersize, SEEK_END); $APEfooterID3v1 = fread($fd, $id3v1tagsize + $apetagheadersize); if (substr($APEfooterID3v1, 0, strlen('APETAGEX')) == 'APETAGEX' && substr($APEfooterID3v1, $apetagheadersize, strlen('TAG')) == 'TAG') { // APE tag found before ID3v1 $APEfooterData = substr($APEfooterID3v1, 0, $apetagheadersize); $APEfooterOffset = 0 - $apetagheadersize - $id3v1tagsize; } elseif (substr($APEfooterID3v1, $id3v1tagsize, strlen('APETAGEX')) == 'APETAGEX') { // APE tag found, no ID3v1 $APEfooterData = substr($APEfooterID3v1, $id3v1tagsize, $apetagheadersize); $APEfooterOffset = 0 - $apetagheadersize; } else { // APE tag not found return false; } $ThisFileInfo['ape']['tag_offset_end'] = $ThisFileInfo['filesize'] - ($APEfooterOffset + $apetagheadersize); if (empty($ThisFileInfo['fileformat'])) { $ThisFileInfo['fileformat'] = 'ape'; } if (!($ThisFileInfo['ape']['footer'] = parseAPEheaderFooter($APEfooterData))) { $ThisFileInfo['error'] .= "\n" . 'Error parsing APE footer at offset ' . $ThisFileInfo['ape']['tag_offset_end']; return false; } if (isset($ThisFileInfo['ape']['footer']['flags']['header']) && $ThisFileInfo['ape']['footer']['flags']['header']) { fseek($fd, $APEfooterOffset - $ThisFileInfo['ape']['footer']['raw']['tagsize'] + $apetagheadersize - $apetagheadersize, SEEK_END); $ThisFileInfo['ape']['tag_offset_start'] = ftell($fd); $APEtagData = fread($fd, $ThisFileInfo['ape']['footer']['raw']['tagsize'] + $apetagheadersize); } else { fseek($fd, $APEfooterOffset - $ThisFileInfo['ape']['footer']['raw']['tagsize'] + $apetagheadersize, SEEK_END); $ThisFileInfo['ape']['tag_offset_start'] = ftell($fd); $APEtagData = fread($fd, $ThisFileInfo['ape']['footer']['raw']['tagsize']); } $offset = 0; if (isset($ThisFileInfo['ape']['footer']['flags']['header']) && $ThisFileInfo['ape']['footer']['flags']['header']) { if ($ThisFileInfo['ape']['header'] = parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) { $offset += $apetagheadersize; } else { $ThisFileInfo['error'] .= "\n" . 'Error parsing APE header at offset ' . $ThisFileInfo['ape']['tag_offset_start']; return false; } } for ($i = 0; $i < $ThisFileInfo['ape']['footer']['raw']['tag_items']; $i++) { $value_size = LittleEndian2Int(substr($APEtagData, $offset, 4)); $offset += 4; $item_flags = LittleEndian2Int(substr($APEtagData, $offset, 4)); $offset += 4; if (strstr(substr($APEtagData, $offset), chr(0)) === false) { $ThisFileInfo['error'] .= "\n" . 'Cannot find null-byte (0x00) seperator between ItemKey #' . $i . ' and value. ItemKey starts ' . $offset . ' bytes into the APE tag, at file offset ' . ($ThisFileInfo['ape']['tag_offset_start'] + $offset); return false; } $ItemKeyLength = strpos($APEtagData, chr(0), $offset) - $offset; $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength)); $offset += $ItemKeyLength + 1; // skip 0x00 terminator $ThisFileInfo['ape']['items']["{$item_key}"]['data'] = substr($APEtagData, $offset, $value_size); $offset += $value_size; if ($ThisFileInfo['ape']['footer']['tag_version'] >= 2) { $ThisFileInfo['ape']['items']["{$item_key}"]['flags'] = parseAPEtagFlags($item_flags); } switch ($ThisFileInfo['ape']['items']["{$item_key}"]['flags']['item_contents_raw']) { case 0: // UTF-8 // UTF-8 case 3: // Locator (URL, filename, etc), UTF-8 encoded $ThisFileInfo['ape']['items']["{$item_key}"]['data'] = explode(chr(0), $ThisFileInfo['ape']['items']["{$item_key}"]['data']); foreach ($ThisFileInfo['ape']['items']["{$item_key}"]['data'] as $key => $value) { $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'][$key] = RoughTranslateUnicodeToASCII($value, 3); } break; default: // binary data //$ThisFileInfo['ape']['items']["$item_key"]['data_ascii'] = null; break; } switch ($item_key) { case 'replaygain_track_gain': $ThisFileInfo['replay_gain']['radio']['adjustment'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'][0]; $ThisFileInfo['replay_gain']['radio']['originator'] = 'unspecified'; break; case 'replaygain_track_peak': $ThisFileInfo['replay_gain']['radio']['peak'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'][0]; $ThisFileInfo['replay_gain']['radio']['originator'] = 'unspecified'; break; case 'replaygain_album_gain': $ThisFileInfo['replay_gain']['audiophile']['adjustment'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'][0]; $ThisFileInfo['replay_gain']['audiophile']['originator'] = 'unspecified'; break; case 'replaygain_album_peak': $ThisFileInfo['replay_gain']['audiophile']['peak'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'][0]; $ThisFileInfo['replay_gain']['audiophile']['originator'] = 'unspecified'; break; default: foreach ($ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'] as $comment) { $ThisFileInfo['ape']['comments'][strtolower($item_key)][] = $comment; } break; } } if (isset($ThisFileInfo['ape']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['ape']['comments'], $ThisFileInfo, true, true, true); } return true; }
function getRealHeaderFilepointer(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'real'; $ThisFileInfo['bitrate'] = 0; $ThisFileInfo['playtime_seconds'] = 0; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $ChunkCounter = 0; while (ftell($fd) < $ThisFileInfo['avdataend']) { $ChunkData = fread($fd, 8); $ChunkName = substr($ChunkData, 0, 4); $ChunkSize = BigEndian2Int(substr($ChunkData, 4, 4)); $ThisFileInfo['real']['chunks'][$ChunkCounter]['name'] = $ChunkName; $ThisFileInfo['real']['chunks'][$ChunkCounter]['offset'] = ftell($fd) - 8; $ThisFileInfo['real']['chunks'][$ChunkCounter]['length'] = $ChunkSize; $ChunkData .= fread($fd, $ChunkSize - 8); $offset = 8; switch ($ChunkName) { case '.RMF': // RealMedia File Header $ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; switch ($ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version']) { case 0: $ThisFileInfo['real']['chunks'][$ChunkCounter]['file_version'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['headers_count'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; break; default: //$ThisFileInfo['warning'] .= "\n".'Expected .RMF-object_version to be "0", actual value is "'.$ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'].'" (should not be a problem)'; break; } break; case 'PROP': // Properties Header $ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; if ($ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] == 0) { $ThisFileInfo['real']['chunks'][$ChunkCounter]['max_bit_rate'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['avg_bit_rate'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['max_packet_size'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['avg_packet_size'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['num_packets'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['duration'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['preroll'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['index_offset'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['data_offset'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['num_streams'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['real']['chunks'][$ChunkCounter]['flags_raw'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['real']['chunks'][$ChunkCounter]['duration'] / 1000; if ($ThisFileInfo['real']['chunks'][$ChunkCounter]['duration'] > 0) { $ThisFileInfo['bitrate'] += $ThisFileInfo['real']['chunks'][$ChunkCounter]['avg_bit_rate']; } $ThisFileInfo['real']['chunks'][$ChunkCounter]['flags']['save_enabled'] = (bool) ($ThisFileInfo['real']['chunks'][$ChunkCounter]['flags_raw'] & 0x1); $ThisFileInfo['real']['chunks'][$ChunkCounter]['flags']['perfect_play'] = (bool) ($ThisFileInfo['real']['chunks'][$ChunkCounter]['flags_raw'] & 0x2); $ThisFileInfo['real']['chunks'][$ChunkCounter]['flags']['live_broadcast'] = (bool) ($ThisFileInfo['real']['chunks'][$ChunkCounter]['flags_raw'] & 0x4); } break; case 'MDPR': // Media Properties Header $ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; if ($ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] == 0) { $ThisFileInfo['real']['chunks'][$ChunkCounter]['stream_number'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['real']['chunks'][$ChunkCounter]['max_bit_rate'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['avg_bit_rate'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['max_packet_size'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['avg_packet_size'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['start_time'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['preroll'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['duration'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['stream_name_size'] = BigEndian2Int(substr($ChunkData, $offset, 1)); $offset += 1; $ThisFileInfo['real']['chunks'][$ChunkCounter]['stream_name'] = substr($ChunkData, $offset, $ThisFileInfo['real']['chunks'][$ChunkCounter]['stream_name_size']); $offset += $ThisFileInfo['real']['chunks'][$ChunkCounter]['stream_name_size']; $ThisFileInfo['real']['chunks'][$ChunkCounter]['mime_type_size'] = BigEndian2Int(substr($ChunkData, $offset, 1)); $offset += 1; $ThisFileInfo['real']['chunks'][$ChunkCounter]['mime_type'] = substr($ChunkData, $offset, $ThisFileInfo['real']['chunks'][$ChunkCounter]['mime_type_size']); $offset += $ThisFileInfo['real']['chunks'][$ChunkCounter]['mime_type_size']; $ThisFileInfo['real']['chunks'][$ChunkCounter]['type_specific_len'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['type_specific_data'] = substr($ChunkData, $offset, $ThisFileInfo['real']['chunks'][$ChunkCounter]['type_specific_len']); $offset += $ThisFileInfo['real']['chunks'][$ChunkCounter]['type_specific_len']; if (empty($ThisFileInfo['playtime_seconds'])) { $ThisFileInfo['playtime_seconds'] = max($ThisFileInfo['playtime_seconds'], ($ThisFileInfo['real']['chunks'][$ChunkCounter]['duration'] + $ThisFileInfo['real']['chunks'][$ChunkCounter]['start_time']) / 1000); } if ($ThisFileInfo['real']['chunks'][$ChunkCounter]['duration'] > 0) { if (strstr($ThisFileInfo['real']['chunks'][$ChunkCounter]['mime_type'], 'audio')) { $ThisFileInfo['audio']['bitrate'] = (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0) + $ThisFileInfo['real']['chunks'][$ChunkCounter]['avg_bit_rate']; $ThisFileInfo['audio']['dataformat'] = 'real'; } elseif (strstr($ThisFileInfo['real']['chunks'][$ChunkCounter]['mime_type'], 'video')) { $ThisFileInfo['video']['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + $ThisFileInfo['real']['chunks'][$ChunkCounter]['avg_bit_rate']; $ThisFileInfo['video']['dataformat'] = 'real'; } $ThisFileInfo['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0); } } break; case 'CONT': // Content Description Header $ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; if ($ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] == 0) { $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['title_len'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['real']['chunks'][$ChunkCounter]['title'] = (string) substr($ChunkData, $offset, $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['title_len']); $offset += $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['title_len']; $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['artist_len'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['real']['chunks'][$ChunkCounter]['artist'] = (string) substr($ChunkData, $offset, $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['artist_len']); $offset += $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['artist_len']; $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['copyright_len'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['real']['chunks'][$ChunkCounter]['copyright'] = (string) substr($ChunkData, $offset, $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['copyright_len']); $offset += $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['copyright_len']; $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['comment_len'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['real']['chunks'][$ChunkCounter]['comment'] = (string) substr($ChunkData, $offset, $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['comment_len']); $offset += $ThisFileInfo['real']['chunks'][$ChunkCounter]['raw']['comment_len']; $commentkeystocopy = array('title' => 'title', 'artist' => 'artist', 'comment' => 'comment'); foreach ($commentkeystocopy as $key => $val) { if ($ThisFileInfo['real']['chunks'][$ChunkCounter]["{$key}"]) { $ThisFileInfo['real']['comments']["{$val}"] = $ThisFileInfo['real']['chunks'][$ChunkCounter]["{$key}"]; } } // RealMedia tags have highest priority if (!empty($ThisFileInfo['real']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['real']['comments'], $ThisFileInfo, true, true, true); } // add tag to array of tags $ThisFileInfo['tags'][] = 'real'; } break; case 'DATA': // Data Chunk Header // do nothing break; case 'INDX': // Index Section Header $ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; if ($ThisFileInfo['real']['chunks'][$ChunkCounter]['object_version'] == 0) { $ThisFileInfo['real']['chunks'][$ChunkCounter]['num_indices'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; $ThisFileInfo['real']['chunks'][$ChunkCounter]['stream_number'] = BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; $ThisFileInfo['real']['chunks'][$ChunkCounter]['next_index_header'] = BigEndian2Int(substr($ChunkData, $offset, 4)); $offset += 4; if ($ThisFileInfo['real']['chunks'][$ChunkCounter]['next_index_header'] == 0) { // last index chunk found, ignore rest of file return true; } else { // non-last index chunk, seek to next index chunk (skipping actual index data) fseek($fd, $ThisFileInfo['real']['chunks'][$ChunkCounter]['next_index_header'], SEEK_SET); } } break; default: $ThisFileInfo['warning'] .= "\n" . 'Unhandled RealMedia chunk "' . $ChunkName . '" at offset ' . $ThisFileInfo['real']['chunks'][$ChunkCounter]['offset']; break; } $ChunkCounter++; } return true; }
function getVQFHeaderFilepointer(&$fd, &$ThisFileInfo) { // based loosely on code from TTwinVQ by Jurgen Faul // jfaul@gmx.de http://jfaul.de/atl $ThisFileInfo['fileformat'] = 'vqf'; $ThisFileInfo['audio']['dataformat'] = 'vqf'; $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['lossless'] = false; $HasVQFTags = false; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $VQFheaderData = fread($fd, 16); $offset = 0; $ThisFileInfo['vqf']['raw']['header_tag'] = substr($VQFheaderData, $offset, 4); $offset += 4; $ThisFileInfo['vqf']['raw']['version'] = substr($VQFheaderData, $offset, 8); $offset += 8; $ThisFileInfo['vqf']['raw']['size'] = BigEndian2Int(substr($VQFheaderData, $offset, 4)); $offset += 4; while (ftell($fd) < $ThisFileInfo['avdataend']) { $ChunkBaseOffset = ftell($fd); $chunkoffset = 0; $ChunkData = fread($fd, 8); $ChunkName = substr($ChunkData, $chunkoffset, 4); if ($ChunkName == 'DATA') { $ThisFileInfo['avdataoffset'] = $ChunkBaseOffset; break; } $chunkoffset += 4; $ChunkSize = BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); $chunkoffset += 4; if ($ChunkSize > $ThisFileInfo['avdataend'] - ftell($fd)) { $ThisFileInfo['error'] .= "\n" . 'Invalid chunk size (' . $ChunkSize . ') for chunk "' . $ChunkName . '" at offset ' . $ChunkBaseOffset; break; } $ChunkData .= fread($fd, $ChunkSize); switch ($ChunkName) { case 'COMM': $ThisFileInfo['vqf']["{$ChunkName}"]['channel_mode'] = BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); $chunkoffset += 4; $ThisFileInfo['vqf']["{$ChunkName}"]['bitrate'] = BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); $chunkoffset += 4; $ThisFileInfo['vqf']["{$ChunkName}"]['sample_rate'] = BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); $chunkoffset += 4; $ThisFileInfo['vqf']["{$ChunkName}"]['security_level'] = BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); $chunkoffset += 4; $ThisFileInfo['audio']['channels'] = $ThisFileInfo['vqf']["{$ChunkName}"]['channel_mode'] + 1; $ThisFileInfo['audio']['sample_rate'] = VQFchannelFrequencyLookup($ThisFileInfo['vqf']["{$ChunkName}"]['sample_rate']); $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['vqf']["{$ChunkName}"]['bitrate'] * 1000; if ($ThisFileInfo['audio']['bitrate'] == 0) { $ThisFileInfo['error'] .= 'Corrupt VQF file: bitrate_audio == zero'; return false; } break; case 'NAME': case 'AUTH': case '(c) ': case 'FILE': case 'COMT': case 'ALBM': $HasVQFTags = true; $ThisFileInfo['vqf']['comments'][VQFcommentNiceNameLookup($ChunkName)][] = trim(substr($ChunkData, 8)); break; case 'DSIZ': $ThisFileInfo['vqf']['DSIZ'] = BigEndian2Int(substr($ChunkData, 8, 4)); break; default: $ThisFileInfo['warning'] .= "\n" . 'Unhandled chunk type "' . $ChunkName . '" at offset ' . $ChunkBaseOffset; break; } } $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']; if (isset($ThisFileInfo['vqf']['DSIZ']) && $ThisFileInfo['vqf']['DSIZ'] != $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] - strlen('DATA')) { switch ($ThisFileInfo['vqf']['DSIZ']) { case 0: case 1: $ThisFileInfo['warning'] .= "\n" . 'Invalid DSIZ value "' . $ThisFileInfo['vqf']['DSIZ'] . '". This is known to happen with VQF files encoded by Ahead Nero, and seems to be its way of saying this is TwinVQF v' . ($ThisFileInfo['vqf']['DSIZ'] + 1) . '.0'; $ThisFileInfo['audio']['encoder'] = 'Ahead Nero'; break; default: $ThisFileInfo['warning'] .= "\n" . 'Probable corrupted file - should be ' . $ThisFileInfo['vqf']['DSIZ'] . ' bytes, actually ' . ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] - strlen('DATA')); break; } } // Any VQF tags present? if ($HasVQFTags) { // add tag to array of tags $ThisFileInfo['tags'][] = 'vqf'; // Yank other comments - VQF highest preference CopyFormatCommentsToRootComments($ThisFileInfo['vqf']['comments'], $ThisFileInfo, true, true, true); } return true; }
function getAPEtagFilepointer(&$fd, &$ThisFileInfo) { $id3v1tagsize = 128; $apetagheadersize = 32; fseek($fd, 0 - $id3v1tagsize - $apetagheadersize, SEEK_END); $APEfooterID3v1 = fread($fd, $id3v1tagsize + $apetagheadersize); if (substr($APEfooterID3v1, 0, strlen('APETAGEX')) == 'APETAGEX') { // APE tag found before ID3v1 $APEfooterData = substr($APEfooterID3v1, 0, $apetagheadersize); $APEfooterOffset = 0 - $apetagheadersize - $id3v1tagsize; } elseif (substr($APEfooterID3v1, $id3v1tagsize, strlen('APETAGEX')) == 'APETAGEX') { // APE tag found, no ID3v1 $APEfooterData = substr($APEfooterID3v1, $id3v1tagsize, $apetagheadersize); $APEfooterOffset = 0 - $apetagheadersize; } else { // APE tag not found return false; } if (empty($ThisFileInfo['fileformat'])) { $ThisFileInfo['fileformat'] = 'ape'; } $ThisFileInfo['ape']['footer'] = parseAPEheaderFooter($APEfooterData); if (isset($ThisFileInfo['ape']['footer']['flags']['header']) && $ThisFileInfo['ape']['footer']['flags']['header']) { fseek($fd, $APEfooterOffset - $ThisFileInfo['ape']['footer']['raw']['tagsize'] + $apetagheadersize - $apetagheadersize, SEEK_END); $APEtagData = fread($fd, $ThisFileInfo['ape']['footer']['raw']['tagsize'] + $apetagheadersize); } else { fseek($fd, $APEfooterOffset - $ThisFileInfo['ape']['footer']['raw']['tagsize'] + $apetagheadersize, SEEK_END); $APEtagData = fread($fd, $ThisFileInfo['ape']['footer']['raw']['tagsize']); } $offset = 0; if (isset($ThisFileInfo['ape']['footer']['flags']['header']) && $ThisFileInfo['ape']['footer']['flags']['header']) { $ThisFileInfo['ape']['header'] = parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize)); $offset += $apetagheadersize; } for ($i = 0; $i < $ThisFileInfo['ape']['footer']['raw']['tag_items']; $i++) { $value_size = LittleEndian2Int(substr($APEtagData, $offset, 4)); $offset += 4; $item_flags = LittleEndian2Int(substr($APEtagData, $offset, 4)); $offset += 4; $ItemKeyLength = strpos($APEtagData, chr(0), $offset) - $offset; $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength)); $offset += $ItemKeyLength + 1; // skip 0x00 terminator $data = substr($APEtagData, $offset, $value_size); $offset += $value_size; $ThisFileInfo['ape']['items']["{$item_key}"]['raw']['value_size'] = $value_size; $ThisFileInfo['ape']['items']["{$item_key}"]['raw']['item_flags'] = $item_flags; if ($ThisFileInfo['ape']['footer']['tag_version'] >= 2) { $ThisFileInfo['ape']['items']["{$item_key}"]['flags'] = parseAPEtagFlags($item_flags); } $ThisFileInfo['ape']['items']["{$item_key}"]['data'] = $data; $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'] = $data; if (APEtagItemIsUTF8Lookup($item_key)) { $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii'] = RoughTranslateUnicodeToASCII($ThisFileInfo['ape']['items']["{$item_key}"]['data'], 3); } switch ($item_key) { case 'replaygain_track_gain': $ThisFileInfo['replay_gain']['radio']['adjustment'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii']; $ThisFileInfo['replay_gain']['radio']['originator'] = 'unspecified'; break; case 'replaygain_track_peak': $ThisFileInfo['replay_gain']['radio']['peak'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii']; $ThisFileInfo['replay_gain']['radio']['originator'] = 'unspecified'; break; case 'replaygain_album_gain': $ThisFileInfo['replay_gain']['audiophile']['adjustment'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii']; $ThisFileInfo['replay_gain']['audiophile']['originator'] = 'unspecified'; break; case 'replaygain_album_peak': $ThisFileInfo['replay_gain']['audiophile']['peak'] = (double) $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii']; $ThisFileInfo['replay_gain']['audiophile']['originator'] = 'unspecified'; break; case 'title': case 'artist': case 'album': case 'track': case 'genre': case 'comment': case 'year': $ThisFileInfo['ape']['comments']["{$item_key}"][] = $ThisFileInfo['ape']['items']["{$item_key}"]['data_ascii']; break; } } if (isset($ThisFileInfo['ape']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['ape']['comments'], $ThisFileInfo, true, true, true); } return true; }
function getRIFFHeaderFilepointer(&$fd, &$ThisFileInfo) { fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $RIFFheader = fread($fd, 12); switch (substr($RIFFheader, 0, 4)) { case 'RIFF': case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) $ThisFileInfo['fileformat'] = 'riff'; $ThisFileInfo['RIFF'][substr($RIFFheader, 8, 4)] = ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + LittleEndian2Int(substr($RIFFheader, 4, 4)), $ThisFileInfo); break; default: $ThisFileInfo['error'] .= "\n" . 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?)'; unset($ThisFileInfo['fileformat']); return false; break; } $streamindex = 0; $arraykeys = array_keys($ThisFileInfo['RIFF']); switch ($arraykeys[0]) { case 'WAVE': $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['dataformat'] = 'wav'; if (isset($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data'])) { $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($ThisFileInfo['RIFF']['WAVE']['fmt '][0]['data']); if ($ThisFileInfo['RIFF']['audio'][$streamindex] == 0) { $ThisFileInfo['error'] .= 'Corrupt RIFF file: bitrate_audio == zero'; return false; } $ThisFileInfo['RIFF']['raw']['fmt '] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw']; unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']); $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]); $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate']; $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']); if (isset($ThisFileInfo['RIFF']['WAVE']['data'][0]['offset']) && isset($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag'])) { switch ($ThisFileInfo['RIFF']['raw']['fmt ']['wFormatTag']) { case 85: // LAME ACM require_once GETID3_INCLUDEPATH . 'getid3.mp3.php'; getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['RIFF']['WAVE']['data'][0]['offset'], false); $ThisFileInfo['audio']['dataformat'] = 'mp3'; if (isset($ThisFileInfo['mpeg']['audio'])) { $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate'] * 1000; $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate']; $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitratemode']); } break; default: // do nothing break; } } } if (isset($ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data'])) { require_once GETID3_INCLUDEPATH . 'getid3.rgad.php'; $rgadData = $ThisFileInfo['RIFF']['WAVE']['rgad'][0]['data']; $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude'] = LittleEndian2Float(substr($rgadData, 0, 4)); $ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust'] = LittleEndian2Int(substr($rgadData, 4, 2)); $ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust'] = LittleEndian2Int(substr($rgadData, 6, 2)); $nRadioRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); $nAudiophileRgAdjustBitstring = str_pad(Dec2Bin($ThisFileInfo['RIFF']['raw']['rgad']['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1)); $ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'] = Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1)); $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'] = Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9)); $ThisFileInfo['RIFF']['rgad']['peakamplitude'] = $ThisFileInfo['RIFF']['raw']['rgad']['fPeakAmplitude']; if ($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator'] != 0) { $ThisFileInfo['RIFF']['rgad']['radio']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['name']); $ThisFileInfo['RIFF']['rgad']['radio']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['originator']); $ThisFileInfo['RIFF']['rgad']['radio']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['radio']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['radio']['signbit']); } if ($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name'] != 0 && $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator'] != 0) { $ThisFileInfo['RIFF']['rgad']['audiophile']['name'] = RGADnameLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['name']); $ThisFileInfo['RIFF']['rgad']['audiophile']['originator'] = RGADoriginatorLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['originator']); $ThisFileInfo['RIFF']['rgad']['audiophile']['adjustment'] = RGADadjustmentLookup($ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['adjustment'], $ThisFileInfo['RIFF']['raw']['rgad']['audiophile']['signbit']); } } if (isset($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'])) { $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] = LittleEndian2Int(substr($ThisFileInfo['RIFF']['WAVE']['fact'][0]['data'], 0, 4)); if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec'] > 0) { $ThisFileInfo['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['raw']['fact']['NumberOfSamples'] / $ThisFileInfo['RIFF']['raw']['fmt ']['nSamplesPerSec']; } if (isset($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) && $ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec']) { $ThisFileInfo['audio']['bitrate'] = CastAsInt($ThisFileInfo['RIFF']['raw']['fmt ']['nAvgBytesPerSec'] * 8); } } if (!isset($ThisFileInfo['audio']['bitrate']) && isset($ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate'])) { $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['RIFF']['audio'][$streamindex]['bitrate']; $ThisFileInfo['playtime_seconds'] = (double) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']); } break; case 'AVI ': $ThisFileInfo['video']['bitrate_mode'] = 'cbr'; $ThisFileInfo['video']['dataformat'] = 'avi'; $ThisFileInfo['mime_type'] = 'video/avi'; if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data'])) { $avihData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['avih'][$streamindex]['data']; $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] = LittleEndian2Int(substr($avihData, 0, 4)); // frame display rate (or 0L) if ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] == 0) { $ThisFileInfo['error'] .= 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero'; return false; } $ThisFileInfo['RIFF']['raw']['avih']['dwMaxBytesPerSec'] = LittleEndian2Int(substr($avihData, 4, 4)); // max. transfer rate $ThisFileInfo['RIFF']['raw']['avih']['dwPaddingGranularity'] = LittleEndian2Int(substr($avihData, 8, 4)); // pad to multiples of this size; normally 2K. $ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] = LittleEndian2Int(substr($avihData, 12, 4)); // the ever-present flags $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] = LittleEndian2Int(substr($avihData, 16, 4)); // # frames in file $ThisFileInfo['RIFF']['raw']['avih']['dwInitialFrames'] = LittleEndian2Int(substr($avihData, 20, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwStreams'] = LittleEndian2Int(substr($avihData, 24, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwSuggestedBufferSize'] = LittleEndian2Int(substr($avihData, 28, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwWidth'] = LittleEndian2Int(substr($avihData, 32, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwHeight'] = LittleEndian2Int(substr($avihData, 36, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwScale'] = LittleEndian2Int(substr($avihData, 40, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwRate'] = LittleEndian2Int(substr($avihData, 44, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwStart'] = LittleEndian2Int(substr($avihData, 48, 4)); $ThisFileInfo['RIFF']['raw']['avih']['dwLength'] = LittleEndian2Int(substr($avihData, 52, 4)); $ThisFileInfo['RIFF']['raw']['avih']['flags']['hasindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10); $ThisFileInfo['RIFF']['raw']['avih']['flags']['mustuseindex'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20); $ThisFileInfo['RIFF']['raw']['avih']['flags']['interleaved'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x100); $ThisFileInfo['RIFF']['raw']['avih']['flags']['trustcktype'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x800); $ThisFileInfo['RIFF']['raw']['avih']['flags']['capturedfile'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x10000); $ThisFileInfo['RIFF']['raw']['avih']['flags']['copyrighted'] = (bool) ($ThisFileInfo['RIFF']['raw']['avih']['dwFlags'] & 0x20010); $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width'] = $ThisFileInfo['RIFF']['raw']['avih']['dwWidth']; $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height'] = $ThisFileInfo['RIFF']['raw']['avih']['dwHeight']; $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate'] = round(1000000 / $ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'], 3); if (!isset($ThisFileInfo['video']['resolution_x'])) { $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_width']; } if (!isset($ThisFileInfo['video']['resolution_y'])) { $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_height']; } $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['RIFF']['video'][$streamindex]['frame_rate']; } if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][0]['data'])) { if (is_array($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'])) { for ($i = 0; $i < count($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh']); $i++) { if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { $strhData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strh'][$i]['data']; $strhfccType = substr($strhData, 0, 4); if (isset($ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data'])) { $strfData = $ThisFileInfo['RIFF']['AVI ']['hdrl']['strl']['strf'][$i]['data']; switch ($strhfccType) { case 'auds': $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['dataformat'] = 'wav'; if (isset($ThisFileInfo['RIFF']['audio']) && is_array($ThisFileInfo['RIFF']['audio'])) { $streamindex = count($ThisFileInfo['RIFF']['audio']); } $ThisFileInfo['RIFF']['audio'][$streamindex] = RIFFparseWAVEFORMATex($strfData); $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex] = $ThisFileInfo['RIFF']['audio'][$streamindex]['raw']; unset($ThisFileInfo['RIFF']['audio'][$streamindex]['raw']); $ThisFileInfo['audio'] = array_merge_noclobber($ThisFileInfo['audio'], $ThisFileInfo['RIFF']['audio'][$streamindex]); switch ($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['wFormatTag']) { case 85: $ThisFileInfo['audio']['dataformat'] = 'mp3'; break; case 8192: $ThisFileInfo['audio']['dataformat'] = 'ac3'; break; default: $ThisFileInfo['audio']['dataformat'] = 'wav'; break; } break; case 'iavs': case 'vids': $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccType'] = substr($strhData, 0, 4); // same as $strhfccType; $ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler'] = substr($strhData, 4, 4); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwFlags'] = LittleEndian2Int(substr($strhData, 8, 4)); // Contains AVITF_* flags $ThisFileInfo['RIFF']['raw']['strh'][$i]['wPriority'] = LittleEndian2Int(substr($strhData, 12, 2)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['wLanguage'] = LittleEndian2Int(substr($strhData, 14, 2)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwInitialFrames'] = LittleEndian2Int(substr($strhData, 16, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwScale'] = LittleEndian2Int(substr($strhData, 20, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwRate'] = LittleEndian2Int(substr($strhData, 24, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwStart'] = LittleEndian2Int(substr($strhData, 28, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwLength'] = LittleEndian2Int(substr($strhData, 32, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSuggestedBufferSize'] = LittleEndian2Int(substr($strhData, 36, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwQuality'] = LittleEndian2Int(substr($strhData, 40, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['dwSampleSize'] = LittleEndian2Int(substr($strhData, 44, 4)); $ThisFileInfo['RIFF']['raw']['strh'][$i]['rcFrame'] = LittleEndian2Int(substr($strhData, 48, 4)); $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strh'][$i]['fccHandler']); if (!$ThisFileInfo['RIFF']['video'][$streamindex]['codec'] && isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) { $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']); } $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec']; switch ($strhfccType) { case 'vids': $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSize'] = LittleEndian2Int(substr($strfData, 0, 4)); // number of bytes required by the BITMAPINFOHEADER structure $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biWidth'] = LittleEndian2Int(substr($strfData, 4, 4)); // width of the bitmap in pixels $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biHeight'] = LittleEndian2Int(substr($strfData, 8, 4)); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biPlanes'] = LittleEndian2Int(substr($strfData, 12, 2)); // number of color planes on the target device. In most cases this value must be set to 1 $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biBitCount'] = LittleEndian2Int(substr($strfData, 14, 2)); // Specifies the number of bits per pixels $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'] = substr($strfData, 16, 4); // $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biSizeImage'] = LittleEndian2Int(substr($strfData, 20, 4)); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures) $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biXPelsPerMeter'] = LittleEndian2Int(substr($strfData, 24, 4)); // horizontal resolution, in pixels per metre, of the target device $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biYPelsPerMeter'] = LittleEndian2Int(substr($strfData, 28, 4)); // vertical resolution, in pixels per metre, of the target device $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrUsed'] = LittleEndian2Int(substr($strfData, 32, 4)); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression $ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['biClrImportant'] = LittleEndian2Int(substr($strfData, 36, 4)); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important if ($ThisFileInfo['RIFF']['video'][$streamindex]['codec'] == 'DV') { $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 2; } break; case 'iavs': $ThisFileInfo['RIFF']['video'][$streamindex]['dv_type'] = 1; break; } break; default: $ThisFileInfo['warning'] .= "\n" . 'Unhandled fccType for stream (' . $i . '): "' . $strhfccType . '"'; break; } } } if (isset($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']) && RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc'])) { $ThisFileInfo['RIFF']['video'][$streamindex]['codec'] = RIFFfourccLookup($ThisFileInfo['RIFF']['raw']['strf']["{$strhfccType}"][$streamindex]['fourcc']); $ThisFileInfo['video']['codec'] = $ThisFileInfo['RIFF']['video'][$streamindex]['codec']; } } } } break; case 'CDDA': $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['dataformat'] = 'cda'; unset($ThisFileInfo['mime_type']); if (isset($ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data'])) { $fmtData = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['data']; $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown1'] = LittleEndian2Int(substr($fmtData, 0, 2)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num'] = LittleEndian2Int(substr($fmtData, 2, 2)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['disc_id'] = LittleEndian2Int(substr($fmtData, 4, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] = LittleEndian2Int(substr($fmtData, 8, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] = LittleEndian2Int(substr($fmtData, 12, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown6'] = LittleEndian2Int(substr($fmtData, 16, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['unknown7'] = LittleEndian2Int(substr($fmtData, 20, 4)); $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['start_offset_frame'] / 75; $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds'] = (double) $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_frames'] / 75; $ThisFileInfo['comments']['track'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['track_num']; $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['CDDA']['fmt '][0]['playtime_seconds']; // hardcoded data for CD-audio $ThisFileInfo['audio']['sample_rate'] = 44100; $ThisFileInfo['audio']['channels'] = 2; $ThisFileInfo['audio']['bits_per_sample'] = 16; $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['audio']['sample_rate'] * $ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['bits_per_sample']; $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; } break; default: unset($ThisFileInfo['fileformat']); break; } if (isset($ThisFileInfo['RIFF']['WAVE']['DISP']) && is_array($ThisFileInfo['RIFF']['WAVE']['DISP'])) { $ThisFileInfo['tags'][] = 'riff'; $ThisFileInfo['RIFF']['comments']['title'][] = trim(substr($ThisFileInfo['RIFF']['WAVE']['DISP'][count($ThisFileInfo['RIFF']['WAVE']['DISP']) - 1]['data'], 4)); } if (isset($ThisFileInfo['RIFF']['WAVE']['INFO']) && is_array($ThisFileInfo['RIFF']['WAVE']['INFO'])) { $ThisFileInfo['tags'][] = 'riff'; $RIFFinfoKeyLookup = array('IART' => 'artist', 'IGNR' => 'genre', 'ICMT' => 'comment', 'ICOP' => 'copyright', 'IENG' => 'engineers', 'IKEY' => 'keywords', 'IMED' => 'orignalmedium', 'INAM' => 'name', 'ISRC' => 'sourcesupplier', 'ITCH' => 'digitizer', 'ISBJ' => 'subject', 'ISRF' => 'digitizationsource'); foreach ($RIFFinfoKeyLookup as $key => $value) { foreach ($ThisFileInfo['RIFF']['WAVE']['INFO']["{$key}"] as $commentid => $commentdata) { if (trim($commentdata['data']) != '') { $ThisFileInfo['RIFF']['comments']["{$value}"][] = trim($commentdata['data']); } } } } if (!empty($ThisFileInfo['RIFF']['comments'])) { CopyFormatCommentsToRootComments($ThisFileInfo['RIFF']['comments'], $ThisFileInfo, true, true, true); } if (!isset($ThisFileInfo['playtime_seconds'])) { $ThisFileInfo['playtime_seconds'] = 0; } if (isset($ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames']) && isset($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'])) { $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['RIFF']['raw']['avih']['dwTotalFrames'] * ($ThisFileInfo['RIFF']['raw']['avih']['dwMicroSecPerFrame'] / 1000000); } if ($ThisFileInfo['playtime_seconds'] > 0) { if (isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) { if (!isset($ThisFileInfo['bitrate'])) { $ThisFileInfo['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; } } elseif (isset($ThisFileInfo['RIFF']['audio']) && !isset($ThisFileInfo['RIFF']['video'])) { if (!isset($ThisFileInfo['audio']['bitrate'])) { $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; } } elseif (!isset($ThisFileInfo['RIFF']['audio']) && isset($ThisFileInfo['RIFF']['video'])) { if (!isset($ThisFileInfo['video']['bitrate'])) { $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; } } } if (isset($ThisFileInfo['RIFF']['video']) && isset($ThisFileInfo['audio']['bitrate']) && $ThisFileInfo['audio']['bitrate'] > 0 && $ThisFileInfo['playtime_seconds'] > 0) { $ThisFileInfo['audio']['bitrate'] = 0; $ThisFileInfo['video']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8; foreach ($ThisFileInfo['RIFF']['audio'] as $channelnumber => $audioinfoarray) { $ThisFileInfo['video']['bitrate'] -= $audioinfoarray['bitrate']; $ThisFileInfo['audio']['bitrate'] += $audioinfoarray['bitrate']; } if ($ThisFileInfo['video']['bitrate'] <= 0) { unset($ThisFileInfo['video']['bitrate']); } if ($ThisFileInfo['audio']['bitrate'] <= 0) { unset($ThisFileInfo['audio']['bitrate']); } } if (!empty($ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample'])) { $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['RIFF']['raw']['fmt ']['nBitsPerSample']; } // Skip RIFF header $ThisFileInfo['avdataoffset'] += 44; return true; }