Realtime stream conversion from RTSP to RTMP

Questions involving a Windows version of FFmpeg.
Post Reply
rtalintyrecubic
Posts: 1
Joined: Wed Sep 25, 2019 9:29 am

Realtime stream conversion from RTSP to RTMP

Post by rtalintyrecubic » Wed Sep 25, 2019 9:58 am

We are using ffmpeg to convert a stream in realtime from a HiLook PTZ camera RTSP and sending it to NGINX via RTMP where it is then re-served and consumed in videojs player on a webpage.

The command line we have currently is:

ffmpeg -rtsp_transport tcp -i rtsp://{Stream URL} -an -vcodec copy -f flv -movflags frag_keyframe+empty_moov -reset_timestamps 1 -vsync 1 -flags global_header -bsf:v dump_extra -y rtmp://127.0.0.1:1935/show/{camera id}

This works really well, however when ffmpeg is first starting up it takes approx 5 seconds and this results in the stream lagging by the same amount when viewed in a browser. If you have the stream from the camera side by side with the output from ffmpeg you can see the lag between the two. My theory on the cause of this is that ffmpeg is buffering a few seconds the RTSP stream and then processing the buffer so there is a constant lag of a few seconds.

My question is, are there any command line arguments we can add to force ffmpeg to not buffer and only pass through the very latest frame received - there by minimising the lag between the real time camera feed and the stream emitted from ffmpeg. I realise there are going to be other factors within this process that are introducing lag, but we are trying to minimise any lag introduced by ffmpeg buffering the RTSP stream.

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: Realtime stream conversion from RTSP to RTMP

Post by pandy » Mon Oct 14, 2019 6:10 pm

perhaps try '-re' before input also read and experiment with:
https://ffmpeg.org/ffmpeg-all.html#Format-Options
avioflags flags (input/output)

Possible values:

‘direct’

Reduce buffering.
but also
-max_muxing_queue_size packets (output,per-stream)

When transcoding audio and/or video streams, ffmpeg will not begin writing into the output until it has one packet for each such stream. While waiting for that to happen, packets for other streams are buffered. This option sets the size of this buffer, in packets, for the matching output stream.

The default value of this option should be high enough for most uses, so only touch this option if you are sure that you need it.

Post Reply
'