Media sources
Manage one-based source slots that publish assigned media over RTSP or HTTP MJPEG. A normal workflow is list videos โ assign a slot โ start it โ inspect state โ stop it before changing or deleting media.
List assignable media files
Returns a flat, sorted list of media-library paths whose extensions are supported by the source streamer. Use these exact relative paths in the assignment endpoint; the broader media tree can contain files that are inspectable but not streamable.
Get source assignments and playback state
Returns every configured one-based source slot with its assigned file, persisted playback state, detected codec, selected transport, compatible transports, and ready-to-use stream URLs. Read this endpoint before mutating sources so automation can avoid unnecessary restarts and choose a compatible transport.
Assign or clear one source slot
Assigns a media-library path to one one-based source slot. Send an empty `file` value to clear the slot. Insight probes the media, normalizes the requested transport to one supported by the detected codec, persists the assignment, and automatically restarts the source when it was already playing. Obtain valid paths from `/api/mediasrc/videos`. Returns 409 when an external publisher holds the slot and Insight has no stream of its own on it; use `/api/mediasrc/takeover` first. Returns 409 while Insight pulls a network stream into the slot; use `/api/mediasrc/stop` first.
Register one source slot for a browser webcam
Marks one one-based source slot as a browser-published webcam and returns the WHIP URL the browser posts its WebRTC offer to. Unlike `/api/mediasrc/assign`, Insight does not start a publisher itself: the browser publishes the camera over WHIP to an internal ingest path, MediaMTX normalizes it to baseline H.264 with regular keyframes and republishes it on the `urls.rtsp` path (the same shape a file source produces, so detection apps and hardware decoders can consume it directly), and `/api/mediasrc/start` only confirms that the stream arrived. Any file assignment on the slot is cleared, and a playing file source is stopped first. The returned `urls.whip` host and port already account for SDK port remapping, so use it exactly as returned.
Assign available videos to source slots
Convenience operation for test setup. Insight stops every active source, walks the sorted assignable-video list, assigns unique files to source slots in index order, persists the result, and leaves all slots stopped. A slot whose file changes loses its `fps` override, exactly as with a manual assign. Call the bulk-start endpoint afterward when playback should begin. Slots held by an external publisher are skipped and listed in `skipped_external`. Slots Insight is pulling a network stream into are skipped too and listed in `skipped_pulled`.
Start one source
Starts streaming the file assigned to one one-based source slot and persists its state as `playing`. The slot must exist and have a valid assignment. Repeated calls are safe for normal control flows, but callers should inspect `/api/mediasrc` when they need to distinguish newly started from already-running sources. Returns 409 when an external publisher holds the slot and Insight has no stream of its own on it; use `/api/mediasrc/takeover` first. Returns 409 while Insight pulls a network stream into the slot; use `/api/mediasrc/stop` first. When the slot has an `fps` that differs from the media's native frame rate, the matching rendition is created (synchronously, without progress output) or reused before the stream starts; use `/api/mediasrc/prepare` first to observe progress. Because that preparation can take minutes, the slot is re-read afterwards; if another request stopped, reassigned, reset or unassigned it meanwhile, or an external publisher took the slot, the start is abandoned with 409 and nothing is persisted. A start for a slot that a concurrent start already launched succeeds without changing anything.
Prepare the FPS rendition for one source
Creates or reuses the constant-frame-rate rendition that `/api/mediasrc/start` will stream when the slot's `fps` differs from the media's native frame rate. Streams plain-text progress: `Encoding <file> at <fps> fps (<encoder>)...`, `progress <seconds>/<total>` lines, then one of `Rendition ready: <path>`, `Reusing rendition: <path>`, `Source frame rate matches; no rendition needed.` or `Error: <message>`. Renditions are keyed by source content hash, fps, codec and profile, so replacing a source file never reuses an old rendition, while byte-identical files share one rendition that survives until the last of them is deleted or replaced. `/api/mediasrc/start` performs the same preparation without progress output when it is skipped. Returns 409 while Insight pulls a network stream into the slot; use `/api/mediasrc/stop` first.
Get cached FPS rendition disk usage
Returns how many FPS renditions are currently stored under `.renditions/` in the media directory and how many bytes they occupy. Rendition records whose file is missing are pruned before counting.
Delete cached FPS renditions
Deletes every stored FPS rendition file and record, except a rendition that a currently playing source is streaming. Renditions are re-created on the next start that needs them.
Start multiple assigned sources
Targets the first `count` assigned source slots in index order and starts each one independently. The result separates newly started slots, slots that were already running, and per-slot failures, allowing test automation to continue with partial success while preserving detailed diagnostics.
Stop one source
Stops the process backing one source slot and persists its state as `stopped` without clearing the assigned file. The same slot can subsequently be started again without reassignment. Returns 409 when an external publisher holds the slot and Insight has no stream of its own on it; use `/api/mediasrc/takeover` first. Stopping a pulled slot releases the pull and restores the stored file assignment.
Stop every source
Stops all running source processes while preserving their file assignments and transport choices. Use this before deleting media, changing a group of assignments, or shutting down a test; the response reports how many sources were previously playing. The external stream on a slot held by an external publisher is left running and the slot is listed in `skipped_external`. A network stream Insight pulls into a slot is stopped like a file source: the slot returns to its previous file assignment and is listed in `stopped_pulled`, and counts toward `stopped_count`. A pull still being set up, or one MediaMTX did not confirm cleared, keeps running and is listed in `skipped_pulled`; stop it again later.
Reset all source assignments
Returns source management to its initial state by stopping every source and rewriting the persisted slot configuration with empty assignments. This is destructive configuration cleanup; use `stop-all` instead when assignments should be retained. The stored record of every slot is cleared, including a slot held by an external publisher; that external stream is left running and its slot is listed in `skipped_external`. A network stream Insight pulls into a slot is stopped like a file source and the slot is listed in `stopped_pulled`. A pull still being set up, or one MediaMTX did not confirm cleared, keeps running and is listed in `skipped_pulled`; stop it again later. Its stored record is cleared either way.
Disconnect the external publisher holding a slot
Kicks the non-Insight publisher currently holding one source slot through the mediamtx control API. Readers of that stream are disconnected too. Afterwards the slot reports its persisted state again and can be assigned and started. Idempotent when the publisher already left. Returns 409 while Insight pulls a network stream into the slot; use `/api/mediasrc/stop` first.
Pull an existing RTSP stream into a slot
Points the slot's mediamtx path at a stream that already exists on the network (an IP camera, another server) so applications read it at `rtsp://โฆ/srcN`. The packets are forwarded unchanged. Only `rtsp://` and `rtsps://` URLs are accepted; credentials go in `username`/`password` or in the URL and never appear in any response. Insight checks the camera once before configuring the pull: rejected credentials answer 400 with `reason: 'auth_failed'` and nothing is configured; an unreachable camera still configures the pull (status `unreachable`) and the slot recovers by itself. The pull is session-only and needs the loopback mediamtx control API.
Stream an active HTTP MJPEG source
Relays the live multipart MJPEG output for a source slot configured with HTTP transport. The source must be assigned, started, and actively producing frames; RTSP sources are not converted by this route. The response remains open until the client disconnects or the source stops.
Get one frame from an active HTTP MJPEG source
Waits for and returns a single JPEG frame from an active HTTP MJPEG source. This is useful for thumbnails, readiness checks, and test assertions without maintaining a streaming connection. A stopped or non-HTTP source returns a conflict, and a frame acquisition timeout returns `504`.
MJPEG preview of a live slot
Multipart MJPEG rendering of whatever is currently published on one slot, external or Insight-owned, scaled to at most 640 px wide and following the source frame rate. The ffmpeg reader runs only while the HTTP connection is open. At most 4 previews run concurrently.