You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Claude 39700129ec
MediaMtx: use dr_frucht's JsonCpp instead of nlohmann/json
22 hours ago
..
internal MediaMtx: use dr_frucht's JsonCpp instead of nlohmann/json 22 hours ago
.gitignore MediaMtx: C++ replacement for the MediaMTX parts la_mojo uses 22 hours ago
LICENSE.mediamtx MediaMtx: C++ replacement for the MediaMTX parts la_mojo uses 22 hours ago
README.md MediaMtx: use dr_frucht's JsonCpp instead of nlohmann/json 22 hours ago
main.cpp MediaMtx: C++ replacement for the MediaMTX parts la_mojo uses 22 hours ago
makefile MediaMtx: use dr_frucht's JsonCpp instead of nlohmann/json 22 hours ago
mediamtx.paths.example MediaMtx: C++ replacement for the MediaMTX parts la_mojo uses 22 hours ago
mediamtx.service.example MediaMtx: C++ replacement for the MediaMTX parts la_mojo uses 22 hours ago

README.md

MediaMtx (C++)

A C++ replacement for the parts of MediaMTX that la_mojo uses:

  • RTSP pull of the camera streams (live555), H264 video, TCP or UDP, automatic reconnect
  • WebRTC / WHEP playback in the browser on port 8889 (libdatachannel) - the same URLs as MediaMTX: POST http://<host>:8889/stream_N/whep, so mojo_dashboard.js works unchanged
  • Recording as fragmented MP4 segments (the camera's H264 as it is, no transcoding) that a browser plays with <video src=...>; same file names as MediaMTX: recordings/stream_N/2026-12-02_16-58-35-953775.mp4
  • a control API with the MediaMTX v3 URLs for paths (/v3/paths/list, /v3/config/paths/add/...)

Not included (MediaMTX has them): RTSP/RTMP/HLS/SRT servers, publishing, audio, H265, authentication, playback server, metrics. The source keeps MediaMTX's module layout, so they can be added the same way.

MediaMTX is MIT licensed (see LICENSE.mediamtx); this is a rewrite of its design, not a copy of its code.

Layout

MediaMtx (C++) MediaMTX (Go)
main.cpp main.go
internal/core/core.* internal/core/core.go
internal/core/pathManager.*, path.* internal/core/path_manager.go, path.go
internal/conf/conf.* internal/conf
internal/logger/logger.* internal/logger
internal/stream/stream.* internal/stream
internal/unit/unit.h internal/unit
internal/staticsources/rtsp/rtspSource.* internal/staticsources/rtsp
internal/servers/webrtc/* internal/servers/webrtc
internal/recorder/* internal/recorder
internal/api/api.* internal/api
internal/protocols/httpp/httpServer.* internal/protocols/httpp
internal/codecs/h264/h264.* mediacommon/pkg/codecs/h264

Data flow: RtspSource -> Path -> Stream -> readers (WebrtcSession, Recorder). Every reader has its own queue and thread (AsyncReader): a slow browser or disk never stalls the camera or the others; an overflowing reader drops units and continues at the next IDR.

Build

Dependencies:

  • live555 - the same as for la_mojo (pkg-config live555); old (char volatile) and new (std::atomic_char) event loop variables both build
  • libdatachannel >= 0.20 (not packaged in Ubuntu 24.04):
    git clone --branch v0.22.6 https://github.com/paullouisageneau/libdatachannel
    cd libdatachannel && git submodule update --init --depth 1 deps/plog deps/libjuice
    sudo apt install libsrtp2-dev libusrsctp-dev libssl-dev cmake
    cmake -B build -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_SRTP=ON -DUSE_SYSTEM_USRSCTP=ON -DNO_EXAMPLES=ON -DNO_TESTS=ON -DNO_WEBSOCKET=ON
    cmake --build build -j8 && sudo cmake --install build && sudo ldconfig
    
  • OpenSSL
  • JSON: JsonCpp of dr_frucht (lib/include/json, lib/data/json), compiled in by the makefile
make               # Release/mediamtx
make CFG=Debug     # Debug/mediamtx

Other library locations: make LIVE555_CFLAGS=... LIVE555_LIBS=... DATACHANNEL_CFLAGS=-I... DATACHANNEL_LIBS="-L... -ldatachannel"

Run

No mediamtx.yml. Global settings are command line options (MediaMTX names), the streams are in a paths file:

# name     source                                    options
stream_3   rtsp://user:pass@10.0.0.5:554/stream1     record=yes transport=tcp
stream_4   rtsp://10.0.0.6/live                      record=no  transport=udp
mediamtx --paths /srv/etc/mediamtx.paths --logFile mediamtx.log \
         --recordPath ./recordings/%path/%Y-%m-%d_%H-%M-%S-%f --recordSegmentDuration 60s
  • kill -HUP <pid> reloads the paths file: only added / removed / changed paths restart
  • the API changes paths at once and writes the paths file:
    curl -X POST  -d '{"source":"rtsp://10.0.0.5/s1","record":true}' http://127.0.0.1:9997/v3/config/paths/add/stream_3
    curl -X PATCH -d '{"record":false}' http://127.0.0.1:9997/v3/config/paths/patch/stream_3
    curl -X DELETE http://127.0.0.1:9997/v3/config/paths/delete/stream_3
    curl http://127.0.0.1:9997/v3/paths/list
    
  • http://<host>:8889/stream_3/ is a small player page
  • mediamtx --help lists all options (WebRTC ICE servers, UDP port range, timeouts, ...)

Log lines have the MediaMTX format that kernelHelperMediaMTX parses, e.g.

2026/12/02 17:00:30 INF [path stream_3] [RTSP source] ready: 1 track (H264)
2026/12/02 17:00:30 INF [path stream_3] stream is available and online, 1 track (H264 640x360)
2026/12/02 17:00:20 ERR [path stream_3] [RTSP source] no data for 10 s

Network

  • WebRTC media uses UDP ports 8189-8289 (--webrtcUDPPorts); open them like 8889/tcp.
  • Behind NAT give a STUN server (--webrtcICEServers stun:stun.l.google.com:19302), so the answer carries the public address.

Tested

With a GStreamer RTSP test camera (H264 640x360, 25 fps) and Chromium:

  • WHEP with the dashboard's code (offer without trickle) and with the player page: video plays; DELETE ends a session; a closed browser is detected (ICE timeout, ~25 s)
  • camera down: no data for 10 s, sessions closed, recording closed; camera back: reconnect, recording continues, the player page reconnects
  • recordings: every segment starts with an IDR, exact length (10 s = 250 frames), decodes with ffmpeg and plays to the end in Chromium, also the segment cut by a shutdown
  • API add / patch / delete, paths file written, SIGHUP reload
  • AddressSanitizer + UBSan build through all of the above: no reports