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

Stephan
  • 41,764
  • 65
  • 238
  • 329
Rajasekar
  • 18,392
  • 34
  • 106
  • 137

4 Answers4

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}";
Derek Gathright
  • 741
  • 5
  • 10
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.

Jim Baca
  • 6,112
  • 2
  • 24
  • 30
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');
Fragsworth
  • 33,919
  • 27
  • 84
  • 97
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 )

derobert
  • 49,731
  • 15
  • 94
  • 124
Mead
  • 1,126
  • 8
  • 8
  • How to install ffmpeg? plz help – Rajasekar Sep 24 '09 at 05:52
  • @Rajasekar: What OS are you using? Google either "install ffmpeg windows/osx/linux" depending on what you are using. – Derek Gathright Sep 24 '09 at 06: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 '09 at 07: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 '09 at 01:25
  • I've edited your post for you to enable the links. Hope this helps :-) – derobert Sep 26 '09 at 06:41
  • No ffmpeg allowed for GoDaddy shared hosting :( – TARKUS Jul 05 '13 at 11:13