简体   繁体   中英

Create thumbnail image from video in server in php

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.

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

If you don't want to use ffmpeg you could use mencoder as an alternative too. But in the end you will need to install ffmpeg/mencoder and then use that to render the thumbnail as PHP has no built in functionality to handle video.

If you're on a shared webhost you might want to look into services like zencoder that can generate you converted streams of video including thumbnails:

https://app.zencoder.com/docs/api/encoding/thumbnails

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM