The render API returns a .mp4 URL, and the download comes back with HTTP 200. Can you mark the job done? In Deck the Halls Dance AI, two photos become a 15-second Christmas dance clip like this sample MP4 . Before the Worker hands out a download link, it checks that the file has both video and audio, that each track runs for about 15 seconds, and that the full file made it into storage.
A valid-looking response can still carry a silent clip or end halfway through a box. Downloading the whole thing into an ArrayBuffer would make those checks straightforward, but memory would grow with every download. The Worker already has to read the response to save the video in Cloudflare R2, so it inspects the MP4 during that same pass.
Read the MP4 boxes as the bytes arrive
An MP4 is organized into boxes. Each box has a type and a size. For this check the Worker cares about three top-level types: ftyp for file type information, moov for the movie metadata, and mdat for the actual media bytes.…