ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
GetId3\Module\AudioVideo\Nsv Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Inheritance diagram for GetId3\Module\AudioVideo\Nsv:
+ Collaboration diagram for GetId3\Module\AudioVideo\Nsv:

Public Member Functions

 analyze ()
 
 getNSVsHeaderFilepointer ($fileoffset)
 
 getNSVfHeaderFilepointer ($fileoffset, $getTOCoffsets=false)
 
- Public Member Functions inherited from GetId3\Handler\BaseHandler
 __construct (GetId3Core $getid3, $call_module=null)
 
 analyze ()
 Analyze from file pointer. More...
 
 AnalyzeString (&$string)
 Analyze from string instead. More...
 
 saveAttachment (&$ThisFileInfoIndex, $filename, $offset, $length)
 

Static Public Member Functions

static NSVframerateLookup ($framerateindex)
 array $NSVframerateLookup More...
 

Additional Inherited Members

- Protected Member Functions inherited from GetId3\Handler\BaseHandler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
- Protected Attributes inherited from GetId3\Handler\BaseHandler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

module for analyzing Nullsoft NSV files

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g http://www.getid3.org

Definition at line 29 of file Nsv.php.

Member Function Documentation

◆ analyze()

GetId3\Module\AudioVideo\Nsv::analyze ( )
Returns
boolean

Definition at line 36 of file Nsv.php.

References $info, GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Module\AudioVideo\Nsv\getNSVfHeaderFilepointer(), GetId3\Module\AudioVideo\Nsv\getNSVsHeaderFilepointer(), and GetId3\Lib\Helper\PrintHexBytes().

37  {
38  $info = &$this->getid3->info;
39 
40  fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
41  $NSVheader = fread($this->getid3->fp, 4);
42 
43  switch ($NSVheader) {
44  case 'NSVs':
45  if ($this->getNSVsHeaderFilepointer(0)) {
46  $info['fileformat'] = 'nsv';
47  $info['audio']['dataformat'] = 'nsv';
48  $info['video']['dataformat'] = 'nsv';
49  $info['audio']['lossless'] = false;
50  $info['video']['lossless'] = false;
51  }
52  break;
53 
54  case 'NSVf':
55  if ($this->getNSVfHeaderFilepointer(0)) {
56  $info['fileformat'] = 'nsv';
57  $info['audio']['dataformat'] = 'nsv';
58  $info['video']['dataformat'] = 'nsv';
59  $info['audio']['lossless'] = false;
60  $info['video']['lossless'] = false;
61  $this->getNSVsHeaderFilepointer($info['nsv']['NSVf']['header_length']);
62  }
63  break;
64 
65  default:
66  $info['error'][] = 'Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.Helper::PrintHexBytes($NSVheader).'"';
67 
68  return false;
69  break;
70  }
71 
72  if (!isset($info['nsv']['NSVf'])) {
73  $info['warning'][] = 'NSVf header not present - cannot calculate playtime or bitrate';
74  }
75 
76  return true;
77  }
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: Helper.php:36
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
getNSVsHeaderFilepointer($fileoffset)
Definition: Nsv.php:84
getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets=false)
Definition: Nsv.php:165
+ Here is the call graph for this function:

◆ getNSVfHeaderFilepointer()

GetId3\Module\AudioVideo\Nsv::getNSVfHeaderFilepointer (   $fileoffset,
  $getTOCoffsets = false 
)
Parameters
type$fileoffset
type$getTOCoffsets
Returns
boolean

Definition at line 165 of file Nsv.php.

References $info, GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), and GetId3\Lib\Helper\LittleEndian2Int().

Referenced by GetId3\Module\AudioVideo\Nsv\analyze().

