2012/3/21 Martin Storsjö <mar...@martin.st>:
> Hi,
>
>
> On Wed, 21 Mar 2012, Jindřich Makovička wrote:
>
>> 2012/3/21 Martin Storsjö <mar...@martin.st>:
>>>
>>> In general though, for HLS, if you use interleaving and flush the
>>> interleaver buffers before cutting a new segment, the last packets of the
>>> previous segment actually could actually have timestamps larger than the
>>> ones at the start of the new segment. (Not sure if that's an issue in
>>> practice.)
>>
>>
>> Yes, it's not 100% clean, but we did not encounter any issues, at
>> least when cutting the chunks at the IDR frame.
>
>
> Yeah, it's most probably just a theoretical issue.
>
>
>>> Also, as a completely orthogonal issue, I don't know the mpegts muxer in
>>> detail - I think it buffers small audio packets before writing them out -
>>> would it make sense to have the flush command also flush these (that is,
>>> implement the flush semantics of write_packet in the muxer)?
>>
>>
>> This patch should take care of that.
>
>
> Yes, the patch seems good for implementing this - go ahead and post it to
> the list :-)

Darn, this was supposed to go to the list, obviously :)

> The question then is, if we implement flushing the interleaving queues by
> av_interleaved_write_frame(ctx, NULL) (which was what you need, right?), is
> there any problem if the muxer buffers are flushed at the same time? I don't
> think there should be any problem in that case.

I think that's ok for MPEG-TS. For our case it doesn't even matter if
the short audio packets are flushed or not.

-- 
Jindřich Makovička
From 28d2b5605fb370a15808f0c207dff74ef7c6386b Mon Sep 17 00:00:00 2001
From: Jindrich Makovicka <jindrich.makovi...@nangu.tv>
Date: Wed, 21 Mar 2012 12:35:15 +0100
Subject: [PATCH 2/2] mpegtsenc: allow user triggered PES packet flushing

Signed-off-by: Jindrich Makovicka <jindrich.makovi...@nangu.tv>
---
 libavformat/mpegtsenc.c |   40 +++++++++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index a594ca2..91a8953 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -935,7 +935,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
     avio_flush(s->pb);
 }
 
-static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
+static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
 {
     AVStream *st = s->streams[pkt->stream_index];
     int size = pkt->size;
@@ -1059,27 +1059,48 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
-static int mpegts_write_end(AVFormatContext *s)
+static void mpegts_write_flush(AVFormatContext *s)
 {
-    MpegTSWrite *ts = s->priv_data;
-    MpegTSWriteStream *ts_st;
-    MpegTSService *service;
-    AVStream *st;
     int i;
 
     /* flush current packets */
     for(i = 0; i < s->nb_streams; i++) {
-        st = s->streams[i];
-        ts_st = st->priv_data;
+        AVStream *st = s->streams[i];
+        MpegTSWriteStream *ts_st = st->priv_data;
         if (ts_st->payload_size > 0) {
             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;
         }
+    }
+    avio_flush(s->pb);
+}
+
+static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    if (!pkt) {
+        mpegts_write_flush(s);
+        return 1;
+    } else {
+        return mpegts_write_packet_internal(s, pkt);
+    }
+}
+
+static int mpegts_write_end(AVFormatContext *s)
+{
+    MpegTSWrite *ts = s->priv_data;
+    MpegTSService *service;
+    int i;
+
+    mpegts_write_flush(s);
+
+    for(i = 0; i < s->nb_streams; i++) {
+        AVStream *st = s->streams[i];
+        MpegTSWriteStream *ts_st = st->priv_data;
         av_freep(&ts_st->payload);
         av_freep(&ts_st->adts);
     }
-    avio_flush(s->pb);
 
     for(i = 0; i < ts->nb_services; i++) {
         service = ts->services[i];
@@ -1103,5 +1124,6 @@ AVOutputFormat ff_mpegts_muxer = {
     .write_header      = mpegts_write_header,
     .write_packet      = mpegts_write_packet,
     .write_trailer     = mpegts_write_end,
+    .flags = AVFMT_ALLOW_FLUSH,
     .priv_class = &mpegts_muxer_class,
 };
-- 
1.7.9.1

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to