[FFmpeg-devel] adding RGBA and BGRA to nvenc.c

Sven C. Dack sven.c.dack at sky.com
Wed Sep 7 12:41:48 EEST 2016


On 07/09/16 10:40, Sven C. Dack wrote:
>
> It is necessary in order to make it work. The twist here is intentional as I 
> pointed out earlier. If you do it the other way around as described in the 
> documentation then you get false and missing colours.
>
> I'd like to keep in the transparency channel unless you know there is an 
> actual problem with it. The encoder may not use it, but it is no reason not to 
> pass it on. Otherwise will RGBA/BGRA have to be converted into RGB0/BGR0 and 
> you will again get a performance penalty.
>
> Sven
>

--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -81,6 +81,10 @@ const enum AVPixelFormat ff_nvenc_pix_fmts[] = {
      AV_PIX_FMT_P010,
      AV_PIX_FMT_YUV444P,
      AV_PIX_FMT_YUV444P16,
+    AV_PIX_FMT_RGB0,
+    AV_PIX_FMT_BGR0,
+    AV_PIX_FMT_RGBA,
+    AV_PIX_FMT_BGRA,
  #if CONFIG_CUDA
      AV_PIX_FMT_CUDA,
  #endif
@@ -1032,6 +1036,16 @@ static av_cold int nvenc_alloc_surface(AVCodecContext 
*avctx, int idx)
          ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_YUV444_10BIT;
          break;

+    case AV_PIX_FMT_RGB0:
+    case AV_PIX_FMT_RGBA:
+        ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ABGR;
+        break;
+
+    case AV_PIX_FMT_BGR0:
+    case AV_PIX_FMT_BGRA:
+        ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ARGB;
+        break;
+
      default:
          av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format\n");
          return AVERROR(EINVAL);
@@ -1350,6 +1364,11 @@ static int nvenc_copy_frame(AVCodecContext *avctx, 
NvencSurface *inSurf,
          av_image_copy_plane(buf, lockBufferParams->pitch,
              frame->data[2], frame->linesize[2],
              avctx->width << 1, avctx->height);
+    } else if (frame->format == AV_PIX_FMT_RGBA || frame->format == 
AV_PIX_FMT_RGB0 ||
+              frame->format == AV_PIX_FMT_BGRA || frame->format == 
AV_PIX_FMT_BGR0) {
+      av_image_copy_plane(buf, lockBufferParams->pitch,
+           frame->data[0], frame->linesize[0],
+           avctx->width << 2, avctx->height);
      } else {
          av_log(avctx, AV_LOG_FATAL, "Invalid pixel format!\n");
          return AVERROR(EINVAL);



More information about the ffmpeg-devel mailing list