Installing ffmpeg should be easy. On any Ubuntu / Debian based distribution, use apt-get:
apt-get install ffmpeg
After that, you can use it to create a thumbnail.
First you need to get a random time location from your file:
$video = $path . escapeshellcmd($_FILES['video']['name']); $cmd = "ffmpeg -i $video 2>&1"; $second = 1; if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) { $total = ($time[2] * 3600) + ($time[3] * 60) + $time[4]; $second = rand(1, ($total - 1)); }
Now that your $second variable is set. Get the actual thumbnail:
$image = 'thumbnails/random_name.jpg'; $cmd = "ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1"; $do = `$cmd`;
It will automatically save the thumbnail to thumbnails/random_name.jpg (you can change this name based on the downloaded video)
If you want to resize the thumbnail, use the -s ( -s 300x300 )
See the ffmpeg documentation for a complete list of options you can use.
source share