22 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
23 $NSVheader = fread($fd, 4);
28 $ThisFileInfo[
'fileformat'] =
'nsv';
29 $ThisFileInfo[
'audio'][
'dataformat'] =
'nsv';
30 $ThisFileInfo[
'video'][
'dataformat'] =
'nsv';
31 $ThisFileInfo[
'audio'][
'lossless'] =
false;
32 $ThisFileInfo[
'video'][
'lossless'] =
false;
38 $ThisFileInfo[
'fileformat'] =
'nsv';
39 $ThisFileInfo[
'audio'][
'dataformat'] =
'nsv';
40 $ThisFileInfo[
'video'][
'dataformat'] =
'nsv';
41 $ThisFileInfo[
'audio'][
'lossless'] =
false;
42 $ThisFileInfo[
'video'][
'lossless'] =
false;
48 $ThisFileInfo[
'error'][] =
'Expecting "NSVs" or "NSVf" at offset '.$ThisFileInfo[
'avdataoffset'].
', found "'.$NSVheader.
'"';
53 if (!isset($ThisFileInfo[
'nsv'][
'NSVf'])) {
54 $ThisFileInfo[
'warning'][] =
'NSVf header not present - cannot calculate playtime or bitrate';
61 fseek($fd, $fileoffset, SEEK_SET);
62 $NSVsheader = fread($fd, 28);
65 $ThisFileInfo[
'nsv'][
'NSVs'][
'identifier'] = substr($NSVsheader, $offset, 4);
68 if ($ThisFileInfo[
'nsv'][
'NSVs'][
'identifier'] !=
'NSVs') {
69 $ThisFileInfo[
'error'][] =
'expected "NSVs" at offset ('.$fileoffset.
'), found "'.$ThisFileInfo[
'nsv'][
'NSVs'][
'identifier'].
'" instead';
70 unset($ThisFileInfo[
'nsv'][
'NSVs']);
74 $ThisFileInfo[
'nsv'][
'NSVs'][
'offset'] = $fileoffset;
76 $ThisFileInfo[
'nsv'][
'NSVs'][
'video_codec'] = substr($NSVsheader, $offset, 4);
78 $ThisFileInfo[
'nsv'][
'NSVs'][
'audio_codec'] = substr($NSVsheader, $offset, 4);
102 switch ($ThisFileInfo[
'nsv'][
'NSVs'][
'audio_codec']) {
111 $ThisFileInfo[
'audio'][
'sample_rate'] = $ThisFileInfo[
'nsv'][
'NSVs'][
'sample_rate'];
122 $ThisFileInfo[
'video'][
'resolution_x'] = $ThisFileInfo[
'nsv'][
'NSVs'][
'resolution_x'];
123 $ThisFileInfo[
'video'][
'resolution_y'] = $ThisFileInfo[
'nsv'][
'NSVs'][
'resolution_y'];
124 $ThisFileInfo[
'nsv'][
'NSVs'][
'frame_rate'] = $this->
NSVframerateLookup($ThisFileInfo[
'nsv'][
'NSVs'][
'framerate_index']);
125 $ThisFileInfo[
'video'][
'frame_rate'] = $ThisFileInfo[
'nsv'][
'NSVs'][
'frame_rate'];
126 $ThisFileInfo[
'video'][
'bits_per_sample'] = 24;
127 $ThisFileInfo[
'video'][
'pixel_aspect_ratio'] = (float) 1;
133 fseek($fd, $fileoffset, SEEK_SET);
134 $NSVfheader = fread($fd, 28);
137 $ThisFileInfo[
'nsv'][
'NSVf'][
'identifier'] = substr($NSVfheader, $offset, 4);
140 if ($ThisFileInfo[
'nsv'][
'NSVf'][
'identifier'] !=
'NSVf') {
141 $ThisFileInfo[
'error'][] =
'expected "NSVf" at offset ('.$fileoffset.
'), found "'.$ThisFileInfo[
'nsv'][
'NSVf'][
'identifier'].
'" instead';
142 unset($ThisFileInfo[
'nsv'][
'NSVf']);
146 $ThisFileInfo[
'nsv'][
'NSVs'][
'offset'] = $fileoffset;
153 if ($ThisFileInfo[
'nsv'][
'NSVf'][
'file_size'] > $ThisFileInfo[
'avdataend']) {
154 $ThisFileInfo[
'warning'][] =
'truncated file - NSVf header indicates '.$ThisFileInfo[
'nsv'][
'NSVf'][
'file_size'].
' bytes, file actually '.$ThisFileInfo[
'avdataend'].
' bytes';
166 if ($ThisFileInfo[
'nsv'][
'NSVf'][
'playtime_ms'] == 0) {
167 $ThisFileInfo[
'error'][] =
'Corrupt NSV file: NSVf.playtime_ms == zero';
171 $NSVfheader .= fread($fd, $ThisFileInfo[
'nsv'][
'NSVf'][
'meta_size'] + (4 * $ThisFileInfo[
'nsv'][
'NSVf'][
'TOC_entries_1']) + (4 * $ThisFileInfo[
'nsv'][
'NSVf'][
'TOC_entries_2']));
172 $NSVfheaderlength = strlen($NSVfheader);
173 $ThisFileInfo[
'nsv'][
'NSVf'][
'metadata'] = substr($NSVfheader, $offset, $ThisFileInfo[
'nsv'][
'NSVf'][
'meta_size']);
174 $offset += $ThisFileInfo[
'nsv'][
'NSVf'][
'meta_size'];
176 if ($getTOCoffsets) {
178 while ($TOCcounter < $ThisFileInfo[
'nsv'][
'NSVf'][
'TOC_entries_1']) {
179 if ($TOCcounter < $ThisFileInfo[
'nsv'][
'NSVf'][
'TOC_entries_1']) {
187 if (trim($ThisFileInfo[
'nsv'][
'NSVf'][
'metadata']) !=
'') {
188 $ThisFileInfo[
'nsv'][
'NSVf'][
'metadata'] = str_replace(
'`',
"\x01", $ThisFileInfo[
'nsv'][
'NSVf'][
'metadata']);
189 $CommentPairArray = explode(
"\x01".
' ', $ThisFileInfo[
'nsv'][
'NSVf'][
'metadata']);
190 foreach ($CommentPairArray as $CommentPair) {
191 if (strstr($CommentPair,
'='.
"\x01")) {
192 list($key, $value) = explode(
'='.
"\x01", $CommentPair, 2);
193 $ThisFileInfo[
'nsv'][
'comments'][strtolower($key)][] = trim(str_replace(
"\x01",
'', $value));
198 $ThisFileInfo[
'playtime_seconds'] = $ThisFileInfo[
'nsv'][
'NSVf'][
'playtime_ms'] / 1000;
199 $ThisFileInfo[
'bitrate'] = ($ThisFileInfo[
'nsv'][
'NSVf'][
'file_size'] * 8) / $ThisFileInfo[
'playtime_seconds'];
206 if ($framerateindex <= 127) {
207 return (
float) $framerateindex;
210 static $NSVframerateLookup = array();
211 if (empty($NSVframerateLookup)) {
212 $NSVframerateLookup[129] = (float) 29.970;
213 $NSVframerateLookup[131] = (float) 23.976;
214 $NSVframerateLookup[133] = (float) 14.985;
215 $NSVframerateLookup[197] = (float) 59.940;
216 $NSVframerateLookup[199] = (float) 47.952;
218 return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] :
false);