166  {
167  $info = &$this->getid3->info;
168  fseek($this->getid3->fp, $fileoffset, SEEK_SET);
169  $NSVfheader = fread($this->getid3->fp, 28);
170  $offset = 0;
171 
172  $info['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4);
173  $offset += 4;
174 
175  if ($info['nsv']['NSVf']['identifier'] != 'NSVf') {
176  $info['error'][] = 'expected "NSVf" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVf']['identifier'].'" instead';
177  unset($info['nsv']['NSVf']);
178 
179  return false;
180  }
181 
182  $info['nsv']['NSVs']['offset'] = $fileoffset;
183 
184  $info['nsv']['NSVf']['header_length'] = Helper::LittleEndian2Int(substr($NSVfheader, $offset, 4));
185  $offset += 4;
186  $info['nsv']['NSVf']['file_size'] = Helper::LittleEndian2Int(substr($NSVfheader, $offset, 4));
187  $offset += 4;
188 
189  if ($info['nsv']['NSVf']['file_size'] > $info['avdataend']) {
190  $info['warning'][] = 'truncated file - NSVf header indicates '.$info['nsv']['NSVf']['file_size'].' bytes, file actually '.$info['avdataend'].' bytes';
191  }
192 
193  $info['nsv']['NSVf']['playtime_ms'] = Helper::LittleEndian2Int(substr($NSVfheader, $offset, 4));
194  $offset += 4;
195  $info['nsv']['NSVf']['meta_size'] = Helper::LittleEndian2Int(substr($NSVfheader, $offset, 4));
196  $offset += 4;
197  $info['nsv']['NSVf']['TOC_entries_1'] = Helper::LittleEndian2Int(substr($NSVfheader, $offset, 4));
198  $offset += 4;
199  $info['nsv']['NSVf']['TOC_entries_2'] = Helper::LittleEndian2Int(substr($NSVfheader, $offset, 4));
200  $offset += 4;
201 
202  if ($info['nsv']['NSVf']['playtime_ms'] == 0) {
203  $info['error'][] = 'Corrupt NSV file: NSVf.playtime_ms == zero';
204 
205  return false;
206  }
207 
208  $NSVfheader .= fread($this->getid3->fp, $info['nsv']['NSVf']['meta_size'] + (4 * $info['nsv']['NSVf']['TOC_entries_1']) + (4 * $info['nsv']['NSVf']['TOC_entries_2']));
209  $NSVfheaderlength = strlen($NSVfheader);
210  $info['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $info['nsv']['NSVf']['meta_size']);
211  $offset += $info['nsv']['NSVf']['meta_size'];
212 
213  if ($getTOCoffsets) {
214  $TOCcounter = 0;
215  while ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) {
216  if ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) {
217  $info['nsv']['NSVf']['TOC_1'][$TOCcounter] = Helper::LittleEndian2Int(substr($NSVfheader, $offset, 4));
218  $offset += 4;
219  $TOCcounter++;
220  }
221  }
222  }
223 
224  if (trim($info['nsv']['NSVf']['metadata']) != '') {
225  $info['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $info['nsv']['NSVf']['metadata']);
226  $CommentPairArray = explode("\x01".' ', $info['nsv']['NSVf']['metadata']);
227  foreach ($CommentPairArray as $CommentPair) {
228  if (strstr($CommentPair, '='."\x01")) {
229  list($key, $value) = explode('='."\x01", $CommentPair, 2);
230  $info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value));
231  }
232  }
233  }
234 
235  $info['playtime_seconds'] = $info['nsv']['NSVf']['playtime_ms'] / 1000;
236  $info['bitrate'] = ($info['nsv']['NSVf']['file_size'] * 8) / $info['playtime_seconds'];
237 
238  return true;
239  }
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
static LittleEndian2Int($byteword, $signed=false)
Definition: Helper.php:413
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNSVsHeaderFilepointer()

GetId3\Module\AudioVideo\Nsv::getNSVsHeaderFilepointer (   $fileoffset)
Parameters
type$fileoffset
Returns
boolean

Definition at line 84 of file Nsv.php.

References $info, GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Lib\Helper\LittleEndian2Int(), and GetId3\Module\AudioVideo\Nsv\NSVframerateLookup().

Referenced by GetId3\Module\AudioVideo\Nsv\analyze().

