module.audio-video.ivf.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  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. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.audio.ivf.php //
  11. // module for analyzing IVF audio-video files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
  16. exit;
  17. }
  18. class getid3_ivf extends getid3_handler
  19. {
  20. /**
  21. * @return bool
  22. */
  23. public function Analyze() {
  24. $info = &$this->getid3->info;
  25. $info['fileformat'] = 'ivf';
  26. $info['video']['dataformat'] = 'ivf';
  27. $this->fseek($info['avdataoffset']);
  28. $IVFheader = $this->fread(32);
  29. if (substr($IVFheader, 0, 4) == 'DKIF') {
  30. // https://wiki.multimedia.cx/index.php/IVF
  31. $info['ivf']['header']['signature'] = substr($IVFheader, 0, 4);
  32. $info['ivf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 4, 2)); // should be 0
  33. $info['ivf']['header']['headersize'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 6, 2));
  34. $info['ivf']['header']['fourcc'] = substr($IVFheader, 8, 4);
  35. $info['ivf']['header']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 12, 2));
  36. $info['ivf']['header']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 14, 2));
  37. $info['ivf']['header']['timebase_numerator'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 16, 4));
  38. $info['ivf']['header']['timebase_denominator'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 20, 4));
  39. $info['ivf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 24, 4));
  40. //$info['ivf']['header']['reserved'] = substr($IVFheader, 28, 4);
  41. $info['ivf']['header']['frame_rate'] = (float) $info['ivf']['header']['timebase_numerator'] / $info['ivf']['header']['timebase_denominator'];
  42. if ($info['ivf']['header']['version'] > 0) {
  43. $this->warning('Expecting IVF header version 0, found version '.$info['ivf']['header']['version'].', results may not be accurate');
  44. }
  45. $info['video']['resolution_x'] = $info['ivf']['header']['resolution_x'];
  46. $info['video']['resolution_y'] = $info['ivf']['header']['resolution_y'];
  47. $info['video']['codec'] = $info['ivf']['header']['fourcc'];
  48. $info['ivf']['frame_count'] = 0;
  49. while (!$this->feof()) {
  50. if ($frameheader = $this->fread(12)) {
  51. $framesize = getid3_lib::LittleEndian2Int(substr($frameheader, 0, 4)); // size of frame in bytes (not including the 12-byte header)
  52. $timestamp = getid3_lib::LittleEndian2Int(substr($frameheader, 4, 8)); // 64-bit presentation timestamp
  53. $this->fseek($framesize, SEEK_CUR);
  54. $info['ivf']['frame_count']++;
  55. }
  56. }
  57. if ($info['ivf']['frame_count']) {
  58. $info['playtime_seconds'] = $timestamp / 100000;
  59. $info['video']['frame_rate'] = (float) $info['ivf']['frame_count'] / $info['playtime_seconds'];
  60. }
  61. } else {
  62. $this->error('Expecting "DKIF" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($IVFheader, 0, 4)).'"');
  63. return false;
  64. }
  65. return true;
  66. }
  67. }