Wednesday, 22 March 2023

Take snapshots of Youtube videos to create a preview GIF programatically

I use the Youtube API to integrate content into my site. But, it doesn't provide any good snapshots of the videos. It provides a few very low quality snapshots that are virtually unusable.

https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

For example: https://img.youtube.com/vi/XdwaASKJGxo/1.jpg creates the following:

enter image description here

This snapshot is such low quality it's unusable. So I need to make my own!

My goal is to have a unique thumbnail/preview for each video. I would like to programmatically take 3 snapshots of the video within the middle of the video to avoid intros/outros. Then I would like to take these snapshots and generate a GIF.

I know how to generate a GIF using PHP, but I cannot find a way to take snapshots of a video.

Is it possible to do this using PHP or Python? Or any other code for that matter.

Example:

enter image description here



from Take snapshots of Youtube videos to create a preview GIF programatically

No comments:

Post a Comment