You are not logged in.
I have a PHP script which I am using to grab a poster frame from an arbitrary video ($video). Currently it breaks the video into all its frames, counts the files, and grabs the middle one...
system("mplayer -vo png $video");
system("mv " . sprintf("%08d.png", floor(system("ls -1 | wc -l") / 2)) . " /home/.");
The issue with the code above is that, until completion, it fills up a large portion of the hard drive on the server. I know I can figure out the number of the middle frame with the code below, but I do not know of a way to pull out the middle frame without pulling out all the other frames too...
$fps = system("x=$(mplayer -msglevel all=0 -identify -vo null -frames 0 $video 2>&1 | grep ID_VIDEO_FPS) ; echo ${x#*=}");
$length = system("x=$(mplayer -msglevel all=0 -identify -vo null -frames 0 $video 2>&1 | grep ID_LENGTH) ; echo ${x#*=}");
$midframe = floor($fps * $length / 2);
Does anyone have any ideas? At the very least, is there a way I can read each frame but only save the middle one?
Offline
mplayer -nosound -vo png -ss 20 -frames 1 $video
seeks to 20 seconds and saves one frame.
Edit: http://www.londatiga.net/it/programming … r-and-php/
Last edited by karol (2010-12-15 03:51:35)
Offline
Yeah; I may end up going with a solution like that. I had hoped to be able to seek to a specific frame. Really I'd like the script to be very robust - for example, if I pass it a 30-fps video that is one second long, I'd like to get the #15 frame...
Offline
Yeah; I may end up going with a solution like that. I had hoped to be able to seek to a specific frame. Really I'd like the script to be very robust - for example, if I pass it a 30-fps video that is one second long, I'd like to get the #15 frame...
Google told me mplayer can't seek to a specific frame, but does 1/100th of a second seeks. I'm not sure how precise the duration estimates are.
Offline
Thanks, Karol - I ended up implementing your idea. For anyone else who is interested, here is the PHP I'm using,
$halfwaytime = substr(system("mplayer -msglevel all=0 -identify -vo null -frames 0 $video 2>&1 | grep ID_LENGTH"), 10) / 2;
system("mplayer -nosound -vo png -ss $halfwaytime -frames 1 $video");
system("mv 00000001.png /home/poster_frame.png");
Offline