Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a thumbnail from a video that a user has uploaded to my server?


I'm working on a video sharing website where people can upload their own videos and I want the most recent uploads to be shown on the index page, but not as videos but thumbnails, so that when you click on the thumbnail you get to the video page. You guys all know how youtube's index looks/works -- that's what I'm trying to simulate.

I read about ffmpeg but it seems to me it would only work if you have ffmpeg installed on your computer. I want this to be an automated process though without the user having to first install something on their pc.
Is there a way I can code this? Or do i have to use some kind of framework or CMS? Could this problem be solved by simply getting ffmpeg hosting (example)?
If there is no manual way to do this in php, is there way using python?

Fyi, my website is written in php and i use jwplayer to stream the videos.
Please note that I want to get a thumbnail from a video that's been uploaded on my server and not a youtube or vimeo thumbnail.

like image 701
user3041398 Avatar asked Oct 03 '22 07:10

user3041398


1 Answers

I have worked on this kind of issue and I am sure that user don't need ffmpeg on there pc instead you need a server which has ffmpeg installed.

To create thumbnail from video try the code below.

<?php
 $video = 'path/to/video.flv';
 $thumbnail = 'path/to/thumbnail.jpg';
 shell_exec("ffmpeg -i $video -deinterlace -an -ss 1 -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $thumbnail 2>&1");
 ?>
like image 58
Ram Sharma Avatar answered Oct 13 '22 11:10

Ram Sharma