-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetFLVDuration.php
More file actions
39 lines (29 loc) · 816 Bytes
/
GetFLVDuration.php
File metadata and controls
39 lines (29 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// Copyright (C) 2011 Michael Bemmerl
// Released under a CC0 license (http://creativecommons.org/publicdomain/zero/1.0/)
// https://github.com/mibe/misc_stuff/blob/master/GetFLVDuration.php
//
// This function returns the duration of a Flash Video file in seconds or false,
// if an error occurred.
function GetFLVDuration($file)
{
if (!file_exists($file))
return false;
$handle = fopen($file, "r");
$header = fread($handle, 3);
if ($header != "FLV")
{
fclose($handle);
return false;
}
fseek($handle, -4, SEEK_END);
$bytes = fread($handle, 4);
$taglen = unpack("N", $bytes);
$taglen = $taglen[1];
fseek($handle, -1 * $taglen, SEEK_END);
$bytes = fread($handle, 3);
$duration = unpack("N", "\x00" . $bytes);
$duration = $duration[1];
fclose($handle);
return $duration / 1000;
}