Creating Thumbnail Images From Video

To Create thumbnail image for the video which is uploaded then you can use a library called “ffmpeg”
This library is used to manipulate videos.


Steps for creating thumbnail from video:

1). Download the ffmpeg library into the system, or you can add ffmpeg-php extension.

2). To see that ffmpeg is installed you can check it by viewing phpinfo() function.

3).
$tmpfile = $_FILES['video']["tmp_name"];
$file = $_FILES['video']["name"];
$abc = date("dmyHis");
$insertVideo = $abc . $file;
move_uploaded_file($tmpfile, $sub_dir . $insertVideo);
$image_name = $abc . "_image.jpg";
$file_thumb = create_movie_thumb($sub_dir . $insertVideo,$sub_dir,$image_name);

Below is the actual function to create thumbnail

function create_movie_thumb($src_file,$fullpath,$image_name)
{
global $CONFIG, $ERROR;
if ($_SERVER['HTTP_HOST'] == 'dev.yourapp.com') {
$CONFIG['ffmpeg_path'] = 'c:/ffmpeg/bin/'; // path of your ffmpeg bin folder this is for windows
}else{
$CONFIG['ffmpeg_path'] = '/usr/local/bin/'; // this path is for linux
}
$CONFIG['fullpath'] = $fullpath;
$CONFIG['debug_mode'] = 1;

$src_file = $src_file;
$imgname = $image_name;
$dest_file = $CONFIG['fullpath'].$imgname;

$cmd = "\"".str_replace("\\","/", $CONFIG['ffmpeg_path'])."ffmpeg\" -i ".str_replace("\\","/" ,$src_file )." -an -ss 00:00:03 -r 1 -vframes 1 -y ".str_replace("\\","/" ,$dest_file);
exec($cmd);
echo $cmd;
}

Advertisements

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