1

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

4 Answers 4

2

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}";
1

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');
1

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.

0

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 )

6
  • How to install ffmpeg? plz help
    – Rajasekar
    Sep 24, 2009 at 5:52
  • @Rajasekar: What OS are you using? Google either "install ffmpeg windows/osx/linux" depending on what you are using. Sep 24, 2009 at 6:05
  • I need it for php. To Install ffmpeg they r asking to edit php.ini file. I am working in my local system. I want to know while hosting any problem would arise? will the hoster allow us to edit php.ini??. Or we have to use any special type of hosting???@Derek Gathright
    – Rajasekar
    Sep 24, 2009 at 7:51
  • Depends on the hosting provider - if you're not paying much, don't expect to be allowed to install software or have php.ini altered.
    – Mead
    Sep 25, 2009 at 1:25
  • I've edited your post for you to enable the links. Hope this helps :-)
    – derobert
    Sep 26, 2009 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.