Generating a thumbnail / screenshot of a video has many uses. Many video websites out there, including the ever popular YouTube, use this function to show a static preview of the video through a screen grab or set of screen grabs in image format. You may think it is difficult to create thumbnails from a video file. But I'm here to say 'no, it's not'!
To accomplish this task, I made use of this tool: FFmpeg. First a little information about FFmpeg. If you haven't come across this yet then you're missing out on an excellent bit of software to put in your tool kit. It can convert and stream all manner of video and audio files, it is open source (under LGPL, but with some optional GPL bits), and it is constantly being worked on and developed, thus improved.
FFmpeg's homepage is where you can grab the latest revision from SVN. If you want it for Windows, then one location I found with quite recent builds is http://ffdshow.faireal.net/mirror/ffmpeg/.
Once I had these tools installed, I was ready to begin utilising FFmpeg to convert a specific point in a video file to a thumbnail image. Using the FFmpeg documentation as resources, I eventually arrived at the following command (which should all be on one line) for generating a thumbnail:
ffmpeg -y -i /path/to/video.avi -f mjpeg -1 -ss 10 -vframes 1 -s 120x90 -an /path/to/picture.jpg
The key components of that command are:
- f mjpeg: specifies that the output should be a JPG
- ss 10: sets that image should be taken from the point 10 seconds from the beginning
- s 120x90: sets the dimension of the image that would be generated
You could use Imagemagick to resize or edit the image generated if you wish, as ffmpeg is not really designed for this.
A tip to consider if you're taking user input for the video file or output image file, then please remember to escape your variables accordingly! Use something like the escapeshellcmd() PHP function.
Comments
blog comments powered by Disqus