aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/avienc.c
diff options
context:
space:
mode:
authorMats Peterson <matsp888@yahoo.com>2016-02-20 12:57:50 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2016-02-21 03:30:50 +0100
commita51d82b85c83aa0d1a8295ed44a1c835065675e7 (patch)
treeffbf4f4c94a8780e486610ff71972ef619338404 /libavformat/avienc.c
parentf8d685270e5829ef670f7dc5eaa5f57a66c331d8 (diff)
downloadffmpeg-a51d82b85c83aa0d1a8295ed44a1c835065675e7.tar.gz
lavf/avienc: Add palette after BITMAPINFOHEADER
lavf/riffenc: Write space for palette tests/ref/vsynth: Update 1 bpp files for pal8 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/avienc.c')
-rw-r--r--libavformat/avienc.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 0b0f8fcec6..7480c86dd0 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -74,6 +74,9 @@ typedef struct AVIStream {
int max_size;
int sample_requested;
+ int64_t pal_offset;
+ int hdr_pal_done;
+
int64_t last_dts;
AVIIndex indexes;
@@ -359,6 +362,7 @@ 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;
+ avist->pal_offset = avio_tell(pb) + 40;
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 +656,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 +678,25 @@ 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);
+ avio_seek(pb, avist->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);
+ 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);