Animated Previews (og:video)
Messages on iOS and macOS downloads an MP4 og:video and plays it automatically in the link preview (Apple TN3156). Set video, and the module renders your Takumi template's CSS animations to an MP4. The MP4 has the image's URL with an .mp4 extension. video: true renders 3 seconds at 30 fps.
<script lang="ts" setup>
const code = String(useRoute().params.code)
useSeoMeta({ title: `Join Beaver · Invite code: ${code}` })
defineOgImage('Invite.takumi', { code }, { video: { durationMs: 2000, fps: 30 } })
</script><script lang="ts" setup>
defineProps<{ code: string }>()
</script>
<template>
<div class="h-full w-full flex items-center justify-between bg-black px-24">
<p class="text-9xl font-bold text-white">
{{ code }}
</p>
<div class="w-56 h-56 rounded-3xl bg-amber-400 animate-spin" />
</div>
</template>A prerendered page gets both renditions:
<meta property="og:image" content="https://example.com/_og/s/o_98b47b78dd1cefbb.png">
<meta property="og:video" content="https://example.com/_og/s/o_98b47b78dd1cefbb.mp4">
<meta property="og:video:secure_url" content="https://example.com/_og/s/o_98b47b78dd1cefbb.mp4">
<meta property="og:video:type" content="video/mp4">
<meta property="og:video:width" content="1200">
<meta property="og:video:height" content="600">In testing, Discord played the video once, with player controls. Clients that don't play og:video, such as Slack, X, LinkedIn and WhatsApp, show og:image.
Animations
Takumi samples CSS animations at each frame. Use a Tailwind animate-* utility such as animate-spin. For your own keyframes, define them in takumi.css and apply them with an inline animation style:
defineOgImage('Float.takumi', {}, {
video: true,
takumi: {
css: [{ keyframes: 'float', steps: [
{ offset: 'from', style: { transform: 'translateY(0)' } },
{ offset: 'to', style: { transform: 'translateY(-24px)' } },
] }],
},
})<template>
<div class="h-full w-full flex items-center justify-center bg-black">
<div class="w-40 h-40 bg-amber-400" style="animation: float 1s linear infinite" />
</div>
</template>takumi.timeMs picks the point on the timeline for the still og:image.
Requirements
- The Takumi renderer. With another renderer, the page gets no
og:video, and dev mode logs a warning. - An
ffmpegbinary where the video renders: on the server, or at build time for prerendered pages. To use a binary outsidePATH, setNUXT_OG_IMAGE_FFMPEG. - URL signing for videos that render at runtime. Signing is on by default.
Prerendered and Runtime Videos
If ffmpeg is missing at build time, the prerender fails the build. Edge runtimes can't spawn FFmpeg, so prerender pages with video there. With security.strict, prerendered pages keep dynamic image URLs. Their videos then render at runtime and need ffmpeg on the server.
Without URL signing, a request could add video to any image URL. So with security.secret: false, only prerendered videos work. Runtime pages then get no og:video tag, and a runtime .mp4 URL answers 403. The .mp4 URL also answers 400 for an image without video.
The og:video tag comes from the server HTML, which link previews read. After client-side navigation, the page head carries og:image only.
Limits
durationMs is capped at 10 seconds and fps at 60. The render timeout (security.renderTimeout, 15 seconds by default) covers every frame and the encode. Messages limits a preview's images and videos to 10 MB in total. The invite clip above, 2 seconds at 1200x600 and 30 fps, encodes to about 75 KB.