[FFmpeg-devel] [PATCH] avcodec/cuviddec: Properly check capability for chroma format

Holy Wu holywu at gmail.com
Sat Oct 5 04:57:54 EEST 2019


From: Holy Wu <HolyWu at users.noreply.github.com>

---
 libavcodec/cuviddec.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index acee78cf2c..c14e381bb5 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -722,6 +722,7 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx)
 
 static int cuvid_test_capabilities(AVCodecContext *avctx,
                                    const CUVIDPARSERPARAMS *cuparseinfo,
+                                   cudaVideoChromaFormat probed_chroma_format,
                                    int probed_width,
                                    int probed_height,
                                    int bit_depth)
@@ -748,7 +749,7 @@ static int cuvid_test_capabilities(AVCodecContext *avctx,
     ctx->caps8.eCodecType = ctx->caps10.eCodecType = ctx->caps12.eCodecType
         = cuparseinfo->CodecType;
     ctx->caps8.eChromaFormat = ctx->caps10.eChromaFormat = ctx->caps12.eChromaFormat
-        = cudaVideoChromaFormat_420;
+        = probed_chroma_format;
 
     ctx->caps8.nBitDepthMinus8 = 0;
     ctx->caps10.nBitDepthMinus8 = 2;
@@ -783,13 +784,8 @@ static int cuvid_test_capabilities(AVCodecContext *avctx,
             return res8;
     }
 
-    if (!ctx->caps8.bIsSupported) {
-        av_log(avctx, AV_LOG_ERROR, "Codec %s is not supported.\n", avctx->codec->name);
-        return AVERROR(EINVAL);
-    }
-
     if (!caps->bIsSupported) {
-        av_log(avctx, AV_LOG_ERROR, "Bit depth %d is not supported.\n", bit_depth);
+        av_log(avctx, AV_LOG_ERROR, "Hardware is lacking required capabilities\n");
         return AVERROR(EINVAL);
     }
 
@@ -830,13 +826,21 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
                                        AV_PIX_FMT_NV12,
                                        AV_PIX_FMT_NONE };
 
+    cudaVideoChromaFormat probed_chroma_format = cudaVideoChromaFormat_420;
     int probed_width = avctx->coded_width ? avctx->coded_width : 1280;
     int probed_height = avctx->coded_height ? avctx->coded_height : 720;
     int probed_bit_depth = 8;
 
     const AVPixFmtDescriptor *probe_desc = av_pix_fmt_desc_get(avctx->pix_fmt);
-    if (probe_desc && probe_desc->nb_components)
-        probed_bit_depth = probe_desc->comp[0].depth;
+    if (probe_desc) {
+        if (probe_desc->log2_chroma_w == 1 && probe_desc->log2_chroma_h == 0)
+            probed_chroma_format = cudaVideoChromaFormat_422;
+        else if (probe_desc->log2_chroma_w == 0 && probe_desc->log2_chroma_h == 0)
+            probed_chroma_format = cudaVideoChromaFormat_444;
+
+        if (probe_desc->nb_components)
+            probed_bit_depth = probe_desc->comp[0].depth;
+    }
 
     // Accelerated transcoding scenarios with 'ffmpeg' require that the
     // pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the
@@ -1023,6 +1027,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
         goto error;
 
     ret = cuvid_test_capabilities(avctx, &ctx->cuparseinfo,
+                                  probed_chroma_format,
                                   probed_width,
                                   probed_height,
                                   probed_bit_depth);
-- 
2.23.0.windows.1



More information about the ffmpeg-devel mailing list