From 7ac962af38f0f0adf6dcfb6716faee9729ef8036 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 18 Feb 2016 20:57:32 +0100 Subject: avformat/avienc: Store pal8 palette This can be made more efficient, but first and the main goal of this change is to store it at all Signed-off-by: Michael Niedermayer --- libavformat/avienc.c | 19 +++++++++++++++++++ libavformat/internal.h | 7 ++++++- libavformat/rawutils.c | 5 +++-- libavformat/version.h | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 09ec63beba..4e7bca43fe 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -646,7 +646,11 @@ static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts) static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) { + unsigned char tag[5]; const int stream_index = pkt->stream_index; + const uint8_t *data = pkt->data; + int size = pkt->size; + AVIOContext *pb = s->pb; AVCodecContext *enc = s->streams[stream_index]->codec; int ret; @@ -667,6 +671,21 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; if (ret) { + if (ret == CONTAINS_PAL) { + int pc_tag, i; + 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_wl16(pb, 0); // reserved + for (i = 0; i<256; i++) { + uint32_t v = AV_RL32(data + size - 1024 + 4*i); + avio_wb32(pb, v<<8); + } + ff_end_tag(pb, pc_tag); + } ret = avi_write_packet_internal(s, pkt); av_packet_free(&pkt); return ret; diff --git a/libavformat/internal.h b/libavformat/internal.h index 93be63249e..bc6a6c2716 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -560,11 +560,16 @@ void ff_format_io_close(AVFormatContext *s, AVIOContext **pb); */ int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds); + +#define CONTAINS_PAL 2 /** * Reshuffles the lines to use the user specified stride. * * @param ppkt input and output packet - * @return negative error code or 0 or 1, 1 indicates that ppkt needs to be freed + * @return negative error code or + * 0 if no new packet was allocated + * non-zero if a new packet was allocated and ppkt has to be freed + * CONTAINS_PAL if in addition to a new packet the old contained a palette */ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *enc, int expected_stride); diff --git a/libavformat/rawutils.c b/libavformat/rawutils.c index 1e6148dab8..26ebbb5629 100644 --- a/libavformat/rawutils.c +++ b/libavformat/rawutils.c @@ -29,7 +29,8 @@ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *en int64_t bpc = enc->bits_per_coded_sample != 15 ? enc->bits_per_coded_sample : 16; int min_stride = (enc->width * bpc + 7) >> 3; int with_pal_size = min_stride * enc->height + 1024; - int size = bpc == 8 && pkt->size == with_pal_size ? min_stride * enc->height : pkt->size; + int contains_pal = bpc == 8 && pkt->size == with_pal_size; + int size = contains_pal ? min_stride * enc->height : pkt->size; int stride = size / enc->height; int padding = expected_stride - FFMIN(expected_stride, stride); int y; @@ -58,7 +59,7 @@ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *en } *ppkt = new_pkt; - return 1; + return 1 + contains_pal; fail: av_packet_free(&new_pkt); diff --git a/libavformat/version.h b/libavformat/version.h index 62050a2e27..a696474ff6 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MINOR 25 -#define LIBAVFORMAT_VERSION_MICRO 101 +#define LIBAVFORMAT_VERSION_MICRO 102 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- cgit v1.2.3