jwz

RTMP / HLS segment corruption


Listen Later

Dear Lazyweb,

When my internal video encoder machine relays its RTMP stream to the external public server, MPEG glitches get introduced, and I would like to know how to fix that.

I am hoping for answers from someone who actually understands how RTMP transports and reconstitutes MPEG frames, or who knows how to take these TS files apart and identify why they are glitching.

(I shouldn't have to say this but I do: If your suggestions are more along the lines of, "Have you tried changing this magic number in the config file?" without a coherent theory of why, then your suggestions are almost certainly unhelpful. Likewise, "Why don't you just..." ← not the question I asked.)

Details:

  • Both machines are running nginx-1.17.10 and nginx-rtmp-module Feb 2022.

  • Internal machine runs OBS 31.0.3 streaming to rtmp://localhost/live/

  • Internal nginx rtmp is configured like so. Notably, hls_fragment 10s, hls_playlist_length 30s.

  • External nginx rtmp is configured like so. Notably, hls_fragment 6s. Why are they different? I don't remember. At some point I thought that seemed to improve... something.

Here are some example TS files covering approximately the same time range from the internal and external streams. The the internal ones play fine; the external ones contain glitches.

The first handclap happens at around 6s in the internal stream, and 3s in the external, so if you plot the segments on a timeline, it looks like this. Asterisks indicate glitches. They don't correlate well to segment changes in either the internal or external streams.

= 00 ext 1: 1748393053750.ts | 01 | 02 = | 03 int 1: 1748393056339.ts | | 04 | | 05 | = 06 ext 2: 1748393061627.ts (handclap) | | * 07 | | * 08 | | * 09 | | * 10 | | 11 | = 12 ext 3: 1748393066847.ts = | 13 int 2: 1748393066342.ts | | 14 | | 15 | | * 16 | | * 17 | = 18 ext 4: 1748393073414.ts | | 19 | | 20 | | 21 | | 22 = | 23 int 3: 1748393076343.ts | = 24 ext 5: 1748393079981.ts | | 25 | | 26 | | 27 | | * 28 | | * 29 | = 30 ext 6: 1748393086982.ts | | 31 | | 32 = | * 33 int 4: 1748393086341.ts | | * 34 | | * 35 | = * 36 ext end | 37 | 38 | 39 | 40 | 41 = 42 int end

Another thing that I don't understand, which is probably unrelated: when I pack these TS files into an MP4 with:

ffmpeg -f concat -i concat.txt -c copy out.mp4

the audio de-synchronizes by like half a second. Why?

Previously, previously, previously.

...more
View all episodesView all episodes
Download on the App Store

jwzBy