85  {
86  $info = &$this->getid3->info;
87  fseek($this->getid3->fp, $fileoffset, SEEK_SET);
88  $NSVsheader = fread($this->getid3->fp, 28);
89  $offset = 0;
90 
91  $info['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4);
92  $offset += 4;
93 
94  if ($info['nsv']['NSVs']['identifier'] != 'NSVs') {
95  $info['error'][] = 'expected "NSVs" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVs']['identifier'].'" instead';
96  unset($info['nsv']['NSVs']);
97 
98  return false;
99  }
100 
101  $info['nsv']['NSVs']['offset'] = $fileoffset;
102 
103  $info['nsv']['NSVs']['video_codec'] = substr($NSVsheader, $offset, 4);
104  $offset += 4;
105  $info['nsv']['NSVs']['audio_codec'] = substr($NSVsheader, $offset, 4);
106  $offset += 4;
107  $info['nsv']['NSVs']['resolution_x'] = Helper::LittleEndian2Int(substr($NSVsheader, $offset, 2));
108  $offset += 2;
109  $info['nsv']['NSVs']['resolution_y'] = Helper::LittleEndian2Int(substr($NSVsheader, $offset, 2));
110  $offset += 2;
111 
112  $info['nsv']['NSVs']['framerate_index'] = Helper::LittleEndian2Int(substr($NSVsheader, $offset, 1));
113  $offset += 1;
114  //$info['nsv']['NSVs']['unknown1b'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
115  $offset += 1;
116  //$info['nsv']['NSVs']['unknown1c'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
117  $offset += 1;
118  //$info['nsv']['NSVs']['unknown1d'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
119  $offset += 1;
120  //$info['nsv']['NSVs']['unknown2a'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
121  $offset += 1;
122  //$info['nsv']['NSVs']['unknown2b'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
123  $offset += 1;
124  //$info['nsv']['NSVs']['unknown2c'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
125  $offset += 1;
126  //$info['nsv']['NSVs']['unknown2d'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
127  $offset += 1;
128 
129  switch ($info['nsv']['NSVs']['audio_codec']) {
130  case 'PCM ':
131  $info['nsv']['NSVs']['bits_channel'] = Helper::LittleEndian2Int(substr($NSVsheader, $offset, 1));
132  $offset += 1;
133  $info['nsv']['NSVs']['channels'] = Helper::LittleEndian2Int(substr($NSVsheader, $offset, 1));
134  $offset += 1;
135  $info['nsv']['NSVs']['sample_rate'] = Helper::LittleEndian2Int(substr($NSVsheader, $offset, 2));
136  $offset += 2;
137 
138  $info['audio']['sample_rate'] = $info['nsv']['NSVs']['sample_rate'];
139  break;
140 
141  case 'MP3 ':
142  case 'NONE':
143  default:
144  //$info['nsv']['NSVs']['unknown3'] = GetId3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4));
145  $offset += 4;
146  break;
147  }
148 
149  $info['video']['resolution_x'] = $info['nsv']['NSVs']['resolution_x'];
150  $info['video']['resolution_y'] = $info['nsv']['NSVs']['resolution_y'];
151  $info['nsv']['NSVs']['frame_rate'] = $this->NSVframerateLookup($info['nsv']['NSVs']['framerate_index']);
152  $info['video']['frame_rate'] = $info['nsv']['NSVs']['frame_rate'];
153  $info['video']['bits_per_sample'] = 24;
154  $info['video']['pixel_aspect_ratio'] = (float) 1;
155 
156  return true;
157  }
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
static NSVframerateLookup($framerateindex)
array $NSVframerateLookup
Definition: Nsv.php:247
static LittleEndian2Int($byteword, $signed=false)
Definition: Helper.php:413
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NSVframerateLookup()

static GetId3\Module\AudioVideo\Nsv::NSVframerateLookup (   $framerateindex)
static

array $NSVframerateLookup

Parameters
type$framerateindex
Returns
type

Definition at line 247 of file Nsv.php.

References array.

Referenced by GetId3\Module\AudioVideo\Nsv\getNSVsHeaderFilepointer().

248  {
249  if ($framerateindex <= 127) {
250  return (float) $framerateindex;
251  }
252  static $NSVframerateLookup = array();
253  if (empty($NSVframerateLookup)) {
254  $NSVframerateLookup[129] = (float) 29.970;
255  $NSVframerateLookup[131] = (float) 23.976;
256  $NSVframerateLookup[133] = (float) 14.985;
257  $NSVframerateLookup[197] = (float) 59.940;
258  $NSVframerateLookup[199] = (float) 47.952;
259  }
260 
261  return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false);
262  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: