Skip to content

bug: media-playback: RTSP source never reconnects when the camera goes silent (upstream #12958) #189

Closed

Description

@rdoupe

Upstream OBS bug, reported by canadianlocomotivelogistics in obsproject/obs-studio#12958 (related: obsproject/obs-studio#11537). Code unchanged in this fork.

Location

shared/media-playback/media-playback/media.c:690

	if (!m->is_local_file) {
		av_dict_set(&opts, "stimeout", "30000000", 0);

Class

Logic error: hang with no recovery.

Cause

FFmpeg 5.0 renamed the RTSP demuxer's stimeout option to timeout (default 0, no timeout). avformat_open_input() leaves unknown options unused and OBS frees the dictionary without checking, so RTSP inputs have had no socket timeout on every FFmpeg OBS supports (6.1+). The interrupt callback (media.c:642-656) only aborts on stop/kill.

How it is reached

A Media Source plays an RTSP camera. The camera loses power or the network drops without closing the TCP connection. av_read_frame blocks forever, stop_cb never runs, so media_stopped never sets destroy_media and ffmpeg_source_reconnect never starts. The source stays frozen with nothing in the log.

Reproduced against a localhost mediamtx server: SIGSTOP the server and the source sits at 0 fps for 54 s with no error, over both RTSP/TCP and RTSP/UDP. A clean server restart does reconnect (FFmpeg sees EOF). Workaround today: timeout=5000000 in the source's FFmpeg Options.

Proposed fix and failing test

Fix: for rtsp:///rtsps:// inputs set timeout (≈5 s, microseconds) with AV_DICT_DONT_OVERWRITE, so a user-set value wins. Other protocols use timeout differently, so not blindly for every scheme.

RED test (cmocka, test_media_network_timeout), with the option moved into a small mp_media_set_network_timeouts():

  1. every option set is known to the linked libavformat's RTSP demuxer (av_opt_find): fails on stimeout
  2. RTSP inputs get a socket timeout: fails
  3. a user-set timeout is kept: passes, guards the fix
  4. a fake camera on 127.0.0.1 answers OPTIONS/DESCRIBE/SETUP/PLAY then goes silent; media must stop within 20 s: fails

With the fix, all 4 pass in ~10 s.

Activity

  1. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_media_network_timeout (4 cases above, 3 failing), option moved into mp_media_set_network_timeouts() with no behaviour change.
    2. GREEN: set timeout for RTSP inputs without overwriting user options.
      First PR within a day.
  2. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    @canadianlocomotivelogistics @fzwoch @djcalcutt @dzek69 you reported or hit this in obsproject/obs-studio#12958 / obsproject/obs-studio#11537, so a heads-up: it's fixed here in obs-rust by #193.

    Cause: OBS sets the RTSP option stimeout, which FFmpeg 5.0 renamed to timeout, so RTSP sources have had no read timeout. A camera that drops off without closing the connection leaves the source frozen forever, and nothing is logged.

    Workaround on stock OBS: add timeout=5000000 to the Media Source's FFmpeg Options. The source then gives up on a dead camera after about 10 s and reconnects when it's back.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR.

    If you get a chance to try it, a short reply here on whether it fixes it for you would really help, especially if it does not. Your distro, OBS version and how you capture (camera or server, TCP or UDP) are the useful details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions