How I embed videos in notes now
Every video on this site now lives next to the note that uses it, the same way images do. I drop a video into the note folder, reference it with one shortcode line, and pnpm ready handles the rest – transcoding, thumbnail/poster, upload, and the player.
- Drop the recording into the note folder, like
content/raw/some-note/demo.mov - Reference the mp4 name in the note, even when the dropped file is a
.mov
{% video "./demo.mp4" %}
- Running
pnpm readytranscodes the file to an optimized web-ready MP4 (H.264, yuv420p, faststart, crf 26, width capped at 1600px), extracts a poster frame from about 25% in asdemo-poster.webp, records state in_data/cache/video-cache.json, and uploads the mp4 and poster to R2 underraw/some-note/folder.
The above shortcode attaches the poster automatically, the player loads nothing until someone presses play, and nothing is fetched from a third party. I used to do this by hand and wrote down the ffmpeg commands earlier, but now it's all automatic.
Also, a few things worth knowing:
- If I place my own
demo-poster.webpnext to the video, the pipeline keeps it instead of generating one - Videos are gitignored like images, so recordings never reach the repository
- To reprocess a video, run
node scripts/process-videos.js --forceagain - The whole thing runs through ffmpeg, which keeps surprising me with what it can do
The first video I published this way is the demo in my whimsical Pi extension note, showing the rotating status phrases while Pi works.