Commit 5ef7b18
DatanoiseTV
fix(hls): carry DTS for B-frame reordering — no more video "boomerang"
The PES header only advertised PTS (PTS_DTS_flags = 0b10), which means
decoders displayed frames in decode order. B-frames in H.264 reference
frames both before and after them in display order, so without a
separate DTS the picture jumps back and forth between the B-frame pair
and the P-frame they reference — the "boomerang" mpv and the web
player were both showing.
Changes:
- Frame struct gains a DTS field (90 kHz). Audio always sets DTS ==
PTS (no B-frames in audio).
- RTMP OnVideo now reads videoTag.CompositionTime (int32 ms, signed)
and splits it into DTS = ts*90, PTS = (ts+comp)*90, matching how
FLV already encodes A/V timing. OBS and most other H.264 RTMP
publishers populate CompositionTime whenever B-frames are
enabled.
- buildPESHeader takes (pts, dts) and emits both when they differ,
using the spec-correct prefix nibbles (0011 for PTS, 0001 for DTS)
via a shared encodePTSWithPrefix helper. When dts == pts it emits
only the 5-byte PTS header exactly as before.
- writeVideoPES now takes a dts parameter and derives PCR from the
lower of DTS/PTS (PCR must never be ahead of any DTS).
- writeAudioPES passes dts == pts (no change in PES size).
- pesUnit in the HLS framed segmenter carries dts too; videoBatch
and audioBatch entries both populate it on frame dispatch.
- MuxAVSegment's legacy byte-buffer path (single PES per segment)
keeps dts == pts since it doesn't have CompositionTime info.1 parent 12dec98 commit 5ef7b18
4 files changed
Lines changed: 84 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
346 | | - | |
| 346 | + | |
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| 351 | + | |
351 | 352 | | |
352 | 353 | | |
353 | | - | |
| 354 | + | |
| 355 | + | |
354 | 356 | | |
355 | 357 | | |
356 | 358 | | |
| |||
407 | 409 | | |
408 | 410 | | |
409 | 411 | | |
410 | | - | |
411 | | - | |
412 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
| 420 | + | |
| 421 | + | |
416 | 422 | | |
417 | 423 | | |
418 | | - | |
| 424 | + | |
| 425 | + | |
419 | 426 | | |
420 | 427 | | |
421 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
76 | 79 | | |
77 | | - | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
| |||
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
138 | | - | |
139 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
140 | 147 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
145 | 155 | | |
146 | 156 | | |
147 | 157 | | |
| |||
232 | 242 | | |
233 | 243 | | |
234 | 244 | | |
235 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
236 | 248 | | |
237 | 249 | | |
238 | 250 | | |
| |||
342 | 354 | | |
343 | 355 | | |
344 | 356 | | |
345 | | - | |
346 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
347 | 363 | | |
348 | 364 | | |
349 | 365 | | |
| |||
352 | 368 | | |
353 | 369 | | |
354 | 370 | | |
355 | | - | |
356 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
357 | 378 | | |
358 | 379 | | |
359 | | - | |
| 380 | + | |
360 | 381 | | |
361 | 382 | | |
362 | 383 | | |
363 | 384 | | |
364 | | - | |
365 | 385 | | |
366 | | - | |
367 | | - | |
368 | | - | |
| 386 | + | |
369 | 387 | | |
370 | 388 | | |
371 | | - | |
372 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
373 | 398 | | |
374 | 399 | | |
375 | 400 | | |
376 | 401 | | |
377 | | - | |
| 402 | + | |
| 403 | + | |
378 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
379 | 414 | | |
380 | | - | |
381 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
382 | 418 | | |
383 | 419 | | |
384 | 420 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
210 | | - | |
| 214 | + | |
211 | 215 | | |
212 | 216 | | |
213 | 217 | | |
| |||
224 | 228 | | |
225 | 229 | | |
226 | 230 | | |
227 | | - | |
| 231 | + | |
228 | 232 | | |
229 | 233 | | |
230 | 234 | | |
| |||
242 | 246 | | |
243 | 247 | | |
244 | 248 | | |
245 | | - | |
| 249 | + | |
246 | 250 | | |
247 | 251 | | |
248 | 252 | | |
| |||
0 commit comments