How to create thumbnail of a video file?

how to create thumbnail from video in php
To create this we will be using ffmepg.
For this script to work make sure your system has the ffmpeg installed.

Here is the code to create a thumbnail from a video :-
<?php
$ffmpeg =’C:\ffmpeg\bin\ffmpeg’; // path of installed ffmpeg
$videofile = “test.wmv”;
$imagefile =”thumbnail.jpg”;
$size = ‘200×120’;
$interval =2; // At what time the screenshot to be taken after video is started
$cmd = “$ffmpeg -i $videofile -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $imagefile 2>&1”;
shell_exec($cmd);
?>
This will create a thumbnail.jpg file in the directory where this script is residing. You can also set you own path.
We can use ffmpeg to convert videos from one format to another.
For example for this script I am using .wmv video.
suppose if i want to convert this video to .mp4 format i can easily achieve this using ffmpeg.

We can use this ffmpeg command:-
$cmd=”$ffmpeg -i $videofile -vcodec libx264 -acodec libfaac test.mp4“;

The installed ffmpeg should support the libx264 and libfaac.

http://itwigle.com/twig/Capturing_video_thumbnails_with_PHP

http://blog.amnuts.com/2007/06/22/create-a-random-thumbnail-of-a-video-file/

 

Advertisements

About pj

I am an expertise web programmer in PHP.
This entry was posted in Interview Questions, PHP. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s