Engineering · Infrastructure · Performance
Study Videos Up to 10 Minutes: Moving Video Making Off the Request
Why our study videos stopped at 2 minutes, where their 70 seconds went, and how a background job and three small changes fixed both
A student asks Cereby for a three-minute video on the Krebs cycle. The card offers two minutes, the longest it will make. Asked through a connected AI app, the same request comes back as two 90-second parts. The request is synthetic; the 2-minute cap is what the app enforced until this change.
It mattered less than that sounds, at first. Students asked for 5 videos in the 60 days before this work. But the one 2-minute video in that window took 69.5 seconds to make, and the cap meant a student who wanted a full walkthrough of a topic could not get one.
This post is about the study video maker, the pipeline that turns a topic or a file into a narrated video with a picture for each scene and captions along the bottom. We read where its time went in production, changed three things about how it builds a video, and moved it out of the chat request into a background job.
What the 2-minute cap was protecting
The video maker ran inside the chat request itself, and our host stops a request at 300 seconds. In September a student asked for a 5-minute video at full HD, three times. Each render was still going when the request was cut off, and all the app could say was "Load failed".
So the cap came in: 2 minutes, at 720p, with an estimate of how long a video takes fitted to real renders. It worked: none of the 5 video requests in our turn records, which start in November, was cut off. But it was set by where the work ran, not by how much work there was, and that is the part we came back to.
Here is a 2-minute video's path through the old maker, with the steps that cost time for nothing in red:
Where the 70 seconds went
Every video logs how long each of its steps took, a line we added to recalibrate that estimate. The last video made before this work was 30 seconds long and took 24.5 seconds. Two fifths of that was building the file:
The waiting is the work of other people's servers: a small, fast model writes the script, a voice model reads each scene, a picture model draws each still. We could not make those calls faster, but we were making them in rounds. Narration and pictures went out six scenes at a time, so an 8-scene video waited through two rounds of each, and a 17-scene one through three.
Building the file was ours, and it grew with every second of video. A study video is a slideshow: one picture per scene, the narration, and captions that change a few times a second. We encoded it like footage, at 24 frames a second, and only once the last picture and the last line of narration were in. It also ran on whatever share of CPU a chat request gets, which is small.
Three changes that help wherever the video is built
Half the frames. The picture in a study video changes once a scene and the captions a few times a second, so 24 frames a second paid for frames nobody sees change. At 12, a caption shows at most a twelfth of a second late. We measured it on a synthetic 2-minute test video (17 stills, a new caption every 1.2 seconds), on a test machine; the timings are what the encoder took:
The file came out smaller too: 1.3 MB at 24 frames a second, under 1 MB at 12.
Each scene built as soon as it is ready. A scene becomes its own short clip the moment its picture and narration arrive, and the clips are joined at the end without being encoded again, the way our lessons already join theirs. Our first try at this was slower than building the whole file: 18.8 seconds against 8.2. Each scene's encoder was told to loop its picture, and it decoded the picture again for every frame. Handed the picture once, with how long to show it, the same 17 scenes took 10.3 seconds one after another, and 6.0 with the scenes built in parallel. Scene by scene is a little more work in total, but it can start while other scenes are still waiting on their pictures, and it spreads across every core a machine has.
Every scene asked for at once. The rounds of six became one round, sent through a limiter that keeps us under the picture model's per-minute limit for our account. A long video now waits for its slowest picture, not for its slowest picture in each of three rounds.
Off the request
With those three changes, a 3-minute video would have fit inside the old request. A 10-minute one would not, and a student who closed the chat mid-video was relying on the request to finish without them. So we moved the whole maker, from the script to the upload, into a background job on per-second CPU containers, on the same platform we moved the humanizer to in Moving the AI Humanizer to Serverless GPUs.
We looked at a GPU first, since that platform has them. It would only have sped up the build, and by our estimate, copying every frame to it and waiting for it to start would have eaten most of what the faster encoding saved. The slow parts that were left already ran on other people's GPUs. A CPU container starts in seconds, runs as long as a job needs, has cores to build scenes side by side, and is billed only while it works.
The app keeps everything that touches a student's account. It checks their consent to AI processing, reserves the coins before the job starts and refunds them if it fails, and hands the job one-time upload links for the video and its thumbnail. The job holds the keys to the AI services and nothing else: it never sees our database. It reports back when the video is uploaded, and the card in the chat fills in, or the video is waiting in the student's library if they have left.
A long script is the one new piece of the maker. A 10-minute video has about 40 scenes, and we had never asked for one plan that long, so past 3 minutes the script is written as an outline first and then part by part.
The first long videos showed why every part needs a safety net. Written four at a time, a part now and then came back as JSON our parser could not read, or far shorter than it was asked to be, and one such part was enough to fail the whole video. Now a part's small slips are mended where they stand, a part that still cannot be read is written again, and a part far under its length is written again as two halves of half the length each. Students choose which model writes their scripts, so we wrote a 10-minute script on every one of them: each came back between about 1,000 and 1,400 words, where the target is about 1,350.
Before and after
| Before | After | |
|---|---|---|
| 30-second video | 24.5 s | 18.9 s |
| 2-minute video | 69.5 s | 26 to 31 s |
| 10-minute video | not offered | 96 s |
| Longest video | 2 minutes | 10 minutes |
| Where it is made | inside the chat request | a background job |
| A student who leaves mid-video | relies on the request finishing | finds it in their library |
| Hosting cost per video | a share of the chat request | about 2 cents for 2 minutes, 3 cents for 10 |
The times are the maker's own, from the script to the upload, as the "before" times were. Starting the job adds about 6 seconds in front of them. The cost counts the minute a container stays warm after its job, which is most of it for a short video.
What this taught us
A cap is a symptom. Ours said 2 minutes, but what it meant was 300 seconds of one request, and the work itself fit in a quarter of that.
A slideshow encoded like footage pays for frames nobody sees change. Halving the frame rate was the smallest change in this post, a few lines, and on its own cut the test build by 44%.
Waiting in rounds cost more than any single slow call. Nothing about the models changed; an 8-scene video simply stopped waiting twice.
The stage logs paid for themselves. Every "before" number here came from a log line added months ago to keep a time estimate honest.
What's next
The picture model's per-minute limit now decides how fast a long video really is: the first 10-minute video spent 61 of its 96 seconds waiting on its pictures, about 30 of them, kept under that limit by the limiter. And the price has not caught up with the length. By today's formula a 10-minute video costs 465 coins, while two of the last five video requests stopped at the 101 a 2-minute video costs.