[FFmpeg-devel] [libav-devel] mpegts encoder not interleaving audio/video packets well

Tony Strauss tony at animoto.com
Wed Jun 29 16:22:01 CEST 2011


On Mon, Jun 27, 2011 at 1:41 PM, Mike Scheutzow <
mike.scheutzow at alcatel-lucent.com> wrote:

> Tony Strauss wrote:
>
>> +    /*
>> +     * Flush the audio packets once we've amassed a full PES payload or
>> +     * once the stream has moved a certain amount of time past the first
>> audio
>> +     * packet in the buffer.
>> +     */
>> +    if ((ts_st->payload_index + size > DEFAULT_PES_PAYLOAD_SIZE) ||
>> +        ((ts_st->payload_index > 0) && (dts - ts_st->payload_dts >
>> max_delay))) {
>> +        mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
>> +                         ts_st->payload_pts, ts_st->payload_dts);
>> +        ts_st->payload_index = 0;
>> +    }
>> +
>>     if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
>>         // for video and subtitle, write a single pes packet
>>         mpegts_write_pes(s, st, buf, size, pts, dts);
>>
>
>
> This implementation won't send the accumulated audio packet(s) until a
> newer audio packet is written.
>
> This means the delay might be much longer than max_delay. Is that what you
> want?

Actually, a newer video packet also can trigger flushing the buffered audio
packets.

This setup works for my use case.  The interleaving will be within
max_delay.

Tony


More information about the ffmpeg-devel mailing list