2026-11-01 17:35:09 +01:00
2026-03-27 20:23:51 +01:00
2026-11-01 17:35:09 +01:00
2026-09-09 18:42:04 +02:00
2026-03-27 15:55:43 +01:00
2026-11-01 17:35:09 +01:00
2026-11-01 17:35:09 +01:00
2026-11-01 17:35:09 +01:00
2026-10-31 12:57:33 +01:00

dalain

A small, fast DLNA video server for Linux. Point it at a directory of videos and a TV on the same network can browse and stream them. Nothing else.

Why

Most DLNA servers are architected around a hot metadata cache: they won't serve until the database is built, which takes minutes to days on a large library. They also drag in SQLite, taglib, web UIs, transcoding pipelines, plugin systems, and scripting hooks -- for a protocol that fundamentally just needs to list files and stream bytes.

dalain inverts this: serving is the priority, caching is best-effort. The filesystem is already a mature, queryable, indexed store; walking it on startup is cheap and inotify keeps it current. Thumbnails are generated later, in the background, and the TV sees them as they appear.

Non-goals

These are deliberately out of scope and won't be added:

  • No transcoding. Files are served as-is. If your TV can't play the codec, re-encode the file yourself or use a different tool.
  • No audio/music library. Video only.
  • No admin UI. Configuration is command-line flags only. There is a plain HTML browse page (see Features), but nothing in it configures anything -- no settings, no accounts, no uploads.
  • No database. The filesystem is the source of truth. A rescan on startup takes milliseconds even for thousands of files.
  • No Windows/macOS. Uses inotify for live updates.

If you need any of the above, Jellyfin, Gerbera, or MiniDLNA will serve you better.

Intentional omissions

  • One media directory. dalain serves a single tree. If your library is split across several locations, a bind mount, symlink, or a small housekeeping script gets you there without dragging virtual-filesystem plumbing into the server.
  • No symlink sandbox. Symlinks are followed deliberately, and the point above depends on it: the catalog is one directory, but what sits inside it may point anywhere, so ln -s /mnt/big/series media/series is a supported way to assemble a library. The consequence is the obvious one -- whatever a link resolves to is catalogued and served, which means whoever can create links in the tree decides what the server exposes. That is the administrator, by design, and there is no --no-follow flag. dalain serves everything it can read with no authentication anyway, so the control that matters is the account it runs as: keep it unprivileged (the OpenRC script defaults to nobody) and a stray link reaches no further than that user's read permissions.
  • No sendfile/splice zero-copy path. A kernel-side send would shave ~20% off CPU per byte streamed and push throughput past 3 GB/s. It's not wired in because the user-space read/write loop already sustains 1-2 GB/s per connection, and a 4K HEVC stream to a TV peaks around 0.05 GB/s. The complexity (non-blocking socket EAGAIN handling, fallback when the client seeks mid-stream, losing tokio's clean AsyncWrite abstraction) buys nothing at real-world rates.

Features

  • Instant startup. Streaming works immediately; thumbnail generation runs in the background.
  • In-memory catalog. A Vec<Node> plus two indexes over it -- path hash to node, directory to its children -- so a browse and an inotify event are both lookups rather than scans of the whole catalog. No SQLite, no WAL files, no schema migrations.
  • Live updates via inotify. Add, delete, or rename a file and the TV sees the change on the next browse -- no restart, no rescan.
  • Background thumbnails. When --cache-dir is set, dalain extracts embedded cover art (if present) or a frame at ~30 s (falling back to 1 s for short clips), scales to 160 px wide JPEGs, and caches them.
  • Failure markers. Files that ffmpeg can't decode get a .failed marker so they aren't retried on every update.
  • Graceful shutdown. SIGTERM/SIGINT propagates to inotify, HTTP, and thumbnail tasks; SSDP sends byebye before exit.
  • One server per interface. Pass --ip multiple times and dalain runs a full HTTP listener and SSDP responder on each address, building URLs from the interface the client actually reached. A TV on the LAN and a phone on a VPN are served by one process, one catalog, one set of thumbnails.
  • HTML browse page. / and /browse/{id} render the same tree as DLNA does, with thumbnails and breadcrumbs. Links are relative, so the page is correct on every interface. Handy wherever UPnP discovery cannot work: no SSDP involved, just links.
  • M3U playlists. /playlist/{id}.m3u returns a folder's files as a queue -- the one thing a plain URL cannot express, and the only reason the endpoint exists. Sent as an attachment so a mobile browser hands it to a real player instead of trying to play it inline. Individual files need no wrapper: the browse page links them directly as /media/{id}.ext, which is also the URL to copy and hand to a player on another machine.

Requirements

  • Linux (inotify)
  • Rust 1.85+ (edition 2024)
  • ffmpeg and ffprobe -- optional, only used when --cache-dir is set

Build

cargo build --release

The binary lands at target/release/dalain.

Usage

dalain /path/to/videos --ip 192.168.1.10

Flags

