Save costs with on-demand video encoding
Video encoding prepares video files for playback on phones, laptops, and TVs, yet it is both computationally intensive and expensive. Transloadit’s on-demand video encoding service can reduce unnecessary processing by encoding requested video segments instead of preparing every rendition of a library in advance. Startup time and savings depend on the source, encoding settings, player, and cache state.
Video encoding overview
Raw videos captured by mobile cameras or screen recorders are optimized for recording speed, not delivery efficiency. These often use outdated codecs, lack streaming-friendly packaging, and are much larger than necessary. Converting these files into adaptive streaming formats (e.g., HLS or DASH) solves the problem, but conventional ‘encode-everything-up-front’ workflows come with three major drawbacks:
- Preparation time – an upfront pipeline must produce playable output before it can serve it.
- Up-front cost – encoding a video nobody ever watches ends up wasting CPU cycles and money.
- Inflexibility – changing a watermark, switching codecs, or adding higher resolution support means re-encoding the entire back catalog.
On-demand video encoding
Transloadit’s on-demand video encoding service inverts the traditional model. Instead of pre-processing an entire file, it encodes only the segment a viewer requests and streams the result. Smart CDN caches the output. A request served from cache avoids repeating the encoding, but cached delivery still counts toward usage. Expired or evicted entries can require processing again.
Key benefits:
- Process requested segments – segments that are never requested need no encoding. Players can prefetch segments that a viewer ultimately does not watch.
- Rapid iteration – update watermarks, subtitles, or codecs by editing a Template; new requests can generate the changed output without an upfront library-wide re-encode. Account for cached output when rolling out changes.
- Earlier playback – a player need not wait for the entire video to be encoded. The first request still has import and encoding work to do.
How it works under the hood
/video/ondemand encodes videos into HLS playlists on demand. Here's how it works when used with our Smart CDN:
- The player asks the Smart CDN for the HLS multivariant playlist (master playlist).
- The Smart CDN forwards the request to Transloadit if the playlist isn't yet cached.
- Transloadit retrieves the source file, generates the HLS multivariant playlist on the fly, and returns it to the player.
- When the player requests a variant playlist or a specific
.ts(Transport Stream) segment, the same cache lookup happens. Missing playlists are generated; missing media segments are encoded and served. Segment duration is configured in the Robot's parameters. - The Smart CDN caches both the playlists and encoded segments, so subsequent viewers receive them directly from the edge.
Range-capable imports let Transloadit retrieve the relevant parts of the source file. The sample below uses an S3 file stub for that workflow. Source format, storage latency, and encoding settings still affect how quickly a requested segment becomes available.
Demo
Choose a watermark, press Load video, then use the player's playback controls. The demo does not request a video until you submit it. Submitting again replaces the previous player; unchanged settings keep the same URL so the CDN can reuse cached output. Browser timing alone does not prove whether a request was a cache hit.
Watermarked video preview
Use cases
Here's a list of the most common use cases for our new on-demand video encoding service.
Large archives
Conference libraries, surveillance footage, or collections of lecture recordings often span thousands of hours, yet only a sliver is ever replayed. On-demand encoding spares you from processing the entire archive in advance. A first viewer may still wait for requested segments to be prepared.
User-generated content platforms
Most uploads receive few – if any – views, while a small percentage of them go viral. Deferring compute until content is requested can reduce wasted encoding. Compare representative workloads before choosing it over an upfront pipeline.
A/B testing video features
Need to compare codecs, bitrates, or watermark placement? Point separate players at different Templates, measure engagement, and discard the losing variant. No pre-encode or complex rollout required.
Flexible delivery strategy
Want to change your delivery strategy quickly? With on-demand encoding, you can update your encoding settings, add or remove quality levels, or change watermarks without scheduling an upfront re-encode of your entire video library. Plan for cache invalidation or versioned delivery URLs when changing already-served output.
Cost-savings calculator
The calculator below is an illustrative usage model, not a price quote or a prediction of your
invoice. It assumes three upfront renditions, one requested on-demand rendition, and equal input
and output sizes. Its fixed processing multipliers model a particular pipeline, not current plan
prices: the upfront factor is 12 times the source size, and the on-demand factor is 5 times the
source size, multiplied by retention and watch rate. The on-demand factor includes one
/file/serve pass. Repeated views, prefetching, cache misses, storage, and CDN bandwidth can change
actual usage; they are not measured here. Check current pricing and test your own files
before budgeting.
Parameters considered:
- Number of videos – the size of your library.
- Average video size – the source size in mebibytes (MiB).
- Average viewer retention – the fraction of each video a typical user watches.
- Watch rate – the portion of the catalog that receives at least one view.
Results
Sample Template
Developers usually want to see a JSON before anything else. Here is a minimal Template that imports a video from S3 and offers 480p, 720p, and 1080p HLS variants on demand:
{
"steps": {
"import": {
"robot": "/s3/import",
"path": "${fields.input}",
"credentials": "YOUR_AWS_CREDENTIALS",
"return_file_stubs": true
},
"vod": {
"robot": "/video/ondemand",
"use": "import",
"variants": {
"480p": {
"preset": "hls/480p"
},
"720p": {
"preset": "hls/720p"
},
"1080p": {
"preset": "hls/1080p"
}
}
},
"serve": {
"use": "vod",
"robot": "/file/serve"
}
}
}
Save the snippet as a Template, then when you open a URL like
https://[workspace].tlcdn.com/[template]/[path], an Assembly with those
Instructions is automatically created, which takes care of the file importing, encoding,
and serving. This illustrates the URL structure, not a complete authorized request. Configure
Smart CDN URL signing on your backend and authorize the
requested source and Template before issuing a URL. Set require_signature_auth to 1 through
the Template API to reject unsigned requests; this setting
belongs outside the Instructions JSON. Keep signing secrets out of the browser.
Get started
For a full walk-through, see our 🤖 /video/ondemand Robot documentation.
Conclusion
On-demand video encoding can reduce work on rarely watched content and make delivery changes easier. Compare it with upfront encoding using your actual files, player behavior, and cache conditions to choose the right approach for your application.
