Here's a somewhat experimental patch with a new AVOption
write_keyframe_palette that allows you to write the palette to every
keyframe. It is disabled by default, but it is needed for any file that
contains palette changes.
This patch has to be applied after the previous 2-part patch set.
Mats
--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From 582f36e474ac96adaf0f00739a6c22a9da3601c3 Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Mon, 7 Mar 2016 19:38:38 +0100
Subject: [PATCH] lavf/avienc: New AVOption write_keyframe_palette
---
libavformat/avienc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index fe4dc7e..aaa396c 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -66,6 +66,7 @@ typedef struct AVIContext {
int64_t frames_hdr_all;
int riff_id;
int write_channel_mask;
+ int write_keyframe_palette;
} AVIContext;
typedef struct AVIStream {
@@ -680,6 +681,7 @@ static int avi_write_xxpc(AVFormatContext *s, int stream_index, uint32_t *palett
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
{
const int stream_index = pkt->stream_index;
+ AVIContext *avi = s->priv_data;
AVIOContext *pb = s->pb;
AVCodecContext *enc = s->streams[stream_index]->codec;
AVIStream *avist = s->streams[stream_index]->priv_data;
@@ -711,13 +713,13 @@ 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 || (avi->write_keyframe_palette && (pkt->flags & AV_PKT_FLAG_KEY))) {
int pal_size = 1 << enc->bits_per_coded_sample;
int i;
av_assert0(enc->bits_per_coded_sample >= 0 && enc->bits_per_coded_sample <= 8);
- if (pb->seekable && avist->pal_offset) {
+ if (ret2 && pb->seekable && avist->pal_offset) {
int64_t cur_offset = avio_tell(pb);
avio_seek(pb, avist->pal_offset, SEEK_SET);
for (i = 0; i < pal_size; i++) {
@@ -728,7 +730,8 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
memcpy(avist->old_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) ||
+ (avi->write_keyframe_palette && (pkt->flags & AV_PKT_FLAG_KEY))) {
avi_write_xxpc(s, stream_index, avist->palette);
memcpy(avist->old_palette, avist->palette, pal_size * 4);
if (pb->seekable && avist->strh_flags_offset) {
@@ -887,6 +890,7 @@ static int avi_write_trailer(AVFormatContext *s)
#define ENC AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{ "write_channel_mask", "write channel mask into wave format header", OFFSET(write_channel_mask), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
+ { "write_keyframe_palette", "write palette at keyframes", OFFSET(write_keyframe_palette), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
{ NULL },
};
--
1.7.10.4
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel