Source for file module.audio-video.flv.php
Documentation is available at module.audio-video.flv.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.archive.gzip.php |
// | module for analyzing GZIP files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
// | FLV module by Seth Kaufman <sethØwhirl-i.gig*com> |
// | * version 0.1 (26 June 2005) |
// | minor modifications by James Heinrich <infoØgetid3*org> |
// | * version 0.1.1 (15 July 2005) |
// | Support for On2 VP6 codec and meta information by |
// | Steve Webster <steve.websterØfeaturecreep*com> |
// | * version 0.2 (22 February 2006) |
// | Modified to not read entire file into memory |
// | by James Heinrich <infoØgetid3*org> |
// | * version 0.3 (15 June 2006) |
// | Modifications by Allan Hansen <ahØartemis*dk> |
// | Adapted module for PHP5 and getID3 2.0.0. |
// +----------------------------------------------------------------------+
// $Id: module.audio-video.flv.php,v 1.7 2006/11/10 11:20:12 ah Exp $
$info_flv = &$info['flv'];
fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
$flv_data_length = $info['avdataend'] - $info['avdataoffset'];
$info['fileformat'] = 'flv';
$info_flv['header']['signature'] = substr($flv_header, 0, 3);
$info_flv['header']['hasAudio'] = (bool) ($type_flags & 0x04);
$info_flv['header']['hasVideo'] = (bool) ($type_flags & 0x01);
$flv_header_frame_length = 9;
if ($frame_size_data_length > $flv_header_frame_length) {
fseek($this->getid3->fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) {
$next_offset = ftell($this->getid3->fp) - 1 + $data_length;
if (!isset ($info_flv['audio']['audioFormat'])) {
$info_flv['audio']['audioFormat'] = $last_header_byte & 0x07;
$info_flv['audio']['audioRate'] = ($last_header_byte & 0x30) / 0x10;
$info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40;
$info_flv['audio']['audioType'] = ($last_header_byte & 0x80) / 0x80;
if (!isset ($info_flv['video']['videoCodec'])) {
$info_flv['video']['videoCodec'] = $last_header_byte & 0x07;
if ($info_flv['video']['videoCodec'] != getid3_flv::VIDEO_VP6) {
$picture_size_type = $picture_size_type & 0x0007;
$info_flv['header']['videoSizeType'] = $picture_size_type;
switch ($picture_size_type) {
$info['video']['resolution_x'] = ($picture_size_enc & 0xFF00) >> 8;
$info['video']['resolution_y'] = ($picture_size_enc & 0xFF00) >> 8;
$info['video']['resolution_x'] = ($picture_size_enc & 0xFFFF0000) >> 16;
$info['video']['resolution_y'] = ($picture_size_enc & 0xFFFF0000) >> 16;
$info['video']['resolution_x'] = 352;
$info['video']['resolution_y'] = 288;
$info['video']['resolution_x'] = 176;
$info['video']['resolution_y'] = 144;
$info['video']['resolution_x'] = 128;
$info['video']['resolution_y'] = 96;
$info['video']['resolution_x'] = 320;
$info['video']['resolution_y'] = 240;
$info['video']['resolution_x'] = 160;
$info['video']['resolution_y'] = 120;
$info['video']['resolution_x'] = 0;
$info['video']['resolution_y'] = 0;
$event_name = $reader->readData();
$info['meta'][$event_name] = $reader->readData();
$info['video']['frame_rate'] = @$info['meta']['onMetaData']['framerate'];
$info['video']['resolution_x'] = @$info['meta']['onMetaData']['width'];
$info['video']['resolution_y'] = @$info['meta']['onMetaData']['height'];
if ($timestamp > $duration) {
if ($info['playtime_seconds'] = $duration / 1000) {
$info['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds'];
if ($info_flv['header']['hasAudio']) {
$info['audio']['codec'] = $this->FLVaudioFormat($info_flv['audio']['audioFormat']);
$info['audio']['sample_rate'] = $this->FLVaudioRate($info_flv['audio']['audioRate']);
$info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info_flv['audio']['audioSampleSize']);
$info['audio']['channels'] = $info_flv['audio']['audioType'] + 1; // 0=mono,1=stereo
$info['audio']['lossless'] = ($info_flv['audio']['audioFormat'] ? false : true); // 0=uncompressed
$info['audio']['dataformat'] = 'flv';
if (@$info_flv['header']['hasVideo']) {
$info['video']['codec'] = $this->FLVvideoCodec($info_flv['video']['videoCodec']);
$info['video']['dataformat'] = 'flv';
$info['video']['lossless'] = false;
5 => 'Nellymoser 8kHz mono',
return (@$lookup[$id] ? @$lookup[$id] : false);
return (@$lookup[$id] ? @$lookup[$id] : false);
return (@$lookup[$id] ? @$lookup[$id] : false);
getid3_flv::VIDEO_H263 => 'Sorenson H.263',
getid3_flv::VIDEO_SCREEN => 'Screen video',
getid3_flv::VIDEO_VP6 => 'On2 VP6',
return (@$lookup[$id] ? @$lookup[$id] : false);
return $this->read($length);
return $this->read($length);
public function read($length) {
$type = $this->stream->readByte();
// XML (handled as string)
// Typed object (handled as object)
$value = '(unknown or unsupported data type)';
return $this->stream->readDouble();
return $this->stream->readByte() == 1;
return $this->stream->readUTF();
// Get highest numerical index - ignored
$highestIndex = $this->stream->readLong();
while ($key = $this->stream->readUTF()) {
// Mixed array record ends with empty string (0x00 0x00) and 0x09
if (($key == '') && ($this->stream->peekByte() == 0x09)) {
// Get highest numerical index - ignored
$highestIndex = $this->stream->readLong();
while ($key = $this->stream->readUTF()) {
// Mixed array record ends with empty string (0x00 0x00) and 0x09
if (($key == '') && ($this->stream->peekByte() == 0x09)) {
$length = $this->stream->readLong();
for ($i = 0; $i < count($length); $i++ ) {
$timestamp = $this->stream->readDouble();
$timezone = $this->stream->readInt();
return $this->stream->readLongUTF();
return $this->stream->readLongUTF();
$className = $this->stream->readUTF();
|