PHP - grabbing a thumb from FLV's (function)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i wanted to get my server to grab a thumbnail (video capture) of an FLV
using PHP, and ffmpeg-php is not an option (at the moment, can't spare the
possible downtime, many money-making sites involved).

i installed ffmpeg.  Fedora Core 4 users try this:

yum install ffmpeg

I went a more circuitous route and installed Subversion (SVN) (google it),
THEN installed ffmpeg using the link on their download page.  (get it,
configure it, make it)

Then, like i do with imageMagick, i use a system() call to ffmpeg.

NOTE: (i had to put the full path to ffmpeg (usr/local/bin/ffmpeg) in my
system call, this messed me up for a bit)

here's my impromptu function (have to pass the FLV file, width, height,
hour, min, sec, append (any value you want to put on the end of the
resulting jpg's filename)):

function
flvThumb($file,$width=50,$height=50,$hour=00,$min=00,$sec=01,$append) {
if ($append == "") {
 $append = time();
}

if ($file == "" or !is_file($file)) {
 return false;
}

$width = eregi_replace("[^0-9]","",$width);
$height = eregi_replace("[^0-9]","",$height);

if ($width == "") {
 $width = 50;
}
if ($height == "") {
 $height = 50;
}

$hour = eregi_replace("[^0-9]","",$hour);
$min = eregi_replace("[^0-9]","",$min);
$sec = eregi_replace("[^0-9]","",$sec);

if (strlen($hour) == 1) {
 $hour = "0" . $hour;
}
if (strlen($min) == 1) {
 $min = "0" . $min;
}
if (strlen($sec) == 1) {
 $sec = "0" . $sec;
}

$try = explode(".",$file);
$ext = array_pop($try);
$desig = implode(".",$try);
$thumbname = $desig . "_" . $append . "." . "jpg";

$varmake = @system("/usr/local/bin/ffmpeg -i $file -vcodec png -vframes 1
-an -f rawvideo -s " . $width . "x" . $height . " -ss " . "$hour" . ":" .
"$min" . ":" . "$sec" . " -y " . "$thumbname",$retval);
$tmp = @stat($thumbname);
if ($tmp['size'] == 0) {
 @unlink($thumbname);
 return false;
}
if ($retval != 0) {
 return false;
} else {
 return $thumbname;
}

}
if it returns anything but false, you may have a problem.  of course, the
problem may be with the function and application.

i know that improvements can be made, but i wish i had seen this before i
started trying to figure everything out.  i like having a starting point.
(i'm sending this to my gmail for my 'reference archive')

HOPE THIS HELPS SOMEONE
(plz don't burn me)

1337 c0d1ng 2 a11, & 2 a11 @ g00d n173,
mellomutt

p.s. it only just now strikes me that many other video formats can be
thumbnailed.  mpg, wmv, mov, avi, etc....   this really changes the way i'm
thinking about my sites.  i was using a desktop client to make thumbnails,
and it's a good one, but to have ur server do it for you...that just makes
it that much easier to add content, and thusly, that much more likely for me
to add content because i'm a lazy wanker.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux