Sommerregen / grav-plugin-mediaembed

This plugin embeds several media sites (e.g. YouTube, Vimeo, Soundcloud) by only providing the URL to the medium.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ability to display thumbnail instead of embed

woutgg opened this issue · comments

To construct a gallery containing both local images and online vimeo/youtube videos, it would be handy if mediaembed could display a thumbnail instead of an embed, preferrably usable from twig.

The idea is this: twig loops over local file names and online URLs specified in the page header, rendering a thumbnail for each, using mediaembed to get thumbnail URLs where needed. Clicking on a thumbnail then shows a lightbox in which (for videos) mediaembed generates the actual embed.

Mediaembed seems like a good place for this as it already contains (most of) the oembed logic.

Hi @woutgg that's a great idea and I will definitely consider it in the next big release. However I'm not that clear how the thumbnail generation should be implemented. For PHP (as far as I know of) there exists no good library to generate screenshots from videos, if no thumbnail for that medium is provided. Do you know any solution or point me to a good library?

Glad to hear you like the idea! As I understand it, you don't have to generate the thumbnail yourself: the oEmbed response includes a thumbnail_url. Although it is optional, at least vimeo and youtube apparently include it.
See for instance: https://vimeo.com/api/oembed.json?url=https://vimeo.com/100785455&width=320&height=240. Playing around with the dimensions, it seems to return one of several predefined sizes; if needed the plugin could resize afterwards using grav's cropZoom().

Perhaps if I can find my way in the code, I can give a try at implementing this.
If a PHP solution is needed after all, ffmpeg might be an option.

@woutgg I guess we need a PHP solution after all. ffmpeg is great solution, but sadly it is not installed by default 😞 Otherwise only videos with a thumbnail provided will be shown correctly. However it was long time ago, I wrote MediaEmbed and I have seen it already supports thumbnails (see https://github.com/Sommerregen/grav-plugin-mediaembed/blob/master/classes/OEmbed/OEmbed.php#L289). The thumbnail is used with the media.preview: true option. See for example https://github.com/Sommerregen/grav-plugin-mediaembed/blob/master/templates/partials/mediaembed.html.twig#L91 .

Although it supports it, your approach is more far reaching due to include also local images. This cannot be done with a simple custom Twig template. I have to think more about it. If you have a good solution, I'm glad to hear :-)