[Libav-user] latency of mpegts handling in libavformat

Alex Cohn alexcohn at netvision.net.il
Tue Jul 26 10:00:47 CEST 2011


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
>
> Carmel
>
>
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,
&packet)
    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
input!!).
    If you have pCodecCtx->max_b_frames == 1, frameFinished will be true
now.
    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.

Regards,
Alex

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
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20110726/3b7f66c0/attachment.html>


More information about the Libav-user mailing list