Michael, I've modified your patch to work with stream copy as well. Also, I've simplified it a bit in one place. It seems to produce identical files, but I might have missed something.

Mats

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

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

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 0cfffb7..8e0ed64 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;
 
@@ -696,7 +697,7 @@ 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)) {
                 int pal_size = 1 << enc->bits_per_coded_sample;
                 int pc_tag, i;
 
@@ -711,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