How CineLocal Works: HTTP 206 Streaming, SSE Remote, mDNS & FFmpeg
Technical notes on how CineLocal streams large videos via HTTP 206 Byte-Range in Python, discovers the host via mDNS, injects AAC audio with FFmpeg, and pairs a QR Code SSE remote.
This note documents how CineLocal works under the hood to turn an old laptop and external HDD into a home-network media center for Smart TVs and browsers without cloud hosting.
What It Solves
CineLocal scans local folders with TMDb API metadata, exposes zero-config local discovery via mDNS (`cinelocal.local:8000`), seeks smoothly through 10GB+ files, and pairs a smartphone remote via QR Code + SSE.
1. HTTP 206 Byte-Range Streaming in Python
Instead of pushing an entire multi-gigabyte video file at once, the multi-threaded Python server inspects the HTTP Range header and returns only the requested byte chunk with 206 Partial Content:
range_header = self.headers.get("Range")
file_size = os.path.getsize(video_path)
if range_header:
byte_range = range_header.replace("bytes=", "").split("-")
start = int(byte_range[0])
end = int(byte_range[1]) if byte_range[1] else min(start + CHUNK_SIZE, file_size - 1)
length = end - start + 1
self.send_response(206)
self.send_header("Content-Range", f"bytes {start}-{end}/{file_size}")
self.send_header("Accept-Ranges", "bytes")
self.send_header("Content-Length", str(length))
self.end_headers()2. Live FFmpeg AAC Audio Injection & 1-Click Subtitles
Browsers often fail to play AC3/DTS audio inside MKV containers. CineLocal uses FFprobe to inspect streams and FFmpeg (`-c:v copy`) to transcode only audio to AAC on the fly without touching video frames, plus 1-click pt-BR subtitle sync.
3. QR Code Remote Control via Server-Sent Events (SSE)
Scanning the on-screen QR Code opens a touch remote on the phone; HTTP commands trigger updates across an open EventSource SSE stream in the TV/browser player with sub-20ms latency.
4. Canvas 2D Ambilight & 300% Web Audio Boost
An HTML5 <canvas> projects ambient border colors behind playback while a Web Audio API GainNode boosts quiet tracks up to 300% inside a clean PWA shell.
Miguel Riquelme
Front-end Engineer. Software Engineering MBA student at USP/Esalq.