[FFmpeg-user] RTSP Latency Question

Marton Balint cus at passwd.hu
Tue Jan 15 01:25:51 CET 2013



On Mon, 14 Jan 2013, Tom Hendrick wrote:

> Hello,
>
> I am working with an rtsp stream from an Axis IP camera and am
> seeing some latency issues.  There was a separate thread that mentioned a
> patch from Marton Balint and I posted a response but it wasn't accepted
> for some reason.

If I remember correctly that patch was not meant to improve latency, it 
only avoids frame drops occuring at the beginning of playing a realtime 
stream.

> Basically, when I use the command  ffplay -i
> rtsp://192.168.0.90/mpeg4/media.amp i see about 1 second of latency when
> waiving my hand in front of the camera.  I tried several settings
> including probesize and analyze duration and I could not get the latency
> down any more.
>
> When I try this with mplayer using the following command: mplayer rtsp://192.168.0.90/mpeg4.media.amp
>  it plays the stream right away and there is practically no latency at
> all. 

The biggest latency is probably caused by analyzing the stream before 
playing it, it should be much better with -analyzeduration 0.1 or so.

You can also improve the latency by allowing less frames in the packet 
buffer of ffplay before speeding up its external clock to play the video 
faster. To do that you should modify the #define MIN_FRAMES in the source 
code of ffplay.c to 1.

You may also want ffplay increase the maximum external clock speed to a 
bigger value to get rid of the buffered packets more quickly at the 
beginning of the stream. Modify the defined EXTERNAL_CLOCK_SPEED_MAX to 
1.1.

After this adjustment, no more than 3-4 frames should be the latency. You 
may win an extra frame if you decrease the frame queue of the decoded 
frames of ffplay by setting VIDEO_PICTURE_QUEUE_SIZE to 3.

>
> What I am most interested in doing is re-encoding the rtsp stream to an h.264 stream
> and writing to a piped file. When I re-encode with ffmpeg and open the piped file with ffplay I still see the latency of a second or more.
>

Reencoding will always cause additional latency, so this is probably a 
different issue. You may try using some low-latency mode of the h264 
encoder.

>
> Is the bug/fix that Marton Balint worked on likely to help my
> situation?  Is the rtsp bug/fix just for ffplay, or will it affect ffmpeg?

No, I don't think so. :)

Regards,
Marton


More information about the ffmpeg-user mailing list