diff mbox

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

Message ID d8f1056f-8dd1-e3a4-f0d5-7c1fa765df58@sky.com
State Superseded
Headers show

Commit Message

Sven C. Dack Sept. 7, 2016, 2:01 p.m. UTC
On 07/09/16 14:33, Timo Rothenpieler wrote:
> 0RGB/0BGR does not mean the alpha bits are zeroed.
> It means they are undefined, so you convert from ARGB to 0RGB by doing
> nothing. There is no performance to gain by supporting a format that
> falsely advertises support for an alpha channel.
>
> Also, the correct formats to use are AV_PIX_FMT_0RGB32, which
> corresponds to NV_ENC_BUFFER_FORMAT_ARGB, and AV_PIX_FMT_0BGR32 for ABGR.
Thanks for finally explaining it. I also tested it with 0RGB32 and it does work 
with those, too.

Sven

          return AVERROR(EINVAL);
@@ -1350,6 +1360,10 @@ 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_0RGB32 || frame->format == 
AV_PIX_FMT_0BGR32) {
+      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

Timo Rothenpieler Sept. 7, 2016, 4:52 p.m. UTC | #1
applied
Sven C. Dack Sept. 7, 2016, 5:19 p.m. UTC | #2
On 07/09/16 17:52, Timo Rothenpieler wrote:
> applied
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

I've updated my git clone and it is now seg faulting.


Sven


$ ffmpeg -f x11grab -framerate 200 -s hd1080 -i :0.0 -c:v hevc_nvenc -y test.mkv
ffmpeg version N-81588-g3e886e7 Copyright (c) 2000-2016 the FFmpeg developers
   built with gcc 6.2.0 (GCC)
   configuration: --prefix=/home/sven/av --enable-gpl --enable-version3 
--enable-nonfree --arch=x86_64 --cpu=native --disable-debug --disable-shared 
--enable-static --enable-libvorbis --enable-libopus --enable-libx264 
--enable-libx265 --enable-opengl --enable-opencl --enable-vaapi --enable-vdpau 
--enable-cuda --enable-cuvid --enable-nvenc --enable-libnpp 
--extra-cflags='-I/home/sven/av/include -I/usr/local/cuda/include 
-I/usr/local/Video_Codec_SDK_7.0.1/Samples/common/inc' 
--extra-ldflags='-L/home/sven/av/lib -L/usr/local/cuda/lib64' --ar=gcc-ar 
--nm=gcc-nm --ranlib=true
   libavutil      55. 29.100 / 55. 29.100
   libavcodec     57. 55.101 / 57. 55.101
   libavformat    57. 48.102 / 57. 48.102
   libavdevice    57.  0.102 / 57.  0.102
   libavfilter     6. 61.100 /  6. 61.100
   libswscale      4.  1.100 /  4.  1.100
   libswresample   2.  1.100 /  2.  1.100
   libpostproc    54.  0.100 / 54.  0.100
[x11grab @ 0x2352fe0] Stream #0: not enough frames to estimate rate; consider 
increasing probesize
Input #0, x11grab, from ':0.0':
   Duration: N/A, start: 1473268691.319742, bitrate: N/A
     Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 200 fps, 
1000k tbr, 1000k tbn, 1000k tbc
[matroska @ 0x235b2a0] Using AVStream.codec to pass codec parameters to muxers 
is deprecated, use AVStream.codecpar instead.
Output #0, matroska, to 'test.mkv':
   Metadata:
     encoder         : Lavf57.48.102
     Stream #0:0: Video: hevc (hevc_nvenc) (Main), bgr0, 1920x1080, q=-1--1, 
2000 kb/s, 1000k fps, 1k tbn, 1000k tbc
     Metadata:
       encoder         : Lavc57.55.101 hevc_nvenc
     Side data:
       cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: -1
Stream mapping:
   Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (hevc_nvenc))
Press [q] to stop, [?] for help
Segmentation fault
Pedro Arthur Sept. 7, 2016, 9:57 p.m. UTC | #3
Your patch was truncated before being applied [1], someone needs to revert
and apply it properly.
[1] - http://ffmpeg.org/pipermail/ffmpeg-devel/2016-September/199079.html
<http://ffmpeg.org/pipermail/ffmpeg-devel/2016-September/199079.html>‚Äč
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_0RGB32,
+    AV_PIX_FMT_0BGR32,
  #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_0RGB32:
+        ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ABGR;
+        break;
+
+    case AV_PIX_FMT_0BGR32:
+        ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ARGB;
+        break;
+
      default:
          av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format\n");