Flag Description
<media_dir> Directory to serve (positional, required)
-a, --ip <ADDR> IP to advertise on. Repeat for multiple interfaces. Required.
-p, --port <PORT> HTTP port (default 8201)
-n, --name <NAME> Friendly device name shown on the TV (default Dalain)
--uuid <UUID> UPnP device UUID
--notify-interval <SEC> SSDP NOTIFY interval in seconds (default 30)
--max-age <SEC> CACHE-CONTROL max-age advertised in SSDP (default 1800)
--event-timeout <SEC> UPnP event callback HTTP timeout in seconds (default 3)
--request-timeout <SEC> Deadline for a client to send its request headers (default 15)
--stream-timeout <SEC> Deadline for one write while streaming; 0 disables (default 0)
--ffmpeg-timeout <SEC> Deadline for one thumbnail extraction (default 60)
--cache-dir <DIR> Enable thumbnails, cache them under this directory (created 0700)
-m, --dated Suppress timestamps in log output (for systemd/journald)
-v to -vvvv Verbosity: warn / info / debug / trace (default: error)
-d, --daemon Run in the background; the flags below require it
-o, --out <FILE> Append stdout to this file, stderr too unless --err is set
-e, --err <FILE> Append stderr to this file
-i, --pid <FILE> Write the PID to this file
-u, --user <USER> Drop to this user
-g, --group <GROUP> Drop to this group
-w, --workdir <DIR> Working directory (default /)

Example

dalain /data/tv \
    --ip 10.0.0.5 \
    --name "Living Room" \
    --cache-dir /var/cache/dalain \
    -vv

Serving over a VPN tunnel

Pass the tunnel address as an extra --ip and dalain will listen and announce there too. Discovery, however, is not automatic on a layer-3 tunnel:

  • WireGuard drops multicast unless a peer claims the SSDP group. Without 239.255.255.250/32 in that peer's allowed-ips, announcements fail with ENOKEY (os error 126). Note that allowed-ips is checked against the destination when sending and against the source when receiving, so incoming M-SEARCH and our unicast replies work without any change -- the group entry is needed only so the server can announce itself. Only one peer can hold a given prefix, and wg set does not survive a restart; put it in the config file.
  • Client support varies. Control points built on Cling/jUPnP (BubbleUPnP) register a device from an unsolicited ssdp:alive and work fine this way. Those built on libupnp (VLC for Android) send M-SEARCH out a physical interface regardless of routing, and will not find a server across a tunnel no matter how it is configured. Nothing on the server side can change that.

Where discovery cannot work, skip it: open the HTML browse page, or hand a /media/{id}.ext (one file) or /playlist/{id}.m3u (a whole folder) URL straight to a player.

Running in the background

Add -d and dalain detaches itself:

dalain /data/tv --ip 10.0.0.5 -vv -d --out /tmp/dalain.log --pid /tmp/dalain.pid

Without --out the log goes to /dev/null. The working directory becomes / unless --workdir says otherwise, so keep the paths absolute. SIGTERM shuts it down cleanly.

Running under a supervisor

Without -d dalain stays in the foreground -- let your supervisor handle PID, user, working directory, and restarts. OpenRC init scripts live in scripts/.

systemd (/etc/systemd/system/dalain.service):

[Unit]
Description=dalain DLNA video server
After=network-online.target

[Service]
ExecStart=/usr/local/bin/dalain /data/tv --ip 10.0.0.5 --cache-dir /var/cache/dalain -m
User=dalain
Restart=on-failure

[Install]
WantedBy=multi-user.target

Name

Named after Многорукий бог Далайна (Mnogorukiy bog Dalaina, The Multi-Armed God of Dalain) by Svyatoslav Loginov -- a world built of finite cubes, methodically explored. Fits a media server that walks a filesystem node by node.

Dependencies

dalain has a small, focused dependency list. Each crate has a single job:

  • tokio -- async runtime and primitives (task spawning, channels, TCP/UDP, filesystem, process spawning).
  • parking_lot -- the lock around the catalog. Its critical sections are short and never span an await, so a blocking lock is cheaper than an async one.
  • socket2 -- low-level socket options needed for SSDP (multicast interface selection, SO_REUSEPORT).
  • signal-hook + signal-hook-tokio -- async-friendly Unix signal handling (SIGTERM, SIGINT, SIGHUP, SIGQUIT). Transitive: they come in through logger, not from dalain's own manifest.
  • daemonize -- the forks and session setup behind -d. Transitive as well, through logger.
  • futures -- StreamExt for the inotify event stream and join_all for the SSDP byebye fan-out.
  • clap (with derive) -- command-line argument parsing.
  • askama -- compile-time checked templates for SOAP, DIDL, SSDP and HTTP response bodies.
  • inotify -- filesystem event monitoring for live catalog updates.
  • anyhow -- error propagation with context, instead of a typed error enum per module.
  • logger -- a small in-house logging crate.

Notably absent: no SQLite, no HTTP framework (the HTTP server is hand-rolled), no UPnP library (SSDP is hand-rolled from the spec), no image-processing library (ffmpeg is invoked out-of-process when thumbnails are wanted).

License

MIT

S
Description
Simple dlna server "Многорукий бог Далайна" in Rust
Readme
308 KiB
0 Stars 1 Watchers 0 Forks
Languages
Rust 96.7%
Shell 1.7%
HTML 1.6%