[FFmpeg-devel] [PATCH 2/2] avformat/mpegtsenc: fix flushing of audio packets

Andreas Håkon andreas.hakon at protonmail.com
Wed Aug 28 10:48:57 EEST 2019


Hi Marton,


‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, 27 de August de 2019 23:33, Marton Balint <cus at passwd.hu> wrote:

> > Please, note that the main problem at time with the mpegts muxer is that all PES packets are
> > written sequentially. And this generates a lot of problems when the video PES packets are large,
> > or when the audio packets aren't flushed at regular intervals. If you prefer to improve the
> > current sequential mode before you do anything with the interleaved mode, then I give this
> > suggestion: Use a PES SIZE INTERVAL for audio packets instead of calculating a TIME DELAY. With
> > CBR audio steams, every audio PES packet has the same payload size.
>
> I am not sure what you mean when you say PES size interval, but if you are
> referring to the size of the PES packet - that is exactly what we had in
> the very beginning, and it was not sufficent because for low bitrate
> streams when combining small audio packets to a PES packet it took too
> long time, and in order to generate a proper TS we have to make sure that
> we don't delay the audio packets too much, becuase if we do, then it will
> arrive at the destination later then the PCR which makes presentation
> impossible.

The problem is that you're thinking of using the same pes_size for all audio packets!
For each audio stream you need to calculate the correct pes_size.
And the value is based on the bitrate. So for CBR audio streams the value is
fixed, and you only need to recalculate it for VBR audio streams.

Please, try to add some "pes_top_size" member at stream level, and use it for
audio streams. You can calculate the value when you know the bitrate, and
after that a simple "if ts_st->payload >= ts_st->pes_top_size" will be sufficient
to trigger the dispatch of the PES packet.


> So that is why timestamp based checks were added, but those checks were
> not sufficent.

Timestamp checks are required for VBR streams. But you can replace the checks
with a function to recalculate the "pes_top_size" of such streams.


Regards.
A.H.

---



More information about the ffmpeg-devel mailing list