Camera stream stalls after ~15-30 min (corrupted FLV timestamps) #90
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The
/api/camera/h264and/api/camera/streamendpoints degrade and stall after a variable time (~15-30 min). The FLV source emits valid H264 but with non-monotonic container timestamps (large PTS jumps). When ffmpeg's live transcoding hits one of these jumps, its realtime timestamping breaks and output collapses, stalling the stream.The video data itself is fine; only the container timestamps are broken. Verified by capturing the source directly (not through the bridge):
curlsaves the raw FLV to a file, and decoding that file afterwards withffmpeg -f null -completes with zero errors.Steps to Reproduce
/api/camera/h264or/api/camera/streamand leave it running.Expected Behavior
Stream stays stable for hours regardless of the source's corrupted timestamps.
Actual Behavior
MJPEG becomes choppy and stalls; H264 stops producing frames with the connection still open. H264 frames produced in 1h of wall-clock: 9572 without fix vs 28694 with the fix below.
invalid dropping/ non-monotonic DTS messages appear only without the fix.Out-of-phase timestamps in the raw source capture (
ffprobeon thecurldump, PTS in seconds):Proposed Fix
Add
-use_wallclock_as_timestamps 1to the non-RTSP input args. InCameraCache._input_args:handle_camera_streambuilds its ffmpeg input args locally instead of using_input_args, so the same flag needs to be added there as well for the MJPEG endpoint.Environment
Related question: 429 on
/api/camera/streamDuring testing I repeatedly hit HTTP 429 from the printer.
handle_camera_streamspawns a dedicated FLV ffmpeg per request, so each MJPEG client opens its own FLV connection to the printer. Would it be possible to route/api/camera/streamthrough theCameraCachefanout (as/api/camera/h264already does), so all MJPEG clients share the single FLV connection?Thanks for the excellent write-up and root-cause analysis. Applied your proposed fix (
-use_wallclock_as_timestamps 1on both theCameraCacheFLV input and the MJPEG endpoint inhandle_camera_stream) — will be included in the next nightly build.The fanout suggestion for
/api/camera/stream(routing MJPEG through the sharedCameraCacheconnection instead of a per-client FLV connection) makes sense too and would address the 429s you saw. Tracking that separately as it is a bigger architectural change than the timestamp fix.