On Sun, 13 Aug 2006 16:44:11 -0500, Karl Groves wrote:
Does anyone out there know of a way to capture a frame (at random, if
possible) of a movie file with PHP?
The easiest way will be to call out to mplayer to do it. You'll have to
do it twice, once to get the length of the movie (and then optionally a
second time if you don't want the first frame).
This will print out (amongst many many other things):
ID_LENGTH=4498. 26
This ID_LENGTH is the the length of the movie in seconds.
Calling mplayer like this will create a file called 000001.jpg which
you'll need to rename (and implement some locking PHP-side to ensure you
don't run two mplayer instances simultaneously which will whack the same
file).
So, along with exec($cmdline, &$output) you have all you need :-)
Sorry, forgot to mention -ss mm:ss is the offset. Here I use 20 minutes
in, but you should call it with 00:00 initially to get the first frame in
case the movie isn't 20 minutes long ;-)
Andy Jeffries <news@andyjeffr ies.co.ukwrote in
news:pan.2006.0 8.15.12.48.50.5 0049@andyjeffri es.co.uk:
On Sun, 13 Aug 2006 16:44:11 -0500, Karl Groves wrote:
>Does anyone out there know of a way to capture a frame (at random, if
>possible) of a movie file with PHP?
>
The easiest way will be to call out to mplayer to do it. You'll have to
do it twice, once to get the length of the movie (and then optionally a
second time if you don't want the first frame).
>
mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi
>
This will print out (amongst many many other things):
>
ID_LENGTH=4498. 26
>
This ID_LENGTH is the the length of the movie in seconds.
>
Calling mplayer like this will create a file called 000001.jpg which
you'll need to rename (and implement some locking PHP-side to ensure you
don't run two mplayer instances simultaneously which will whack the same
file).
>
So, along with exec($cmdline, &$output) you have all you need :-)
>
Thanks for the excellent response.
Do you have, perhaps, a more comprehensive example? I don't have much
experience with using exec(), except for using it to perform ImageMagick
commands.
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.
The easiest way will be to call out to mplayer to do it. You'll have to
do it twice, once to get the length of the movie (and then optionally a
second time if you don't want the first frame).
>
mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi
Sorry for my ignorance, is mplayer a Linux utility or Windows?
>The easiest way will be to call out to mplayer to do it. You'll have to
>do it twice, once to get the length of the movie (and then optionally a
>second time if you don't want the first frame).
>>
>mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi
>
Sorry for my ignorance, is mplayer a Linux utility or Windows?
Primarily Linux, but there's a Windows version too:
Comment