Wowza Community

Delay in streaming with ffmpeg

Hi Guys,

I’m trying to stream a video in my application with as low possible delay from starting the video in ffmpeg until viewing the file in the player. I checked out the low latency page here: https://www.wowza.com/docs/how-to-set-up-low-latency-applications-in-wowza-streaming-engine-for-rtmp-streaming but that doesn’t seem to do the job.

On the wowza server side of things I have a live application. I feed this live application with ffmpeg, using following command:

ffmpeg -re -i https://s3-us-west-2.amazonaws.com/filename.mp4 -c:v copy -c:a copy -f flv rtmp://*@myurl

I’m using Apple HLS in wowza. What I can see that when I start the ffmpeg command it takes 10-15 seconds before I can see the video plaining in the wowza player/native apple player. When I kill the ffmpeg command I can see it running for another 10-15 seconds in my player. I want this delay to be as low as possible.

This because I want to have clips playing after each other on the fly. Meaning that I kill one ffmpeg command and start a new one instantly. Or even overlap. But this switch is user triggered so should be done instantly.

Can anyone help me on this issue?

We have an article specifically for addressing lower latency using Apple’s HLS. It can be found at the link below:
https://www.wowza.com/docs/how-to-improve-playback-of-lower-latency-apple-hls-streams

Some older Android phones support both RTSP and HLS. Mobile phones never support RTMP. HTTP segmented content, specifically HLS, is what everyone is using these days as it plays back on both the desktop and mobile phones.

There will always be some latency between the encoder and the live video. This is the nature of streaming media. A few things can help.

A) The protocol you choose for playback can add a fair amount of latency. RTSP playback and RTMP playback have much lower latency than segmented HTTP delivered content like Apple HLS, MPEG-DASH, Adobe HDS, and Microsoft Smooth Streaming. The reason for this is that the player will not play a segment until three entire segments are finished downloading to the client to help smooth out networking issues. Content is segmented into chunks based upon the keyframe distance and time specified in Wowza Streaming Engine. Apple strongly recommends ten second segments, however that increases latency dramatically.

https://developer.apple.com/library/content/technotes/tn2224/_index.html#//apple_ref/doc/uid/DTS40009745-CH1-MEDIASTREAMSEGMENTATION-USE_10_SECOND_TARGET_DURATIONS

B) Make sure that your keyframe distance, also known as a “Group of Pictures” or GOP, is two seconds and is consistent. Your encoder should be using the H.264 video codec and have an option to make sure that keyframes are created at that exact distance every time. If you can, please force the keyframe distance using whichever option your encoder documentation specifies. If you are using the x264 implementation of the H.264 codec you can add the “no-scenecut” option if your encoder allows it.

If keyframes are not in perfect cadence then chunk sizes will be random in duration and cause buffering and possibly connection timeouts.

C) We have a guide that may help provide insight in lowering latency for RTMP playback for desktop players.

https://www.wowza.com/docs/how-to-set-up-low-latency-applications-in-wowza-streaming-engine-for-rtmp-streaming

More on low latency can be found at the following link.

https://www.wowza.com/blog/what-is-low-latency-and-who-needs-it

D) If you are delivering content using Apple HLS, Adobe HDS, Microsoft Smooth Streaming, or MPEG-DASH you will want to modify your ChunkDurationTarget as shown in the following articles:

Apple HLS:
https://www.wowza.com/docs/how-to-configure-apple-hls-packetization-cupertinostreaming

Adobe HDS:
https://www.wowza.com/docs/how-to-configure-adobe-hds-packetization-sanjosestreaming

Microsoft Smooth Streaming:
https://www.wowza.com/docs/how-to-configure-microsoft-smooth-streaming-packetization-smoothstreaming

MPEG-DASH:
https://www.wowza.com/docs/how-to-configure-mpeg-dash-packetization-mpegdashstreaming

I hope that this helps to address your latency concerns.