lavf/segment: only use reference frames for computing the segment end time

This avoids a systematic overestimate of the segments duration when there
are several streams.

Fix trac ticket #3724.
lavf/segment: show incoming packet duration in debug message
lavf/segment: fix weird indent
lavf/segment: set segment end time when the first packet arrives

Avoid negative durations in case there is a single packet in the current
segment, since in that case the end time is still set to the previous
segment end time.
ffserver: use av_mallocz_array()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
avcodec/resample2: Use av_malloc(z)_array()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
avcodec/resample: Use av_m/realloc_array()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>