Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create thumbnail image from video in server in php

Tags:

php

ffmpeg

In my website I have a option to upload video file by the user. In that I want to create a thumbnail image of that video. I have tried in local system with some coding it is working fine. I tried same coding in to service it is not working. I checked for ffmpeg enabled in server, it was disabled. Is their any other option to creating thumbnail in server with out enabling the ffmpeg? Please help me to find the solution.

like image 251
swamy Avatar asked Apr 20 '12 05:04

swamy


1 Answers

you can use ffmpeg ( Form you tag i guess you knew )

What you needed to pass to ffmpeg is

-i = input file
-deinterlace = deinterlace pictures
-an = disable audio recording
-ss = start time in the video (seconds)
-t = duration of the recording (seconds)
-r = set frame rate
-y = overwrite existing file
-s = resolution size
-f = force format

Example

// where ffmpeg is located  
$ffmpeg = '/usr/bin/ffmpeg';  
//video dir  
$video = 'path/to/video';  
//where to save the image  
$image = 'path/to/image.jpg';  
//time to take screenshot at  
$interval = 5;  
//screenshot size  
$size = '640x480';  
//ffmpeg command  
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1";

exec($cmd);

Or try

$second = 15;
$cmd = "$ffmpeg  -itsoffset -$second  -i $video -vcodec mjpeg -vframes 1 -an -f rawvideo -s $size $image";
exec($cmd);

Think you should also look at detail dissuasion on possible issues

ffmpeg-php to create thumbnail of video

like image 131
Baba Avatar answered Sep 30 '22 13:09

Baba