annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.nsv.php @ 12:2f433df9b961 judyates

[svn r13] Modified esgallery source to enable multiple paypal buttons; got the photo gallery operational and tested.
author rlm
date Mon, 12 Apr 2010 03:24:08 -0400
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.audio-video.nsv.php |
rlm@3 18 // | module for analyzing Nullsoft NSV files |
rlm@3 19 // | dependencies: NONE |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio-video.nsv.php,v 1.3 2006/11/02 10:48:00 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_nsv extends getid3_handler
rlm@3 27 {
rlm@3 28
rlm@3 29 public function Analyze() {
rlm@3 30
rlm@3 31 $getid3 = $this->getid3;
rlm@3 32
rlm@3 33 $getid3->info['fileformat'] = 'nsv';
rlm@3 34 $getid3->info['audio']['dataformat'] = 'nsv';
rlm@3 35 $getid3->info['video']['dataformat'] = 'nsv';
rlm@3 36 $getid3->info['audio']['lossless'] = false;
rlm@3 37 $getid3->info['video']['lossless'] = false;
rlm@3 38
rlm@3 39 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 40 $nsv_header = fread($getid3->fp, 4);
rlm@3 41
rlm@3 42 switch ($nsv_header) {
rlm@3 43
rlm@3 44 case 'NSVs':
rlm@3 45 $this->getNSVsHeader();
rlm@3 46 break;
rlm@3 47
rlm@3 48 case 'NSVf':
rlm@3 49 if ($this->getNSVfHeader()) {
rlm@3 50 $this->getNSVsHeader($getid3->info['nsv']['NSVf']['header_length']);
rlm@3 51 }
rlm@3 52 break;
rlm@3 53
rlm@3 54 default:
rlm@3 55 throw new getid3_exception('Expecting "NSVs" or "NSVf" at offset '.$getid3->info['avdataoffset'].', found "'.$nsv_header.'"');
rlm@3 56 break;
rlm@3 57 }
rlm@3 58
rlm@3 59 if (!isset($getid3->info['nsv']['NSVf'])) {
rlm@3 60 $getid3->warning('NSVf header not present - cannot calculate playtime or bitrate');
rlm@3 61 }
rlm@3 62
rlm@3 63 return true;
rlm@3 64 }
rlm@3 65
rlm@3 66
rlm@3 67
rlm@3 68 private function getNSVsHeader($file_offset = 0) {
rlm@3 69
rlm@3 70 $getid3 = $this->getid3;
rlm@3 71
rlm@3 72 fseek($getid3->fp, $file_offset, SEEK_SET);
rlm@3 73 $nsvs_header = fread($getid3->fp, 28);
rlm@3 74
rlm@3 75 $getid3->info['nsv']['NSVs'] = array ();
rlm@3 76 $info_nsv_NSVs = &$getid3->info['nsv']['NSVs'];
rlm@3 77
rlm@3 78 $info_nsv_NSVs['identifier'] = substr($nsvs_header, 0, 4);
rlm@3 79 if ($info_nsv_NSVs['identifier'] != 'NSVs') {
rlm@3 80 throw new getid3_exception('expected "NSVs" at offset ('.$file_offset.'), found "'.$info_nsv_NSVs['identifier'].'" instead');
rlm@3 81 }
rlm@3 82
rlm@3 83 $info_nsv_NSVs['offset'] = $file_offset;
rlm@3 84
rlm@3 85 getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 4,
rlm@3 86 array (
rlm@3 87 'video_codec' => -4, // string
rlm@3 88 'audio_codec' => -4, // string
rlm@3 89 'resolution_x' => 2,
rlm@3 90 'resolution_y' => 2,
rlm@3 91 'framerate_index' => 1,
rlm@3 92 )
rlm@3 93 );
rlm@3 94
rlm@3 95 if ($info_nsv_NSVs['audio_codec'] == 'PCM ') {
rlm@3 96
rlm@3 97 getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 24,
rlm@3 98 array (
rlm@3 99 'bits_channel' => 1,
rlm@3 100 'channels' => 1,
rlm@3 101 'sample_rate' => 2
rlm@3 102 )
rlm@3 103 );
rlm@3 104 $getid3->info['audio']['sample_rate'] = $info_nsv_NSVs['sample_rate'];
rlm@3 105
rlm@3 106 }
rlm@3 107
rlm@3 108 $getid3->info['video']['resolution_x'] = $info_nsv_NSVs['resolution_x'];
rlm@3 109 $getid3->info['video']['resolution_y'] = $info_nsv_NSVs['resolution_y'];
rlm@3 110 $info_nsv_NSVs['frame_rate'] = getid3_nsv::NSVframerateLookup($info_nsv_NSVs['framerate_index']);
rlm@3 111 $getid3->info['video']['frame_rate'] = $info_nsv_NSVs['frame_rate'];
rlm@3 112 $getid3->info['video']['bits_per_sample'] = 24;
rlm@3 113 $getid3->info['video']['pixel_aspect_ratio'] = (float)1;
rlm@3 114
rlm@3 115 return true;
rlm@3 116 }
rlm@3 117
rlm@3 118
rlm@3 119
rlm@3 120 private function getNSVfHeader($file_offset = 0, $get_toc_offsets=false) {
rlm@3 121
rlm@3 122 $getid3 = $this->getid3;
rlm@3 123
rlm@3 124 fseek($getid3->fp, $file_offset, SEEK_SET);
rlm@3 125 $nsvf_header = fread($getid3->fp, 28);
rlm@3 126
rlm@3 127 $getid3->info['nsv']['NSVf'] = array ();
rlm@3 128 $info_nsv_NSVf = &$getid3->info['nsv']['NSVf'];
rlm@3 129
rlm@3 130 $info_nsv_NSVf['identifier'] = substr($nsvf_header, 0, 4);
rlm@3 131 if ($info_nsv_NSVf['identifier'] != 'NSVf') {
rlm@3 132 throw new getid3_exception('expected "NSVf" at offset ('.$file_offset.'), found "'.$info_nsv_NSVf['identifier'].'" instead');
rlm@3 133 }
rlm@3 134
rlm@3 135 $getid3->info['nsv']['NSVs']['offset'] = $file_offset;
rlm@3 136
rlm@3 137 getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVf, $nsvf_header, 4,
rlm@3 138 array (
rlm@3 139 'header_length' => 4,
rlm@3 140 'file_size' => 4,
rlm@3 141 'playtime_ms' => 4,
rlm@3 142 'meta_size' => 4,
rlm@3 143 'TOC_entries_1' => 4,
rlm@3 144 'TOC_entries_2' => 4
rlm@3 145 )
rlm@3 146 );
rlm@3 147
rlm@3 148 if ($info_nsv_NSVf['playtime_ms'] == 0) {
rlm@3 149 throw new getid3_exception('Corrupt NSV file: NSVf.playtime_ms == zero');
rlm@3 150 }
rlm@3 151
rlm@3 152 if ($info_nsv_NSVf['file_size'] > $getid3->info['avdataend']) {
rlm@3 153 $getid3->warning('truncated file - NSVf header indicates '.$info_nsv_NSVf['file_size'].' bytes, file actually '.$getid3->info['avdataend'].' bytes');
rlm@3 154 }
rlm@3 155
rlm@3 156 $nsvf_header .= fread($getid3->fp, $info_nsv_NSVf['meta_size'] + (4 * $info_nsv_NSVf['TOC_entries_1']) + (4 * $info_nsv_NSVf['TOC_entries_2']));
rlm@3 157 $nsvf_headerlength = strlen($nsvf_header);
rlm@3 158 $info_nsv_NSVf['metadata'] = substr($nsvf_header, 28, $info_nsv_NSVf['meta_size']);
rlm@3 159
rlm@3 160 $offset = 28 + $info_nsv_NSVf['meta_size'];
rlm@3 161 if ($get_toc_offsets) {
rlm@3 162 $toc_counter = 0;
rlm@3 163 while ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
rlm@3 164 if ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
rlm@3 165 $info_nsv_NSVf['TOC_1'][$toc_counter] = getid3_lib::LittleEndian2Int(substr($nsvf_header, $offset, 4));
rlm@3 166 $offset += 4;
rlm@3 167 $toc_counter++;
rlm@3 168 }
rlm@3 169 }
rlm@3 170 }
rlm@3 171
rlm@3 172 if (trim($info_nsv_NSVf['metadata']) != '') {
rlm@3 173 $info_nsv_NSVf['metadata'] = str_replace('`', "\x01", $info_nsv_NSVf['metadata']);
rlm@3 174 $comment_pair_array = explode("\x01".' ', $info_nsv_NSVf['metadata']);
rlm@3 175 foreach ($comment_pair_array as $comment_pair) {
rlm@3 176 if (strstr($comment_pair, '='."\x01")) {
rlm@3 177 list($key, $value) = explode('='."\x01", $comment_pair, 2);
rlm@3 178 $getid3->info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value));
rlm@3 179 }
rlm@3 180 }
rlm@3 181 }
rlm@3 182
rlm@3 183 $getid3->info['playtime_seconds'] = $info_nsv_NSVf['playtime_ms'] / 1000;
rlm@3 184 $getid3->info['bitrate'] = ($info_nsv_NSVf['file_size'] * 8) / $getid3->info['playtime_seconds'];
rlm@3 185
rlm@3 186 return true;
rlm@3 187 }
rlm@3 188
rlm@3 189
rlm@3 190
rlm@3 191 public static function NSVframerateLookup($frame_rate_index) {
rlm@3 192
rlm@3 193 if ($frame_rate_index <= 127) {
rlm@3 194 return (float)$frame_rate_index;
rlm@3 195 }
rlm@3 196
rlm@3 197 static $lookup = array (
rlm@3 198 129 => 29.970,
rlm@3 199 131 => 23.976,
rlm@3 200 133 => 14.985,
rlm@3 201 197 => 59.940,
rlm@3 202 199 => 47.952
rlm@3 203 );
rlm@3 204 return (isset($lookup[$frame_rate_index]) ? $lookup[$frame_rate_index] : false);
rlm@3 205 }
rlm@3 206
rlm@3 207 }
rlm@3 208
rlm@3 209
rlm@3 210 ?>