[FFmpeg-devel] [PATCH] avcodec/ffv1: Support for GBRAP10 and GBRAP12

Jerome Martinez jerome at mediaarea.net
Wed Feb 14 10:48:20 EET 2018


Add support for 10- and 12-bit/component RGB with Alpha encoding and 
decoding in FFV1.

Benched with START/STOP_TIMER around "for (x = 0; x < w; x++)" part 
during decoding, before the previous patch and with the previous patch + 
this patch, no obvious impact (+/-1%), e.g. with 1 second of gbrp12 4K 
content:
ffmpeg -i a.mkv -f framemd5 a.framemd5 -y
  325549 UNITS in decode_rgb_frame,  130899 runs,    173 skips
frame=   24 fps=1.3 q=-0.0 Lsize=       2kB time=00:00:01.00 bitrate=  
17.1kbits/s speed=0.0544x

The 2 deleted lines are the ones I inadvertently kept after testing in 
my previous patch, they are actually never used.

Some input test files used for testing (input file framemd5 = FFV1 file 
framemd5):
https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket2392/converted_image_gets_skewed.dpx
https://samples.ffmpeg.org/image-samples/dpx_samples.zip

For reference, this leads to the following array of supported pix_fmt 
(underscore means not supported):
Y       : 8/_/10/12/__/16
YA      : 8/_/__/__/__/__
YUV  420: 8/9/10/12/__/16
YUVA 420: 8/9/10/__/__/16
YUV  422: 8/9/10/12/__/16
YUVA 422: 8/9/10/__/__/16
YUV  444: 8/9/10/12/__/16
YUVA 444: 8/9/10/__/__/16
RGB     : 8/9/10/12/14/16
RGBA    : 8/_/10/12/__/16
and 8-bit for YUV 410/411/440
it could be interesting for coherency in the listed supported pix_fmt to 
fill some gaps when corresponding pix_fmt exists in FFmpeg e.g. YUVA 
12-bit, GRAY9 or YA16

-------------- next part --------------
From 3d24b30f2f23a2624e00333911e82fb48cf6d35c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Martinez?= <jerome at mediaarea.net>
Date: Wed, 14 Feb 2018 08:39:15 +0100
Subject: [PATCH] avcodec/ffv1: Support for GBRAP10 and GBRAP12

---
 libavcodec/ffv1dec.c          | 4 ++++
 libavcodec/ffv1dec_template.c | 4 +---
 libavcodec/ffv1enc.c          | 3 +++
 libavcodec/ffv1enc_template.c | 2 +-
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 923b79f3ab..3d2ee2569f 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -688,8 +688,12 @@ static int read_header(FFV1Context *f)
             f->avctx->pix_fmt = AV_PIX_FMT_GBRP9;
         else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency)
             f->avctx->pix_fmt = AV_PIX_FMT_GBRP10;
+        else if (f->avctx->bits_per_raw_sample == 10 && f->transparency)
+            f->avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
         else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency)
             f->avctx->pix_fmt = AV_PIX_FMT_GBRP12;
+        else if (f->avctx->bits_per_raw_sample == 12 && f->transparency)
+            f->avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
         else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency)
             f->avctx->pix_fmt = AV_PIX_FMT_GBRP14;
         else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) {
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index a25b3384f1..f8a42a6d44 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -155,7 +155,7 @@ static void RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int
 
             if (lbd)
                 *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24);
-            else if (sizeof(TYPE) == 4) {
+            else if (sizeof(TYPE) == 4 || transparency) {
                 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g;
                 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b;
                 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
@@ -165,8 +165,6 @@ static void RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int
                 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
                 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
                 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
-                if (transparency)
-                    *((uint16_t*)(src[3] + x*2 + stride[3]*y)) = a;
             }
         }
     }
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 49b8d590a3..d71d952c6d 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -648,9 +648,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
         if (!avctx->bits_per_raw_sample)
             s->bits_per_raw_sample = 9;
     case AV_PIX_FMT_GBRP10:
+    case AV_PIX_FMT_GBRAP10:
         if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample)
             s->bits_per_raw_sample = 10;
     case AV_PIX_FMT_GBRP12:
+    case AV_PIX_FMT_GBRAP12:
         if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample)
             s->bits_per_raw_sample = 12;
     case AV_PIX_FMT_GBRP14:
@@ -1326,6 +1328,7 @@ AVCodec ff_ffv1_encoder = {
         AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
         AV_PIX_FMT_GRAY16,    AV_PIX_FMT_GRAY8,     AV_PIX_FMT_GBRP9,     AV_PIX_FMT_GBRP10,
         AV_PIX_FMT_GBRP12,    AV_PIX_FMT_GBRP14,
+        AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12,
         AV_PIX_FMT_YA8,
         AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
         AV_PIX_FMT_GBRP16, AV_PIX_FMT_RGB48,
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index b93336538b..bc0add5ed7 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -160,7 +160,7 @@ static int RENAME(encode_rgb_frame)(FFV1Context *s, const uint8_t *src[4],
                 b = p[2];
                 if (transparency)
                   a = p[3];
-            } else if (sizeof(TYPE) == 4) {
+            } else if (sizeof(TYPE) == 4 || transparency) {
                 g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
                 b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
                 r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
-- 
2.13.3.windows.1



More information about the ffmpeg-devel mailing list