M2: BuildArgs assumes single combined AV input — -map 0:v:0/-map 0:a:0 hardcoded #2

Closed
opened 2026-05-03 01:04:37 -04:00 by zgaetano · 0 comments
Owner

Context

Found while running an end-to-end WHEP smoke test against the live M2 deploy on TrueNAS (commit 0417aff).

What's wrong

app/webrtc/ffmpeg_args.go BuildArgs emits the two RTP legs with hardcoded stream maps:

-map 0:v:0 -c:v ... -f rtp udp://...
-map 0:a:0 -c:a libopus ... -f rtp udp://...

Correct for production: an RTMP or SRT publisher arrives as a single muxed input where stream 0:v:0 and 0:a:0 are both valid. Breaks for any process whose audio lives on a different input index (multi-input pipelines, lavfi test sources). FFmpeg dies before WebRTC sources can receive:

Stream map '0:a:0' matches no streams.
Failed to set value '0:a:0' for option 'map': Invalid argument
Error opening output files: Invalid argument

Repro

Process JSON with two lavfi inputs and a base output that maps them:

{
  "id":"smoke-multi","autostart":true,
  "input":[
    {"id":"vid","address":"testsrc2=size=320x180:rate=15","options":["-f","lavfi","-re"]},
    {"id":"aud","address":"sine=frequency=440","options":["-f","lavfi","-re"]}
  ],
  "output":[{"id":"out0","address":"-","options":["-map","0:v:0","-map","1:a:0","-c:v","libx264","-c:a","libopus","-f","null"]}],
  "webrtc":{"enabled":true,"force_transcode":true}
}

state.command shows the user's -map 1:a:0 is fine, but the appended WebRTC leg uses -map 0:a:0 which doesn't exist on input #0.

Proposal (M3)

ConfigWebRTC gains explicit map selectors:

type ConfigWebRTC struct {
    Enabled        bool   `json:"enabled"`
    VideoPT        uint8  `json:"video_pt,omitempty"`
    AudioPT        uint8  `json:"audio_pt,omitempty"`
    ForceTranscode bool   `json:"force_transcode,omitempty"`
    VideoMap       string `json:"video_map,omitempty"` // default "0:v:0"
    AudioMap       string `json:"audio_map,omitempty"` // default "0:a:0"
}

BuildArgs reads these instead of constants. UI exposes both as advanced settings; the default still works for RTMP/SRT.

Severity

Soft — production RTMP/SRT inputs are unaffected. Test scaffolding and atypical pipelines hit it. Tracked as M3 robustness.

## Context Found while running an end-to-end WHEP smoke test against the live M2 deploy on TrueNAS (commit `0417aff`). ## What's wrong `app/webrtc/ffmpeg_args.go` `BuildArgs` emits the two RTP legs with hardcoded stream maps: ``` -map 0:v:0 -c:v ... -f rtp udp://... -map 0:a:0 -c:a libopus ... -f rtp udp://... ``` Correct for production: an RTMP or SRT publisher arrives as a single muxed input where stream `0:v:0` and `0:a:0` are both valid. Breaks for any process whose audio lives on a different input index (multi-input pipelines, lavfi test sources). FFmpeg dies before WebRTC sources can receive: ``` Stream map '0:a:0' matches no streams. Failed to set value '0:a:0' for option 'map': Invalid argument Error opening output files: Invalid argument ``` ## Repro Process JSON with two lavfi inputs and a base output that maps them: ```json { "id":"smoke-multi","autostart":true, "input":[ {"id":"vid","address":"testsrc2=size=320x180:rate=15","options":["-f","lavfi","-re"]}, {"id":"aud","address":"sine=frequency=440","options":["-f","lavfi","-re"]} ], "output":[{"id":"out0","address":"-","options":["-map","0:v:0","-map","1:a:0","-c:v","libx264","-c:a","libopus","-f","null"]}], "webrtc":{"enabled":true,"force_transcode":true} } ``` `state.command` shows the user's `-map 1:a:0` is fine, but the appended WebRTC leg uses `-map 0:a:0` which doesn't exist on input #0. ## Proposal (M3) `ConfigWebRTC` gains explicit map selectors: ```go type ConfigWebRTC struct { Enabled bool `json:"enabled"` VideoPT uint8 `json:"video_pt,omitempty"` AudioPT uint8 `json:"audio_pt,omitempty"` ForceTranscode bool `json:"force_transcode,omitempty"` VideoMap string `json:"video_map,omitempty"` // default "0:v:0" AudioMap string `json:"audio_map,omitempty"` // default "0:a:0" } ``` `BuildArgs` reads these instead of constants. UI exposes both as advanced settings; the default still works for RTMP/SRT. ## Severity Soft — production RTMP/SRT inputs are unaffected. Test scaffolding and atypical pipelines hit it. Tracked as M3 robustness.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: zgaetano/datarhei-dragonfork-core#2
No description provided.