Minor changes.

--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From 89273db7f36475d80e0f054939b84746fa86c947 Mon Sep 17 00:00:00 2001
From: Mats Peterson <[email protected]>
Date: Sun, 28 Feb 2016 23:03:37 +0100
Subject: [PATCH v6 2/2] lavf/movenc: Add support for palette side data packets

---
 libavformat/movenc.c |   26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 3295266..44dddec 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1717,12 +1717,13 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr
         avio_wb16(pb, 0x18); /* Reserved */
 
     if (track->is_unaligned_qt_rgb && track->enc->pix_fmt == AV_PIX_FMT_PAL8) {
+        int pal_size = 1 << track->enc->bits_per_coded_sample;
         int i;
         avio_wb16(pb, 0);             /* Color table ID */
         avio_wb32(pb, 0);             /* Color table seed */
         avio_wb16(pb, 0x8000);        /* Color table flags */
-        avio_wb16(pb, 255);           /* Color table size (zero-relative) */
-        for (i = 0; i < 256; i++) {
+        avio_wb16(pb, pal_size - 1);  /* Color table size (zero-relative) */
+        for (i = 0; i < pal_size; i++) {
             uint32_t rgb = AV_RL32(&track->palette[i]);
             uint16_t r = (rgb >> 16) & 0xff;
             uint16_t g = (rgb >> 8)  & 0xff;
@@ -4763,19 +4764,28 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
             }
         }
 
-        if (trk->is_unaligned_qt_rgb) {
+        if (trk->is_unaligned_qt_rgb && pkt->size) {
             const uint8_t *data = pkt->data;
             int size = pkt->size;
             int64_t bpc = trk->enc->bits_per_coded_sample != 15 ? trk->enc->bits_per_coded_sample : 16;
             int expected_stride = ((trk->enc->width * bpc + 15) >> 4)*2;
+            const uint8_t *pal = NULL;
+            int sd_size;
             int ret = ff_reshuffle_raw_rgb(s, &pkt, trk->enc, expected_stride);
             if (ret < 0)
                 return ret;
-            if (ret == CONTAINS_PAL && !trk->pal_done) {
-                int pal_size = 1 << trk->enc->bits_per_coded_sample;
-                memset(trk->palette, 0, AVPALETTE_SIZE);
-                memcpy(trk->palette, data + size - 4*pal_size, 4*pal_size);
-                trk->pal_done++;
+            if (!trk->pal_done) {
+                pal = av_packet_get_side_data(pkt, AV_PKT_DATA_PALETTE, &sd_size);
+                if (pal && sd_size != AVPALETTE_SIZE) {
+                    av_log(s, AV_LOG_ERROR, "Invalid palette side data\n");
+                    return AVERROR_INVALIDDATA;
+                }
+                if (!pal && ret == CONTAINS_PAL)
+                    pal = data + size - AVPALETTE_SIZE;
+                if (pal) {
+                    memcpy(trk->palette, pal, AVPALETTE_SIZE);
+                    trk->pal_done++;
+                }
             } else if (trk->enc->pix_fmt == AV_PIX_FMT_GRAY8 ||
                        trk->enc->pix_fmt == AV_PIX_FMT_MONOBLACK) {
                 for (i = 0; i < pkt->size; i++)
-- 
1.7.10.4

_______________________________________________
ffmpeg-devel mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to