在PHP中用视频创建缩略图的更好方法是什么?

I am creating a video broadcasting site, in which i need to know how to create thumbnails from the video. Please Help. Any Suggestions or References will be highly appreciated

You can use ffmpeg.

Once it's installed on your server, you can use it in PHP by writing a command line, and calling exec on it.

e.g.:

exec('ffmpeg -i mymovie.mov -vcodec mjpeg -vframes 1 -an -f rawvideo -s 64x64 foo.jpg');

Here's a snippet to grab a frame from the middle of a video. It is old code I have lying around, so I'm sure it could be simplified. Be sure to adjust the ffmpeg path in line 1 to match the location of your install.

$output = shell_exec("/usr/local/bin/ffmpeg -i {$path}");
preg_match('/Duration: ([0-9]{2}):([0-9]{2}):([^ ,])+/', $output, $matches);
$time = str_replace("Duration: ", "", $matches[0]);
$time_breakdown = explode(":", $time);
$total_seconds = round(($time_breakdown[0]*60*60) + ($time_breakdown[1]*60) + $time_breakdown[2]);
shell_exec("/usr/local/bin/ffmpeg -y  -i {$input_filepath} -f mjpeg -vframes 1 -ss " . ($total_seconds / 2) . " -s {$w}x{$h} {$output_filepath}";

I've used ffmpeg, starting a task with exec(), and append an ampersand to the command so that teh php script can continue. If I want ffmpeg to finish first, I don't have an ampersand.

From the FAQ: "How do I encode movie to single pictures?" http://ffmpeg.org/faq.html#SEC15

ffmpeg -i movie.mpg movie%d.jpg

This generates many images.

From the docs: "Video and Audio file format conversion" http://ffmpeg.org/ffmpeg-doc.html#SEC5

ffmpeg -i foo.avi -r 1 -s WxH -f image2 -vframes 1 foo.jpeg

Replace W & H with width/height (see http://ffmpeg.org/ffmpeg-doc.html#SEC9 ), replace vframes with number of frames wanted, add %d to filename for sequence number if you're doing multiple images. To grab at a certain point in the video, use -ss (see http://ffmpeg.org/ffmpeg-doc.html#SEC8 )

I know this question is old. But I came across it when I was looking for a similar solution. Here are my findings. I hope it helps someone else.