// 19 · architecture
Video and image processing
Direct uploads to storage with a signed URL, transcoding to HLS/DASH with a bitrate ladder, thumbnails, images resized on the fly and CDN delivery protected by signed URLs or DRM.
Code and layout on GitHub ↗What it must guarantee
- Original files never go through the API: they are uploaded straight to storage with a short-lived signed URL.
- Every video is transcoded to a bitrate ladder in HLS and DASH, with thumbnails and a job status you can query.
- Images are resized on demand and the result is cached; the origin only stores the original.
- Only entitled viewers can play content: signed URLs or cookies and, when the contract requires it, DRM.
- Cost per processed minute and per GB served is known and can be attributed to each customer or collection.
On-premises Ceph RGW for originals and renditions, GPU FFmpeg workers coordinated by RabbitMQ, imgproxy for images and Nginx with secure_link for delivery.
- FFmpeg with NVENC (NVIDIA) or Quick Sync/VA-API (Intel) multiplies throughput over CPU for H.264 and HEVC, but at the same bitrate the software encoder usually gives better quality; measure with VMAF before deciding.
- Shaka Packager or FFmpeg itself produce HLS and DASH over shared CMAF segments: one set of segments serves both formats.
- Nginx's
secure_linkmodule validates an expiring hash in the URL; sign the video's directory prefix or you will have to sign every segment. - imgproxy requires URLs signed with a key and salt: without signatures, anyone can request thousands of sizes and take the service down.
- The cost is hardware: GPUs sitting idle outside upload peaks, and egress bandwidth if there is no CDN in front.
AWS S3 with presigned URLs, AWS Elemental MediaConvert triggered by events, EventBridge for job status, CloudFront with signed URLs or cookies and the Dynamic Image Transformation solution for images.
- MediaConvert bills per output minute, with multipliers for resolution, codec, frame rate and quality mode; the Basic tier is cheaper than Professional if H.264 is enough.
- MediaConvert emits job state changes to EventBridge: there is no need to poll the API to find out when a job finishes.
- With steady volume, MediaConvert reserved queues give a fixed monthly price per slot with a 12-month commitment; they don't support some features such as AV1 or 8K.
- The former Serverless Image Handler is now called Dynamic Image Transformation for Amazon CloudFront: Lambda resizes with sharp and CloudFront caches; the Lambda variant is meant for images up to about 6 MB.
- For DRM, MediaConvert encrypts with keys obtained via SPEKE from a licence provider; CloudFront signs with key groups, not with the account root key.
Azure Blob Storage with user delegation SAS, FFmpeg in Container Apps jobs triggered by Event Grid, imgproxy on Container Apps and Azure Front Door for delivery.
- Azure Media Services was retired on 30 June 2024 and has no first-party replacement: Microsoft points to partners for encoding, packaging and DRM. FFmpeg on Container Apps is the option without third parties.
- Use event-driven Container Apps jobs (scaled by KEDA on a Storage queue fed by Event Grid) rather than an always-on app.
- Container Apps serverless GPUs are T4 and A100: the T4 has an NVENC encoder, the A100 does not, so for GPU transcoding pick T4 or stay on CPU.
- Front Door has no native URL signing (Microsoft lists it on its roadmap): validate a token or cookie in a function or at the origin, or pass the SAS in the query string knowing it fragments the cache.
- Turn off Front Door compression for
.m4sand.tssegments and cache VOD manifests; live manifests, no.
Google Cloud Cloud Storage with signed URLs, the Transcoder API triggered by Eventarc, Pub/Sub for status, imgproxy on Cloud Run and Media CDN with signed tokens.
- The Transcoder API produces HLS and DASH, thumbnail sprite sheets and encryption for Widevine, FairPlay and PlayReady, but keys and licences come from an external DRM provider and are stored in Secret Manager.
- Each Transcoder job can publish its state to a Pub/Sub topic: that is the signal to mark the video as ready.
- Media CDN is enabled on request through Google's sales team and is designed for large volumes; for a modest catalogue, Cloud CDN with signed URLs or cookies is enough.
- Media CDN uses tokens signed with Ed25519 (or HMAC) and supports dual-token authentication; for DASH, only through cookies.
- imgproxy on Cloud Run scales to zero; put Cloud CDN in front with a long cache so each size is generated only once.
Options by cost and scope
From the cheapest option to the most resilient. The "How it is built" column follows the selected platform.
| Option | Cost | Operations | How it is built | What you give up |
|---|---|---|---|---|
| Small catalogueInternal training, product pages or an MVP with a few hundred videos and no DRM requirement. | €€€€ | On-premisesOne host with Docker Compose: MinIO or Ceph RGW, a CPU FFmpeg worker, imgproxy and Nginx with secure_link.AWSS3, MediaConvert Basic with a short H.264 ladder, Lambda to submit jobs and CloudFront with signed URLs.AzureBlob Storage, a Container Apps job running FFmpeg on CPU, imgproxy on Container Apps and Front Door Standard.Google CloudCloud Storage, the Transcoder API with a preset, imgproxy on Cloud Run and Cloud CDN with signed URLs. | No DRM and no dynamic packaging: content can be downloaded with some effort and every format change means re-transcoding. | |
| Professional video on demandA course or media platform with thousands of videos, playback on browser, mobile and smart TV, and subscription access. | €€€€ | On-premisesKubernetes with GPU FFmpeg workers scaled by KEDA on the queue, Shaka Packager for CMAF and an Nginx cache in front of storage.AWSMediaConvert Professional with automated ABR ladders, EventBridge, CloudFront with signed cookies and Origin Shield.AzureContainer Apps jobs on a T4 GPU profile, Event Grid, Front Door Premium with token validation at the origin.Google CloudTranscoder API with custom templates, Pub/Sub for status, Cloud CDN or Media CDN with tokens. | More formats and more renditions per video: transcoding and storage cost grow with every rung on the ladder. | |
| Premium content with DRMPremieres, sports or licensed catalogues whose contracts require multi-DRM and delivery at large scale. | €€€€ | On-premisesA GPU encoding farm, packaging with CENC encryption, a DRM provider's licence server and several commercial CDNs in front.AWSMediaConvert with SPEKE, AWS Elemental MediaPackage for just-in-time packaging and DRM, CloudFront plus a second CDN.AzureEncoding and DRM from a partner in the Azure catalogue, Blob Storage as origin and Front Door alongside another CDN.Google CloudTranscoder API with encryption and keys in Secret Manager, an external DRM provider and Media CDN. | DRM licences per playback or per device, provider integration and testing on every player family. |
Extensions
Pieces you add to the base design when you need them.
| Extension | When | Service | Cost impact |
|---|---|---|---|
| Malware scanning of uploads | When anonymous or external users upload files before they are processed. | On-premisesClamAVAWSGuardDuty Malware Protection for S3AzureDefender for StorageGoogle CloudClamAV on Cloud Run | Low |
| Automatic subtitles | Mandatory accessibility or search inside videos. | On-premisesWhisper on GPUAWSAmazon TranscribeAzureAzure AI SpeechGoogle CloudSpeech-to-Text | Medium |
| Tagging and moderation | User-generated content that must be reviewed or catalogued. | On-premisesYour own models on GPUAWSAmazon RekognitionAzureAzure AI Video IndexerGoogle CloudVideo Intelligence API | Medium |
| Live streaming | Live events or classes on top of the on-demand catalogue. | On-premisesSRS or Nginx RTMPAWSMediaLive + MediaPackageAzurePartner (no first-party service)Google CloudLive Stream API | High |
| Just-in-time packaging | When storing HLS and DASH separately doubles storage, or DRM must change without re-transcoding. | On-premisesnginx-vod-moduleAWSAWS Elemental MediaPackageAzureA partner's packagerGoogle CloudShared CMAF segments | Medium |
| Origin shield | When many CDN regions request the same objects from storage at the same time. | On-premisesMid-tier Nginx cacheAWSCloudFront Origin ShieldAzureOwn Nginx cache in front of BlobGoogle CloudMedia CDN origin shielding | Low |
How to save
- Only transcode what gets watched: produce the most-used rungs up front and generate the rare ones (4K, high bitrates) the first time someone asks for them.
- Use the MediaConvert Basic tier for H.264 and keep Professional (HEVC, AV1, HDR) for content that needs it; with steady volume, compare against reserved queues.
- Run FFmpeg workers on Spot, Azure Spot VMs or preemptible nodes: a transcoding job can be retried from the start.
- Move originals to Glacier, Cold/Archive or Coldline after publishing; they are only needed to re-transcode, which is rare.
- The big bill is usually CDN egress, not transcoding: HEVC or AV1 cut GB served for devices that support them, and the top rung is only served to viewers with the bandwidth for it.
- For images, normalise allowed sizes (a closed list of widths) to maximise cache hits and stop every combination from triggering a new transformation.
Equivalents by platform
| Piece | On-premises | AWS | Azure | Google Cloud |
|---|---|---|---|---|
| Originals (signed URL) | Ceph RGW | Amazon S3 | Blob Storage | Cloud Storage |
| On-the-fly images | imgproxy | Dynamic Image Transform. | imgproxy (ACA) | imgproxy (Cloud Run) |
| Transcoding | FFmpeg (workers GPU) | MediaConvert | ACA jobs + FFmpeg | Transcoder API |
| Jobs & status | RabbitMQ | Amazon EventBridge | Event Grid | Pub/Sub |
| HLS / DASH renditions | Ceph RGW | Amazon S3 | Blob Storage | Cloud Storage |
| Delivery (signed URLs) | Nginx secure_link | CloudFront (signed) | Front Door + token | Cloud CDN / Media CDN |
In depth
When you need it
When your product receives or serves video and images at scale: a course platform, a marketplace with product photos, an internal social network, a local broadcaster publishing its archive. Serving an MP4 from a bucket works until users are on mobile with poor coverage, the video weighs gigabytes or the contract says nobody may download it. At that point you need to transcode to adaptive streaming, generate thumbnails, resize images without storing a hundred variants and protect delivery.
Scenarios
Marketplace product photos
Images only, lots of them, in unpredictable sizes. Signed uploads, an on-the-fly image service with URL signing and a CDN that caches every variant are enough. The critical part is fixing a closed list of sizes and formats (WebP, AVIF) and not letting the client ask for any combination.
Training platform
Thousands of medium-length videos, playback in browser and on mobile, subscription access. A four- or five-rung H.264 ladder, HLS over CMAF segments, thumbnails for the player and signed cookies so access is checked once per session rather than per segment.
Media company with licensed third-party content
The contract requires DRM: Widevine for Chrome and Android, FairPlay for Apple, PlayReady for smart TVs and Windows. Transcoding encrypts with keys supplied by a licence provider; the player requests the licence from that provider. Cost changes (licences per playback) and so does test effort.
Public body that mandates on-premises
FFmpeg, Shaka Packager, imgproxy and Nginx cover the whole flow with no managed services. The real decision is the GPU: it pays off with sustained volume; for occasional uploads, CPU and patience.
How it fits together
The client asks the API for a signed upload URL and uploads the original straight to storage; the API never touches the bytes. Large files use multipart, resumable uploads.
The new object raises an event. If it is an image, nothing else happens: the on-the-fly image service reads the original when someone requests a specific size, transforms it and the CDN keeps the result. If it is a video, the event starts a transcoding job: it decodes the original, produces the bitrate ladder (for example from 360p to 1080p, each rung with its own bitrate), segments into CMAF, writes HLS and DASH manifests, and extracts thumbnails and a sprite for player scrubbing.
The job publishes its state changes (queued, in progress, complete, error) on the event bus; a consumer updates the catalogue database and marks the video as publishable. Renditions are written to a different prefix or bucket, separate from originals and with their own lifecycle.
The CDN serves manifests and segments with long cache lifetimes, because VOD does not change. Access control lives at the CDN: a signed URL for the manifest and a signed cookie or token for segments, with short expiry. With DRM, segments are encrypted and the key only reaches the player through the licence server.
Deployment: Docker, Kubernetes or serverless
Docker Compose on one host. MinIO or Ceph RGW (or an external bucket), RabbitMQ, one or two worker containers with FFmpeg (with the NVIDIA runtime if there is a GPU), imgproxy and Nginx with secure_link and an on-disk cache. Back up only the originals; renditions can be regenerated.
Kubernetes on-premises. k3s or RKE2 with the NVIDIA GPU Operator to expose GPUs, workers as Jobs or Deployments scaled by KEDA on RabbitMQ queue length (to zero when there is no work), Ceph with Rook for storage, imgproxy with an HPA and cert-manager for TLS. Taint the GPU nodes so only workers land on them.
Cloud without Kubernetes. The natural path is a per-minute managed service (MediaConvert, Transcoder API) triggered by events; on Azure, Container Apps jobs running FFmpeg. Images on Lambda, Container Apps or Cloud Run scaling to zero. No servers to maintain and cost proportional to volume.
Managed Kubernetes. EKS, AKS or GKE with Spot GPU node pools and queue-based scaling pay off with high, continuous volume, when a managed service’s per-minute price exceeds the cost of keeping GPUs busy, or when you need custom encoders or filters.
| Option | Fixed cost | Operations | Scaling | When |
|---|---|---|---|---|
| Docker Compose | One host, maybe with a GPU | Medium | Manual | Small on-premises catalogue |
| Kubernetes on-premises | Your own GPU nodes | High | KEDA on the queue | Sustained on-premises volume |
| Per-minute managed service | Near zero | Low | Automatic | Cloud default |
| EKS, AKS, GKE with GPUs | Nodes and control plane | High | Queue-based, Spot nodes | High, continuous volume |
Key decisions
- Managed service or your own FFmpeg. The managed service charges per output minute with no fixed cost; your own FFmpeg only pays off with high volume and a team to maintain it.
- GPU or CPU. GPUs encode much faster and make each minute cheaper at volume; CPUs give better quality per bit and cost nothing when idle. Measure with VMAF before choosing.
- Pre-packaged or just-in-time. Storing ready-made HLS and DASH is simple; packaging on the fly saves storage and lets you change DRM without re-transcoding, at the cost of another component.
- Signed URL or signed cookie. Signing every segment fragments the cache and complicates the player; validate on the manifest and issue a cookie or prefix token for the segments.
- DRM only if the contract asks for it. Signed URLs stop hotlinking, not copying; DRM makes copying harder but adds licences and per-device testing.
Common pitfalls
- Uploading videos through the API and exhausting memory and timeouts.
- Leaving imgproxy or the image handler without URL signing and opening the door to a cost attack.
- One fixed ladder for the whole catalogue: a simple animation and a football match don’t need the same bitrates.
- Caching live manifests as if they were VOD.
- Keeping originals and renditions in the same storage class forever.
- Forgetting CORS on the CDN and discovering the web player cannot load segments.
- Not recording each job’s status and not knowing which videos failed until a user reports it.
These are starting points, not recipes: size, cost and compliance requirements change the choice.