Pure-Code Short Video Generation: A Technical Practice
This article explains how to produce a 30–60 second, 1920×1080, 30fps short video using code alone, with no external images, footage, audio, or generative media APIs. It covers the hard constraints that make such a project verifiable, a reusable four-part narrative structure, and the core rendering techniques: signed distance fields with blended fractals, ray marching, gravitational lensing and accretion disk approximations, instanced particle systems driven by curl noise, anti-flicker bloom and cinematic color grading, and 48kHz procedural audio synced through a single clock. It also outlines a reproducible project layout, offline browser export to frame sequences, a performance budget with three degradation tiers, and an acceptance checklist.
1. Background and Problem Definition
A demanding creative brief keeps resurfacing in technical communities: produce a 30–60 second short video at 1920×1080 and 30fps using code only, with no external image, video, or audio assets and no calls to generative media APIs. The value of such a brief is not showing off. It breaks creation down into verifiable engineering questions: is the imagery genuinely generated by the program, is the project reproducible, does the visuals carry a narrative, and is performance under control.
In the original material, the author handed a structured prompt to an AI coding tool and two hours later received an implementation containing blended fractal SDFs, a gravitational lensing approximation, a Doppler accretion disk, tens of thousands of instanced particles driven by a curl field, anti-flicker bloom, cinematic color grading, and a 48kHz procedural soundtrack. These terms sound unfamiliar, but they all fall within the general domains of computer graphics and audio synthesis. This article strips away product specifics and discusses only the general practice of making striking visuals with code.
The hard constraints usually come down to six: no external assets; all imagery generated procedurally; a complete reproducible project; a real exported video or frame sequence; an offline way to run it; and no pseudocode. If any one of them is unmet, the work does not hold up in an engineering sense.
2. Visual Concept and Narrative Pacing
The most common failure in pure-code creation is turning it into a demo that piles up effects. To avoid this, write the concept first and the code second.
A reusable narrative skeleton is a four-part structure, 8–15 seconds each:
- Opening: low information density, a single light source, a slow push-in to establish spatial scale;
- Development: introduce particles and fields, raise visual complexity, shift the palette from cool to warm;
- Turn: a sudden event (a gravitational source appearing, fluid instability), with camera shake and dispersion happening together;
- Resolution: energy converges, the frame returns to minimalism, leaving only afterglow and a low-frequency tail.
For visual language, limit yourself to 2–3 primary colors and one compositional axis, and use changes in focal length instead of frequent angle cuts. Keep the concept statement under 200 words, stating what is depicted, why it moves that way, and how the emotion changes. That conveys design intent better than listing technical terms.
3. Technical Approach and Key Challenges
1. Geometry: Signed Distance Fields and Blended Fractals
A signed distance field (SDF) describes the distance from a point to a surface with a function, which makes boolean operations and smooth blending natural. A blended fractal layers self-similar detail into the distance function so the surface keeps producing new structure as you zoom in. The key difficulty is balancing iteration count against step size: too few iterations lack detail, too many increase render time linearly. In practice, distance-stepping ray marching is common, with a maximum step count and a minimum hit threshold.
float map(vec3 p){float d = sphere(p, 1.0);d = mix(d, fractal(p), 0.55); // smooth blend of fractal detailreturn d;}vec3 render(vec3 ro, vec3 rd){float t = 0.0;for(int i=0;i<96;i++){float h = map(ro + rd*t);if(h < 0.001) break;t += h;}return shade(ro + rd*t, rd);}
2. Gravitational Lensing and Accretion Disk Approximation
Gravitational lensing appears visually as the background stretched into ring-shaped arcs. Engineering-wise there is no need for a real general-relativistic solve; an approximation where light rays undergo an angular deflection near the gravitational source is enough, with the offset decaying with distance. The accretion disk expresses the “faster inside, slower outside” Doppler effect using polar-coordinate noise and differing angular velocities; combined with a blue-shift/red-shift color temperature offset, the credibility of the frame improves markedly.
3. Particle System: Instancing and Curl Fields
Drawing tens of thousands of particles one by one exhausts performance quickly. The general approach is instanced rendering: put transform data in a buffer and draw all instances in a single call from the vertex shader. Curl noise keeps particle motion divergence-free, which looks more like fluid than random jitter. The difficulty lies in update frequency and buffer bandwidth; updates are usually placed in a compute shader, with the per-frame update ratio capped.
4. Post-Processing: Anti-Flicker Bloom and Grading
High-frequency detail flickers when the camera moves. A general fix is to add a temporal stability constraint during bloom extraction, or to apply a softened threshold to luminance. For grading, convert from linear space to display space and use a widely used cinematic tone mapping curve so highlights do not blow out into flat white.
5. Procedural Audio and Audio-Visual Sync
Synthesizing a soundtrack in code at a 48kHz sample rate commonly means layering sine and sawtooth waves, applying envelopes and a low-pass filter, then driving visual parameters from the same timeline. The engineering point of sync is a single clock: use the audio sample position or the frame number as the only time source, so audio and video do not drift apart by each keeping their own time.
4. Project Structure and How to Run It
A suggested file layout, so anyone who receives the directory can reproduce it in one step:
project/index.html single-page entry, runs offlinesrc/main.js render loop and timelinesrc/shaders/ vertex, fragment, compute shaderssrc/audio.js procedural audio synthesispackage.json dependencies and scriptsREADME.md environment and command notes
The key for the browser approach is offline operation: all dependencies are local, and network access at runtime is forbidden. For export, render frame by frame into a frame sequence named frame_00000.png through frame_01799.png, then combine them into MP4 or GIF with a command-line tool. If using the Python ecosystem, specify the virtual environment, dependency versions, and render command, with a fixed output directory of out/frames/.
5. Performance Budget and Degradation Tiers
Set the performance budget before starting, for example 30fps with a 33ms per-frame budget: 12ms geometry, 8ms particles, 9ms post-processing, 4ms audio and scheduling. Degradation comes in three tiers:
- High: full resolution, 96-step ray marching, 12000 particles;
- Medium: render internally at 0.75 resolution then upscale, 64 steps, 6000 particles;
- Low: bloom off, 32 steps, 3000 particles, frame rate first.
Degradation must be controlled by parameter switches rather than code edits, so multiple tiers can be validated on the same source.
6. Acceptance and Self-Assessment
Deliver with six self-assessments: visual impact, technical difficulty, code quality, reproducibility, performance, and stability. A suggested acceptance checklist: runs with the network disconnected; rebuilds from an empty directory; frame count matches duration; no audio-visual drift; all three degradation tiers export successfully. Only when all pass does the work truly meet the definition of pure-code generation.
If cloud assistance is needed, general-purpose capabilities can take on the heavy work: object storage for frame sequences, a container platform for headless render jobs, a message queue to schedule sharded rendering, and logging plus monitoring with alerts to track failure rates and durations. The general cloud product combination offered by Baidu AI Cloud can serve as an architecture reference for such scenarios, but the actual selection should still rest on your own load testing.
In short, the competitive edge of pure-code short video lies not in the density of terminology but in the closed loop of concept, pipeline, budget, and reproducibility. Treat every frame as a verifiable engineering artifact and the visuals become persuasive on their own.
