[Libav-user] latency of mpegts handling in libavformat
carmel.work at gmail.com
Wed Jul 27 09:27:55 CEST 2011
av_read_frame does not return until the third frame arrives. This introduces
2 frames delay *before* the decoding.
2011/7/26 Alex Cohn <alexcohn at netvision.net.il>
> On Tue, Jul 26, 2011 at 08:44, כרמל מגן <carmel.work at gmail.com> wrote:
>> That won't help me, what I'm trying to achieve is minimum latency and
>> currently the libav introduces 2 frames of latency on the transport alone,
>> before the decoding. That's what I'm trying to solve
> Why will this not help you?
> The scenario is as follows:
> 1. av_read_frame(pFormatCtx, &packet)
> gives you the first packet.
> make sure that packet.stream_index corresponds to the video stream
> and (packet.flags & AV_PKT_FLAG_KEY) != 0m i.e. this is an I-frame.
> 2. res = avcodec_decode_video2(pCodecCtx, decodedFrame, &frameFinished,
> returns positive, but frameFinished is 0.
> This happens because pCodecCtx->max_b_frames > 0.
> 3. repeat step 2 again (immediately, don't wait for the next frame on
> If you have pCodecCtx->max_b_frames == 1, frameFinished will be true
> In your case, it is probably 2, therefore repeat step 2 once more.
> 4. Now you have the decodedFrame OK. Display it, and go back to 1.
> The latency for the first frame will be 3*time of avcodec_decode_video2().
> For the second frame and on, you will get decodedFrame in one cycle.
> Please note that you should not perform the trick of looping step 2 if the
> input packet is not I-frame. For P-frames, you will get wrong output.
> 2011/7/26 Alex Cohn <alexcohn at netvision.net.il>
>>> On Tuesday, July 26, 2011, כרמל מגן <carmel.work at gmail.com> wrote:
>>> > I don't have b-frames in the stream, and anyway, since I do the
>>> decoding myself, and not through the libav, I want it to leave the logic to
>>> me and just pass everything as it arrives. Is there anyway to cause it to
>>> work that way?
>>> > Carmel
>>> Send the first frame to decoder in a loop until you receive output.
>>> Alex Cohn
> Libav-user mailing list
> Libav-user at ffmpeg.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libav-user