Termux DLNA Server

Runs on your phone, serves Movies/TV Shows from an SMB share to Kodi over DLNA, transcoding to h264/AAC 720p via h264_mediacodec only when the source file needs it.

Files

Setup

pkg install ffmpeg python
pip install -r requirements.txt
  1. Edit config.py — at minimum: SMB_SERVER, SMB_SHARE, SMB_USERNAME, SMB_PASSWORD, SMB_MOVIES_PATH, SMB_TVSHOWS_PATH. Generate a real UUID for UUID (e.g. python3 -c "import uuid; print(uuid.uuid4())") and keep it stable — Kodi uses it to identify the server across restarts.

  2. Confirm the hardware encoder exists before relying on transcoding:

    ffmpeg -encoders | grep mediacodec
    

    If nothing prints, h264_mediacodec isn’t in your ffmpeg build. Direct-stream playback (files already h264/AAC/720p/mp4-or-mkv) still works fine without it — only transcoding is affected. main.py logs an error at startup if it’s missing but does not refuse to start, since direct-stream is still useful on its own.

  3. Run it:

    python3 main.py
    

    First run does a full library scan before the server starts listening, so expect a delay proportional to your library size and SMB latency.

  4. On Kodi (RPi3): Settings → Media → check “Show unavailable added-on files source” isn’t relevant — instead add a UPnP source, or it should just appear under Videos → Add-ons → UPnP/DLNA devices automatically once SSDP announces.

How playback decisions work

Known gaps / things that will bite you

Testing checklist (in order)

  1. ffmpeg -encoders | grep mediacodec — confirms transcode path is even possible.
  2. Run main.py, check log for “SSDP listening” and “HTTP server listening”.
  3. curl http://<phone-ip>:8200/description.xml from another device — confirms HTTP + description are reachable.
  4. Check Kodi finds it under UPnP devices — confirms SSDP is working across the LAN (multicast can be blocked by some router/AP configs, this is the most likely first failure point).
  5. Browse into Movies/TV Shows in Kodi — confirms SOAP Browse + SQLite library.
  6. Play a file you know is already h264/AAC/720p — confirms direct-stream path, no ffmpeg involved.
  7. Play a file that needs transcoding — confirms ffmpeg pipe path end-to-end.
  8. Play a file with foreign dialogue you expect a forced sub on — confirms CaptionInfoEx + Kodi’s handling of it.