Creating dynamic thumbs

3

How to site such as Youtube, Netflix and many other sites do this function? Are the thumbs created at the time of the mousemove / mouseenter in the progress bar, or have they already been created before and the player only displays? If they are generated at the moment, how is it done?

    
asked by anonymous 28.11.2016 / 23:45

1 answer

2

If you have the current time information from video to mouse over the progress bar of the video duration, you could send this information to the server with Ajax and use ffmpeg to capture the thumb with the current time of the video.

Example:

$video = 'path/to/video.flv';
$thumbnail = 'path/to/thumbnail.jpg';
$currentTime = isset($_POST['current_time']) ? $_POST['current_time'] : '00:00:01';
shell_exec("ffmpeg -i $video -deinterlace -an -ss 1 -t {$currentTime} -r 1 -y -vcodec mjpeg -f mjpeg $thumbnail 2>&1")

Code snippet taken from this SOEN response: How can I get a thumbnail from a video that a user has uploaded to my server?

Update

There is a library called PHP-FFMpeg that makes it easy to manipulate video formats in PHP. With it you can also extract images of a certain stretch.

For example:

$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('video.mpg');
$frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(42));
$frame->save('image.jpg'); 

In the example above, the frame 42 of the video will be captured and saved in jpg format. Therefore, you can also use this feature to provide a temporary image of the video.

    
29.11.2016 / 11:31