[FFmpeg-devel] [PATCH 05/10] avformat/mpegtsenc: add padding to m2ts streams

Marton Balint cus at passwd.hu
Tue Nov 12 23:29:01 EET 2019


6144 byte alignment is needed.

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/mpegtsenc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index eac0e5ab81..726e4786ad 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1774,6 +1774,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
 
 static void mpegts_write_flush(AVFormatContext *s)
 {
+    MpegTSWrite *ts = s->priv_data;
     int i;
 
     /* flush current packets */
@@ -1788,6 +1789,12 @@ static void mpegts_write_flush(AVFormatContext *s)
             ts_st->opus_queued_samples = 0;
         }
     }
+
+    if (ts->m2ts_mode) {
+        int packets = (avio_tell(s->pb) / (TS_PACKET_SIZE + 4)) % 32;
+        while (packets++ < 32)
+            mpegts_insert_null_packet(s);
+    }
 }
 
 static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
-- 
2.16.4



More information about the ffmpeg-devel mailing list