<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jeff Li</title>
    <description>The latest articles on DEV Community by Jeff Li (@jeff_li_deee6ec68274e6300).</description>
    <link>https://dev.to/jeff_li_deee6ec68274e6300</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4220500%2F982594ca-3cd7-4ffd-b814-30e1cb89a1c5.png</url>
      <title>DEV Community: Jeff Li</title>
      <link>https://dev.to/jeff_li_deee6ec68274e6300</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jeff_li_deee6ec68274e6300"/>
    <language>en</language>
    <item>
      <title>Building a no-sign-up image-to-video app on Cloudflare Workers and the fal.ai queue</title>
      <dc:creator>Jeff Li</dc:creator>
      <pubDate>Wed, 04 Nov 2026 16:14:41 +0000</pubDate>
      <link>https://dev.to/jeff_li_deee6ec68274e6300/building-a-no-sign-up-image-to-video-app-on-cloudflare-workers-and-the-falai-queue-375b</link>
      <guid>https://dev.to/jeff_li_deee6ec68274e6300/building-a-no-sign-up-image-to-video-app-on-cloudflare-workers-and-the-falai-queue-375b</guid>
      <description>&lt;p&gt;I recently shipped a small tool that turns one photo into a 5-second AI video. It has no accounts at all, not even for paid users. Video generation takes 20–90 seconds, which is far longer than a Worker request is allowed to run, so most of the interesting work was in the plumbing around the model, not the model call itself.&lt;/p&gt;

&lt;p&gt;The stack: Cloudflare Workers, plus D1 for state, R2 for files, a Cloudflare Container running FFmpeg, and cron triggers. The models run on fal.ai's queue API. Here is how the pieces fit together, and the few things that bit me.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Never wait on the model inside a request
&lt;/h2&gt;

&lt;p&gt;fal's queue API returns immediately with a &lt;code&gt;status_url&lt;/code&gt; and a &lt;code&gt;response_url&lt;/code&gt;. The Worker stores both in a &lt;code&gt;videos&lt;/code&gt; row and answers the browser right away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queued&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;resolution&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`INSERT INTO videos (id, token, status, fal_status_url, fal_response_url, ...)
  VALUES (?, ?, 'queued', ?, ?, ...)`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;queued&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;queued&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;responseUrl&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queued&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One gotcha: for models on a sub-path (for example &lt;code&gt;xai/grok-imagine-video/v1.5/lite/image-to-video&lt;/code&gt;), the status lives under the app root, not the path you posted to. Use the URLs fal hands back instead of building them yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Two ways a job moves forward
&lt;/h2&gt;

&lt;p&gt;The browser polls &lt;code&gt;GET /api/videos/:id&lt;/code&gt; every few seconds. Each poll may check fal, but at most once every 4 seconds per job, so a tab left open doesn't turn into a flood of requests.&lt;/p&gt;

&lt;p&gt;People also close tabs, so a cron trigger running every minute moves along the jobs nobody is polling. Both paths call the same &lt;code&gt;advance()&lt;/code&gt; function.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Claim the row before finishing
&lt;/h2&gt;

&lt;p&gt;When fal reports &lt;code&gt;COMPLETED&lt;/code&gt;, the clip still has to be downloaded, checked, maybe re-encoded, and written to R2. Two pollers, or a poller and the cron, can arrive at the same moment, so the first step is an atomic claim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;claim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s2"&gt;`UPDATE videos SET status = 'finishing', updated_at = ? WHERE id = ? AND status = 'queued'`&lt;/span&gt;
&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;claim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;changes&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// someone else has it&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;waitUntil&lt;/code&gt; lets the response return while the finishing work continues. If a Worker dies halfway, the minute cron puts any row stuck in &lt;code&gt;finishing&lt;/code&gt; for more than 5 minutes back to &lt;code&gt;queued&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. FFmpeg in a Container, not in the Worker
&lt;/h2&gt;

&lt;p&gt;I needed two video operations: grab a middle frame for a content check, and scale free videos down to 480p. Workers can't run FFmpeg, so a tiny Node server in a Cloudflare Container (&lt;code&gt;node:22&lt;/code&gt; + &lt;code&gt;ffmpeg&lt;/code&gt;) exposes &lt;code&gt;POST /frame&lt;/code&gt; and &lt;code&gt;POST /downscale&lt;/code&gt;, and exits after 2 idle minutes. The Worker reaches it through a Durable Object binding.&lt;/p&gt;

&lt;p&gt;Two lessons from this part:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep the &lt;code&gt;Container&lt;/code&gt; subclass in its own module. &lt;code&gt;@cloudflare/containers&lt;/code&gt; doesn't load in plain Node, and that broke my unit tests until I split it out.&lt;/li&gt;
&lt;li&gt;My first idea was to burn a watermark into free videos with a hosted blend-video endpoint. It worked in YUV and gave everything a magenta tint. Doing it in my own FFmpeg was trivial. In the end I dropped the watermark entirely and made free videos 480p instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Serving video from R2 with Range support
&lt;/h2&gt;

&lt;p&gt;Video players seek, and Safari in particular insists on Range requests. R2's &lt;code&gt;get&lt;/code&gt; accepts the request headers directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MEDIA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;range&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;// respond 206 with Content-Range when object.range is set and the request had a Range header&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Each model gets one backup
&lt;/h2&gt;

&lt;p&gt;Models refuse some inputs, and sometimes they just fail. Every model has exactly one fallback from a different vendor, so it also has a different safety filter. If the fallback fails too, the job ends with a friendly error, and nothing is counted against the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Paid access without accounts
&lt;/h2&gt;

&lt;p&gt;Paying users get a "pass" (&lt;code&gt;&amp;lt;uuid&amp;gt;.&amp;lt;token&amp;gt;&lt;/code&gt;) stored in localStorage. It's sent as a header and spent with a conditional update, so two tabs can never spend the same clip:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;passes&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;pack_clips&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pack_clips&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;pack_clips&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;pack_expires_at&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a video fails, its clips go back to the pass, exactly once. A lost pass can be restored with the payment email (stored only as a salted hash) plus the order number. Payment webhooks are verified, de-duplicated by event ID, and recorded only after they've been handled, so a crash lets the provider's retry run again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Numbers so far
&lt;/h2&gt;

&lt;p&gt;The first live end-to-end free video took 63 seconds and cost about $0.05 in model fees. An HD clip on Grok Imagine costs $0.16.&lt;/p&gt;

&lt;p&gt;The server side is about 1,250 lines of plain JavaScript, and the test suite runs against an in-memory D1 built on &lt;code&gt;node:sqlite&lt;/code&gt; with a fake R2 and a fake container.&lt;/p&gt;

&lt;p&gt;If you want to see the result, it's live at &lt;a href="https://pikmova.com" rel="noopener noreferrer"&gt;pikmova.com&lt;/a&gt;. It gives 2 free videos a day with no sign-up. I'm happy to answer questions about any of the pieces above.&lt;/p&gt;

</description>
      <category>cloudflare</category>
      <category>serverless</category>
      <category>ai</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Measuring faces in the browser with MediaPipe: three things that broke</title>
      <dc:creator>Jeff Li</dc:creator>
      <pubDate>Sun, 01 Nov 2026 11:45:49 +0000</pubDate>
      <link>https://dev.to/jeff_li_deee6ec68274e6300/measuring-faces-in-the-browser-with-mediapipe-three-things-that-broke-3mk</link>
      <guid>https://dev.to/jeff_li_deee6ec68274e6300/measuring-faces-in-the-browser-with-mediapipe-three-things-that-broke-3mk</guid>
      <description>&lt;p&gt;I wanted a face-measurement tool with three properties most "face rating" sites don't have: the photo never leaves the browser, the same photo always gives the same numbers, and every formula is public. The result is &lt;a href="https://facialratio.com/" rel="noopener noreferrer"&gt;FacialRatio&lt;/a&gt;, and its engine is &lt;a href="https://github.com/newjia/facialratio-engine" rel="noopener noreferrer"&gt;open source&lt;/a&gt;. This post is about the parts that did not work the first time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Landmarks:&lt;/strong&gt; Google's MediaPipe Face Landmarker, loaded as WebAssembly only after the user picks a photo, so it never slows the first page load. It returns up to 478 points with a rough depth value for each.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Engine:&lt;/strong&gt; one pure TypeScript function, &lt;code&gt;analyze(input)&lt;/code&gt;. No DOM, no randomness, no network. It takes landmark coordinates, not pixels, which makes it easy to unit-test against MediaPipe's canonical face mesh.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hosting:&lt;/strong&gt; static files. There is no server endpoint that could receive an image, which is a simpler privacy promise than "we delete it after processing".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every length is divided by the pupil distance, so photo resolution doesn't matter. From there the engine computes 58 measurements and four scored parts: symmetry, facial thirds, facial fifths and a few golden-ratio comparisons. Each part is &lt;code&gt;100 − k × deviation&lt;/code&gt;, clamped to 0–100, and the overall score is a weighted sum (35 / 25 / 25 / 15). All the constants live in one file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem 1: level heads looked tilted
&lt;/h2&gt;

&lt;p&gt;I started with a pitch gate of ±8°: tilt the head more than that and the tool asks for a retake. On 13 ordinary front-facing portraits, 7 were rejected. When I looked at the numbers, MediaPipe read heads that were visibly level at a &lt;strong&gt;median pitch of +8.2°&lt;/strong&gt;. One plainly level photo came out at 14.6°.&lt;/p&gt;

&lt;p&gt;The fix was boring: centre the window on the offset the model actually has. The gate is now −8° to +16°. The lesson is that a landmark model's pose output has its own bias, and you only see it if you test on everyday photos rather than the canonical mesh.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem 2: a slight head turn read as asymmetry
&lt;/h2&gt;

&lt;p&gt;Symmetry is measured by mirroring each landmark across a fitted midline and averaging the distance to its partner. On a perfectly frontal mesh that works. On a real photo with the head turned 5–8°, the far side of the face is foreshortened, and the engine reported it as asymmetry. That's exactly the kind of result that feels unfair to a user.&lt;/p&gt;

&lt;p&gt;Since MediaPipe gives a depth estimate per point, the engine now estimates yaw, rotates the points back to frontal, and only then measures. On the same 13 portraits, the &lt;strong&gt;median mirror error dropped from 7.31% to 2.28% of pupil distance&lt;/strong&gt;. Turns beyond ±10° still trigger a retake instead of being corrected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem 3: the model can't see the hairline
&lt;/h2&gt;

&lt;p&gt;Facial thirds are usually measured hairline → brow → nose base → chin. MediaPipe has no hairline point. The highest point it offers sits on the upper forehead. So the upper third and the face length are estimates, and the tool says so in the result and in the report instead of pretending. The reference I use (18 / 41 / 41%) is defined from that same upper-forehead point, so at least the comparison is like-for-like.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the golden ratio only gets 15%
&lt;/h2&gt;

&lt;p&gt;It's the most-searched part of the topic and the weakest evidence. Holland (2008) found that φ-based masks don't describe a wide range of faces, and Pallett, Link and Lee (2010) found preferred proportions that differ from φ. The tool still shows each ratio and its deviation from 1.618, because people want to see them, but it carries the lowest weight. Nothing in the tool is validated against human ratings, and the methodology page says that plainly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Counting without analytics code
&lt;/h2&gt;

&lt;p&gt;I wanted to know how many people finish an analysis without adding an analytics SDK. When an analysis completes, the page requests an empty static file such as &lt;code&gt;/e/done-golden-ratio-face.txt&lt;/code&gt;. The CDN's request log counts those requests. The request carries no image, score, cookie or identifier, only which step happened on which page.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Collect a small set of everyday test photos on day one. The canonical mesh hides every real-world bias.&lt;/li&gt;
&lt;li&gt;Write down every constant in one config file from the start. It made the methodology page a direct render of the code, so the two can't drift apart.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The engine, its tests and the canonical-face fixture are on &lt;a href="https://github.com/newjia/facialratio-engine" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. The full method, including known limits, is on the &lt;a href="https://facialratio.com/methodology" rel="noopener noreferrer"&gt;FacialRatio methodology page&lt;/a&gt;. Feedback on the measurement approach is very welcome.&lt;/p&gt;

</description>
      <category>privacy</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>mediapipe</category>
    </item>
  </channel>
</rss>
