Creation of dynamic Thumbs

Asked

Viewed 160 times

3

How do websites like Youtube, Netflix and many other sites do this function? Are Thumbs created at the time of Mousemove / mouseenter in the Ogress bar, or have they been created before and the player only displays? If they are generated at the moment, how is it done?

Thumbs dinâmicas Youtube

  • Speaking specifically of youtube, it is not possible to do this using the v3 API. Most likely they are created in the first use and saved for the next. Like, when you hover your mouse and you see a low-resolution preview, then you switch to a better-resolution one. How do I do not know, but if I were to invent something like this, I would probably upload a reduced/compressed version of the video in that frame and save jpg.

  • Is Xuxa in the video? kkkk

  • Yeah, I just opened the first video that came on youtube kk

1 answer

2

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

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 excerpt from the SOEN reply: How can I get a thumbnail from a video that a user has uploaded to my server?

Updating

There is a library called PHP-Ffmpeg that facilitates the handling of video formats in PHP. With it it is also possible to extract images from a given 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 above example, the frame 42 video will be captured and saved in format jpg. Therefore, you can also use this feature to provide a temporary image of the video.

  • 1

    But if the person leaves by sliding the mouse over the progress bar, will be made several and ajax requests, this can not come to overload the server in any way?

  • No, but then you can make a cache. I only gave an overview, since your question seemed more "theoretical". In fact, there may be countless ways to do this.

  • I understand, I will try to install ffmpeg here to test, it was a little "theoretical" but this is an interesting feature to learn since there is no tutorial on

  • @Leoletto I didn’t want to publish here talking about some libraries, because I never used them, but there are some Ibraries that also help in this. If I find any, I’ll let you know. (I’m kind of stuck right now on a website I’m doing).

  • No problem, this is a feature that I would like to put on a site that I am also locking doing but still do not understand much about ffmpeg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.