I’m encountering issues with timestamp discontinuities and non-monotonic DTS errors while attempting to multiplex multiple TV programs from an MPEG-TS input stream using FFmpeg.
The input is a live MPEG-TS stream delivered via UDP.
Information about input from ffmpeg:
Input #0, mpegts, from 'udp://192.168.0.20:1236':
Duration: N/A, start: 13165.765389, bitrate: N/A
Program 10352
Metadata:
service_name : MDR Sachsen HD
service_provider: DD
Stream #0:1[0x65]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn
Stream #0:2[0x66](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:3[0x67](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s (visual impaired) (descriptions)
Stream #0:4[0x68](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s (hearing impaired)
Stream #0:5[0x69](deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006), 492x250
Stream #0:6[0x6a](deu): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, stereo, fltp, 448 kb/s
Stream #0:7[0x6b]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:8[0x6c](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
Program 10355
Metadata:
service_name : hr-fernsehen HD
service_provider: DD
Stream #0:13[0xc9]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn
Stream #0:14[0xca](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
Stream #0:15[0xcb](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s (visual impaired) (descriptions)
Stream #0:16[0xcc](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s (hearing impaired)
Stream #0:9[0xcd](deu): Subtitle: dvb_teletext, 492x250
Stream #0:17[0xce](deu): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, 5.1(side), fltp, 448 kb/s
Stream #0:18[0xcf]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:19[0xd0](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
Program 73
Metadata:
service_name : DMAX Austria
service_provider: DD
Stream #0:11[0x12e](deu): Subtitle: dvb_teletext, 492x250
Stream #0:10[0x12d]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 544x576 [SAR 32:17 DAR 16:9], 25 fps, 25 tbr, 90k tbn
Side data:
cpb: bitrate max/min/avg: 15000000/0/0 buffer size: 1835008 vbv_delay: N/A
Stream #0:12[0x12f](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s (clean effects)
Stream #0:20[0x130]: Unknown: none ([5][0][0][0] / 0x0005)
No Program
Stream #0:0[0x12]: Data: epg
The goal is: to map several video and audio streams into a single MPEG-TS output while maintaining a constant bitrate (CBR) of 31668449 bps and outputting to a DVB device.
Say if I map one Program (program_num=10352:title=”MDR Sachsen HD”) with all their streams, like that:
ffmpeg -i "udp://192.168.0.20:1236?fifo_size=10000000&overrun_nonfatal=1&reconnect=1&reconnect_streamed=1&reconnect_delay_max=2"
-map 0:v:i:0x65 -map 0:a:i:0x66 -map 0:a:i:0x67 -map 0:a:i:0x68 -map 0:a:i:0x6a
-program program_num=10352:title="MDR Sachsen HD":st=0:st=1:st=2:st=3:st=4
-ignore_unknown
-c copy -copyts -muxrate 31668449 -f mpegts -y /dev/dvb/adapter0/mod0
It works very well!
But if i try to map multiple programs, each with its own video and audio streams, as follows:
Program 10352: MDR Sachsen HD
- Video: H.264, 1280×720, 50 fps
- Multiple audio streams: MP2 and AC3
Program 73: DMAX Austria
- Video: MPEG2, 544×576, 25 fps
- Multiple audio streams: MP2 and AC3
I encounter errors like:
- Timestamp Discontinuity: Errors indicating mismatches in timestamps
when FFmpeg aligns the streams. - Non-Monotonic DTS: Warnings about DTS
values not being strictly increasing, leading to potential
synchronization issues.
Questions:
- How can I resolve timestamp discontinuities and non-monotonic DTS errors when multiplexing multiple TV channels into a single MPEG-TS stream with FFmpeg?
- Are there specific FFmpeg options or settings that can help synchronize streams with different characteristics?
- Are there alternative tools or approaches for achieving constant bitrate multiplexing of multiple TV channels that might handle these synchronization issues better?
Any insights or suggestions on handling these errors and successfully multiplex multiple TV channels would be greatly appreciated.
I have tried next options (nothing helps thought ):
- async 1 -vsync 1 -> handle synchronization issues by adjusting the audio and video streams to align better.
- copyts -> (copy timestamps) to preserve original timestamps
- fflags:
- +genpts -> flag tells FFmpeg to generate presentation timestamps (PTS) when they are missing.
- +discardcorrupt -> Discards corrupted frames.
- +igndts -> Ignores DTS (Decoding Time Stamps) if present.
- avoid_negative_ts make_zero -> Adjusts the timestamps to avoid negative values.
- mpegts_flags: Configures MPEG-TS specific flags for the output.
- +resend_headers: Resends the PAT/PMT headers periodically.
- +pat_pmt_at_frames: Forces PAT/PMT to be sent at the start of frames.
- +latm: Enables LATM (Low-Level Audio Transport Multiplex).
- pcr_period 20 -> Sets the Periodical PCR (Program Clock Reference) interval in milliseconds.