Big latency when using mpegtsmux

Hello,

I’m streaming H264 video over RTP. And the latency is fine for me. Around 250ms.

But when I add a muxer, mpegtsmux, the output latency is enormous. Around 1.2 seconds.

What could be causing this?

Not sure for your case, though if it can help, you may try:

  • On receiver side if using gstreamer, setting tsdemux property latency (default value is 700 ms for audio/video synchro, not needed here).
  • On sender side setting mpegtsmux property latency (and if UDP transport is expected, unsure for other use cases, setting property alignment to 7).

Thanks for your answer.

I tried the second solution.The problem is the same :(.

For tsdemux, on my client the property latency is not available. this means that latency is default ?

"Element Properties:
-name : The name of the object
flags: readable, writable
String. Default: “tsdemux0”

-parent : The parent of the object
flags: readable, writable
Object of type “GstObject”

-parse-private-sections: Parse private sections
flags: readable, writable
Boolean. Default: true

-program-number : Program Number to demux for (-1 to ignore)
flags: readable, writable
Integer. Range: -1 - 2147483647 Default: -1

-emit-stats : Emit messages for every pcr/opcr/pts/dts
flags: readable, writable
Boolean. Default: false
"

Sorry, I can’t tell about your case. Seems you’re running an old gstreamer version.
What gives ?

gst-inspect-1.0 --version

You may also tell the platform you’re running on.

For old versions, I may not be able to further advise, though I’m sure that some gstreamer developers here may be able to better help, otherwise have a look yourself to gstreamer source code improvements.

So I’d just advise to build a more recent gstreamer version if possible.

When done or for other users getting into this question, just here streaming with RTSP to localhost, I measured around 130 ms additional latency for streaming as RTP/MP2T using gstreamer-1.20.

  1. Python RTSP server for RTP/MP2T to be saved as test_RTSP_latency.py (assuming you’ve installed gst rtsp server):
# Note that this example is streaming to localhost so near zero latency can be achieved. 
# You might get best latency benchmarking your real case with different latency targets. 

import gi
gi.require_version('Gst','1.0')
gi.require_version('GstRtspServer','1.0')
from gi.repository import GLib, Gst, GstRtspServer

Gst.init(None)
mainloop = GLib.MainLoop()
server = GstRtspServer.RTSPServer()
mounts = server.get_mount_points()
factoryMp2t = GstRtspServer.RTSPMediaFactory()
# This pipeline would send test video with timeoverlay to both local display and stream as RTP/MP2T to RTSP server clients (would require a client to connect for starting displays)
factoryMp2t_pipeline = ('\
videotestsrc is-live=1 pattern=ball ! video/x-raw,width=640,height=480,framerate=30/1,format=NV12 ! timeoverlay font-desc="Sans,48" ! tee name=t \
t. ! queue leaky=2 ! autovideoconvert ! autovideosink \
t. ! queue leaky=2 ! x264enc tune=zerolatency key-int-max=30 insert-vui=1 ! h264parse ! queue ! mpegtsmux latency=0 alignment=7 ! rtpmp2tpay name=pay0')
factoryMp2t.set_launch(factoryMp2t_pipeline)
mounts.add_factory("/test_rtp-mp2t", factoryMp2t)
server.attach(None)
print ("stream ready at rtsp://127.0.0.1:8554/test_rtp-mp2t")
mainloop.run()
  1. Start RTSP server:
python3 test_RTSP_latency.py
  1. In an other terminal, launch RTSP client:
gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test_rtp-mp2t latency=0 ! queue ! rtpmp2tdepay ! tsdemux latency=0 ! decodebin ! queue ! autovideoconvert ! autovideosink
  1. When both videos are playing, you may try a screen shot and look at time difference for evaluating the streaming latency overhead.