-- Mats Peterson http://matsp888.no-ip.org/~mats/
>From ace9b5d852e1da540927498989220c7b1e9e1c2b Mon Sep 17 00:00:00 2001 From: Mats Peterson <matsp...@yahoo.com> Date: Fri, 19 Feb 2016 23:56:11 +0100 Subject: [PATCH v2 2/4] lavf/avienc: Write palette after BITMAPINFOHEADER in strf chunk
--- libavformat/avienc.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 4e7bca4..13a74e8 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -73,6 +73,7 @@ typedef struct AVIStream { int entry; int max_size; int sample_requested; + int hdr_pal_done; int64_t last_dts; @@ -359,6 +360,12 @@ static int avi_write_header(AVFormatContext *s) && enc->pix_fmt == AV_PIX_FMT_RGB555LE && enc->bits_per_coded_sample == 15) enc->bits_per_coded_sample = 16; + /* Use private data for palette offset */ + if (enc->bits_per_coded_sample >= 1 && enc->bits_per_coded_sample <= 8) { + enc->priv_data = av_malloc(sizeof(int64_t)); + if (!enc->priv_data) + return AVERROR(ENOMEM); + } ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 0, 0); pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi, enc->bits_per_coded_sample); @@ -652,6 +659,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) int size = pkt->size; AVIOContext *pb = s->pb; AVCodecContext *enc = s->streams[stream_index]->codec; + AVIStream *avist = s->streams[stream_index]->priv_data; int ret; if (enc->codec_id == AV_CODEC_ID_H264 && enc->codec_tag == MKTAG('H','2','6','4') && pkt->size) { @@ -673,15 +681,27 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) if (ret) { if (ret == CONTAINS_PAL) { int pc_tag, i; + int pal_size = 1 << enc->bits_per_coded_sample; + if (!avist->hdr_pal_done) { + int64_t cur_offset = avio_tell(pb); + int64_t *pal_offset = (int64_t *)enc->priv_data; + avio_seek(pb, *pal_offset, SEEK_SET); + for (i = 0; i < pal_size; i++) { + uint32_t v = AV_RL32(data + size - 4*pal_size + 4*i); + avio_wl32(pb, v & 0xffffff); + } + avio_seek(pb, cur_offset, SEEK_SET); + av_free(enc->priv_data); + avist->hdr_pal_done++; + } avi_stream2fourcc(tag, stream_index, enc->codec_type); tag[2] = 'p'; tag[3] = 'c'; - pc_tag = ff_start_tag(pb, tag); avio_w8(pb, 0); - avio_w8(pb, 0); + avio_w8(pb, pal_size); avio_wl16(pb, 0); // reserved - for (i = 0; i<256; i++) { - uint32_t v = AV_RL32(data + size - 1024 + 4*i); + for (i = 0; i < pal_size; i++) { + uint32_t v = AV_RL32(data + size - 4*pal_size + 4*i); avio_wb32(pb, v<<8); } ff_end_tag(pb, pc_tag); -- 1.7.10.4
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel