2 /////////////////////////////////////////////////////////////////
3 /// getID3() by James Heinrich <info@getid3.org> //
4 // available at https://github.com/JamesHeinrich/getID3 //
5 // or https://www.getid3.org //
6 // or http://getid3.sourceforge.net //
7 // see readme.txt for more details //
8 /////////////////////////////////////////////////////////////////
10 // module.audio.ivf.php //
11 // module for analyzing IVF audio-video files //
12 // dependencies: NONE //
14 /////////////////////////////////////////////////////////////////
16 if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
20 class getid3_ivf
extends getid3_handler
25 public function Analyze() {
26 $info = &$this->getid3
->info
;
28 $info['fileformat'] = 'ivf';
29 $info['video']['dataformat'] = 'ivf';
31 $this->fseek($info['avdataoffset']);
32 $IVFheader = $this->fread(32);
34 if (substr($IVFheader, 0, 4) == 'DKIF') {
36 // https://wiki.multimedia.cx/index.php/IVF
37 $info['ivf']['header']['signature'] = substr($IVFheader, 0, 4);
38 $info['ivf']['header']['version'] = getid3_lib
::LittleEndian2Int(substr($IVFheader, 4, 2)); // should be 0
39 $info['ivf']['header']['headersize'] = getid3_lib
::LittleEndian2Int(substr($IVFheader, 6, 2));
40 $info['ivf']['header']['fourcc'] = substr($IVFheader, 8, 4);
41 $info['ivf']['header']['resolution_x'] = getid3_lib
::LittleEndian2Int(substr($IVFheader, 12, 2));
42 $info['ivf']['header']['resolution_y'] = getid3_lib
::LittleEndian2Int(substr($IVFheader, 14, 2));
43 $info['ivf']['header']['timebase_numerator'] = getid3_lib
::LittleEndian2Int(substr($IVFheader, 16, 4));
44 $info['ivf']['header']['timebase_denominator'] = getid3_lib
::LittleEndian2Int(substr($IVFheader, 20, 4));
45 $info['ivf']['header']['frame_count'] = getid3_lib
::LittleEndian2Int(substr($IVFheader, 24, 4));
46 //$info['ivf']['header']['reserved'] = substr($IVFheader, 28, 4);
48 $info['ivf']['header']['frame_rate'] = (float) $info['ivf']['header']['timebase_numerator'] / $info['ivf']['header']['timebase_denominator'];
50 if ($info['ivf']['header']['version'] > 0) {
51 $this->warning('Expecting IVF header version 0, found version '.$info['ivf']['header']['version'].', results may not be accurate');
54 $info['video']['resolution_x'] = $info['ivf']['header']['resolution_x'];
55 $info['video']['resolution_y'] = $info['ivf']['header']['resolution_y'];
56 $info['video']['codec'] = $info['ivf']['header']['fourcc'];
58 $info['ivf']['frame_count'] = 0;
59 while (!$this->feof()) {
60 if ($frameheader = $this->fread(12)) {
61 $framesize = getid3_lib
::LittleEndian2Int(substr($frameheader, 0, 4)); // size of frame in bytes (not including the 12-byte header)
62 $timestamp = getid3_lib
::LittleEndian2Int(substr($frameheader, 4, 8)); // 64-bit presentation timestamp
63 $this->fseek($framesize, SEEK_CUR
);
64 $info['ivf']['frame_count']++
;
67 if ($info['ivf']['frame_count']) {
68 $info['playtime_seconds'] = $timestamp / 100000;
69 $info['video']['frame_rate'] = (float) $info['ivf']['frame_count'] / $info['playtime_seconds'];
73 $this->error('Expecting "DKIF" at offset '.$info['avdataoffset'].', found "'.getid3_lib
::PrintHexBytes(substr($IVFheader, 0, 4)).'"');