5 seconds latency with rtmp stream

1,029 views
Skip to first unread message

Anton Vasiljev

unread,
Apr 8, 2014, 5:37:31 PM4/8/14
to jav...@googlegroups.com

I use ffmpeg with h264 build and javacv on android to stream video from camera to rtmp server. I was trying to set all possible video framerates and bitrates, set preset ultrafast, but I still have stable 5 seconds delay. If i use android mediarecorder sending mpegts stream with rtmp to server,i have only 2 seconds delay, and if I use -fflags nobuffer options on the client(ffmpeg), the video is appearing immediately.

I don`t know how in android ffmpeg reduces this latency. Here the configuration code for FFmpegFrameRecorder:

    recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1);
    recorder.setFormat("flv");
    recorder.setFrameRate(frameRate);
    recorder.setVideoBitrate(900*1000);
    recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
    recorder.setVideoOption("preset", "ultrafast");
    recorder.setVideoOption("tune", "zerolatency");
    recorder.setVideoOption("fflags", "nobuffer");
    recorder.setVideoOption("analyzeduration", "0");

Samuel Audet

unread,
Apr 12, 2014, 10:32:14 AM4/12/14
to jav...@googlegroups.com
It may have something to do with the limited amount of bandwidth. There
appears to be a way to hack FFmpeg by resynchronizing the packets
manually to get it working properly according to this post on Stack
Overflow:
http://stackoverflow.com/questions/22342732/ffmpegframerecorder-videobroadcasting-audio-comes-faster-than-video-frame-in-3g

It might also have something to do with the RTMP code in FFmpeg. It
might be doing some sort of additional buffering on its own...

If you figure out anything, please let me know so I can include the fix
in JavaCV :) Thanks

Samuel

On 04/09/2014 06:37 AM, Anton Vasiljev wrote:
> I use ffmpeg with h264 build and javacv on android to stream video from
> camera to rtmp server. I was trying to set all possible video framerates
> and bitrates, set preset ultrafast, but I still have stable 5 seconds
> delay. If i use android mediarecorder sending mpegts stream with rtmp to
> server,i have only 2 seconds delay, and if I use -fflags nobuffer
> options on the client(ffmpeg), the video is appearing immediately.
>
> I don`t know how in android ffmpeg reduces this latency. Here the
> configuration code for FFmpegFrameRecorder:
>
> | recorder= new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1);

Martin Veltins

unread,
Jun 16, 2014, 5:49:26 AM6/16/14
to jav...@googlegroups.com
Any news about that?
I do get the same 5s delay, not that worst, but without it, it'd be ... nicer :)

Samuel Audet

unread,
Jun 16, 2014, 10:14:07 AM6/16/14
to jav...@googlegroups.com
On 06/16/2014 06:49 PM, Martin Veltins wrote:
> Any news about that?
> I do get the same 5s delay, not that worst, but without it, it'd be ... nicer :)

I agree. Please let us know if you find a solution, and I'll add the fix
to the next release of JavaCV! thank you

Samuel
Reply all
Reply to author
Forward
0 new messages