diff mbox

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

Message ID 67a158c2-8043-50ab-c3f4-3bbf805deedb@sky.com
State Superseded
Headers show

Commit Message

Sven C. Dack Sept. 6, 2016, 11:02 p.m. UTC
Hello,

I haven't been sending patches in ages. Can somebody walk me through?

The patch is a "low hanging fruit" and simply adds the pixel formats RGBA and 
BGRA to the Nvidia encoder "nvenc", which supports these two formats natively. 
The gain here is that when one grabs the screen with x11grab and chains it 
through the encoder does it no longer require a RGB->YUV conversion and so 
speeds up live streaming (i.e. from 47fp/s to 62fp/s).

Note the twist in AV_PIX_FMT_RGBA versus NV_ENC_BUFFER_FORMAT_ABGR. This is 
intentionally.

Thanks,
Sven

          return AVERROR(EINVAL);
@@ -1350,6 +1360,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) {
+      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) {
+      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);

Comments

Carl Eugen Hoyos Sept. 6, 2016, 11:43 p.m. UTC | #1
Hi!

2016-09-07 1:02 GMT+02:00 Sven C. Dack <sven.c.dack@sky.com>:

> +    case AV_PIX_FMT_RGBA:

Should be AV_PIX_FMT_RGB0...

> +        ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ABGR;
> +        break;
> +
> +    case AV_PIX_FMT_BGRA:

... and AV_PIX_FMT_BGR0

> +        ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ARGB;

Carl Eugen
Sven C. Dack Sept. 7, 2016, 12:08 a.m. UTC | #2
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?

Sven
diff mbox

Patch

--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -81,6 +81,8 @@  const enum AVPixelFormat ff_nvenc_pix_fmts[] = {
      AV_PIX_FMT_P010,
      AV_PIX_FMT_YUV444P,
      AV_PIX_FMT_YUV444P16,
+    AV_PIX_FMT_RGBA,
+    AV_PIX_FMT_BGRA,
  #if CONFIG_CUDA
      AV_PIX_FMT_CUDA,
  #endif
@@ -1032,6 +1034,14 @@  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_RGBA:
+        ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ABGR;
+        break;
+
+    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");