On Mon, Dec 19, 2011 at 16:20, Janne Grunau <[email protected]> wrote:
> On 2011-12-17 14:42:10 +0100, Luca Barbato wrote:
>> Do not assume the audio packets being always smaller than
>> DEFAULT_PES_PAYLOAD_SIZE.
>>
>> - if (ts_st->payload_size + size > DEFAULT_PES_PAYLOAD_SIZE) {
>> + if (ts_st->payload_size > DEFAULT_PES_PAYLOAD_SIZE) {
>
> that's wrong, ts_st->payload is only DEFAULT_PES_PAYLOAD_SIZE large,
> then this if condition is true, we've already written behind the buffer
I think the attached version should work better.
--
Jindřich Makovička
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 57cfe45..a80b24a 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -999,18 +999,27 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
}
}
+ // write a pes packet at least big DEFAULT_PES_PAYLOAD_SIZE
+ // for video and subtitle, write a single pes packet
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, pkt->flags & AV_PKT_FLAG_KEY);
av_free(data);
return 0;
}
if (ts_st->payload_size + size > DEFAULT_PES_PAYLOAD_SIZE) {
- mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size,
- ts_st->payload_pts, ts_st->payload_dts,
- ts_st->payload_flags & AV_PKT_FLAG_KEY);
- ts_st->payload_size = 0;
+ if (ts_st->payload_size) {
+ mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size,
+ ts_st->payload_pts, ts_st->payload_dts,
+ ts_st->payload_flags & AV_PKT_FLAG_KEY);
+ ts_st->payload_size = 0;
+ }
+ if (size > DEFAULT_PES_PAYLOAD_SIZE) {
+ mpegts_write_pes(s, st, buf, size, pts, dts,
+ pkt->flags & AV_PKT_FLAG_KEY);
+ av_free(data);
+ return 0;
+ }
}
if (!ts_st->payload_size) {
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel