Another fix for non-seekable streams. Once again, Michael, this is your patch modified to work with stream copy.

Mats

--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From cdbb72a0ef1f061b32f56dd390584db4122ec84b Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Sun, 6 Mar 2016 14:04:57 +0100
Subject: [PATCH v4] lavf/avienc: Store palette at keyframes if it differs from the global palette

---
 libavformat/avienc.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 357dd34..d67dc4f 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -84,6 +84,7 @@ typedef struct AVIStream {
 
     uint32_t palette[AVPALETTE_COUNT];
     uint32_t old_palette[AVPALETTE_COUNT];
+    uint32_t global_palette[AVPALETTE_COUNT];
     int64_t pal_offset;
 } AVIStream;
 
@@ -694,7 +695,9 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
             int ret2 = ff_get_packet_palette(s, opkt, ret, avist->palette);
             if (ret2 < 0)
                 return ret2;
-            if (ret2) {
+            if (ret2 || ((pkt->flags & AV_PKT_FLAG_KEY) &&
+                         (!avist->pal_offset || !pb->seekable))
+            ) {
                 int pal_size = 1 << enc->bits_per_coded_sample;
                 int pc_tag, i;
 
@@ -709,9 +712,13 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
                     }
                     avio_seek(pb, cur_offset, SEEK_SET);
                     memcpy(avist->old_palette, avist->palette, pal_size * 4);
+                    memcpy(avist->global_palette, avist->palette, pal_size * 4);
                     avist->pal_offset = 0;
                 }
-                if (memcmp(avist->palette, avist->old_palette, pal_size * 4)) {
+                if (memcmp(avist->palette, avist->old_palette, pal_size * 4) ||
+                    (memcmp(avist->palette, avist->global_palette, pal_size * 4) &&
+                    (pkt->flags & AV_PKT_FLAG_KEY))
+                ) {
                     avi_stream2fourcc(tag, stream_index, enc->codec_type);
                     tag[2] = 'p'; tag[3] = 'c';
                     pc_tag = ff_start_tag(pb, tag);
-- 
1.7.10.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to