Ramesh Inampudi

Media

LanTv: Turn Local Media Folders into Shuffled TV Channels

By Ramesh Inampudi · 2026-10-29 · 4 min read

Having a large local media library is great until you sit down to watch something. You scroll, you pick an episode, you seek, you change your mind. I wanted the opposite: a TV that is already playing something when you turn it on. LanTv is my answer. It turns folders of movies and shows into always-on, randomly shuffled channels that any device on my home network can tune into.

Why I built it

The idea was simple. I have folders such as GOT, LOTR, a dump of new releases and a big mixed library called IRMAX. I did not want to reorganize any of it. I wanted each folder to behave like a channel on a real TV: no menu, no choosing an episode, just tune in and watch whatever is on.

I also wanted it to work on whatever screen was nearby: a laptop browser, VLC, or an Android phone or TV box. That meant the output had to be something every one of those clients already understands, which pointed me to HLS.

What it does

You point each channel at one or more folders in a config.json file. Every channel then gets its own shuffled, effectively infinite playlist.

How it works

The server is Node.js plus ffmpeg, running on a Mac. The Android app is a Kotlin wrapper around the same browser player, so there is only one player to maintain. The web player itself is plain JavaScript and HTML.

One state machine per channel

Each channel, implemented in src/channel.js, follows the same loop:

  1. Scan the configured folders recursively, filtering by file extension and skipping excluded directory names such as recycle bins.
  2. Shuffle the file list with a Fisher-Yates shuffle into a queue.
  3. Play by popping one file, checking with ffprobe whether it is HDR, and spawning ffmpeg to transcode it in real time into the channel's HLS output.
  4. Advance when ffmpeg exits, whether the file ended or was skipped, by starting the next file immediately.
  5. Idle-pause through a background timer in src/server.js that stops ffmpeg if nobody has requested the stream within idleStopSeconds. The next request lazily restarts it.

Making many files look like one stream

The trick that makes this feel like TV is the -hls_flags append_list option. Instead of starting a fresh HLS stream for every file, segments keep accumulating into one continuous live playlist at hls/<id>/stream.m3u8. A player sees one unbroken live stream, and the file boundaries are invisible to it. Only one ffmpeg process runs per channel at a time, one file after another.

Why transcode at all

Source files vary wildly in codec, resolution and dynamic range. Transcoding in real time into a uniform HLS stream means any client can play any channel. On macOS I use VideoToolbox hardware encoding, so even 4K sources transcode faster than real time. The lazy start and idle stop matter for the same reason: without them I would be running a separate encode per channel around the clock for a single viewer.

HDR tonemapping

Simply stripping HDR metadata leaves the picture washed out. LanTv uses the zscale and zimg filters from Homebrew's ffmpeg-full package to do proper tonemapping to SDR. That package installs keg-only, so it can sit next to a regular ffmpeg. If it is missing, LanTv falls back to plain ffmpeg and HDR sources will look dull.

A link that keeps working

Bookmarking an IP address on a home network is fragile, since DHCP leases change. LanTv prints a Bonjour/mDNS hostname of the form <name>.local, which survives Wi-Fi switches and router reboots. On the Mac, caffeinate keeps the machine from sleeping.

What I learned

Conclusion

LanTv is a small server that does one thing: it makes a pile of folders behave like TV channels. The useful parts are reusable beyond this project: one state machine per stream, lazy start with idle shutdown, appending to a single HLS playlist across files, and a stable .local hostname. If you run something similar on your own network, I would start with those four ideas. Questions or feedback can go to hello@iramesh.com.