changeset 3954:0ebebd2ba034 libavformat

matroskadec: merge ASS events which share the same pts in the same AVPavket
author aurel
date Sun, 28 Sep 2008 23:06:25 +0000
parents f1a9ff04eb4b
children 874534fb6d0f
files matroskadec.c
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/matroskadec.c	Sun Sep 28 23:01:07 2008 +0000
+++ b/matroskadec.c	Sun Sep 28 23:06:25 2008 +0000
@@ -205,6 +205,7 @@
     /* the packet queue */
     AVPacket **packets;
     int num_packets;
+    AVPacket *prev_pkt;
 
     int done;
     int has_cluster_id;
@@ -964,6 +965,15 @@
     }
 }
 
+static void matroska_merge_packets(AVPacket *out, AVPacket *in)
+{
+    out->data = av_realloc(out->data, out->size+in->size);
+    memcpy(out->data+out->size, in->data, in->size);
+    out->size += in->size;
+    av_destruct_packet(in);
+    av_free(in);
+}
+
 static void matroska_convert_tags(AVFormatContext *s, EbmlList *list)
 {
     MatroskaTag *tags = list->elem;
@@ -1629,7 +1639,14 @@
                 if (st->codec->codec_id == CODEC_ID_SSA)
                     matroska_fix_ass_packet(matroska, pkt, duration);
 
+                if (matroska->prev_pkt &&
+                    matroska->prev_pkt->pts == timecode &&
+                    matroska->prev_pkt->stream_index == st->index)
+                    matroska_merge_packets(matroska->prev_pkt, pkt);
+                else {
                 dynarray_add(&matroska->packets, &matroska->num_packets, pkt);
+                    matroska->prev_pkt = pkt;
+                }
             }
 
             if (timecode != AV_NOPTS_VALUE)
@@ -1649,6 +1666,7 @@
     MatroskaBlock *blocks;
     int i, res;
     offset_t pos = url_ftell(matroska->ctx->pb);
+    matroska->prev_pkt = NULL;
     if (matroska->has_cluster_id){
         /* For the first cluster we parse, its ID was already read as
            part of matroska_read_header(), so don't read it again */