Reduce the delay while live streaming when pushing the rtsp stream through ffmpeg over tcp by using Wowza Streaming Engine with h.264 video encoder

Hi Guys,

I am using Wowza Streaming Engine Cloud with the low-latency for live streaming the rtsp stream which is pushed through ffmpeg over tcp.

Here I am using hardware h.264 encoder. When I start streaming the video from my android application with the possible low delay until viewing the live stream in the player, it gives me 2 second delay. But after some time the delay becomes 5-6 second. And sometimes it also goes up to 15 seconds or more.

I have also tired by using the -tune zerolatency and nobuffer flag in ffmpeg command as shown below:

ffmpeg -fflags nobuffer -use_wallclock_as_timestamps 1 -loglevel quiet -f h264 -thread_queue_size 8 -r 20 -i /sdcard//LiveStreaming_FIFO_360.264 -f aac -thread_queue_size 8 -i /sdcard//LiveStream_Audio_FIFO_360.aac -acodec copy -vcodec copy -tune zerolatency -b:a 15k -ar 16000 -ac 1 -rtpflags latm -f rtsp -rtsp_transport tcp -y rtsps://url

Please help me out how can I reduce the delay up to 2-3 seconds.

Thanks,

Naisargi.

Hi @Naisargi Mehta, thanks for reaching out. For clarity, you are saying that you are streaming from an android device and that it starts out with low latency of around 2 seconds, but continues to go up. Do you have consistent bandwidth and internet?

Are you transcoding at all or just pushing the single bitrate stream through?

Also, when you say you are using Streaming Engine Cloud, we have a few ways to do that. Can you tell us how you are doing that exactly?

Any additional details you can provide will be very helpful.

Thank you.

Hi @Rose Power-Wowza Community Manager,thanks for your reply. Yes it’s true that I am streaming from an android phone and that it starts out with the low-latency of around 2 seconds, and then after some time the delay reaches up to 5-6 seconds that depends upon the network connectivity. If the internet is consistent then the delay is of 2-3 seconds, but if the internet connectivity is low then delay reaches up to 5-6 seconds. And if again internet is low then delay increases to 9 seconds. After all these if internet becomes stable then also the stream comes with the 9 seconds delay. After this stable internet again if internet goes low the delay increases to 15 seconds. And it continues to stream with the 15 seconds delay even if now the internet is stable.

I am just pushing the single bitrate stream on wowza streaming Engine.

Actually I have purchase the Wowza Streaming Engine with the low-latency and we push the stream by tcp on that URL only.

This is the URL we got after making account :
rtsp://vvdn:vvdn@35.154.177.236:1935/heri_icam_test/myStream
And this is the URL after applying secure token :
rtsps://stage.obotworld-videoplatform.com:443/hero-iot-live/6b7a25c0-08e2-4401-af7c-edfd12baefaa_LOW?wowzatoken=d7ijFRX99XhRXWzkGyHalVUOR98jwNQGOXdztLmmILvATpdolqCl6l1yVDcmKSFWPw5bw7hlWHjW33jwCe72mdRkVW4qE9MIWdf7IEHzbqAEz+yv4qijOituVei9RgKl&sessionId=497abdaa-5a70-4406-a488-6fce887a600f

And below is the whole command I used to push the stream:

ffmpeg -fflags nobuffer -use_wallclock_as_timestamps 1 -loglevel debug -f h264 -thread_queue_size 8 -r 20 -i /sdcard//LiveStreaming_FIFO_360.264 -f aac -thread_queue_size 8 -i /sdcard//LiveStream_Audio_FIFO_360.aac -acodec copy -vcodec copy -tune zerolatency -b:a 15k -ar 16000 -ac 1 -rtpflags latm -f rtsp -rtsp_transport tcp -y rtsps://stage.obotworld-videoplatform.com:443/hero-iot-live/6b7a25c0-08e2-4401-af7c-edfd12baefaa_LOW?wowzatoken=d7ijFRX99XhRXWzkGyHalVUOR98jwNQGOXdztLmmILvATpdolqCl6l1yVDcmKSFWPw5bw7hlWHjW33jwCe72mdRkVW4qE9MIWdf7IEHzbqAEz+yv4qijOituVei9RgKl&sessionId=497abdaa-5a70-4406-a488-6fce887a600f

