On Tue, 15 Aug 2006 09:01:09 -0500, Karl Groves wrote:
To be honest, you should have everything you need above and my normal
response would be RTFM/try it and come back with some code even if it has
problems for us to fix.
However, I'm in a good mood so below is some code I've just knocked and
had a quick test with. It works fine. The locking code could do with a
usleep/while loop to keep trying in the event of a lock failure, but the
basics are surely close enough now for you.
It also gets round a bug where (on the movie I was testing it on at least)
the first frame image is always the start of the movie, but the second
frame is the real one.
#!/usr/bin/env php
<?php
function movie_get_lengt h_in_seconds($m ovie_filename)
{
$cmd = "mplayer -identify -vo null -ao null -frames 1 ".
"$movie_filenam e 2>&1 | grep ID_LENGTH";
$output = exec($cmd);
list(,$length) = explode("=", $output); return $length;
}
function movie_take_scre enshot($movie_f ilename, $time_in_second s,
$image_filename )
{
if (mkdir(".movie. lck")) { // Try to get a lock
$cmd = "mplayer -ss $time_in_second s -vo jpeg ".
"-ao null -frames 2 $movie_filename " 2>&1 | ".
"grep ID_LENGTH";
exec($cmd);
rename("0000000 2.jpg", "$image_filenam e");
unlink("0000000 1.jpg");
rmdir(".movie.l ck"); // Release lock
return true;
}
return false; // Could not obtain lock
}
$movie_filename = "test.mpg";
$movie_length = movie_get_lengt h_in_seconds($m ovie_filename);
$random_seconds = rand(0, floor($movie_le ngth));
$was_image_crea ted = movie_take_scre enshot($movie_f ilename,
$random_seconds , "test_image.jpg ");
?>
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos