I have a camera supplying an h264 stream, whose SPS/PPS claims that it needs 4 reference frames, causing decoding to lag the input by 4 frames. At 5-fps, this is almost 1 second and is very noticeable (and undesired for this app, as in many cases the security person watching the stream can also see the events happening out the window, and a 1 second delay is confusing and seems "broken").

However, when I look at camera specs, and at the streams themselves, they only ever contain I pictures and P pictures (never B pictures). To my (limited) understanding of the h264 protocol, that suggests that it is possible to fully decode and display every image as it arrives, as they will never be out of order.

Alex Cohn suggested in <http://www.mail-archive.com/[email protected]/msg00590.html> to modify ff_h264_get_profile(). I've done this as a test, and it seems to work for the streams that I have; I've also patched the SPS/PPS manually and it also solves the problem. But I would rather not have to do either of these patches (the first is ugly and requires me to rebuild ffmpeg myself all the time; the second is just plain ugly and error prone).

Questions:

1. Does the (known from specs) fact that the input stream will only ever contains I and P really guarantee that it is safe to decode every picture as it arrives? Or have I just been lucky in my test streams, and reordering might still be needed at some point?

2. If (1) is correct, would it work to patch ff_h264_decode_init() and decode_postinit() to also check the AV_DISCARD mode, and if we are discarding B and/or nonref frames, would set avctx->has_b_frames=0 and low_delay=1 ?
Something like that would make it possible to convert _every_ stream to a low-delay stream by dropping the "non-low-delay" frames. For me, it would solve the problem (there are no B frames, so I wouldn't even lose anything by discarding B frames), but it would also be useful for e.g. seek functionality in a media player - if fast-forwarding by showing only I-frames, you would not need to read and discard 3 more frames to show an I frame you have just read.

Thanks in advance for your time and thoughts,
Camera Man
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to