今日已更新 77 条资讯 | 累计 33117 条内容
关于我们

Building a Video Thumbnail Generator Service with Go and FFmpeg Workers

ahmet gedik 2026年08月19日 00:00 0 次阅读 来源:Dev.to

Every video card on our category grids was hotlinking a 1280x720 JPEG from a third-party CDN and then letting CSS scale it down to about 320 device-independent pixels. That is roughly 90 KB of wasted transfer per card, 24 cards per page, across eight regional page variants that each carry their own cache key. Mobile LCP on the busiest category pages sat at 4.1s, and the largest single contributor was an image we did not host, could not resize, and could not re-encode to WebP. The fix was not clever CSS. It was owning the frame. We built a small Go service that takes a source video (a partner preview MP4, or a poster frame that arrives at the wrong dimensions), pulls a representative frame with FFmpeg, encodes it at three widths in WebP, and writes the result to a content-addressed path the front end links directly. That service now feeds the same multi-region cron that runs TrendVidStream , and the generated files ride the same FTP mirror as the rest of the deploy. What follows is the part that actually mattered: the FFmpeg invocations, the Go concurrency model that keeps a 2-core build box from melting, and how a stateless Go daemon hands work to a PHP 8.4 + SQLite front end that cannot run a daemon at all. Why this is not a PHP job Our front end is PHP 8.4 on LiteSpeed shared hosting with SQLite (FTS5 for search) as the only datastore. It is a genuinely good fit for a read-heavy discovery site: no database server to babysit, page cache on disk, cron jobs pulling regional feeds every 2-7 hours depending on the site. It is a terrible fit for thumbnail extraction: Shared hosting caps max_execution_time at 180s. A cold FFmpeg decode of a 4-minute 1080p preview can burn 20-40s. Do 200 of them in one cron tick and you are wearing a hard timeout. shell_exec is frequently disabled, and when it is not, you get one process per request with no way to bound total concurrency. There is no shared memory between PHP requests, so two cron ticks racing on the same video ID will ha

本文内容来源于互联网,版权归原作者所有
查看原文