8

i want to display thumbnails or preview panels for videos listed on my site, i want to fetch a single frame from a video (from a particular time i.e get a frame of exactly after 1 min) and display them as thumbnails as in youtube...

Any help?

Vijay
  • 5,331
  • 10
  • 54
  • 88
  • Try following this tutorial on PHP and ffmpeg, http://www.alberton.info/video_preview_as_animated_gif_with_ffmpeg_and_spl.html – kb. Feb 15 '10 at 11:44

3 Answers3

8

Take a look at the ffmpeg-php library. It's the only simple way to manipulate videos of different formats in PHP.

There's also a wrapper called PHP Video Toolkit, you can find it here: http://sourceforge.net/projects/phpvideotoolkit/

napolux
  • 15,574
  • 9
  • 51
  • 70
  • Can i create thumbnails using ffmpeg-php? I was thinking that it can be used to convert videos to different formats... If it's possible , how can i do that? is there any predefined functions or methods available in ffmpeg? – Vijay Feb 15 '10 at 11:42
  • Dwwnload the package and take a look at example02.php: there's the $toolkit->extractFrames() call that does exactly what you need... ;) You can easily modify the source code to extract only one frame at a given time. – napolux Feb 15 '10 at 12:03
  • Thanks Napolux. That helped me great. But would you mind explaining me , How can we improve the quality of the thumbnail picture? – Vijay Feb 15 '10 at 13:10
7

Adding to how to use the ffmpeg answer, this is the parameters you're looking for:

ffmpeg  -itsoffset -4  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
cregox
  • 17,674
  • 15
  • 85
  • 116
  • 1
    It's also worth noting that even if the audio or video has an image frame available, that the "test.jpg" will still be generated. When there is no image frame, the test.jpg will be a file of size ZERO. So you will need to check the size of the file that was generated to ensure you have one that you can use. – skidadon Apr 17 '15 at 03:35
6

In modern browsers you can also use the video tag and canvas to capture a frame and save it as an image.

see How can we get the screenshot of the video in html5 using canvas

Community
  • 1
  • 1
Thomas
  • 8,426
  • 1
  • 25
  • 49
  • 1
    This should be the answer. We spent day trying to get ffmpeg to work reliably. To get a thumbnail image we ended up using JavaScript, once the video was uploaded we play the video then transfer to canvas the save image from canvas after 5 seconds. Worked way more reliably than ffmpeg. Ffmpeg process on windows would not stop even after sonetimes even after I killed it. – M H Apr 10 '15 at 05:34
  • @michaelhanon for one, both this or the linked answer should summarize the link as much as possible as to create redundancy and, well, shorter version straight to the point. And relying on client side javascript to create thumbnails is far from ideal for many situations, but, it sure could be an awesome way for most. Maybe Thomas will improve his answer if he gets enough upvotes, and bring us a complete solution eventually... ;P – cregox Dec 21 '15 at 00:34