[FFmpeg-devel] [PATCH]Fix stream-copy for grayscale mov files

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Dec 12 13:52:20 CET 2013


Hi!

Attached patches fix ticket #3215 for me. This reverts r12272 for which I 
cannot find the file 256grey.mov. I tried to fix all possible affected 
decoders.
While testing, it appeared to me that inserting a palette into grayscale 
cinepak was always a bad idea: It needed special-handling although the 
decoder does not need the palette. Without this patch, the revert of r12272 
breaks fate/cvid/pcitva15.avi if I change:
if (avctx->bits_per_coded_sample != 8)
into
if ((avctx->bits_per_coded_sample &0x1f) != 8)

Please review, Carl Eugen
-------------- next part --------------
From 9e2b3b2619bcbc10c064914791bfc7f24c5af5ed Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos at ag.or.at>
Date: Thu, 12 Dec 2013 13:42:10 +0100
Subject: [PATCH 1/2] Do not compute a grayscale palette for cinepak in mov.

This was never done for avi files, the decoder always produced
output no matter if a palette was computed or not.
Since a non-standard palette was needed, this simplifies the code.
See issue 1067 and ticket #165.
---
 libavformat/mov.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0157a7d..c52e319 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1308,6 +1308,9 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb,
     /* figure out the palette situation */
     color_depth     = st->codec->bits_per_coded_sample & 0x1F;
     color_greyscale = st->codec->bits_per_coded_sample & 0x20;
+    /* Do not create a greyscale palette for cinepak */
+    if (color_greyscale && st->codec->codec_id == AV_CODEC_ID_CINEPAK)
+        return;
 
     /* if the depth is 2, 4, or 8 bpp, file is palettized */
     if ((color_depth == 2) || (color_depth == 4) || (color_depth == 8)) {
@@ -1323,9 +1326,6 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb,
             color_index = 255;
             color_dec   = 256 / (color_count - 1);
             for (j = 0; j < color_count; j++) {
-                if (st->codec->codec_id == AV_CODEC_ID_CINEPAK){
-                    r = g = b = color_count - 1 - color_index;
-                } else
                 r = g = b = color_index;
                 sc->palette[j] = (0xFFU << 24) | (r << 16) | (g << 8) | (b);
                 color_index -= color_dec;
-- 
1.7.10.4

-------------- next part --------------
From cae73c3600d5bd55576027ba287cee2720d79094 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos at ag.or.at>
Date: Thu, 12 Dec 2013 13:47:44 +0100
Subject: [PATCH] Allow stream-copying grayscale mov files.

This reverts 0de2157f / r12272.
Fixes ticket #3215.
---
 libavcodec/8bps.c   |    2 +-
 libavcodec/msrle.c  |    2 +-
 libavcodec/rawdec.c |    8 ++++----
 libavformat/mov.c   |    1 -
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c
index d01ef92..1709368 100644
--- a/libavcodec/8bps.c
+++ b/libavcodec/8bps.c
@@ -119,7 +119,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
-    if (avctx->bits_per_coded_sample <= 8) {
+    if ((avctx->bits_per_coded_sample & 0x1f) <= 8) {
         const uint8_t *pal = av_packet_get_side_data(avpkt,
                                                      AV_PKT_DATA_PALETTE,
                                                      NULL);
diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c
index 2836fec..7ae4b08 100644
--- a/libavcodec/msrle.c
+++ b/libavcodec/msrle.c
@@ -54,7 +54,7 @@ static av_cold int msrle_decode_init(AVCodecContext *avctx)
 
     s->avctx = avctx;
 
-    switch (avctx->bits_per_coded_sample) {
+    switch (avctx->bits_per_coded_sample & 0x1f) {
     case 1:
         avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
         break;
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 3f4a8fc..e1682e3 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -108,7 +108,7 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
     if (   avctx->codec_tag == MKTAG('r','a','w',' ')
         || avctx->codec_tag == MKTAG('N','O','1','6'))
         avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_mov,
-                                      avctx->bits_per_coded_sample);
+                                      avctx->bits_per_coded_sample & 0x1f);
     else if (avctx->codec_tag == MKTAG('W', 'R', 'A', 'W'))
         avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_avi,
                                       avctx->bits_per_coded_sample);
@@ -134,7 +134,7 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
             memset(context->palette->data, 0, AVPALETTE_SIZE);
     }
 
-    if ((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) &&
+    if (((avctx->bits_per_coded_sample & 0x1f) == 4 || (avctx->bits_per_coded_sample & 0x1f) == 2) &&
         avctx->pix_fmt == AV_PIX_FMT_PAL8 &&
        (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))) {
         context->is_2_4_bpp = 1;
@@ -207,14 +207,14 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
         int i;
         uint8_t *dst = frame->buf[0]->data;
         buf_size = context->frame_size - AVPALETTE_SIZE;
-        if (avctx->bits_per_coded_sample == 4) {
+        if ((avctx->bits_per_coded_sample & 0x1f) == 4) {
             for (i = 0; 2 * i + 1 < buf_size && i<avpkt->size; i++) {
                 dst[2 * i + 0] = buf[i] >> 4;
                 dst[2 * i + 1] = buf[i] & 15;
             }
             linesize_align = 8;
         } else {
-            av_assert0(avctx->bits_per_coded_sample == 2);
+            av_assert0((avctx->bits_per_coded_sample & 0x1f) == 2);
             for (i = 0; 4 * i + 3 < buf_size && i<avpkt->size; i++) {
                 dst[4 * i + 0] = buf[i] >> 6;
                 dst[4 * i + 1] = buf[i] >> 4 & 3;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c52e319..a78837a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1321,7 +1321,6 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb,
         if (color_greyscale) {
             int color_index, color_dec;
             /* compute the greyscale palette */
-            st->codec->bits_per_coded_sample = color_depth;
             color_count = 1 << color_depth;
             color_index = 255;
             color_dec   = 256 / (color_count - 1);
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list