[FFmpeg-devel] adding RGBA and BGRA to nvenc.c
Sven C. Dack
sven.c.dack at sky.com
Wed Sep 7 17:07:02 EEST 2016
On 07/09/16 15:01, Sven C. Dack wrote:
> 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
Last patch I've send had a twist in it. Here is the correct 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_ARGB;
+ break;
+
+ case AV_PIX_FMT_0BGR32:
+ ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ABGR;
+ break;
+
default:
av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format\n");
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);
More information about the ffmpeg-devel
mailing list