使用 Google 云存储从自托管网站在 WhatsApp 中共享视频 link 的缩略图

Thumbnail for Video link shared in WhatsApp from self hosted website using Google Cloud Storage

我打算为我从自托管网站分享的视频 link 添加缩略图。如何获取使用来自 Google Cloud Storage Bucket 的签名 url 提供的视频内容的缩略图。

def get_signed_url(thumbnail):
    blob = bucket.get_blob(thumbnail.path)
    signed_url = blob.generate_signed_url(expiration_time)
    logging.info(signed_url)

    return signed_url

我应该如何使用 html 提供此缩略图? 此外,如果在用户已经在 Whatsapp 中收到 link 的时间戳之前满足 expiration_time 会发生什么?

Google Cloud Storage 不会为任何对象生成缩略图。您需要生成这些缩略图,将它们上传到 Google 云存储,然后自己引用它们

对此有多种方法,即您可以使用 Pillow library for Python 生成图像。

关于过期时间,你的问题我不清楚。到期时间值与 URL 的用法无关。如果您在这段时间后生成一个 URL 15 分钟,URL 将被轮换,您将需要向您的用户

发送一个新的 URL

默认支持 Google Cloud Function 上的 FFMpeg,使用以下 ffmpeg 函数将同时提供静态图像 (png) 和动态图像(webm 或 gif):

ffmpeg.input(video_url, ss=0).filter('scale', png_width, -1).output(out_filesystem_filename, vframes=1).overwrite_output().run()
ffmpeg.input(video_url, ss=0).filter('scale', motion_width, -1).filter('fps', fps=6, round='up').output(out_filesystem_motion_filename, vframes=vframes, loop=0).overwrite_output().run()