How can I get Flash video file sizes from PHP code?

I have an application in which users can upload video files of any size, and I would like to determine the height / width of the Flash video file (flv or f4v) from a PHP script so that I can configure the player correctly. I would like a clean PHP solution, but I would be open to bypassing the command line tool and analyzing the output (if such a tool exists).

Thanks in advance!

+3
source share
5 answers

ffmpeg is probably your best bet, there is even a php module .

ffmpeg -i "FileName"

flv, .

+5

ffmpeg, PHP, getID3, FLV-, .

+2

flv4php.

( ), :

function flvdim($name) {
    $file = @fopen($name, 'rb');
    if($file === false)
        return false;

    $header = fread($file, 2048);
    fclose($file);
    if($header === false)
        return false;

    return array(
        'width' => flvdim_get($header, 'width'),
        'height' => flvdim_get($header, 'height')
    );
}

function flvdim_get($header, $field) {
    $pos = strpos($header, $field);
    if($pos === false)
        return false;

    $pos += strlen($field) + 2;
    return flvdim_decode(ord($header[$pos]), ord($header[$pos + 1]));
}

function flvdim_decode($byte1, $byte2) {
    $high1 = $byte1 >> 4;
    $high2 = $byte2 >> 4;
    $low1 = $byte1 & 0x0f;

    $mantissa = ($low1 << 4) | $high2;

    // (1 + m·2^(-8))·2^(h1 + 1) = (2^8 + m)·2^(h1 - 7)
    return ((256 + $mantissa) << $high1) >> 7;
}

, , , , , .

+1

Tommy Lacroix, , FLV .

0

, getimagesize(), . .

0
source

All Articles