Video Streaming from Linux (Shallow Thoughts)

Akkana's Musings on Open Source Computing and Technology, Science, and Nature.

Sat, 13 Jun 2026

Video Streaming from Linux

As part of a set-top video project, I looked into streaming. Just local streaming: we have a fileserver in one part of the house, running Linux, and the set-top box by the TV (also running Linux though that part is less important); how can I stream a video from the fileserver and play it using mpv on the set-top box?

I thought that would be a dead simple question to answer. But there's surprisingly little related to that that shows up in Google's increasingly broken web search, and what I found in the actual documentation for various programs I tried didn't work.

TL;DR It turns out I probably won't be using this, because it's actually much easier just to mount the fileserver's video directory with sshfs and pretend the video files are local files. Still, I'd been curious about how to do video streaming, and I did find several ways to do it. So here's what I learned.

Basic Streaming with ffmpeg

1: ffmpeg stream to a specific machine

The simplest (in terms of no setup) is to stream with ffmpeg to a specific player machine.

On the machine where you want to watch the video, start this first:

mpv --demuxer=lavf --demuxer-lavf-format=mpegts udp://0.0.0.0:8000
(Of course, modify the port as desired.)

Then, on the server, run ffmpeg:

ffmpeg -re -i video.mp4 -c copy -f mpegts udp://RECEIVER_IP:8000

2: ffmpeg TCP stream

You can also use TCP with ffmpeg, which is more general in that you don't have to aim at a specific client. On the server, run:

ffmpeg -re -i video.mp4 -c copy -f mpegts "tcp://0.0.0.0:8000?listen"

Then, on the client, run

mpv tcp://SENDER_IP:8000

Both of these methods work. They're not seekable, though; you just play through from start to finish.

Serve Files with a Mini Web Server

You can also use a mini web server, like the one that comes with Python, to serve a file — but you have to rewrite the video files first to make them seekable, otherwise mpv will complain:

[ffmpeg] Cannot seek backward in linear streams! [ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: stream 0, offset 0x30: partial file
[lavf] error reading packet: Invalid data found when processing input.

   (repeated a bunch of times, then finally)

[lavf] ...treating it as fatal error.
and mpv exits.

Make video files seekable like this:

ffmpeg -i video.mp4 -c copy -movflags +faststart video_fs.mp4

Needing to do that for every file you might want to stream sounds like a pain, and it is. But it actually doesn't take very long: you're not transcoding the whole video into another format, just adding an index (called the "moov atom") to the beginning of the file.

Then, on the server,

cd /path/to/video/directory
python3 -m http.server 8000

Now, on the client, run

mpv http://SENDER_IP:8000
or
mpv http://SENDER_IP:8080/path/to/video_fs.mp4

In what little testing I did, it works pretty well. I could jump forward and backward with mpv's left- and right-arrow controls. But as I mentioned at the beginning, we decided to use sshfs instead. So I don't have any real-world experience on seeking to arbitrary points in a video.

Supposedly seeking works better if you use a "real" media server instead of just a toy http server. But the one most people recommend, jellyfin, isn't in the Debian repositories so you have to download a binary from Jellyfin's own repos (something I'm always reluctant to do for a project I've just heard of).

VLC can apparently stream pretty well, but it's a GUI program and not a great solution for a headless server.

Debian has minidlna, but the protocol it speaks, DLNA, isn't something that mpv knows how to play. (Edit: I didn't mention earlier that I'm tied to mpv for reasons I'll write about in a future article. Apparently minidlna works fine if you can use VLC as your player, and you can use the command-line VLC, cvlc http://SERVER:PORT/path/to/file.mp4 -- thanks, Stevan).

I didn't try any of these servers. Python's http.server seemed to do well enough in the small amount of testing I did.

Happy streaming!

Tags: ,
[ 14:18 Jun 13, 2026    More linux | permalink to this entry | ]

Comments via Disqus:

blog comments powered by Disqus