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

Sven C. Dack sven.c.dack at sky.com
Wed Sep 7 03:23:57 EEST 2016


On 07/09/16 01:08, Sven C. Dack wrote:
> On 07/09/16 00:43, Carl Eugen Hoyos wrote:
>>
>> Should be AV_PIX_FMT_RGB0...
>>
>>
>> ... and AV_PIX_FMT_BGR0
>
> I was wondering about that. The 0 means undefined/unused and I didn't want to 
> open a can of worms with it. Should I add BGR0 and RGB0, too? Does the 0 mean 
> it is reliably 0?

Just tested it with BGR0 and RGB0 and it does encode at ~100 fp/s from the 
screen with it.

$ ffmpeg -f x11grab -framerate 333 -s 1920x1080 -i :0.0 -c:v hevc_nvenc -b:v 
4096k -y test.mkv

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,14 @@ 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) {
+      av_image_copy_plane(buf, lockBufferParams->pitch,
+           frame->data[0], frame->linesize[0],
+           avctx->width << 2, avctx->height);
+    } else if (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