One thing I would like to clear that how the frames are coming and its flow.

From the camera sensor the frames are encoded by the h.264 hardware encoder. Then these frames are write into fifo. And at last from the fifo these frames are push into wowza by using ffmpeg with tcp.

Please ask me if any more details I can provide you that I have forget to mention here.

Thanks @Naisargi Mehta- I really appreciate that. Have you tried doing adaptive bit rate streaming (ABR) where different stream files are created by the Engine transcoder for different bandwidths? This will automatically switch the stream in the player to either a higher or lower bitrate stream to keep the delivery consistent for the viewer in varying internet conditions.

You can create adaptive bit rate streams right there in the Engine manager.

You can test it out with our sample here:

https://www.wowza.com/docs/how-to-do-adaptive-bitrate-streaming

We have a video tutorial there also.

Here is a blog for you on how this is a great solution in varying internet conditions:

https://www.wowza.com/blog/adaptive-bitrate-streaming-using-wowza-streaming-engine

Let me know if that improves your changing latency situation. Thanks!

Hi @Rose Power-Wowza Community Manager thanks for your wonderful reply. Sorry to say but here I am getting delay in 400 kbs also. If I stream continuously with 640x360 resolution and then internet speed goes low, the delay increases.

So, please can you suggest me another solution.

Thanks.

Hi Naisargi, the problem will occur because of both publisher & watcher.

  • Are you sure about the problem related with publisher buffersize & bandwidth ?
    If yes, question is did you try giving buffer size instead of nobuffer and also keyframe interval parameter in ffmpeg? if device does not have enough bandwidth to send the data, then the next input from camera is ordering in queue even if nobuffer flag given. Therefore giving smaller bufsize + keyframe interval might help, also I wonder did you try to publish stream via gocoder as well with the same env?
  • Which player & device you try to play the stream ? did you try another protocol / device for playback like rtmp ? what’s the delay with it ? if player client getting behind the published stream on wowza & still latency increasing ( you can analyze this watching it different device / platform ) , try using ABR as Rose said.

I would suggest submitting a support ticket @Naisargi Mehta. That way our engineers can see all of your config files and run some tests in simulated bandwidth environments. This will help determine that latency issue for you.

https://www.wowza.com/support/open-ticket

Hi @Emre Karataşoğlu- Advanced Consultant, thanks for your reply.

Yes I think the problem is with publisher’s bandwidith and the watcher’s bandwidth that doesn’t match so the delay increases. As you have suggested to use keyframe in ffmpeg. But as per my understanding keyframe is used with the libx264 encoder i.e. software encoder. But I am using harware H.264 encoder.

I am using ffplay player and my mobile application player, non other than these two players.
And playing through ffplay player with the same environment gives me the same output, increasing the delay with the low network.

Here I am using rtsp protocol for streaming in wowza through tcp. Also tried with the another device the problem remains the same.

And as I mention in my above reply for ABR that with the low resolution (640x360), delay increases if the network is low.

So, please can you suggest me the another solution using among rtsp protocol and hardware encoder.

Thanks!!

Thanks @Rose Power-Wowza Community Manager, with your suggestion I have opened a ticket in wowza.

Hi Naisargi, yes this parametes for software, i missed the hardware encoding info. I dont have enough exp on hardware encoding ( except encoder server devices ) maybe your hardware cant handle the buffer as you expect , maybe not desing for hardware encoding ops ?Also if publisher does not have enough bandwidth or unstable bandwidth the latency increasing is normal ,isnt it ? However still we can investigate the problem with narrowing the scope.

what is your original bitrate & resolution ? did you try to publish it via libx264 lib encoding ? Also I can suggest you to publish the stream not cloud , publish directly to wowza streaming engine to eliminate if problem caused by cdn. Also trying to play it with flash rtmp or vlc rtsp to compare the one you play with ffplay,

lots of work to be done here for addressing the problem