]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/nvdec: Add support for decoding monochrome av1
authorPhilip Langdale <philipl@overt.org>
Sun, 6 Dec 2020 04:25:29 +0000 (20:25 -0800)
committerPhilip Langdale <philipl@overt.org>
Sun, 6 Dec 2020 22:59:24 +0000 (14:59 -0800)
The nvidia hardware explicitly supports decoding monochrome content,
presumably for the AVIF alpha channel. Supporting this requires an
adjustment in av1dec and explicit monochrome detection in nvdec.

I'm not sure why the monochrome path in av1dec did what it did - it
seems non-functional - YUV440P doesn't seem a logical pix_fmt for
monochrome and conditioning on chroma sub-sampling doesn't make sense.
So I changed it.

I've tested 8bit content, but I haven't found a way to create a 10bit
sample, so that path is untested for now.

libavcodec/av1dec.c
libavcodec/nvdec.c
libavcodec/version.h

index d7b2ac9d4605a0b4b58ec86b4bc0919b5aa99d1a..bc897af9cfbf096418063728a2d6112f09e3fc6e 100644 (file)
@@ -387,9 +387,12 @@ static int get_pixel_format(AVCodecContext *avctx)
                 av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
         }
     } else {
-        if (seq->color_config.subsampling_x == 1 &&
-            seq->color_config.subsampling_y == 1)
-            pix_fmt = AV_PIX_FMT_YUV440P;
+        if (bit_depth == 8)
+            pix_fmt = AV_PIX_FMT_GRAY8;
+        else if (bit_depth == 10)
+            pix_fmt = AV_PIX_FMT_GRAY10;
+        else if (bit_depth == 12)
+            pix_fmt = AV_PIX_FMT_GRAY12;
         else
             av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
     }
@@ -430,6 +433,16 @@ static int get_pixel_format(AVCodecContext *avctx)
 #endif
 #if CONFIG_AV1_VAAPI_HWACCEL
         *fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+        break;
+    case AV_PIX_FMT_GRAY8:
+#if CONFIG_AV1_NVDEC_HWACCEL
+        *fmtp++ = AV_PIX_FMT_CUDA;
+#endif
+        break;
+    case AV_PIX_FMT_GRAY10:
+#if CONFIG_AV1_NVDEC_HWACCEL
+        *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
         break;
     }
index 48281293ce3f025c9ef8dc2cb99380ad0a77f2a0..23c84d9acf44ac57623cbe762505b136df3bf6ae 100644 (file)
@@ -83,6 +83,9 @@ static int map_chroma_format(enum AVPixelFormat pix_fmt)
 {
     int shift_h = 0, shift_v = 0;
 
+    if (av_pix_fmt_count_planes(pix_fmt) == 1)
+        return cudaVideoChromaFormat_Monochrome;
+
     av_pix_fmt_get_chroma_sub_sample(pix_fmt, &shift_h, &shift_v);
 
     if (shift_h == 1 && shift_v == 1)
index 4ee221b7f2456a02ccf73fc96040f1764b076630..1c10d105f61fb7531fcdbfbebfea1826ea00e680 100644 (file)
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR 115
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \