Media Optimization
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
This is the server-side home of the topic; the client side is split in two: Media Optimization for the web for browsers and Media Optimization in apps for native and cross-platform apps.
Users upload photos and videos in whatever format their device produced, and a platform has to serve each client a file it can decode, at a size it needs, with as few bytes as possible. This sub-section describes how the backend does that: turn every image into a set of formats and sizes (with a BlurHash placeholder), turn every video into a ladder of renditions that stream adaptively, produce covers and thumbnails, and do all of it in background workers rather than in the HTTP request. It is current as of 2026-10-07. Each page states the versions it was checked against and flags unmaintained or restrictively licensed libraries.
Deliberately out of scope. This section is about turning uploaded images and videos into the files a client can use, and running that work safely. The following topics appear in image-processing, graphics, Spring Boot and messaging books, but live elsewhere on this site or are intentionally not covered:
-
Image-processing algorithms and computer vision (filters, feature detection, face detection, OpenCV) — not covered. The pipeline here only decodes, resizes, converts and encodes. For learned image models see Convolutional neural networks and Hugging Face vision models, and for generative image models Generative models.
-
Real-time graphics, GPUs and texture pipelines (OpenGL, Vulkan, Metal, mipmaps, texture compression) — see Graphics and games. Colour management on a GPU is in Colour spaces, HDR and tone mapping; here only the conversion of an uploaded image to sRGB is covered.
-
Reading documents and extracting content (PDF, Office files, OCR, metadata of arbitrary files) — see Apache Tika, OCR with Tesseract and PDF generation. The security lessons for untrusted files are shared with Office files: security and untrusted files.
-
Multipart handling and file storage in each framework (reactive file controllers, upload endpoints, object stores) — see File Storage and Object Stores, NestJS file upload and streaming and FastAPI forms and file uploads. This section starts after the file is in storage.
-
Message-broker internals (AMQP, Kafka, exchanges, partitions, exactly-once) — see Messaging, and for dead-lettering in RabbitMQ RabbitMQ reliability, dead-lettering and TTL. The upload pipeline page only describes the contract a media worker needs from a queue.
-
Containers, hardening and orchestration in depth — see Docker security, Kubernetes pod security and Kubernetes resource management; this section shows only the flags a media worker needs.
-
Browser-side rendering and players — see Media Optimization for the web and Media Optimization in apps.
-
Live and real-time video (RTMP ingest, WebRTC, low-latency HLS) — see WebRTC and WebSockets; this section covers on-demand files only.
-
Video editing, compositing, subtitles and audio mastering, camera RAW and TIFF workflows, animated images — intentionally not covered. Subtitles appear only as a reason to use a dedicated packager, and animation only as a column of the format table.
-
DRM and licence servers — the streaming page names the options, but key delivery is not covered.
-
Content moderation and abuse detection with machine learning — not covered. Upload validation here is structural (type, size, pixels, duration); for the cost and abuse risks of calling models see Unbounded consumption and denial of wallet.
-
Managed image and video services — see the AWS, Google Cloud and Azure pages in the section below.
What’s covered
| Page | What it covers |
|---|---|
JPEG, PNG, WebP, AVIF, JPEG XL and HEIC compared. Quality settings, EXIF orientation, colour profiles, and the libvips, cwebp and avifenc commands, with measured sizes, SSIM and encode times for the cover ladder. |
|
Width breakpoints with the cost of each ladder worked out, fit and crop modes, storage keys, eager versus on-the-fly generation, a signed and negotiated origin with its cache headers, and what the API must return for srcset and picture. |
|
The equations, the string layout, decoding and punch, a worked example, a real hash unpacked field by field, why implementations return different strings, costs, ThumbHash, and the implementations per language. |
|
Codecs, containers, rate control, GOP, audio, FFmpeg commands, and the bitrate ladder from the Apple HLS Authoring Specification. |
|
Seeking, the thumbnail filter, scene detection, sprite sheets, rotation, and BlurHash on the cover. |
|
Progressive versus adaptive streaming, playlists, segment length, FFmpeg and packagers, CDN delivery, signed cookies and DRM. |
|
Thumbnailator, imgscalr (legacy), TwelveMonkeys, Scrimage, vips-ffm, blurhash-java, Jaffree and JAVE2, with a complete cover job, ImageIO memory behaviour and hard time limits for FFmpeg. |
|
A media service with pre-signed uploads, a queue, workers, a status endpoint and Spring Batch backfills, in both frameworks. |
|
Pillow, pillow-heif, pyvips, BlurHash, ffmpeg-python, MoviePy 2, subprocess and a FastAPI upload endpoint, with a complete cover job and Pillow versus pyvips memory and time. |
|
sharp, Jimp, blurhash, fluent-ffmpeg (legacy), a NestJS and BullMQ example, and Rust with axum, the image crate and tokio. |
|
ImageSharp and its license, SkiaSharp, NetVips, BlurHash, FFMpegCore, Xabe.FFmpeg and an ASP.NET Core upload endpoint. |
|
The reference architecture: pre-signed uploads, events, queues, idempotent workers, retries, dead-letter queues and status, with a runnable queue simulation and worker sizing. |
|
Upload validation, decompression bombs, metadata stripping, sandboxing FFmpeg, patching, cost, lifecycle and monitoring, demonstrated on a batch of hostile files. |
|
A one-page summary of formats, BlurHash, FFmpeg commands, the ladder and a library picker. |
Reading path
-
Images only. Start with formats, then variants, then BlurHash, then the page for your language.
-
Video. Read encoding, streaming and covers, then decide between self-hosted FFmpeg workers and a managed transcoder, see below.
-
A new platform. Read upload pipelines first, since it fixes the architecture the other pages fit into, and security and operations before the first public upload.
Existing pages this section builds on
-
Storage: File Storage and Object Stores, NestJS file upload and streaming and FastAPI forms and file uploads.
-
Queues and jobs: Messaging, Scheduling, Spring Batch, Quarkus messaging, NestJS queues and FastAPI background tasks.
-
Running workers: Docker and Kubernetes Jobs.
Managed alternatives in the cloud
Self-hosted FFmpeg and image workers are one choice. Each cloud offers a managed one, described in its own section:
-
AWS: Elemental MediaConvert, S3 and Lambda image processing, CloudFront delivery and a Video on Demand pipeline.
-
Google Cloud: the Transcoder API, Cloud Run jobs, Media CDN and storage-triggered resizing.
-
Azure: Media Services was retired, so self-hosted FFmpeg in Container Apps jobs, Event Grid with Functions, and Front Door.
Related material on this site
-
Media Optimization for the web covers how a browser asks for the right variant, shows a placeholder and plays adaptive video.
-
Media Optimization in apps covers image loading, video playback and device-side compression on Android, iOS, React Native, Kotlin Multiplatform and Flutter.
-
AWS, Google Cloud and Azure describe the managed alternatives to self-hosted workers.
-
Apache Tika: media types and detection and Apache Tika: robustness, limits and timeouts cover the same ideas (detect by content, bound the work) for documents.
-
Colour spaces, HDR and tone mapping explains the colour models behind the sRGB and Display P3 conversion discussed under image formats.
Bibliography
Every source below is the official site, repository or documentation page of the library, service or standard it supports. Links were checked from an authoring environment with restricted outbound access. Entries marked (unverified) could not be opened from there (the site refused or blocked the request), so open them and confirm the content, version and status before you rely on them. Entries without the mark were opened successfully, or, for package pages, confirmed through the package registry.
BlurHash and ThumbHash
-
blurha.sh (unverified)
-
Blurhash.ImageSharp and blurhash.net (unverified)
-
BlurHashSharp (unverified)
-
docs.rs, blurhash (unverified)
-
halcy/blurhash-python (unverified)
-
hsch/blurhash-java (unverified)
-
ThumbHash (unverified)
-
vanniktech/blurhash (unverified)
-
woltapp/blurhash, Algorithm.md (unverified)
-
woltapp/blurhash, Kotlin implementation (unverified)
-
woltapp/blurhash, list of implementations (unverified)
-
woltapp/blurhash, reference TypeScript code (unverified)
-
woltapp/blurhash, Swift implementation (unverified)
-
woltapp/blurhash, the reference BlurHash repository (unverified)
-
woltapp/blurhash-python (unverified)
Image formats, encoders and libvips
-
AV1 Image File Format specification (unverified)
-
Can I use (unverified)
-
Cloudinary (unverified)
-
Google, cwebp documentation (unverified)
-
imgix (unverified)
-
JPEG, JPEG XL overview (unverified)
-
libavif, AVIF encoder and decoder (unverified)
-
libjxl, JPEG XL reference implementation (unverified)
-
libvips, API documentation (unverified)
-
libvips, command line interface (unverified)
-
libvips, heifsave (unverified)
-
MDN, Cache-Control header (unverified)
-
MDN, HTTP caching (unverified)
-
MDN, image file type and format guide (unverified)
-
MDN, responsive images (unverified)
-
pyvips (unverified)
-
pyvips documentation (unverified)
-
VMAF (unverified)
Java
-
AWS SDK for Java, presigned URLs (unverified)
-
imgscalr (unverified)
-
Jaffree (unverified)
-
Javadoc (unverified)
-
JAVE2 (unverified)
-
JVips (unverified)
-
Quarkus RabbitMQ connector (unverified)
-
Quarkus, building a native executable (unverified)
-
Scrimage (unverified)
-
Spring Framework data access (unverified)
-
Thumbnailator (unverified)
-
TwelveMonkeys ImageIO (unverified)
-
vips-ffm (unverified)
-
webp-imageio (unverified)
Python
-
FastAPI, background tasks (unverified)
-
FastAPI, request files (unverified)
-
ffmpeg-python (unverified)
-
ImageOps (unverified)
-
MoviePy (unverified)
-
MoviePy documentation (unverified)
-
Pillow (unverified)
-
Pillow image file formats (unverified)
-
pillow-avif-plugin (unverified)
-
pillow-heif (unverified)
-
pillow-heif documentation (unverified)
-
Python subprocess (unverified)
Node.js
-
BullMQ documentation (unverified)
-
fluent-ffmpeg (unverified)
-
Jimp (unverified)
-
Jimp documentation (unverified)
-
NestJS queues (unverified)
-
sharp (unverified)
-
sharp, input and metadata API (unverified)
-
sharp, output API (unverified)
-
sharp, resize API (unverified)
Rust
-
axum (unverified)
-
docs.rs, axum (unverified)
-
docs.rs, image (unverified)
-
docs.rs, tokio::process (unverified)
.NET
-
Background tasks with hosted services in ASP.NET Core (unverified)
-
FFMpegCore (unverified)
-
ImageSharp (unverified)
-
ImageSharp documentation (unverified)
-
NetVips (unverified)
-
NetVips documentation (unverified)
-
SkiaSharp (unverified)
-
SkiaSharp API documentation (unverified)
-
System.Threading.Channels (unverified)
-
Xabe.FFmpeg (unverified)
-
Xabe.FFmpeg (unverified)
Video, FFmpeg and streaming
-
Bento4 (unverified)
-
DASH Industry Forum (unverified)
-
FFmpeg wiki, Encode/H.264 (unverified)
-
FFmpeg wiki, Seeking (unverified)
-
FFmpeg, codecs documentation (unverified)
-
FFmpeg, hls muxer (unverified)
-
FFmpeg, main options (unverified)
-
FFmpeg, thumbnail filter (unverified)
-
MDN, web video codec guide (unverified)
-
RFC 8216 (unverified)
-
Shaka Packager (unverified)
Security
-
NVD, CVE-2023-4863 (libwebp heap buffer overflow) (unverified)
Other sources
-
Expo, expo-image documentation (unverified)
-
unlazy (unverified)
-
MDN, picture element (unverified)