How does a video render queue work?
Article by Pedro Henrique Lahr
A render queue is the list of videos waiting to become MP4s. At Konecz, each video is a recipe stored in the database, and a worker on the server takes one request at a time, renders it, checks the file and hands it back. If a request is stuck for more than 30 minutes, it goes back to the queue; if it gets stuck again, it becomes an error and someone looks at it.
What is the video's recipe?
It is everything needed to remake the video, in a single object: the script, the chosen voice, the timing of every word and the edit (which block comes in when, with what text). The video has no loose project folder on disk. As long as the recipe exists, the video can be remade at any time, identical.
The media (the recorded voice, the takes, the brand) is not inside the recipe. It comes in by hash: a fingerprint of the file's content (sha256). Each file is stored once on disk, by its hash. Two videos that use the same music point to the same file.
The hash also protects: the recipe only accepts media that belongs to the video itself. Media from another video, and so from another account, does not get in.
What states does a request go through?
| State | What it means |
|---|---|
| queued | the recipe was checked and the request waits its turn |
| running | the worker took the request and is rendering |
| done | the MP4 came back, was checked by hash and is on the video |
| error | something failed; the tail of the render output is kept on the request |
What is the path, step by step?
- Request. From the screen (with the account checked) or from an agent, the recipe is validated again, and a «queued» request is created with a snapshot of the recipe at that moment.
- Take. The worker asks whether there is work. If there is, the request becomes «running» and counts one more attempt.
- Render. The worker builds a work folder with the recipe and links each media name to the file stored by hash. It assembles the composition and renders at low priority, holding the graphics card lock so it does not fight another heavy job.
- Check. Before the MP4 is moved into place, the engine checks the frames and the audio length. If they do not match, there is no output.
- Hand back. The MP4 is stored by its own hash. The app checks the file by hash before marking it «done».
- Clean up. The work folder is always deleted, success or not.
What happens when a render gets stuck?
- A «running» request stuck for more than 30 minutes goes back to the queue.
- On the second stuck attempt, the request and the video item become «error».
That way a rare hang (once, in a test, an ffmpeg froze for no known reason) does not stop the whole queue, and a repeating problem does not run forever.
Why one render at a time?
Because the machine is shared with production websites. One render already uses the graphics card and part of the processor, under a cap. Two at once would fight over the card and its memory. With one post a day per client, one at a time is enough, and each one's timing stays predictable.
Who writes to the database?
Only the app. The server worker does not touch the database directly: it asks the app, through a command, to take, finish or fail a request. The app, which knows the accounts and the rules, decides. That leaves a single door for changing a video's state.
Frequently asked questions
If the render fails, is the video lost? No. The recipe stays in the database, and the request sits in «error» with the reason. Just request it again after fixing it.
Can a half-written file reach the client? No. The MP4 is assembled under another name and checked (frames and audio length) before it is moved into place.
Why store media by hash? To store each file once, know it has not changed and keep one account's media out of another account's video.
Can an old video be remade? Yes. The recipe holds everything needed, and the same recipe gives the same frames.
This queue is what lets Konecz post a video every day on its clients' profiles without anyone pressing a button. See the plans at /en/ or talk to us at /en/contact.