I am experiencing a 15 second delay between the input and the output of a live RTMP stream.
Is there any way to decrease this?
I have fiddled with the chunk_size directive by moving it from 4096 to 128 and up to 10240, but nothing has really changed it.
Server does not buffer anything. chunk_size is not related to that.
upd: gop interval is encoder feature
I set the gop interval to 6 in my encoder and check the number of keyframes using RichFLV and I have a keyframe roughly ever second. I have set jwplayer to have a 1 second buffer time. Despite this, I frequently get delays of 10-15 seconds or more.
Are there any good ways or tools of debugging these latencies?
Have you tried playing your stream with ffplay?
Thanks for the help. I tried playing my stream with ffplay.
It takes several minutes for the stream to actually start playing, and when it does it is several minutes behind--much worse than jwplayer.
_update_:Â I noticed it says 600 fps, which doesn't sound accurate, so this may be an encoder issue.
ffplay version 1.0 Copyright (c) 2003-2012 the FFmpeg developers
built on Jan 28 2013 19:30:13 with Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.0 --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 51. 73.101 / 51. 73.101
libavcodec 54. 59.100 / 54. 59.100
libavformat 54. 29.104 / 54. 29.104
libavdevice 54. 2.101 / 54. 2.101
libavfilter 3. 17.100 / 3. 17.100
libswscale 2. 1.101 / 2. 1.101
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100
[flv @ 0x7fb2bb011000] Stream #1: not enough frames to estimate rate; consider increasing probesize
[flv @ 0x7fb2bb011000] Could not find codec parameters for stream 1 (Audio: none, 0 channels): unspecified sample format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, flv, from 'rtmp://example.com/live/test':
Metadata:
Server : NGINX RTMP (github.com/arut/nginx-rtmp-module)
displayWidth : 192
displayHeight : 144
fps : 600
profile :
level :
Duration: 00:00:00.00, start: 25.616000, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), yuv420p, 192x144, 215 kb/s, 1k tbr, 1k tbn, 2k tbc
Stream #0:1: Audio: none, 0 channels
Frame changed from size:0x0 to size:192x144
It seems your stream has no audio. That's the reason why ffplay waits.
It's easy to fix with -probesize option (ffplay -probesize 10000 ...).
JWPlayer has no such option. You can use OSMF (strobe) instead which can handle this well with optimizeBuffering=false setting.
Thanks for your help, I have been playing around with http://www.osmf.org/configurator/fmp/ and set Optimize Buffer to false and although this keeps the stream realtime, it is rather choppy--i.e.--the video stops for a few seconds and then plays the missed video really quickly.
ffplayer -probesize 2500 rtmp://... has been rather successful though.
Do you think it would just be easier to add in an audio track for playback? Could this be done on the nginx server (mixing an audio rtmp stream and a video stream together), or would it just be better to add an audio track on the source device?
You can change other buffer settings too. Like initialBufferLength and maxBufferLength.
If you have audio track then add it. I cannot create audio from nothing in nginx-rtmp.
Any recommendations on settings? I have them set to 0.1 and 10 respectively. These work fine with non-live streams.
Naturally, I was imagining ffmpeg streaming a "blank" audio file on loop that could be mixed in. I guess my questions was more if you could pull audio from one source and video from another, but I would imagine not as it would be quite complex.
0.1 is too low. Try 1-3.
Mixing audio and video from different sources was in my plans. However it was only my own idea, no interest from other people and it's not easy to implement. I will get back to that when I have time.
There is no difference when I set it to 1 or 3 unfortunately.
On Tue, Jan 29, 2013 at 9:57 AM, Roman Arutyunyan
[email protected]:
0.1 is too low. Try 1-3.
Mixing audio and video from different sources was in my plans. However it
was only my own idea, no interest from other people and it's not easy to
implement. I will get back to that when I have time.—
Reply to this email directly or view it on GitHubhttps://github.com/arut/nginx-rtmp-module/issues/119#issuecomment-12838250.
Interesting. I have been doing more research, I implementing audio on the encoder side of the stream that is pushed to nginx and it doesn't resolve the delays I am having in playing the the stream.
OSMF with optimizeBuffering=false just stutters, flowplayer and jwplayer just choke--even with the audio. I am going to try recompiling with the very latest HEAD from github here and see if that fixes anything.
could you send me privately (to e-mail) your stream url so that I could look at it.
For what it is worth, I have been able to consistently decrease the delay by putting this in my live application block:
wait_key on;
interleave on;
publish_notify on;
sync 10ms;
But it doesn't work very well, it just keeps the delay to about 10-15 seconds.
The feeds aren't long running and they are temporary so I can't give you a static URL. If you want to hop on gtalk or skype you can find me at (my github username)@gmail.com or on skype as "Alec Gorge".
Thanks!
@arut I have sent you an email with some sample streams.
I have some progress with this problem. It's late here, I'll try to finish that tomorrow. Please prepare a longer stream for testing.
please try fast-start branch
Excellent! That fixed the issue completely! The only delay left is the buffering on the source device and the latency!
I was also able to remove the configuration changes I had earlier.
Alec I've discovered a simpler way to solve the problem. If you set wait_key on; in master branch that will work. Please try that. I think I will not merge the new branch in this case but rather make the setting true by default. It works perfectly for me.
I see you already had that. Did you try to remove 'interleave on`?
I just tried the new HEAD on master with wait_key on;. It does not solve the issue. Here is my complete config
application live {
live on;
record all;
record_path /var/www/media;
record_unique off;
allow publish all;
allow play all;
wait_key on;
on_publish http://127.0.0.1:8080/hooks/publish;
on_play http://127.0.0.1:8080/hooks/play;
on_done http://127.0.0.1:8080/hooks/done;
on_record_done http://127.0.0.1:8080/hooks/record_done;
exec_record_done fix_flv $path;
}
I've merged the branch into master. The feature is turned on when wait_video on is specified.
You can use ffplayer with nobuffer to test the latency, refer to this answer
Most helpful comment
I've merged the branch into master. The feature is turned on when
wait_video onis specified.