FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvenc.c
Go to the documentation of this file.
1 /*
2  * H.264/HEVC hardware encoding using nvidia nvenc
3  * Copyright (c) 2016 Timo Rothenpieler <timo@rothenpieler.org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 
24 #include "nvenc.h"
25 
27 #include "libavutil/hwcontext.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/pixdesc.h"
32 #include "internal.h"
33 
34 #define NVENC_CAP 0x30
35 #define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR || \
36  rc == NV_ENC_PARAMS_RC_2_PASS_QUALITY || \
37  rc == NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP)
38 
49 };
50 
51 #define IS_10BIT(pix_fmt) (pix_fmt == AV_PIX_FMT_P010 || \
52  pix_fmt == AV_PIX_FMT_YUV444P16)
53 
54 #define IS_YUV444(pix_fmt) (pix_fmt == AV_PIX_FMT_YUV444P || \
55  pix_fmt == AV_PIX_FMT_YUV444P16)
56 
57 static const struct {
59  int averr;
60  const char *desc;
61 } nvenc_errors[] = {
62  { NV_ENC_SUCCESS, 0, "success" },
63  { NV_ENC_ERR_NO_ENCODE_DEVICE, AVERROR(ENOENT), "no encode device" },
64  { NV_ENC_ERR_UNSUPPORTED_DEVICE, AVERROR(ENOSYS), "unsupported device" },
65  { NV_ENC_ERR_INVALID_ENCODERDEVICE, AVERROR(EINVAL), "invalid encoder device" },
66  { NV_ENC_ERR_INVALID_DEVICE, AVERROR(EINVAL), "invalid device" },
67  { NV_ENC_ERR_DEVICE_NOT_EXIST, AVERROR(EIO), "device does not exist" },
68  { NV_ENC_ERR_INVALID_PTR, AVERROR(EFAULT), "invalid ptr" },
69  { NV_ENC_ERR_INVALID_EVENT, AVERROR(EINVAL), "invalid event" },
70  { NV_ENC_ERR_INVALID_PARAM, AVERROR(EINVAL), "invalid param" },
71  { NV_ENC_ERR_INVALID_CALL, AVERROR(EINVAL), "invalid call" },
72  { NV_ENC_ERR_OUT_OF_MEMORY, AVERROR(ENOMEM), "out of memory" },
73  { NV_ENC_ERR_ENCODER_NOT_INITIALIZED, AVERROR(EINVAL), "encoder not initialized" },
74  { NV_ENC_ERR_UNSUPPORTED_PARAM, AVERROR(ENOSYS), "unsupported param" },
75  { NV_ENC_ERR_LOCK_BUSY, AVERROR(EAGAIN), "lock busy" },
77  { NV_ENC_ERR_INVALID_VERSION, AVERROR(EINVAL), "invalid version" },
78  { NV_ENC_ERR_MAP_FAILED, AVERROR(EIO), "map failed" },
79  { NV_ENC_ERR_NEED_MORE_INPUT, AVERROR(EAGAIN), "need more input" },
80  { NV_ENC_ERR_ENCODER_BUSY, AVERROR(EAGAIN), "encoder busy" },
81  { NV_ENC_ERR_EVENT_NOT_REGISTERD, AVERROR(EBADF), "event not registered" },
82  { NV_ENC_ERR_GENERIC, AVERROR_UNKNOWN, "generic error" },
83  { NV_ENC_ERR_INCOMPATIBLE_CLIENT_KEY, AVERROR(EINVAL), "incompatible client key" },
84  { NV_ENC_ERR_UNIMPLEMENTED, AVERROR(ENOSYS), "unimplemented" },
85  { NV_ENC_ERR_RESOURCE_REGISTER_FAILED, AVERROR(EIO), "resource register failed" },
86  { NV_ENC_ERR_RESOURCE_NOT_REGISTERED, AVERROR(EBADF), "resource not registered" },
87  { NV_ENC_ERR_RESOURCE_NOT_MAPPED, AVERROR(EBADF), "resource not mapped" },
88 };
89 
90 static int nvenc_map_error(NVENCSTATUS err, const char **desc)
91 {
92  int i;
93  for (i = 0; i < FF_ARRAY_ELEMS(nvenc_errors); i++) {
94  if (nvenc_errors[i].nverr == err) {
95  if (desc)
96  *desc = nvenc_errors[i].desc;
97  return nvenc_errors[i].averr;
98  }
99  }
100  if (desc)
101  *desc = "unknown error";
102  return AVERROR_UNKNOWN;
103 }
104 
105 static int nvenc_print_error(void *log_ctx, NVENCSTATUS err,
106  const char *error_string)
107 {
108  const char *desc;
109  int ret;
110  ret = nvenc_map_error(err, &desc);
111  av_log(log_ctx, AV_LOG_ERROR, "%s: %s (%d)\n", error_string, desc, err);
112  return ret;
113 }
114 
116 {
117  NvencContext *ctx = avctx->priv_data;
119  NVENCSTATUS err;
120  uint32_t nvenc_max_ver;
121  int ret;
122 
123  ret = cuda_load_functions(&dl_fn->cuda_dl);
124  if (ret < 0)
125  return ret;
126 
127  ret = nvenc_load_functions(&dl_fn->nvenc_dl);
128  if (ret < 0)
129  return ret;
130 
131  err = dl_fn->nvenc_dl->NvEncodeAPIGetMaxSupportedVersion(&nvenc_max_ver);
132  if (err != NV_ENC_SUCCESS)
133  return nvenc_print_error(avctx, err, "Failed to query nvenc max version");
134 
135  av_log(avctx, AV_LOG_VERBOSE, "Loaded Nvenc version %d.%d\n", nvenc_max_ver >> 4, nvenc_max_ver & 0xf);
136 
137  if ((NVENCAPI_MAJOR_VERSION << 4 | NVENCAPI_MINOR_VERSION) > nvenc_max_ver) {
138  av_log(avctx, AV_LOG_ERROR, "Driver does not support the required nvenc API version. "
139  "Required: %d.%d Found: %d.%d\n",
141  nvenc_max_ver >> 4, nvenc_max_ver & 0xf);
142  return AVERROR(ENOSYS);
143  }
144 
146 
147  err = dl_fn->nvenc_dl->NvEncodeAPICreateInstance(&dl_fn->nvenc_funcs);
148  if (err != NV_ENC_SUCCESS)
149  return nvenc_print_error(avctx, err, "Failed to create nvenc instance");
150 
151  av_log(avctx, AV_LOG_VERBOSE, "Nvenc initialized successfully\n");
152 
153  return 0;
154 }
155 
157 {
159  NvencContext *ctx = avctx->priv_data;
161  NVENCSTATUS ret;
162 
164  params.apiVersion = NVENCAPI_VERSION;
165  params.device = ctx->cu_context;
167 
168  ret = p_nvenc->nvEncOpenEncodeSessionEx(&params, &ctx->nvencoder);
169  if (ret != NV_ENC_SUCCESS) {
170  ctx->nvencoder = NULL;
171  return nvenc_print_error(avctx, ret, "OpenEncodeSessionEx failed");
172  }
173 
174  return 0;
175 }
176 
178 {
179  NvencContext *ctx = avctx->priv_data;
181  int i, ret, count = 0;
182  GUID *guids = NULL;
183 
184  ret = p_nvenc->nvEncGetEncodeGUIDCount(ctx->nvencoder, &count);
185 
186  if (ret != NV_ENC_SUCCESS || !count)
187  return AVERROR(ENOSYS);
188 
189  guids = av_malloc(count * sizeof(GUID));
190  if (!guids)
191  return AVERROR(ENOMEM);
192 
193  ret = p_nvenc->nvEncGetEncodeGUIDs(ctx->nvencoder, guids, count, &count);
194  if (ret != NV_ENC_SUCCESS) {
195  ret = AVERROR(ENOSYS);
196  goto fail;
197  }
198 
199  ret = AVERROR(ENOSYS);
200  for (i = 0; i < count; i++) {
201  if (!memcmp(&guids[i], &ctx->init_encode_params.encodeGUID, sizeof(*guids))) {
202  ret = 0;
203  break;
204  }
205  }
206 
207 fail:
208  av_free(guids);
209 
210  return ret;
211 }
212 
214 {
215  NvencContext *ctx = avctx->priv_data;
217  NV_ENC_CAPS_PARAM params = { 0 };
218  int ret, val = 0;
219 
221  params.capsToQuery = cap;
222 
223  ret = p_nvenc->nvEncGetEncodeCaps(ctx->nvencoder, ctx->init_encode_params.encodeGUID, &params, &val);
224 
225  if (ret == NV_ENC_SUCCESS)
226  return val;
227  return 0;
228 }
229 
231 {
232  NvencContext *ctx = avctx->priv_data;
233  int ret;
234 
235  ret = nvenc_check_codec_support(avctx);
236  if (ret < 0) {
237  av_log(avctx, AV_LOG_VERBOSE, "Codec not supported\n");
238  return ret;
239  }
240 
242  if (IS_YUV444(ctx->data_pix_fmt) && ret <= 0) {
243  av_log(avctx, AV_LOG_VERBOSE, "YUV444P not supported\n");
244  return AVERROR(ENOSYS);
245  }
246 
248  if (ctx->preset >= PRESET_LOSSLESS_DEFAULT && ret <= 0) {
249  av_log(avctx, AV_LOG_VERBOSE, "Lossless encoding not supported\n");
250  return AVERROR(ENOSYS);
251  }
252 
254  if (ret < avctx->width) {
255  av_log(avctx, AV_LOG_VERBOSE, "Width %d exceeds %d\n",
256  avctx->width, ret);
257  return AVERROR(ENOSYS);
258  }
259 
261  if (ret < avctx->height) {
262  av_log(avctx, AV_LOG_VERBOSE, "Height %d exceeds %d\n",
263  avctx->height, ret);
264  return AVERROR(ENOSYS);
265  }
266 
268  if (ret < avctx->max_b_frames) {
269  av_log(avctx, AV_LOG_VERBOSE, "Max B-frames %d exceed %d\n",
270  avctx->max_b_frames, ret);
271 
272  return AVERROR(ENOSYS);
273  }
274 
276  if (ret < 1 && avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
277  av_log(avctx, AV_LOG_VERBOSE,
278  "Interlaced encoding is not supported. Supported level: %d\n",
279  ret);
280  return AVERROR(ENOSYS);
281  }
282 
284  if (IS_10BIT(ctx->data_pix_fmt) && ret <= 0) {
285  av_log(avctx, AV_LOG_VERBOSE, "10 bit encode not supported\n");
286  return AVERROR(ENOSYS);
287  }
288 
290  if (ctx->rc_lookahead > 0 && ret <= 0) {
291  av_log(avctx, AV_LOG_VERBOSE, "RC lookahead not supported\n");
292  return AVERROR(ENOSYS);
293  }
294 
296  if (ctx->temporal_aq > 0 && ret <= 0) {
297  av_log(avctx, AV_LOG_VERBOSE, "Temporal AQ not supported\n");
298  return AVERROR(ENOSYS);
299  }
300 
301  return 0;
302 }
303 
304 static av_cold int nvenc_check_device(AVCodecContext *avctx, int idx)
305 {
306  NvencContext *ctx = avctx->priv_data;
308  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
309  char name[128] = { 0};
310  int major, minor, ret;
311  CUresult cu_res;
312  CUdevice cu_device;
314  int loglevel = AV_LOG_VERBOSE;
315 
316  if (ctx->device == LIST_DEVICES)
317  loglevel = AV_LOG_INFO;
318 
319  cu_res = dl_fn->cuda_dl->cuDeviceGet(&cu_device, idx);
320  if (cu_res != CUDA_SUCCESS) {
321  av_log(avctx, AV_LOG_ERROR,
322  "Cannot access the CUDA device %d\n",
323  idx);
324  return -1;
325  }
326 
327  cu_res = dl_fn->cuda_dl->cuDeviceGetName(name, sizeof(name), cu_device);
328  if (cu_res != CUDA_SUCCESS) {
329  av_log(avctx, AV_LOG_ERROR, "cuDeviceGetName failed on device %d\n", idx);
330  return -1;
331  }
332 
333  cu_res = dl_fn->cuda_dl->cuDeviceComputeCapability(&major, &minor, cu_device);
334  if (cu_res != CUDA_SUCCESS) {
335  av_log(avctx, AV_LOG_ERROR, "cuDeviceComputeCapability failed on device %d\n", idx);
336  return -1;
337  }
338 
339  av_log(avctx, loglevel, "[ GPU #%d - < %s > has Compute SM %d.%d ]\n", idx, name, major, minor);
340  if (((major << 4) | minor) < NVENC_CAP) {
341  av_log(avctx, loglevel, "does not support NVENC\n");
342  goto fail;
343  }
344 
345  if (ctx->device != idx && ctx->device != ANY_DEVICE)
346  return -1;
347 
348  cu_res = dl_fn->cuda_dl->cuCtxCreate(&ctx->cu_context_internal, 0, cu_device);
349  if (cu_res != CUDA_SUCCESS) {
350  av_log(avctx, AV_LOG_FATAL, "Failed creating CUDA context for NVENC: 0x%x\n", (int)cu_res);
351  goto fail;
352  }
353 
354  ctx->cu_context = ctx->cu_context_internal;
355 
356  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
357  if (cu_res != CUDA_SUCCESS) {
358  av_log(avctx, AV_LOG_FATAL, "Failed popping CUDA context: 0x%x\n", (int)cu_res);
359  goto fail2;
360  }
361 
362  if ((ret = nvenc_open_session(avctx)) < 0)
363  goto fail2;
364 
365  if ((ret = nvenc_check_capabilities(avctx)) < 0)
366  goto fail3;
367 
368  av_log(avctx, loglevel, "supports NVENC\n");
369 
370  dl_fn->nvenc_device_count++;
371 
372  if (ctx->device == idx || ctx->device == ANY_DEVICE)
373  return 0;
374 
375 fail3:
376  cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
377  if (cu_res != CUDA_SUCCESS) {
378  av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
379  return AVERROR_EXTERNAL;
380  }
381 
382  p_nvenc->nvEncDestroyEncoder(ctx->nvencoder);
383  ctx->nvencoder = NULL;
384 
385  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
386  if (cu_res != CUDA_SUCCESS) {
387  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
388  return AVERROR_EXTERNAL;
389  }
390 
391 fail2:
393  ctx->cu_context_internal = NULL;
394 
395 fail:
396  return AVERROR(ENOSYS);
397 }
398 
400 {
401  NvencContext *ctx = avctx->priv_data;
403 
404  switch (avctx->codec->id) {
405  case AV_CODEC_ID_H264:
407  break;
408  case AV_CODEC_ID_HEVC:
410  break;
411  default:
412  return AVERROR_BUG;
413  }
414 
415  if (avctx->pix_fmt == AV_PIX_FMT_CUDA) {
416  AVHWFramesContext *frames_ctx;
417  AVCUDADeviceContext *device_hwctx;
418  int ret;
419 
420  if (!avctx->hw_frames_ctx)
421  return AVERROR(EINVAL);
422 
423  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
424  device_hwctx = frames_ctx->device_ctx->hwctx;
425 
426  ctx->cu_context = device_hwctx->cuda_ctx;
427 
428  ret = nvenc_open_session(avctx);
429  if (ret < 0)
430  return ret;
431 
432  ret = nvenc_check_capabilities(avctx);
433  if (ret < 0) {
434  av_log(avctx, AV_LOG_FATAL, "Provided device doesn't support required NVENC features\n");
435  return ret;
436  }
437  } else {
438  int i, nb_devices = 0;
439 
440  if ((dl_fn->cuda_dl->cuInit(0)) != CUDA_SUCCESS) {
441  av_log(avctx, AV_LOG_ERROR,
442  "Cannot init CUDA\n");
443  return AVERROR_UNKNOWN;
444  }
445 
446  if ((dl_fn->cuda_dl->cuDeviceGetCount(&nb_devices)) != CUDA_SUCCESS) {
447  av_log(avctx, AV_LOG_ERROR,
448  "Cannot enumerate the CUDA devices\n");
449  return AVERROR_UNKNOWN;
450  }
451 
452  if (!nb_devices) {
453  av_log(avctx, AV_LOG_FATAL, "No CUDA capable devices found\n");
454  return AVERROR_EXTERNAL;
455  }
456 
457  av_log(avctx, AV_LOG_VERBOSE, "%d CUDA capable devices found\n", nb_devices);
458 
459  dl_fn->nvenc_device_count = 0;
460  for (i = 0; i < nb_devices; ++i) {
461  if ((nvenc_check_device(avctx, i)) >= 0 && ctx->device != LIST_DEVICES)
462  return 0;
463  }
464 
465  if (ctx->device == LIST_DEVICES)
466  return AVERROR_EXIT;
467 
468  if (!dl_fn->nvenc_device_count) {
469  av_log(avctx, AV_LOG_FATAL, "No NVENC capable devices found\n");
470  return AVERROR_EXTERNAL;
471  }
472 
473  av_log(avctx, AV_LOG_FATAL, "Requested GPU %d, but only %d GPUs are available!\n", ctx->device, nb_devices);
474  return AVERROR(EINVAL);
475  }
476 
477  return 0;
478 }
479 
480 typedef struct GUIDTuple {
481  const GUID guid;
482  int flags;
483 } GUIDTuple;
484 
485 #define PRESET_ALIAS(alias, name, ...) \
486  [PRESET_ ## alias] = { NV_ENC_PRESET_ ## name ## _GUID, __VA_ARGS__ }
487 
488 #define PRESET(name, ...) PRESET_ALIAS(name, name, __VA_ARGS__)
489 
491 {
492  GUIDTuple presets[] = {
493  PRESET(DEFAULT),
494  PRESET(HP),
495  PRESET(HQ),
496  PRESET(BD),
497  PRESET_ALIAS(SLOW, HQ, NVENC_TWO_PASSES),
498  PRESET_ALIAS(MEDIUM, HQ, NVENC_ONE_PASS),
499  PRESET_ALIAS(FAST, HP, NVENC_ONE_PASS),
500  PRESET(LOW_LATENCY_DEFAULT, NVENC_LOWLATENCY),
501  PRESET(LOW_LATENCY_HP, NVENC_LOWLATENCY),
502  PRESET(LOW_LATENCY_HQ, NVENC_LOWLATENCY),
503  PRESET(LOSSLESS_DEFAULT, NVENC_LOSSLESS),
504  PRESET(LOSSLESS_HP, NVENC_LOSSLESS),
505  };
506 
507  GUIDTuple *t = &presets[ctx->preset];
508 
510  ctx->flags = t->flags;
511 }
512 
513 #undef PRESET
514 #undef PRESET_ALIAS
515 
516 static av_cold void set_constqp(AVCodecContext *avctx)
517 {
518  NvencContext *ctx = avctx->priv_data;
520 
522 
523  if (ctx->init_qp_p >= 0) {
524  rc->constQP.qpInterP = ctx->init_qp_p;
525  if (ctx->init_qp_i >= 0 && ctx->init_qp_b >= 0) {
526  rc->constQP.qpIntra = ctx->init_qp_i;
527  rc->constQP.qpInterB = ctx->init_qp_b;
528  } else if (avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) {
529  rc->constQP.qpIntra = av_clip(
530  rc->constQP.qpInterP * fabs(avctx->i_quant_factor) + avctx->i_quant_offset + 0.5, 0, 51);
531  rc->constQP.qpInterB = av_clip(
532  rc->constQP.qpInterP * fabs(avctx->b_quant_factor) + avctx->b_quant_offset + 0.5, 0, 51);
533  } else {
534  rc->constQP.qpIntra = rc->constQP.qpInterP;
535  rc->constQP.qpInterB = rc->constQP.qpInterP;
536  }
537  } else if (ctx->cqp >= 0) {
538  rc->constQP.qpInterP = rc->constQP.qpInterB = rc->constQP.qpIntra = ctx->cqp;
539  if (avctx->b_quant_factor != 0.0)
540  rc->constQP.qpInterB = av_clip(ctx->cqp * fabs(avctx->b_quant_factor) + avctx->b_quant_offset + 0.5, 0, 51);
541  if (avctx->i_quant_factor != 0.0)
542  rc->constQP.qpIntra = av_clip(ctx->cqp * fabs(avctx->i_quant_factor) + avctx->i_quant_offset + 0.5, 0, 51);
543  }
544 
545  avctx->qmin = -1;
546  avctx->qmax = -1;
547 }
548 
549 static av_cold void set_vbr(AVCodecContext *avctx)
550 {
551  NvencContext *ctx = avctx->priv_data;
553  int qp_inter_p;
554 
555  if (avctx->qmin >= 0 && avctx->qmax >= 0) {
556  rc->enableMinQP = 1;
557  rc->enableMaxQP = 1;
558 
559  rc->minQP.qpInterB = avctx->qmin;
560  rc->minQP.qpInterP = avctx->qmin;
561  rc->minQP.qpIntra = avctx->qmin;
562 
563  rc->maxQP.qpInterB = avctx->qmax;
564  rc->maxQP.qpInterP = avctx->qmax;
565  rc->maxQP.qpIntra = avctx->qmax;
566 
567  qp_inter_p = (avctx->qmax + 3 * avctx->qmin) / 4; // biased towards Qmin
568  } else if (avctx->qmin >= 0) {
569  rc->enableMinQP = 1;
570 
571  rc->minQP.qpInterB = avctx->qmin;
572  rc->minQP.qpInterP = avctx->qmin;
573  rc->minQP.qpIntra = avctx->qmin;
574 
575  qp_inter_p = avctx->qmin;
576  } else {
577  qp_inter_p = 26; // default to 26
578  }
579 
580  rc->enableInitialRCQP = 1;
581 
582  if (ctx->init_qp_p < 0) {
583  rc->initialRCQP.qpInterP = qp_inter_p;
584  } else {
585  rc->initialRCQP.qpInterP = ctx->init_qp_p;
586  }
587 
588  if (ctx->init_qp_i < 0) {
589  if (avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) {
590  rc->initialRCQP.qpIntra = av_clip(
591  rc->initialRCQP.qpInterP * fabs(avctx->i_quant_factor) + avctx->i_quant_offset + 0.5, 0, 51);
592  } else {
594  }
595  } else {
596  rc->initialRCQP.qpIntra = ctx->init_qp_i;
597  }
598 
599  if (ctx->init_qp_b < 0) {
600  if (avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) {
601  rc->initialRCQP.qpInterB = av_clip(
602  rc->initialRCQP.qpInterP * fabs(avctx->b_quant_factor) + avctx->b_quant_offset + 0.5, 0, 51);
603  } else {
605  }
606  } else {
607  rc->initialRCQP.qpInterB = ctx->init_qp_b;
608  }
609 }
610 
612 {
613  NvencContext *ctx = avctx->priv_data;
615 
617  rc->constQP.qpInterB = 0;
618  rc->constQP.qpInterP = 0;
619  rc->constQP.qpIntra = 0;
620 
621  avctx->qmin = -1;
622  avctx->qmax = -1;
623 }
624 
626 {
627  NvencContext *ctx = avctx->priv_data;
629 
630  switch (ctx->rc) {
632  set_constqp(avctx);
633  return;
635  if (avctx->qmin < 0) {
636  av_log(avctx, AV_LOG_WARNING,
637  "The variable bitrate rate-control requires "
638  "the 'qmin' option set.\n");
639  set_vbr(avctx);
640  return;
641  }
642  /* fall through */
645  set_vbr(avctx);
646  break;
650  break;
651  }
652 
653  rc->rateControlMode = ctx->rc;
654 }
655 
657 {
658  NvencContext *ctx = avctx->priv_data;
659  int nb_surfaces = 0;
660 
661  if (ctx->rc_lookahead > 0) {
662  nb_surfaces = ctx->rc_lookahead + ((ctx->encode_config.frameIntervalP > 0) ? ctx->encode_config.frameIntervalP : 0) + 1 + 4;
663  if (ctx->nb_surfaces < nb_surfaces) {
664  av_log(avctx, AV_LOG_WARNING,
665  "Defined rc_lookahead requires more surfaces, "
666  "increasing used surfaces %d -> %d\n", ctx->nb_surfaces, nb_surfaces);
667  ctx->nb_surfaces = nb_surfaces;
668  }
669  }
670 
672  ctx->async_depth = FFMIN(ctx->async_depth, ctx->nb_surfaces - 1);
673 
674  return 0;
675 }
676 
678 {
679  NvencContext *ctx = avctx->priv_data;
680 
681  if (avctx->global_quality > 0)
682  av_log(avctx, AV_LOG_WARNING, "Using global_quality with nvenc is deprecated. Use qp instead.\n");
683 
684  if (ctx->cqp < 0 && avctx->global_quality > 0)
685  ctx->cqp = avctx->global_quality;
686 
687  if (avctx->bit_rate > 0) {
689  } else if (ctx->encode_config.rcParams.averageBitRate > 0) {
691  }
692 
693  if (avctx->rc_max_rate > 0)
695 
696  if (ctx->rc < 0) {
697  if (ctx->flags & NVENC_ONE_PASS)
698  ctx->twopass = 0;
699  if (ctx->flags & NVENC_TWO_PASSES)
700  ctx->twopass = 1;
701 
702  if (ctx->twopass < 0)
703  ctx->twopass = (ctx->flags & NVENC_LOWLATENCY) != 0;
704 
705  if (ctx->cbr) {
706  if (ctx->twopass) {
708  } else {
709  ctx->rc = NV_ENC_PARAMS_RC_CBR;
710  }
711  } else if (ctx->cqp >= 0) {
713  } else if (ctx->twopass) {
715  } else if (avctx->qmin >= 0 && avctx->qmax >= 0) {
717  }
718  }
719 
720  if (ctx->flags & NVENC_LOSSLESS) {
721  set_lossless(avctx);
722  } else if (ctx->rc >= 0) {
724  } else {
726  set_vbr(avctx);
727  }
728 
729  if (avctx->rc_buffer_size > 0) {
731  } else if (ctx->encode_config.rcParams.averageBitRate > 0) {
733  }
734 
735  if (ctx->aq) {
738  av_log(avctx, AV_LOG_VERBOSE, "AQ enabled.\n");
739  }
740 
741  if (ctx->temporal_aq) {
743  av_log(avctx, AV_LOG_VERBOSE, "Temporal AQ enabled.\n");
744  }
745 
746  if (ctx->rc_lookahead > 0) {
747  int lkd_bound = FFMIN(ctx->nb_surfaces, ctx->async_depth) -
748  ctx->encode_config.frameIntervalP - 4;
749 
750  if (lkd_bound < 0) {
751  av_log(avctx, AV_LOG_WARNING,
752  "Lookahead not enabled. Increase buffer delay (-delay).\n");
753  } else {
755  ctx->encode_config.rcParams.lookaheadDepth = av_clip(ctx->rc_lookahead, 0, lkd_bound);
758  av_log(avctx, AV_LOG_VERBOSE,
759  "Lookahead enabled: depth %d, scenecut %s, B-adapt %s.\n",
761  ctx->encode_config.rcParams.disableIadapt ? "disabled" : "enabled",
762  ctx->encode_config.rcParams.disableBadapt ? "disabled" : "enabled");
763  }
764  }
765 
766  if (ctx->strict_gop) {
768  av_log(avctx, AV_LOG_VERBOSE, "Strict GOP target enabled.\n");
769  }
770 
771  if (ctx->nonref_p)
773 
774  if (ctx->zerolatency)
776 
777  if (ctx->quality)
779 }
780 
782 {
783  NvencContext *ctx = avctx->priv_data;
784  NV_ENC_CONFIG *cc = &ctx->encode_config;
787 
788  vui->colourMatrix = avctx->colorspace;
789  vui->colourPrimaries = avctx->color_primaries;
790  vui->transferCharacteristics = avctx->color_trc;
793 
795  (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2);
796 
799  || vui->videoFormat != 5
800  || vui->videoFullRangeFlag != 0);
801 
802  h264->sliceMode = 3;
803  h264->sliceModeData = 1;
804 
805  h264->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
806  h264->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
807  h264->outputAUD = ctx->aud;
808 
809  if (avctx->refs >= 0) {
810  /* 0 means "let the hardware decide" */
811  h264->maxNumRefFrames = avctx->refs;
812  }
813  if (avctx->gop_size >= 0) {
814  h264->idrPeriod = cc->gopLength;
815  }
816 
817  if (IS_CBR(cc->rcParams.rateControlMode)) {
818  h264->outputBufferingPeriodSEI = 1;
819  h264->outputPictureTimingSEI = 1;
820  }
821 
827  }
828 
829  if (ctx->flags & NVENC_LOSSLESS) {
831  } else {
832  switch(ctx->profile) {
836  break;
839  avctx->profile = FF_PROFILE_H264_MAIN;
840  break;
843  avctx->profile = FF_PROFILE_H264_HIGH;
844  break;
848  break;
849  }
850  }
851 
852  // force setting profile as high444p if input is AV_PIX_FMT_YUV444P
853  if (ctx->data_pix_fmt == AV_PIX_FMT_YUV444P) {
856  }
857 
859 
860  h264->level = ctx->level;
861 
862  return 0;
863 }
864 
866 {
867  NvencContext *ctx = avctx->priv_data;
868  NV_ENC_CONFIG *cc = &ctx->encode_config;
871 
872  vui->colourMatrix = avctx->colorspace;
873  vui->colourPrimaries = avctx->color_primaries;
874  vui->transferCharacteristics = avctx->color_trc;
877 
879  (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2);
880 
883  || vui->videoFormat != 5
884  || vui->videoFullRangeFlag != 0);
885 
886  hevc->sliceMode = 3;
887  hevc->sliceModeData = 1;
888 
889  hevc->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
890  hevc->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
891  hevc->outputAUD = ctx->aud;
892 
893  if (avctx->refs >= 0) {
894  /* 0 means "let the hardware decide" */
895  hevc->maxNumRefFramesInDPB = avctx->refs;
896  }
897  if (avctx->gop_size >= 0) {
898  hevc->idrPeriod = cc->gopLength;
899  }
900 
901  if (IS_CBR(cc->rcParams.rateControlMode)) {
902  hevc->outputBufferingPeriodSEI = 1;
903  hevc->outputPictureTimingSEI = 1;
904  }
905 
906  switch (ctx->profile) {
909  avctx->profile = FF_PROFILE_HEVC_MAIN;
910  break;
914  break;
917  avctx->profile = FF_PROFILE_HEVC_REXT;
918  break;
919  }
920 
921  // force setting profile as main10 if input is 10 bit
922  if (IS_10BIT(ctx->data_pix_fmt)) {
925  }
926 
927  // force setting profile as rext if input is yuv444
928  if (IS_YUV444(ctx->data_pix_fmt)) {
930  avctx->profile = FF_PROFILE_HEVC_REXT;
931  }
932 
933  hevc->chromaFormatIDC = IS_YUV444(ctx->data_pix_fmt) ? 3 : 1;
934 
935  hevc->pixelBitDepthMinus8 = IS_10BIT(ctx->data_pix_fmt) ? 2 : 0;
936 
937  hevc->level = ctx->level;
938 
939  hevc->tier = ctx->tier;
940 
941  return 0;
942 }
943 
945 {
946  switch (avctx->codec->id) {
947  case AV_CODEC_ID_H264:
948  return nvenc_setup_h264_config(avctx);
949  case AV_CODEC_ID_HEVC:
950  return nvenc_setup_hevc_config(avctx);
951  /* Earlier switch/case will return if unknown codec is passed. */
952  }
953 
954  return 0;
955 }
956 
958 {
959  NvencContext *ctx = avctx->priv_data;
961  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
962 
963  NV_ENC_PRESET_CONFIG preset_config = { 0 };
964  NVENCSTATUS nv_status = NV_ENC_SUCCESS;
965  AVCPBProperties *cpb_props;
966  CUresult cu_res;
968  int res = 0;
969  int dw, dh;
970 
973 
974  ctx->init_encode_params.encodeHeight = avctx->height;
975  ctx->init_encode_params.encodeWidth = avctx->width;
976 
978 
979  nvenc_map_preset(ctx);
980 
981  preset_config.version = NV_ENC_PRESET_CONFIG_VER;
982  preset_config.presetCfg.version = NV_ENC_CONFIG_VER;
983 
984  nv_status = p_nvenc->nvEncGetEncodePresetConfig(ctx->nvencoder,
987  &preset_config);
988  if (nv_status != NV_ENC_SUCCESS)
989  return nvenc_print_error(avctx, nv_status, "Cannot get the preset configuration");
990 
991  memcpy(&ctx->encode_config, &preset_config.presetCfg, sizeof(ctx->encode_config));
992 
994 
995  dw = avctx->width;
996  dh = avctx->height;
997  if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) {
998  dw*= avctx->sample_aspect_ratio.num;
999  dh*= avctx->sample_aspect_ratio.den;
1000  }
1001  av_reduce(&dw, &dh, dw, dh, 1024 * 1024);
1002  ctx->init_encode_params.darHeight = dh;
1003  ctx->init_encode_params.darWidth = dw;
1004 
1007 
1009  ctx->init_encode_params.enablePTD = 1;
1010 
1011  if (ctx->bluray_compat) {
1012  ctx->aud = 1;
1013  avctx->refs = FFMIN(FFMAX(avctx->refs, 0), 6);
1014  avctx->max_b_frames = FFMIN(avctx->max_b_frames, 3);
1015  switch (avctx->codec->id) {
1016  case AV_CODEC_ID_H264:
1017  /* maximum level depends on used resolution */
1018  break;
1019  case AV_CODEC_ID_HEVC:
1020  ctx->level = NV_ENC_LEVEL_HEVC_51;
1021  ctx->tier = NV_ENC_TIER_HEVC_HIGH;
1022  break;
1023  }
1024  }
1025 
1026  if (avctx->gop_size > 0) {
1027  if (avctx->max_b_frames >= 0) {
1028  /* 0 is intra-only, 1 is I/P only, 2 is one B-Frame, 3 two B-frames, and so on. */
1029  ctx->encode_config.frameIntervalP = avctx->max_b_frames + 1;
1030  }
1031 
1032  ctx->encode_config.gopLength = avctx->gop_size;
1033  } else if (avctx->gop_size == 0) {
1034  ctx->encode_config.frameIntervalP = 0;
1035  ctx->encode_config.gopLength = 1;
1036  }
1037 
1038  ctx->initial_pts[0] = AV_NOPTS_VALUE;
1039  ctx->initial_pts[1] = AV_NOPTS_VALUE;
1040 
1041  nvenc_recalc_surfaces(avctx);
1042 
1043  nvenc_setup_rate_control(avctx);
1044 
1045  if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
1047  } else {
1049  }
1050 
1051  res = nvenc_setup_codec_config(avctx);
1052  if (res)
1053  return res;
1054 
1055  cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
1056  if (cu_res != CUDA_SUCCESS) {
1057  av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
1058  return AVERROR_EXTERNAL;
1059  }
1060 
1061  nv_status = p_nvenc->nvEncInitializeEncoder(ctx->nvencoder, &ctx->init_encode_params);
1062 
1063  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
1064  if (cu_res != CUDA_SUCCESS) {
1065  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
1066  return AVERROR_EXTERNAL;
1067  }
1068 
1069  if (nv_status != NV_ENC_SUCCESS) {
1070  return nvenc_print_error(avctx, nv_status, "InitializeEncoder failed");
1071  }
1072 
1073  if (ctx->encode_config.frameIntervalP > 1)
1074  avctx->has_b_frames = 2;
1075 
1076  if (ctx->encode_config.rcParams.averageBitRate > 0)
1078 
1079  cpb_props = ff_add_cpb_side_data(avctx);
1080  if (!cpb_props)
1081  return AVERROR(ENOMEM);
1082  cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate;
1083  cpb_props->avg_bitrate = avctx->bit_rate;
1084  cpb_props->buffer_size = ctx->encode_config.rcParams.vbvBufferSize;
1085 
1086  return 0;
1087 }
1088 
1090 {
1091  switch (pix_fmt) {
1092  case AV_PIX_FMT_YUV420P:
1094  case AV_PIX_FMT_NV12:
1096  case AV_PIX_FMT_P010:
1098  case AV_PIX_FMT_YUV444P:
1100  case AV_PIX_FMT_YUV444P16:
1102  case AV_PIX_FMT_0RGB32:
1104  case AV_PIX_FMT_0BGR32:
1106  default:
1108  }
1109 }
1110 
1111 static av_cold int nvenc_alloc_surface(AVCodecContext *avctx, int idx)
1112 {
1113  NvencContext *ctx = avctx->priv_data;
1115  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1116 
1117  NVENCSTATUS nv_status;
1118  NV_ENC_CREATE_BITSTREAM_BUFFER allocOut = { 0 };
1120 
1121  if (avctx->pix_fmt == AV_PIX_FMT_CUDA) {
1122  ctx->surfaces[idx].in_ref = av_frame_alloc();
1123  if (!ctx->surfaces[idx].in_ref)
1124  return AVERROR(ENOMEM);
1125  } else {
1126  NV_ENC_CREATE_INPUT_BUFFER allocSurf = { 0 };
1127 
1129  if (ctx->surfaces[idx].format == NV_ENC_BUFFER_FORMAT_UNDEFINED) {
1130  av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format: %s\n",
1132  return AVERROR(EINVAL);
1133  }
1134 
1136  allocSurf.width = avctx->width;
1137  allocSurf.height = avctx->height;
1139  allocSurf.bufferFmt = ctx->surfaces[idx].format;
1140 
1141  nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->nvencoder, &allocSurf);
1142  if (nv_status != NV_ENC_SUCCESS) {
1143  return nvenc_print_error(avctx, nv_status, "CreateInputBuffer failed");
1144  }
1145 
1146  ctx->surfaces[idx].input_surface = allocSurf.inputBuffer;
1147  ctx->surfaces[idx].width = allocSurf.width;
1148  ctx->surfaces[idx].height = allocSurf.height;
1149  }
1150 
1151  ctx->surfaces[idx].lockCount = 0;
1152 
1153  /* 1MB is large enough to hold most output frames.
1154  * NVENC increases this automaticaly if it is not enough. */
1155  allocOut.size = 1024 * 1024;
1156 
1158 
1159  nv_status = p_nvenc->nvEncCreateBitstreamBuffer(ctx->nvencoder, &allocOut);
1160  if (nv_status != NV_ENC_SUCCESS) {
1161  int err = nvenc_print_error(avctx, nv_status, "CreateBitstreamBuffer failed");
1162  if (avctx->pix_fmt != AV_PIX_FMT_CUDA)
1163  p_nvenc->nvEncDestroyInputBuffer(ctx->nvencoder, ctx->surfaces[idx].input_surface);
1164  av_frame_free(&ctx->surfaces[idx].in_ref);
1165  return err;
1166  }
1167 
1168  ctx->surfaces[idx].output_surface = allocOut.bitstreamBuffer;
1169  ctx->surfaces[idx].size = allocOut.size;
1170 
1171  return 0;
1172 }
1173 
1175 {
1176  NvencContext *ctx = avctx->priv_data;
1178  CUresult cu_res;
1179  CUcontext dummy;
1180  int i, res;
1181 
1182  ctx->surfaces = av_mallocz_array(ctx->nb_surfaces, sizeof(*ctx->surfaces));
1183  if (!ctx->surfaces)
1184  return AVERROR(ENOMEM);
1185 
1186  ctx->timestamp_list = av_fifo_alloc(ctx->nb_surfaces * sizeof(int64_t));
1187  if (!ctx->timestamp_list)
1188  return AVERROR(ENOMEM);
1190  if (!ctx->output_surface_queue)
1191  return AVERROR(ENOMEM);
1193  if (!ctx->output_surface_ready_queue)
1194  return AVERROR(ENOMEM);
1195 
1196  cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
1197  if (cu_res != CUDA_SUCCESS) {
1198  av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
1199  return AVERROR_EXTERNAL;
1200  }
1201 
1202  for (i = 0; i < ctx->nb_surfaces; i++) {
1203  if ((res = nvenc_alloc_surface(avctx, i)) < 0)
1204  {
1205  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
1206  if (cu_res != CUDA_SUCCESS) {
1207  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
1208  return AVERROR_EXTERNAL;
1209  }
1210  return res;
1211  }
1212  }
1213 
1214  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
1215  if (cu_res != CUDA_SUCCESS) {
1216  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
1217  return AVERROR_EXTERNAL;
1218  }
1219 
1220  return 0;
1221 }
1222 
1224 {
1225  NvencContext *ctx = avctx->priv_data;
1227  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1228 
1229  NVENCSTATUS nv_status;
1230  uint32_t outSize = 0;
1231  char tmpHeader[256];
1232  NV_ENC_SEQUENCE_PARAM_PAYLOAD payload = { 0 };
1234 
1235  payload.spsppsBuffer = tmpHeader;
1236  payload.inBufferSize = sizeof(tmpHeader);
1237  payload.outSPSPPSPayloadSize = &outSize;
1238 
1239  nv_status = p_nvenc->nvEncGetSequenceParams(ctx->nvencoder, &payload);
1240  if (nv_status != NV_ENC_SUCCESS) {
1241  return nvenc_print_error(avctx, nv_status, "GetSequenceParams failed");
1242  }
1243 
1244  avctx->extradata_size = outSize;
1246 
1247  if (!avctx->extradata) {
1248  return AVERROR(ENOMEM);
1249  }
1250 
1251  memcpy(avctx->extradata, tmpHeader, outSize);
1252 
1253  return 0;
1254 }
1255 
1257 {
1258  NvencContext *ctx = avctx->priv_data;
1260  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1261  CUresult cu_res;
1262  CUcontext dummy;
1263  int i;
1264 
1265  /* the encoder has to be flushed before it can be closed */
1266  if (ctx->nvencoder) {
1268  .encodePicFlags = NV_ENC_PIC_FLAG_EOS };
1269 
1270  cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
1271  if (cu_res != CUDA_SUCCESS) {
1272  av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
1273  return AVERROR_EXTERNAL;
1274  }
1275 
1276  p_nvenc->nvEncEncodePicture(ctx->nvencoder, &params);
1277  }
1278 
1282 
1283  if (ctx->surfaces && avctx->pix_fmt == AV_PIX_FMT_CUDA) {
1284  for (i = 0; i < ctx->nb_surfaces; ++i) {
1285  if (ctx->surfaces[i].input_surface) {
1287  }
1288  }
1289  for (i = 0; i < ctx->nb_registered_frames; i++) {
1290  if (ctx->registered_frames[i].regptr)
1292  }
1293  ctx->nb_registered_frames = 0;
1294  }
1295 
1296  if (ctx->surfaces) {
1297  for (i = 0; i < ctx->nb_surfaces; ++i) {
1298  if (avctx->pix_fmt != AV_PIX_FMT_CUDA)
1299  p_nvenc->nvEncDestroyInputBuffer(ctx->nvencoder, ctx->surfaces[i].input_surface);
1300  av_frame_free(&ctx->surfaces[i].in_ref);
1302  }
1303  }
1304  av_freep(&ctx->surfaces);
1305  ctx->nb_surfaces = 0;
1306 
1307  if (ctx->nvencoder) {
1308  p_nvenc->nvEncDestroyEncoder(ctx->nvencoder);
1309 
1310  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
1311  if (cu_res != CUDA_SUCCESS) {
1312  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
1313  return AVERROR_EXTERNAL;
1314  }
1315  }
1316  ctx->nvencoder = NULL;
1317 
1318  if (ctx->cu_context_internal)
1320  ctx->cu_context = ctx->cu_context_internal = NULL;
1321 
1322  nvenc_free_functions(&dl_fn->nvenc_dl);
1323  cuda_free_functions(&dl_fn->cuda_dl);
1324 
1325  dl_fn->nvenc_device_count = 0;
1326 
1327  av_log(avctx, AV_LOG_VERBOSE, "Nvenc unloaded\n");
1328 
1329  return 0;
1330 }
1331 
1333 {
1334  NvencContext *ctx = avctx->priv_data;
1335  int ret;
1336 
1337  if (avctx->pix_fmt == AV_PIX_FMT_CUDA) {
1338  AVHWFramesContext *frames_ctx;
1339  if (!avctx->hw_frames_ctx) {
1340  av_log(avctx, AV_LOG_ERROR,
1341  "hw_frames_ctx must be set when using GPU frames as input\n");
1342  return AVERROR(EINVAL);
1343  }
1344  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1345  ctx->data_pix_fmt = frames_ctx->sw_format;
1346  } else {
1347  ctx->data_pix_fmt = avctx->pix_fmt;
1348  }
1349 
1350  if ((ret = nvenc_load_libraries(avctx)) < 0)
1351  return ret;
1352 
1353  if ((ret = nvenc_setup_device(avctx)) < 0)
1354  return ret;
1355 
1356  if ((ret = nvenc_setup_encoder(avctx)) < 0)
1357  return ret;
1358 
1359  if ((ret = nvenc_setup_surfaces(avctx)) < 0)
1360  return ret;
1361 
1362  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
1363  if ((ret = nvenc_setup_extradata(avctx)) < 0)
1364  return ret;
1365  }
1366 
1367  return 0;
1368 }
1369 
1371 {
1372  int i;
1373 
1374  for (i = 0; i < ctx->nb_surfaces; i++) {
1375  if (!ctx->surfaces[i].lockCount) {
1376  ctx->surfaces[i].lockCount = 1;
1377  return &ctx->surfaces[i];
1378  }
1379  }
1380 
1381  return NULL;
1382 }
1383 
1384 static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *nv_surface,
1385  NV_ENC_LOCK_INPUT_BUFFER *lock_buffer_params, const AVFrame *frame)
1386 {
1387  int dst_linesize[4] = {
1388  lock_buffer_params->pitch,
1389  lock_buffer_params->pitch,
1390  lock_buffer_params->pitch,
1391  lock_buffer_params->pitch
1392  };
1393  uint8_t *dst_data[4];
1394  int ret;
1395 
1396  if (frame->format == AV_PIX_FMT_YUV420P)
1397  dst_linesize[1] = dst_linesize[2] >>= 1;
1398 
1399  ret = av_image_fill_pointers(dst_data, frame->format, nv_surface->height,
1400  lock_buffer_params->bufferDataPtr, dst_linesize);
1401  if (ret < 0)
1402  return ret;
1403 
1404  if (frame->format == AV_PIX_FMT_YUV420P)
1405  FFSWAP(uint8_t*, dst_data[1], dst_data[2]);
1406 
1407  av_image_copy(dst_data, dst_linesize,
1408  (const uint8_t**)frame->data, frame->linesize, frame->format,
1409  avctx->width, avctx->height);
1410 
1411  return 0;
1412 }
1413 
1415 {
1416  NvencContext *ctx = avctx->priv_data;
1418  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1419 
1420  int i;
1421 
1423  for (i = 0; i < ctx->nb_registered_frames; i++) {
1424  if (!ctx->registered_frames[i].mapped) {
1425  if (ctx->registered_frames[i].regptr) {
1426  p_nvenc->nvEncUnregisterResource(ctx->nvencoder,
1427  ctx->registered_frames[i].regptr);
1428  ctx->registered_frames[i].regptr = NULL;
1429  }
1430  return i;
1431  }
1432  }
1433  } else {
1434  return ctx->nb_registered_frames++;
1435  }
1436 
1437  av_log(avctx, AV_LOG_ERROR, "Too many registered CUDA frames\n");
1438  return AVERROR(ENOMEM);
1439 }
1440 
1442 {
1443  NvencContext *ctx = avctx->priv_data;
1445  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1446 
1447  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1449  int i, idx, ret;
1450 
1451  for (i = 0; i < ctx->nb_registered_frames; i++) {
1452  if (ctx->registered_frames[i].ptr == (CUdeviceptr)frame->data[0])
1453  return i;
1454  }
1455 
1456  idx = nvenc_find_free_reg_resource(avctx);
1457  if (idx < 0)
1458  return idx;
1459 
1460  reg.version = NV_ENC_REGISTER_RESOURCE_VER;
1461  reg.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR;
1462  reg.width = frames_ctx->width;
1463  reg.height = frames_ctx->height;
1464  reg.pitch = frame->linesize[0];
1465  reg.resourceToRegister = frame->data[0];
1466 
1467  reg.bufferFormat = nvenc_map_buffer_format(frames_ctx->sw_format);
1468  if (reg.bufferFormat == NV_ENC_BUFFER_FORMAT_UNDEFINED) {
1469  av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format: %s\n",
1470  av_get_pix_fmt_name(frames_ctx->sw_format));
1471  return AVERROR(EINVAL);
1472  }
1473 
1474  ret = p_nvenc->nvEncRegisterResource(ctx->nvencoder, &reg);
1475  if (ret != NV_ENC_SUCCESS) {
1476  nvenc_print_error(avctx, ret, "Error registering an input resource");
1477  return AVERROR_UNKNOWN;
1478  }
1479 
1480  ctx->registered_frames[idx].ptr = (CUdeviceptr)frame->data[0];
1481  ctx->registered_frames[idx].regptr = reg.registeredResource;
1482  return idx;
1483 }
1484 
1486  NvencSurface *nvenc_frame)
1487 {
1488  NvencContext *ctx = avctx->priv_data;
1490  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1491 
1492  int res;
1493  NVENCSTATUS nv_status;
1494 
1495  if (avctx->pix_fmt == AV_PIX_FMT_CUDA) {
1496  int reg_idx = nvenc_register_frame(avctx, frame);
1497  if (reg_idx < 0) {
1498  av_log(avctx, AV_LOG_ERROR, "Could not register an input CUDA frame\n");
1499  return reg_idx;
1500  }
1501 
1502  res = av_frame_ref(nvenc_frame->in_ref, frame);
1503  if (res < 0)
1504  return res;
1505 
1507  nvenc_frame->in_map.registeredResource = ctx->registered_frames[reg_idx].regptr;
1508  nv_status = p_nvenc->nvEncMapInputResource(ctx->nvencoder, &nvenc_frame->in_map);
1509  if (nv_status != NV_ENC_SUCCESS) {
1510  av_frame_unref(nvenc_frame->in_ref);
1511  return nvenc_print_error(avctx, nv_status, "Error mapping an input resource");
1512  }
1513 
1514  ctx->registered_frames[reg_idx].mapped = 1;
1515  nvenc_frame->reg_idx = reg_idx;
1516  nvenc_frame->input_surface = nvenc_frame->in_map.mappedResource;
1517  nvenc_frame->format = nvenc_frame->in_map.mappedBufferFmt;
1518  nvenc_frame->pitch = frame->linesize[0];
1519  return 0;
1520  } else {
1521  NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };
1522 
1523  lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
1524  lockBufferParams.inputBuffer = nvenc_frame->input_surface;
1525 
1526  nv_status = p_nvenc->nvEncLockInputBuffer(ctx->nvencoder, &lockBufferParams);
1527  if (nv_status != NV_ENC_SUCCESS) {
1528  return nvenc_print_error(avctx, nv_status, "Failed locking nvenc input buffer");
1529  }
1530 
1531  nvenc_frame->pitch = lockBufferParams.pitch;
1532  res = nvenc_copy_frame(avctx, nvenc_frame, &lockBufferParams, frame);
1533 
1534  nv_status = p_nvenc->nvEncUnlockInputBuffer(ctx->nvencoder, nvenc_frame->input_surface);
1535  if (nv_status != NV_ENC_SUCCESS) {
1536  return nvenc_print_error(avctx, nv_status, "Failed unlocking input buffer!");
1537  }
1538 
1539  return res;
1540  }
1541 }
1542 
1545 {
1546  NvencContext *ctx = avctx->priv_data;
1547 
1548  switch (avctx->codec->id) {
1549  case AV_CODEC_ID_H264:
1554  break;
1555  case AV_CODEC_ID_HEVC:
1560  break;
1561  }
1562 }
1563 
1564 static inline void timestamp_queue_enqueue(AVFifoBuffer* queue, int64_t timestamp)
1565 {
1566  av_fifo_generic_write(queue, &timestamp, sizeof(timestamp), NULL);
1567 }
1568 
1569 static inline int64_t timestamp_queue_dequeue(AVFifoBuffer* queue)
1570 {
1571  int64_t timestamp = AV_NOPTS_VALUE;
1572  if (av_fifo_size(queue) > 0)
1573  av_fifo_generic_read(queue, &timestamp, sizeof(timestamp), NULL);
1574 
1575  return timestamp;
1576 }
1577 
1580  AVPacket *pkt)
1581 {
1582  NvencContext *ctx = avctx->priv_data;
1583 
1584  pkt->pts = params->outputTimeStamp;
1585 
1586  /* generate the first dts by linearly extrapolating the
1587  * first two pts values to the past */
1588  if (avctx->max_b_frames > 0 && !ctx->first_packet_output &&
1589  ctx->initial_pts[1] != AV_NOPTS_VALUE) {
1590  int64_t ts0 = ctx->initial_pts[0], ts1 = ctx->initial_pts[1];
1591  int64_t delta;
1592 
1593  if ((ts0 < 0 && ts1 > INT64_MAX + ts0) ||
1594  (ts0 > 0 && ts1 < INT64_MIN + ts0))
1595  return AVERROR(ERANGE);
1596  delta = ts1 - ts0;
1597 
1598  if ((delta < 0 && ts0 > INT64_MAX + delta) ||
1599  (delta > 0 && ts0 < INT64_MIN + delta))
1600  return AVERROR(ERANGE);
1601  pkt->dts = ts0 - delta;
1602 
1603  ctx->first_packet_output = 1;
1604  return 0;
1605  }
1606 
1608 
1609  return 0;
1610 }
1611 
1613 {
1614  NvencContext *ctx = avctx->priv_data;
1616  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1617 
1618  uint32_t slice_mode_data;
1619  uint32_t *slice_offsets = NULL;
1620  NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
1621  NVENCSTATUS nv_status;
1622  int res = 0;
1623 
1624  enum AVPictureType pict_type;
1625 
1626  switch (avctx->codec->id) {
1627  case AV_CODEC_ID_H264:
1629  break;
1630  case AV_CODEC_ID_H265:
1632  break;
1633  default:
1634  av_log(avctx, AV_LOG_ERROR, "Unknown codec name\n");
1635  res = AVERROR(EINVAL);
1636  goto error;
1637  }
1638  slice_offsets = av_mallocz(slice_mode_data * sizeof(*slice_offsets));
1639 
1640  if (!slice_offsets)
1641  goto error;
1642 
1643  lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
1644 
1645  lock_params.doNotWait = 0;
1646  lock_params.outputBitstream = tmpoutsurf->output_surface;
1647  lock_params.sliceOffsets = slice_offsets;
1648 
1649  nv_status = p_nvenc->nvEncLockBitstream(ctx->nvencoder, &lock_params);
1650  if (nv_status != NV_ENC_SUCCESS) {
1651  res = nvenc_print_error(avctx, nv_status, "Failed locking bitstream buffer");
1652  goto error;
1653  }
1654 
1655  if (res = ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes,0)) {
1656  p_nvenc->nvEncUnlockBitstream(ctx->nvencoder, tmpoutsurf->output_surface);
1657  goto error;
1658  }
1659 
1660  memcpy(pkt->data, lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
1661 
1662  nv_status = p_nvenc->nvEncUnlockBitstream(ctx->nvencoder, tmpoutsurf->output_surface);
1663  if (nv_status != NV_ENC_SUCCESS)
1664  nvenc_print_error(avctx, nv_status, "Failed unlocking bitstream buffer, expect the gates of mordor to open");
1665 
1666 
1667  if (avctx->pix_fmt == AV_PIX_FMT_CUDA) {
1668  p_nvenc->nvEncUnmapInputResource(ctx->nvencoder, tmpoutsurf->in_map.mappedResource);
1669  av_frame_unref(tmpoutsurf->in_ref);
1670  ctx->registered_frames[tmpoutsurf->reg_idx].mapped = 0;
1671 
1672  tmpoutsurf->input_surface = NULL;
1673  }
1674 
1675  switch (lock_params.pictureType) {
1676  case NV_ENC_PIC_TYPE_IDR:
1677  pkt->flags |= AV_PKT_FLAG_KEY;
1678  case NV_ENC_PIC_TYPE_I:
1679  pict_type = AV_PICTURE_TYPE_I;
1680  break;
1681  case NV_ENC_PIC_TYPE_P:
1682  pict_type = AV_PICTURE_TYPE_P;
1683  break;
1684  case NV_ENC_PIC_TYPE_B:
1685  pict_type = AV_PICTURE_TYPE_B;
1686  break;
1687  case NV_ENC_PIC_TYPE_BI:
1688  pict_type = AV_PICTURE_TYPE_BI;
1689  break;
1690  default:
1691  av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered, expect the output to be broken.\n");
1692  av_log(avctx, AV_LOG_ERROR, "Please report this error and include as much information on how to reproduce it as possible.\n");
1693  res = AVERROR_EXTERNAL;
1694  goto error;
1695  }
1696 
1697 #if FF_API_CODED_FRAME
1699  avctx->coded_frame->pict_type = pict_type;
1701 #endif
1702 
1704  (lock_params.frameAvgQP - 1) * FF_QP2LAMBDA, NULL, 0, pict_type);
1705 
1706  res = nvenc_set_timestamp(avctx, &lock_params, pkt);
1707  if (res < 0)
1708  goto error2;
1709 
1710  av_free(slice_offsets);
1711 
1712  return 0;
1713 
1714 error:
1716 
1717 error2:
1718  av_free(slice_offsets);
1719 
1720  return res;
1721 }
1722 
1723 static int output_ready(AVCodecContext *avctx, int flush)
1724 {
1725  NvencContext *ctx = avctx->priv_data;
1726  int nb_ready, nb_pending;
1727 
1728  /* when B-frames are enabled, we wait for two initial timestamps to
1729  * calculate the first dts */
1730  if (!flush && avctx->max_b_frames > 0 &&
1731  (ctx->initial_pts[0] == AV_NOPTS_VALUE || ctx->initial_pts[1] == AV_NOPTS_VALUE))
1732  return 0;
1733 
1734  nb_ready = av_fifo_size(ctx->output_surface_ready_queue) / sizeof(NvencSurface*);
1735  nb_pending = av_fifo_size(ctx->output_surface_queue) / sizeof(NvencSurface*);
1736  if (flush)
1737  return nb_ready > 0;
1738  return (nb_ready > 0) && (nb_ready + nb_pending >= ctx->async_depth);
1739 }
1740 
1742  const AVFrame *frame, int *got_packet)
1743 {
1744  NVENCSTATUS nv_status;
1745  CUresult cu_res;
1746  CUcontext dummy;
1747  NvencSurface *tmpoutsurf, *inSurf;
1748  int res;
1749 
1750  NvencContext *ctx = avctx->priv_data;
1752  NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
1753 
1754  NV_ENC_PIC_PARAMS pic_params = { 0 };
1755  pic_params.version = NV_ENC_PIC_PARAMS_VER;
1756 
1757  if (frame) {
1758  inSurf = get_free_frame(ctx);
1759  if (!inSurf) {
1760  av_log(avctx, AV_LOG_ERROR, "No free surfaces\n");
1761  return AVERROR_BUG;
1762  }
1763 
1764  cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
1765  if (cu_res != CUDA_SUCCESS) {
1766  av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
1767  return AVERROR_EXTERNAL;
1768  }
1769 
1770  res = nvenc_upload_frame(avctx, frame, inSurf);
1771 
1772  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
1773  if (cu_res != CUDA_SUCCESS) {
1774  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
1775  return AVERROR_EXTERNAL;
1776  }
1777 
1778  if (res) {
1779  inSurf->lockCount = 0;
1780  return res;
1781  }
1782 
1783  pic_params.inputBuffer = inSurf->input_surface;
1784  pic_params.bufferFmt = inSurf->format;
1785  pic_params.inputWidth = inSurf->width;
1786  pic_params.inputHeight = inSurf->height;
1787  pic_params.inputPitch = inSurf->pitch;
1788  pic_params.outputBitstream = inSurf->output_surface;
1789 
1790  if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
1791  if (frame->top_field_first)
1793  else
1795  } else {
1797  }
1798 
1799  if (ctx->forced_idr >= 0 && frame->pict_type == AV_PICTURE_TYPE_I) {
1800  pic_params.encodePicFlags =
1802  } else {
1803  pic_params.encodePicFlags = 0;
1804  }
1805 
1806  pic_params.inputTimeStamp = frame->pts;
1807 
1808  nvenc_codec_specific_pic_params(avctx, &pic_params);
1809  } else {
1810  pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
1811  }
1812 
1813  cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
1814  if (cu_res != CUDA_SUCCESS) {
1815  av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
1816  return AVERROR_EXTERNAL;
1817  }
1818 
1819  nv_status = p_nvenc->nvEncEncodePicture(ctx->nvencoder, &pic_params);
1820 
1821  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
1822  if (cu_res != CUDA_SUCCESS) {
1823  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
1824  return AVERROR_EXTERNAL;
1825  }
1826 
1827  if (nv_status != NV_ENC_SUCCESS &&
1828  nv_status != NV_ENC_ERR_NEED_MORE_INPUT)
1829  return nvenc_print_error(avctx, nv_status, "EncodePicture failed!");
1830 
1831  if (frame) {
1832  av_fifo_generic_write(ctx->output_surface_queue, &inSurf, sizeof(inSurf), NULL);
1834 
1835  if (ctx->initial_pts[0] == AV_NOPTS_VALUE)
1836  ctx->initial_pts[0] = frame->pts;
1837  else if (ctx->initial_pts[1] == AV_NOPTS_VALUE)
1838  ctx->initial_pts[1] = frame->pts;
1839  }
1840 
1841  /* all the pending buffers are now ready for output */
1842  if (nv_status == NV_ENC_SUCCESS) {
1843  while (av_fifo_size(ctx->output_surface_queue) > 0) {
1844  av_fifo_generic_read(ctx->output_surface_queue, &tmpoutsurf, sizeof(tmpoutsurf), NULL);
1845  av_fifo_generic_write(ctx->output_surface_ready_queue, &tmpoutsurf, sizeof(tmpoutsurf), NULL);
1846  }
1847  }
1848 
1849  if (output_ready(avctx, !frame)) {
1850  av_fifo_generic_read(ctx->output_surface_ready_queue, &tmpoutsurf, sizeof(tmpoutsurf), NULL);
1851 
1852  cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
1853  if (cu_res != CUDA_SUCCESS) {
1854  av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
1855  return AVERROR_EXTERNAL;
1856  }
1857 
1858  res = process_output_surface(avctx, pkt, tmpoutsurf);
1859 
1860  cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
1861  if (cu_res != CUDA_SUCCESS) {
1862  av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
1863  return AVERROR_EXTERNAL;
1864  }
1865 
1866  if (res)
1867  return res;
1868 
1869  av_assert0(tmpoutsurf->lockCount);
1870  tmpoutsurf->lockCount--;
1871 
1872  *got_packet = 1;
1873  } else {
1874  *got_packet = 0;
1875  }
1876 
1877  return 0;
1878 }
const GUID guid
Definition: nvenc.c:481
#define FF_PROFILE_H264_MAIN
Definition: avcodec.h:3276
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1287
int no_scenecut
Definition: nvenc.h:147
PNVENCGETENCODEGUIDS nvEncGetEncodeGUIDs
[out]: Client should access NvEncGetEncodeGUIDs() API through this pointer.
Definition: nvEncodeAPI.h:3157
uint32_t idrPeriod
[in]: Specifies the IDR interval.
Definition: nvEncodeAPI.h:1175
Progressive frame.
Definition: nvEncodeAPI.h:271
#define NULL
Definition: coverity.c:32
tcuDeviceGetName * cuDeviceGetName
const struct AVCodec * codec
Definition: avcodec.h:1741
const char const char void * val
Definition: avisynth_c.h:771
PNVENCCREATEBITSTREAMBUFFER nvEncCreateBitstreamBuffer
[out]: Client should access NvEncCreateBitstreamBuffer() API through this pointer.
Definition: nvEncodeAPI.h:3167
BI type.
Definition: avutil.h:280
void * nvencoder
Definition: nvenc.h:133
av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
Definition: nvenc.c:1256
int twopass
Definition: nvenc.h:141
static enum AVPixelFormat pix_fmt
uint32_t vbvBufferSize
[in]: Specifies the VBV(HRD) buffer size.
Definition: nvEncodeAPI.h:1062
Field encoding bottom field first.
Definition: nvEncodeAPI.h:273
NV_ENC_BUFFER_FORMAT format
Definition: nvenc.h:45
NV_ENC_QP constQP
[in]: Specifies the initial QP to be used for encoding, these values would be used for all frames if ...
Definition: nvEncodeAPI.h:1059
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
Definition: nvEncodeAPI.h:1425
int height
Definition: nvenc.h:41
struct NvencContext::@101 registered_frames[MAX_REGISTERED_FRAMES]
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
static av_cold int nvenc_setup_codec_config(AVCodecContext *avctx)
Definition: nvenc.c:944
AVFifoBuffer * timestamp_list
Definition: nvenc.h:115
uint32_t encodeWidth
[in]: Specifies the encode width.
Definition: nvEncodeAPI.h:1315
uint32_t enableTemporalAQ
[in]: Set this to 1 to enable temporal AQ for H.264
Definition: nvEncodeAPI.h:1072
uint32_t pitch
[out]: Pitch of the locked input buffer.
Definition: nvEncodeAPI.h:1602
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
Definition: avpacket.c:668
static void flush(AVCodecContext *avctx)
This indicates that the HW encoder is busy encoding and is unable to encode the input.
Definition: nvEncodeAPI.h:500
static const GUID NV_ENC_H264_PROFILE_HIGH_444_GUID
Definition: nvEncodeAPI.h:164
NvencFunctions * nvenc_dl
Definition: nvenc.h:53
static const GUID NV_ENC_HEVC_PROFILE_MAIN10_GUID
Definition: nvEncodeAPI.h:188
int mapped
Definition: nvenc.h:120
NV_ENC_REGISTERED_PTR registeredResource
[in]: The Registered resource handle obtained by calling NvEncRegisterInputResource.
Definition: nvEncodeAPI.h:1620
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:909
static av_cold void set_vbr(AVCodecContext *avctx)
Definition: nvenc.c:549
Indicates end of the input stream.
Definition: nvEncodeAPI.h:554
AVFrame * in_ref
Definition: nvenc.h:37
This indicates that the NvEncRegisterResource API failed to register the resource.
Definition: nvEncodeAPI.h:528
GUID presetGUID
[in]: Specifies the preset for encoding.
Definition: nvEncodeAPI.h:1314
void * device
[in]: Pointer to client device.
Definition: nvEncodeAPI.h:1716
Memory heap is in cached system memory.
Definition: nvEncodeAPI.h:564
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1797
Memory handling functions.
#define NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER
Macro for constructing the version field of _NV_ENC_SEQUENCE_PARAM_PAYLOAD.
Definition: nvEncodeAPI.h:1691
static av_cold int nvenc_setup_device(AVCodecContext *avctx)
Definition: nvenc.c:399
const char * desc
Definition: nvenc.c:60
void * outputBitstream
[in]: Pointer to the bitstream buffer being locked.
Definition: nvEncodeAPI.h:1566
uint32_t * sliceOffsets
[in,out]: Array which receives the slice offsets.
Definition: nvEncodeAPI.h:1567
uint32_t inBufferSize
[in]: Specifies the size of the spsppsBuffer provied by the client
Definition: nvEncodeAPI.h:1681
int max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition: avcodec.h:1351
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:2018
NV_ENC_INPUT_PTR inputBuffer
[in]: Pointer to the input buffer to be locked, client should pass the pointer obtained from NvEncCre...
Definition: nvEncodeAPI.h:1600
NV_ENC_CONFIG_H264 h264Config
[in]: Specifies the H.264-specific encoder configuration.
Definition: nvEncodeAPI.h:1275
NV_ENC_MAP_INPUT_RESOURCE in_map
Definition: nvenc.h:38
int forced_idr
Definition: nvenc.h:148
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:2469
PNVENCGETENCODECAPS nvEncGetEncodeCaps
[out]: Client should access NvEncGetEncodeCaps() API through this pointer.
Definition: nvEncodeAPI.h:3160
NV_ENC_MEMORY_HEAP memoryHeap
Definition: nvEncodeAPI.h:982
int num
Numerator.
Definition: rational.h:59
#define NV_ENC_CREATE_INPUT_BUFFER_VER
NV_ENC_CREATE_INPUT_BUFFER struct version.
Definition: nvEncodeAPI.h:973
uint32_t chromaFormatIDC
[in]: Specifies the chroma format.
Definition: nvEncodeAPI.h:1210
Forward predicted.
Definition: nvEncodeAPI.h:281
#define PRESET_ALIAS(alias, name,...)
Definition: nvenc.c:485
static av_cold int nvenc_setup_surfaces(AVCodecContext *avctx)
Definition: nvenc.c:1174
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs
Definition: nvenc.h:55
NV_ENC_OUTPUT_PTR bitstreamBuffer
[out]: Pointer to the output bitstream buffer
Definition: nvEncodeAPI.h:984
NvencDynLoadFunctions nvenc_dload_funcs
Definition: nvenc.h:103
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:2143
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:222
int first_packet_output
Definition: nvenc.h:131
NV_ENCODE_API_FUNCTION_LIST.
Definition: nvEncodeAPI.h:3149
This indicates that one or more of the parameter passed to the API call is invalid.
Definition: nvEncodeAPI.h:427
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1960
uint32_t qpPrimeYZeroTransformBypassFlag
[in]: To enable lossless encode set this to 1, set QP to 0 and RC_mode to NV_ENC_PARAMS_RC_CONSTQP an...
Definition: nvEncodeAPI.h:1170
This indicates that the encoder device supplied by the client is not valid.
Definition: nvEncodeAPI.h:396
NV_ENC_INPUT_PTR mappedResource
[out]: Mapped pointer corresponding to the registeredResource.
Definition: nvEncodeAPI.h:1621
This indicates that an unknown internal error has occurred.
Definition: nvEncodeAPI.h:511
static const GUID NV_ENC_HEVC_PROFILE_FREXT_GUID
Definition: nvEncodeAPI.h:193
NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE adaptiveTransformMode
[in]: Specifies the AdaptiveTransform Mode.
Definition: nvEncodeAPI.h:1181
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
static av_cold int nvenc_recalc_surfaces(AVCodecContext *avctx)
Definition: nvenc.c:656
static AVPacket pkt
int init_qp_b
Definition: nvenc.h:159
uint32_t height
[in]: Input buffer width
Definition: nvEncodeAPI.h:962
#define PRESET(name,...)
Definition: nvenc.c:488
NV_ENC_CODEC_PIC_PARAMS codecPicParams
[in]: Specifies the codec specific per-picture encoding parameters.
Definition: nvEncodeAPI.h:1511
int profile
profile
Definition: avcodec.h:3235
uint32_t enableAQ
[in]: Set this to 1 to enable adaptive quantization (Spatial).
Definition: nvEncodeAPI.h:1067
NV_ENC_PARAMS_FRAME_FIELD_MODE frameFieldMode
[in]: Specifies the frame/field mode.
Definition: nvEncodeAPI.h:1292
int preset
Definition: nvenc.h:135
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:2076
static void nvenc_override_rate_control(AVCodecContext *avctx)
Definition: nvenc.c:625
static NvencSurface * get_free_frame(NvencContext *ctx)
Definition: nvenc.c:1370
static av_cold void nvenc_setup_rate_control(AVCodecContext *avctx)
Definition: nvenc.c:677
NV_ENC_QP maxQP
[in]: Specifies the maximum QP used for rate control.
Definition: nvEncodeAPI.h:1079
PNVENCUNLOCKINPUTBUFFER nvEncUnlockInputBuffer
[out]: Client should access NvEncUnlockInputBuffer() API through this pointer.
Definition: nvEncodeAPI.h:3173
10 bit Planar YUV444 [Y plane followed by U and V planes].
Definition: nvEncodeAPI.h:315
int pitch
Definition: nvenc.h:42
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
Definition: fifo.c:122
Constant QP mode.
Definition: nvEncodeAPI.h:255
int nvenc_device_count
Definition: nvenc.h:56
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: avcodec.h:3286
NV_ENC_INPUT_PTR input_surface
Definition: nvenc.h:36
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1869
NVENCSTATUS nverr
Definition: nvenc.c:58
static const GUID NV_ENC_H264_PROFILE_MAIN_GUID
Definition: nvEncodeAPI.h:156
NV_ENC_QP initialRCQP
[in]: Specifies the initial QP used for rate control.
Definition: nvEncodeAPI.h:1080
Bi-directionally predicted with only Intra MBs.
Definition: nvEncodeAPI.h:285
NV_ENC_PARAMS_RC_MODE rateControlMode
[in]: Specifies the rate control mode.
Definition: nvEncodeAPI.h:1058
This indicates that an invalid struct version was used by the client.
Definition: nvEncodeAPI.h:471
int aq
Definition: nvenc.h:146
PNVENCDESTROYINPUTBUFFER nvEncDestroyInputBuffer
[out]: Client should access NvEncDestroyInputBuffer() API through this pointer.
Definition: nvEncodeAPI.h:3166
#define AV_PIX_FMT_P010
Definition: pixfmt.h:394
Creation parameters for input buffer.
Definition: nvEncodeAPI.h:958
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
CUcontext cu_context
Definition: nvenc.h:107
This indicates that API call returned with no errors.
Definition: nvEncodeAPI.h:380
uint32_t strictGOPTarget
[in]: Set this to 1 to minimize GOP-to-GOP rate fluctuations
Definition: nvEncodeAPI.h:1075
uint32_t size
[in]: Size of the bitstream buffer to be created
Definition: nvEncodeAPI.h:981
NV_ENC_CONFIG_H264_VUI_PARAMETERS h264VUIParameters
[in]: Specifies the H264 video usability info pamameters
Definition: nvEncodeAPI.h:1202
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:3274
PNVENCCREATEINPUTBUFFER nvEncCreateInputBuffer
[out]: Client should access NvEncCreateInputBuffer() API through this pointer.
Definition: nvEncodeAPI.h:3165
NV_ENC_CONFIG * encodeConfig
[in]: Specifies the advanced codec specific structure.
Definition: nvEncodeAPI.h:1331
#define DEFAULT
Definition: avdct.c:28
uint8_t
uint32_t inputWidth
[in]: Specifies the input buffer width
Definition: nvEncodeAPI.h:1498
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
Indicates HW support for field mode encoding.
Definition: nvEncodeAPI.h:665
PNVENCGETENCODEGUIDCOUNT nvEncGetEncodeGUIDCount
[out]: Client should access NvEncGetEncodeGUIDCount() API through this pointer.
Definition: nvEncodeAPI.h:3154
float delta
NV_ENC_MEMORY_HEAP memoryHeap
Definition: nvEncodeAPI.h:963
enum AVPixelFormat ff_nvenc_pix_fmts[]
Definition: nvenc.c:39
NV_ENC_PIC_PARAMS_HEVC hevcPicParams
[in]: HEVC encode picture params.
Definition: nvEncodeAPI.h:1487
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
Definition: avcodec.h:2027
PNVENCLOCKBITSTREAM nvEncLockBitstream
[out]: Client should access NvEncLockBitstream() API through this pointer.
Definition: nvEncodeAPI.h:3170
int init_qp_p
Definition: nvenc.h:158
Indicates HW support for 10 bit encoding.
Definition: nvEncodeAPI.h:921
uint32_t colourMatrix
[in]: Specifies the matrix coefficients used in deriving the luma and chroma from the RGB primaries (...
Definition: nvEncodeAPI.h:1107
#define FF_PROFILE_HEVC_MAIN
Definition: avcodec.h:3323
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:388
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
Input struct for querying Encoding capabilities.
Definition: nvEncodeAPI.h:944
Field encoding top field first.
Definition: nvEncodeAPI.h:272
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1847
#define NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER
Macro for constructing the version field of ::_NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS.
Definition: nvEncodeAPI.h:1723
NV_ENC_INITIALIZE_PARAMS init_encode_params
Definition: nvenc.h:105
static AVFrame * frame
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:85
uint32_t maxNumRefFrames
[in]: Specifies the DPB size used for encoding.
Definition: nvEncodeAPI.h:1189
static av_cold int nvenc_alloc_surface(AVCodecContext *avctx, int idx)
Definition: nvenc.c:1111
NV_ENC_OUTPUT_PTR outputBitstream
[in]: Specifies the pointer to output buffer.
Definition: nvEncodeAPI.h:1506
uint32_t outputBufferingPeriodSEI
[in]: Set to 1 to write SEI buffering period syntax in the bitstream
Definition: nvEncodeAPI.h:1158
#define height
This indicates encode driver requires more input buffers to produce an output bitstream.
Definition: nvEncodeAPI.h:493
#define MAX_REGISTERED_FRAMES
Definition: nvenc.h:32
Indicates HW support for lossless encoding.
Definition: nvEncodeAPI.h:887
uint8_t * data
Definition: avcodec.h:1657
static av_cold int nvenc_setup_extradata(AVCodecContext *avctx)
Definition: nvenc.c:1223
static int flags
Definition: log.c:57
This indicates that the client is attempting to use a feature that is not available for the license t...
Definition: nvEncodeAPI.h:517
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
Encode the current picture as an Intra picture.
Definition: nvEncodeAPI.h:549
Encode the current picture as an IDR picture.
Definition: nvEncodeAPI.h:550
NV_ENC_BUFFER_FORMAT
Input buffer formats.
Definition: nvEncodeAPI.h:306
static int nvenc_check_capabilities(AVCodecContext *avctx)
Definition: nvenc.c:230
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:364
static int nvenc_register_frame(AVCodecContext *avctx, const AVFrame *frame)
Definition: nvenc.c:1441
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: avcodec.h:1367
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
Undefined buffer format.
Definition: nvEncodeAPI.h:308
#define FF_PROFILE_HEVC_MAIN_10
Definition: avcodec.h:3324
tcuCtxPushCurrent_v2 * cuCtxPushCurrent
This indicates that the completion event passed in NvEncEncodePicture() API has not been registered w...
Definition: nvEncodeAPI.h:506
#define NV_ENC_MAP_INPUT_RESOURCE_VER
Macro for constructing the version field of _NV_ENC_MAP_INPUT_RESOURCE.
Definition: nvEncodeAPI.h:1628
uint32_t * outSPSPPSPayloadSize
[out]: Size of the sequence and picture header in bytes written by the NvEncodeAPI interface to the S...
Definition: nvEncodeAPI.h:1685
AVFifoBuffer * output_surface_ready_queue
Definition: nvenc.h:114
uint32_t apiVersion
[in]: API version.
Definition: nvEncodeAPI.h:1718
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1312
This indicates that the NvEncLockBitstream() failed to lock the output buffer.
Definition: nvEncodeAPI.h:460
Variable bitrate mode.
Definition: nvEncodeAPI.h:256
#define av_log(a,...)
uint32_t enableInitialRCQP
[in]: Set this to 1 if user suppplied initial QP is used for rate control.
Definition: nvEncodeAPI.h:1066
PNVENCLOCKINPUTBUFFER nvEncLockInputBuffer
[out]: Client should access NvEncLockInputBuffer() API through this pointer.
Definition: nvEncodeAPI.h:3172
CUdeviceptr ptr
Definition: nvenc.h:118
CUcontext cu_context_internal
Definition: nvenc.h:108
An API-specific header for AV_HWDEVICE_TYPE_CUDA.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1689
uint32_t outputBufferingPeriodSEI
[in]: Set 1 to write SEI buffering period syntax in the bitstream
Definition: nvEncodeAPI.h:1230
uint32_t inputPitch
[in]: Specifies the input buffer pitch.
Definition: nvEncodeAPI.h:1500
int async_depth
Definition: nvenc.h:144
uint32_t outputPictureTimingSEI
[in]: Set 1 to write SEI picture timing syntax in the bitstream
Definition: nvEncodeAPI.h:1231
enum AVCodecID id
Definition: avcodec.h:3695
uint32_t disableIadapt
[in]: Set this to 1 to disable adaptive I-frame insertion at scene cuts (only has an effect when look...
Definition: nvEncodeAPI.h:1070
PNVENCGETSEQUENCEPARAMS nvEncGetSequenceParams
[out]: Client should access NvEncGetSequenceParams() API through this pointer.
Definition: nvEncodeAPI.h:3175
uint32_t colourPrimaries
[in]: Specifies color primaries for converting to RGB(as defined in Annex E of the ITU-T Specificatio...
Definition: nvEncodeAPI.h:1105
static av_cold int nvenc_open_session(AVCodecContext *avctx)
Definition: nvenc.c:156
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:2054
static const GUID NV_ENC_CODEC_H264_GUID
Definition: nvEncodeAPI.h:134
Indicates HW support for lookahead encoding (enableLookahead=1).
Definition: nvEncodeAPI.h:908
input resource type is a cuda device pointer surface
Definition: nvEncodeAPI.h:630
static void timestamp_queue_enqueue(AVFifoBuffer *queue, int64_t timestamp)
Definition: nvenc.c:1564
int rc
Definition: nvenc.h:139
NV_ENC_CONFIG presetCfg
[out]: preset config returned by the Nvidia Video Encoder interface.
Definition: nvEncodeAPI.h:1375
uint32_t chromaFormatIDC
[in]: Specifies the chroma format.
Definition: nvEncodeAPI.h:1237
#define NV_ENC_LOCK_BITSTREAM_VER
Macro for constructing the version field of _NV_ENC_LOCK_BITSTREAM.
Definition: nvEncodeAPI.h:1588
uint32_t colourDescriptionPresentFlag
[in]: If set to 1, it specifies that the colourPrimaries, transferCharacteristics and colourMatrix ar...
Definition: nvEncodeAPI.h:1104
#define AVERROR(e)
Definition: error.h:43
int nb_registered_frames
Definition: nvenc.h:122
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
int qmax
maximum quantizer
Definition: avcodec.h:2682
This indicates that the size of the user buffer passed by the client is insufficient for the requeste...
Definition: nvEncodeAPI.h:466
uint64_t inputTimeStamp
[in]: Specifies presentation timestamp associated with the input picture.
Definition: nvEncodeAPI.h:1503
uint32_t disableBadapt
[in]: Set this to 1 to disable adaptive B-frame decision (only has an effect when lookahead is enable...
Definition: nvEncodeAPI.h:1071
static int nvenc_map_error(NVENCSTATUS err, const char **desc)
Definition: nvenc.c:90
NV_ENC_CAPS capsToQuery
[in]: Specifies the encode capability to be queried.
Definition: nvEncodeAPI.h:947
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
Definition: fifo.c:213
static const GUID NV_ENC_H264_PROFILE_BASELINE_GUID
Definition: nvEncodeAPI.h:152
uint32_t videoFullRangeFlag
[in]: Specifies the output range of the luma and chroma samples(as defined in Annex E of the ITU-T Sp...
Definition: nvEncodeAPI.h:1103
#define FF_PROFILE_H264_HIGH
Definition: avcodec.h:3278
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1827
GLenum GLint * params
Definition: opengl_enc.c:114
uint32_t bitstreamSizeInBytes
[out]: Actual number of bytes generated and copied to the memory pointed by bitstreamBufferPtr.
Definition: nvEncodeAPI.h:1571
NV_ENC_INPUT_PTR inputBuffer
[out]: Pointer to input buffer
Definition: nvEncodeAPI.h:966
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:90
simple assert() macros that are a bit more flexible than ISO C assert().
Multi pass encoding optimized for maintaining frame size and works only with low latency mode...
Definition: nvEncodeAPI.h:260
#define AV_PIX_FMT_0BGR32
Definition: pixfmt.h:331
PNVENCGETENCODEPRESETCONFIG nvEncGetEncodePresetConfig
[out]: Client should access NvEncGetEncodePresetConfig() API through this pointer.
Definition: nvEncodeAPI.h:3163
tcuInit * cuInit
This indicates that the client is attempting to unregister a resource that has not been successfully ...
Definition: nvEncodeAPI.h:534
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
Definition: avcodec.h:2069
uint32_t maxNumRefFramesInDPB
[in]: Specifies the maximum number of references frames in the DPB.
Definition: nvEncodeAPI.h:1244
uint32_t averageBitRate
[in]: Specifies the average bitrate(in bits/sec) used for encoding.
Definition: nvEncodeAPI.h:1060
static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
Definition: nvenc.c:865
GLsizei count
Definition: opengl_enc.c:109
static NV_ENC_BUFFER_FORMAT nvenc_map_buffer_format(enum AVPixelFormat pix_fmt)
Definition: nvenc.c:1089
#define FFMAX(a, b)
Definition: common.h:94
NV_ENC_PIC_PARAMS_H264 h264PicParams
[in]: H264 encode picture params.
Definition: nvEncodeAPI.h:1486
static av_cold void set_constqp(AVCodecContext *avctx)
Definition: nvenc.c:516
PNVENCREGISTERRESOURCE nvEncRegisterResource
[out]: Client should access NvEncRegisterResource() API through this pointer.
Definition: nvEncodeAPI.h:3183
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
#define fail()
Definition: checkasm.h:89
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:385
int level
Definition: nvenc.h:137
uint32_t videoSignalTypePresentFlag
[in]: If set to 1, it specifies that the videoFormat, videoFullRangeFlag and colourDescriptionPresent...
Definition: nvEncodeAPI.h:1101
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1663
int quality
Definition: nvenc.h:155
Encoder Session Creation parameters.
Definition: nvEncodeAPI.h:1712
int bluray_compat
Definition: nvenc.h:157
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2709
int aq_strength
Definition: nvenc.h:154
static int nvenc_check_codec_support(AVCodecContext *avctx)
Definition: nvenc.c:177
8 bit Packed A8B8G8R8
Definition: nvEncodeAPI.h:319
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1374
GUID profileGUID
[in]: Specifies the codec profile guid.
Definition: nvEncodeAPI.h:1288
uint32_t pixelBitDepthMinus8
[in]: Specifies pixel bit depth minus 8.
Definition: nvEncodeAPI.h:1238
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
Definition: nvEncodeAPI.h:1193
PNVENCENCODEPICTURE nvEncEncodePicture
[out]: Client should access NvEncEncodePicture() API through this pointer.
Definition: nvEncodeAPI.h:3169
int refs
number of reference frames
Definition: avcodec.h:2413
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1680
int flags
Definition: nvenc.h:143
#define NVENCAPI_MAJOR_VERSION
Definition: nvEncodeAPI.h:114
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
Definition: nvEncodeAPI.h:1461
This indicates that the client is attempting to use a feature that is not implemented for the current...
Definition: nvEncodeAPI.h:523
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:261
10 bit Semi-Planar YUV [Y plane followed by interleaved UV plane].
Definition: nvEncodeAPI.h:314
static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame, NvencSurface *nvenc_frame)
Definition: nvenc.c:1485
tcuCtxCreate_v2 * cuCtxCreate
uint32_t repeatSPSPPS
[in]: Set to 1 to enable writing of Sequence and Picture parameter for every IDR frame ...
Definition: nvEncodeAPI.h:1167
NV_ENC_REGISTERED_PTR regptr
Definition: nvenc.h:119
#define FFMIN(a, b)
Definition: common.h:96
static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
Definition: nvenc.c:957
uint32_t qpInterB
Definition: nvEncodeAPI.h:1048
NV_ENC_BUFFER_FORMAT mappedBufferFmt
[out]: Buffer format of the outputResource.
Definition: nvEncodeAPI.h:1622
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition: error.h:51
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:142
PNVENCOPENENCODESESSIONEX nvEncOpenEncodeSessionEx
[out]: Client should access NvEncOpenEncodeSession() API through this pointer.
Definition: nvEncodeAPI.h:3182
NV_ENC_QP minQP
[in]: Specifies the minimum QP used for rate control.
Definition: nvEncodeAPI.h:1078
int lockCount
Definition: nvenc.h:47
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
uint32_t encodePicFlags
[in]: Specifies bit-wise OR`ed encode pic flags.
Definition: nvEncodeAPI.h:1501
This indicates that device passed to the API call is invalid.
Definition: nvEncodeAPI.h:401
av_cold int ff_nvenc_encode_init(AVCodecContext *avctx)
Definition: nvenc.c:1332
#define width
This indicates that the client is attempting to unmap a resource that has not been successfully mappe...
Definition: nvEncodeAPI.h:540
static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencSurface *tmpoutsurf)
Definition: nvenc.c:1612
Maximum output height supported.
Definition: nvEncodeAPI.h:760
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: nvenc.c:1741
int width
picture width / height.
Definition: avcodec.h:1919
uint32_t idrPeriod
[in]: Specifies the IDR interval.
Definition: nvEncodeAPI.h:1240
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3585
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1497
#define NVENC_CAP
Definition: nvenc.c:34
uint16_t lookaheadDepth
[in]: Maximum depth of lookahead with range 0-32 (only used if enableLookahead=1) ...
Definition: nvEncodeAPI.h:1084
uint32_t aqStrength
[in]: When AQ (Spatial) is enabled (i.e.
Definition: nvEncodeAPI.h:1076
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:980
AVFormatContext * ctx
Definition: movenc.c:48
#define NV_ENCODE_API_FUNCTION_LIST_VER
Macro for constructing the version field of ::_NV_ENCODEAPI_FUNCTION_LIST.
Definition: nvEncodeAPI.h:3194
Multi pass encoding optimized for image quality and works only with low latency mode.
Definition: nvEncodeAPI.h:259
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2448
uint32_t zeroReorderDelay
[in]: Set this to 1 to indicate zero latency operation (no reordering delay, num_reorder_frames=0) ...
Definition: nvEncodeAPI.h:1073
Intra predicted picture.
Definition: nvEncodeAPI.h:283
Maximum output width supported.
Definition: nvEncodeAPI.h:755
static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *nv_surface, NV_ENC_LOCK_INPUT_BUFFER *lock_buffer_params, const AVFrame *frame)
Definition: nvenc.c:1384
#define IS_YUV444(pix_fmt)
Definition: nvenc.c:54
int dummy
Definition: motion.c:64
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1878
int profile
Definition: nvenc.h:136
PNVENCDESTROYBITSTREAMBUFFER nvEncDestroyBitstreamBuffer
[out]: Client should access NvEncDestroyBitstreamBuffer() API through this pointer.
Definition: nvEncodeAPI.h:3168
AVFifoBuffer * output_surface_queue
Definition: nvenc.h:113
#define NV_ENC_INITIALIZE_PARAMS_VER
macro for constructing the version field of _NV_ENC_INITIALIZE_PARAMS
Definition: nvEncodeAPI.h:1346
#define NV_ENC_PRESET_CONFIG_VER
macro for constructing the version field of _NV_ENC_PRESET_CONFIG
Definition: nvEncodeAPI.h:1381
8 bit Packed A8R8G8B8
Definition: nvEncodeAPI.h:316
uint32_t maxBitRate
[in]: Specifies the maximum bitrate for the encoded output.
Definition: nvEncodeAPI.h:1061
uint32_t enableLookahead
[in]: Set this to 1 to enable lookahead with depth <lookaheadDepth> (if lookahead is enabled...
Definition: nvEncodeAPI.h:1069
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
Constant bitrate mode.
Definition: nvEncodeAPI.h:257
HW acceleration through CUDA.
Definition: pixfmt.h:249
static void error(const char *err)
static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
Definition: nvenc.c:781
#define FF_ARRAY_ELEMS(a)
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:476
uint32_t level
[in]: Specifies the encoding level.
Definition: nvEncodeAPI.h:1174
static int nvenc_print_error(void *log_ctx, NVENCSTATUS err, const char *error_string)
Definition: nvenc.c:105
NV_ENC_BUFFER_FORMAT bufferFmt
[in]: Input buffer format
Definition: nvEncodeAPI.h:964
CudaFunctions * cuda_dl
Definition: nvenc.h:52
enum AVPixelFormat data_pix_fmt
Definition: nvenc.h:126
#define IS_10BIT(pix_fmt)
Definition: nvenc.c:51
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:251
#define NV_ENC_CAPS_PARAM_VER
NV_ENC_CAPS_PARAM struct version.
Definition: nvEncodeAPI.h:952
PNVENCUNREGISTERRESOURCE nvEncUnregisterResource
[out]: Client should access NvEncUnregisterResource() API through this pointer.
Definition: nvEncodeAPI.h:3184
uint32_t inputHeight
[in]: Specifies the input buffer height
Definition: nvEncodeAPI.h:1499
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:1346
uint32_t qpInterP
Definition: nvEncodeAPI.h:1047
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
NV_ENC_CONFIG encode_config
Definition: nvenc.h:106
Variable bitrate mode with MinQP.
Definition: nvEncodeAPI.h:258
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:111
uint32_t outputPictureTimingSEI
[in]: Set to 1 to write SEI picture timing syntax in the bitstream
Definition: nvEncodeAPI.h:1159
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
Definition: fifo.c:77
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:960
uint32_t doNotWait
[in]: If this flag is set, the NvEncodeAPI interface will return buffer pointer even if operation is ...
Definition: nvEncodeAPI.h:1563
int strict_gop
Definition: nvenc.h:153
PNVENCMAPINPUTRESOURCE nvEncMapInputResource
[out]: Client should access NvEncMapInputResource() API through this pointer.
Definition: nvEncodeAPI.h:3178
encode device type is a cuda device
Definition: nvEncodeAPI.h:640
#define NVENCAPI_VERSION
Definition: nvEncodeAPI.h:117
void * bitstreamBufferPtr
[out]: Pointer to the generated output bitstream.
Definition: nvEncodeAPI.h:1574
int temporal_aq
Definition: nvenc.h:150
int64_t initial_pts[2]
Definition: nvenc.h:130
Creation parameters for output bitstream buffer.
Definition: nvEncodeAPI.h:978
NV_ENC_H264_FMO_MODE fmoMode
[in]: Specified the FMO Mode.
Definition: nvEncodeAPI.h:1182
main external API structure.
Definition: avcodec.h:1732
uint32_t frameRateNum
[in]: Specifies the numerator for frame rate used for encoding in frames per second ( Frame rate = fr...
Definition: nvEncodeAPI.h:1319
uint8_t * data
The data buffer.
Definition: buffer.h:89
int qmin
minimum quantizer
Definition: avcodec.h:2675
#define BD
uint32_t frameAvgQP
[out]: Average QP of the frame.
Definition: nvEncodeAPI.h:1579
uint32_t disableSPSPPS
[in]: Set 1 to disable VPS,SPS and PPS signalling in the bitstream.
Definition: nvEncodeAPI.h:1234
Rate Control Configuration Paramters.
Definition: nvEncodeAPI.h:1055
int init_qp_i
Definition: nvenc.h:160
Indicates HW support for temporal AQ encoding (enableTemporalAQ=1).
Definition: nvEncodeAPI.h:915
int extradata_size
Definition: avcodec.h:1848
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
NV_ENC_RC_PARAMS rcParams
[in]: Specifies the rate control parameters for the current encoding session.
Definition: nvEncodeAPI.h:1296
This struct is allocated as AVHWDeviceContext.hwctx.
static int nvenc_check_cap(AVCodecContext *avctx, NV_ENC_CAPS cap)
Definition: nvenc.c:213
This indicates that one or more of the pointers passed to the API call is invalid.
Definition: nvEncodeAPI.h:415
GUID encodeGUID
[in]: Specifies the Encode GUID for which the encoder is being created.
Definition: nvEncodeAPI.h:1313
NV_ENC_INPUT_PTR inputBuffer
[in]: Specifies the input buffer pointer.
Definition: nvEncodeAPI.h:1505
uint32_t level
[in]: Specifies the level of the encoded bitstream.
Definition: nvEncodeAPI.h:1224
void * bufferDataPtr
[out]: Pointed to the locked input buffer data.
Definition: nvEncodeAPI.h:1601
uint32_t transferCharacteristics
[in]: Specifies the opto-electronic transfer characteristics to use (as defined in Annex E of the ITU...
Definition: nvEncodeAPI.h:1106
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2462
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2455
int width
Definition: nvenc.h:40
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:117
This indicates that an API call was made in wrong sequence/order.
Definition: nvEncodeAPI.h:432
Indicates HW support for YUV444 mode encoding.
Definition: nvEncodeAPI.h:880
#define NV_ENC_PIC_PARAMS_VER
Macro for constructing the version field of _NV_ENC_PIC_PARAMS.
Definition: nvEncodeAPI.h:1529
static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, NV_ENC_PIC_PARAMS *params)
Definition: nvenc.c:1543
#define IS_CBR(rc)
Definition: nvenc.c:35
AVPictureType
Definition: avutil.h:272
int flags
Definition: nvenc.c:482
int nonref_p
Definition: nvenc.h:152
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:2046
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1736
static const struct @95 nvenc_errors[]
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
Definition: nvEncodeAPI.h:1465
PNVENCUNMAPINPUTRESOURCE nvEncUnmapInputResource
[out]: Client should access NvEncUnmapInputResource() API through this pointer.
Definition: nvEncodeAPI.h:3179
int cbr
Definition: nvenc.h:140
static int nvenc_find_free_reg_resource(AVCodecContext *avctx)
Definition: nvenc.c:1414
uint32_t frameRateDen
[in]: Specifies the denominator for frame rate used for encoding in frames per second ( Frame rate = ...
Definition: nvEncodeAPI.h:1320
int averr
Definition: nvenc.c:59
NV_ENC_CONFIG_HEVC_VUI_PARAMETERS hevcVUIParameters
[in]: Specifies the HEVC video usability info pamameters
Definition: nvEncodeAPI.h:1261
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:498
NV_ENC_CONFIG_HEVC hevcConfig
[in]: Specifies the HEVC-specific encoder configuration.
Definition: nvEncodeAPI.h:1276
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1813
uint32_t gopLength
[in]: Specifies the number of pictures in one GOP.
Definition: nvEncodeAPI.h:1289
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
int reg_idx
Definition: nvenc.h:39
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
Definition: nvEncodeAPI.h:1255
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:917
uint64_t outputTimeStamp
[out]: Presentation timestamp associated with the encoded output.
Definition: nvEncodeAPI.h:1572
This indicates that devices pass by the client is not supported.
Definition: nvEncodeAPI.h:390
IDR picture.
Definition: nvEncodeAPI.h:284
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1945
tcuDeviceGetCount * cuDeviceGetCount
#define NVENCAPI_MINOR_VERSION
Definition: nvEncodeAPI.h:115
static const GUID NV_ENC_HEVC_PROFILE_MAIN_GUID
Definition: nvEncodeAPI.h:184
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
Definition: nvEncodeAPI.h:1421
NV_ENC_CAPS
Encoder capabilities enumeration.
Definition: nvEncodeAPI.h:646
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
Definition: nvEncodeAPI.h:1252
Bi-directionally predicted picture.
Definition: nvEncodeAPI.h:282
This indicates that completion event passed in NvEncEncodePicture() call is invalid.
Definition: nvEncodeAPI.h:421
NV_ENC_PIC_TYPE pictureType
[out]: Picture type of the encoded picture.
Definition: nvEncodeAPI.h:1577
int b_adapt
Definition: nvenc.h:149
#define NV_ENC_REGISTER_RESOURCE_VER
Macro for constructing the version field of _NV_ENC_REGISTER_RESOURCE.
Definition: nvEncodeAPI.h:1650
static int64_t timestamp_queue_dequeue(AVFifoBuffer *queue)
Definition: nvenc.c:1569
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
common internal api header.
uint32_t tier
[in]: Specifies the level tier of the encoded bitstream.
Definition: nvEncodeAPI.h:1225
This indicates that an unsupported parameter was passed by the client.
Definition: nvEncodeAPI.h:451
NV_ENC_DEVICE_TYPE deviceType
[in]: Specified the device Type
Definition: nvEncodeAPI.h:1715
int rc_lookahead
Definition: nvenc.h:145
uint32_t width
[in]: Input buffer width
Definition: nvEncodeAPI.h:961
static int output_ready(AVCodecContext *avctx, int flush)
Definition: nvenc.c:1723
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1714
Bi-dir predicted.
Definition: avutil.h:276
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
PNVENCDESTROYENCODER nvEncDestroyEncoder
[out]: Client should access NvEncDestroyEncoder() API through this pointer.
Definition: nvEncodeAPI.h:3180
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:3152
NV_ENC_PIC_STRUCT pictureStruct
[in]: Specifies structure of the input picture.
Definition: nvEncodeAPI.h:1509
tcuCtxPopCurrent_v2 * cuCtxPopCurrent
static const GUID NV_ENC_CODEC_HEVC_GUID
Definition: nvEncodeAPI.h:138
int size
Definition: nvenc.h:46
NvencSurface * surfaces
Definition: nvenc.h:111
int den
Denominator.
Definition: rational.h:60
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:4122
uint32_t outputAUD
[in]: Set 1 to write Access Unit Delimiter syntax.
Definition: nvEncodeAPI.h:1232
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:769
#define NV_ENC_BUFFER_FORMAT_YV12_PL
Definition: nvEncodeAPI.h:324
uint32_t darWidth
[in]: Specifies the display aspect ratio Width.
Definition: nvEncodeAPI.h:1317
#define FF_PROFILE_HEVC_REXT
Definition: avcodec.h:3326
void * priv_data
Definition: avcodec.h:1774
tcuDeviceComputeCapability * cuDeviceComputeCapability
static int nvenc_set_timestamp(AVCodecContext *avctx, NV_ENC_LOCK_BITSTREAM *params, AVPacket *pkt)
Definition: nvenc.c:1578
#define av_free(p)
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:330
uint32_t repeatSPSPPS
[in]: Set 1 to output VPS,SPS and PPS for every IDR frame.
Definition: nvEncodeAPI.h:1235
static av_cold int nvenc_load_libraries(AVCodecContext *avctx)
Definition: nvenc.c:115
static av_cold int nvenc_check_device(AVCodecContext *avctx, int idx)
Definition: nvenc.c:304
int avg_bitrate
Average bitrate of the stream, in bits per second.
Definition: avcodec.h:1361
#define NV_ENC_BUFFER_FORMAT_NV12_PL
Definition: nvEncodeAPI.h:323
uint32_t enableMaxQP
[in]: Set this to 1 if maximum QP used for rate control.
Definition: nvEncodeAPI.h:1065
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
Definition: nvEncodeAPI.h:1197
int device
Definition: nvenc.h:142
uint32_t darHeight
[in]: Specifies the display aspect ratio height.
Definition: nvEncodeAPI.h:1318
uint32_t enableEncodeAsync
[in]: Set this to 1 to enable asynchronous mode and is expected to use events to get picture completi...
Definition: nvEncodeAPI.h:1321
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
#define NV_ENC_CREATE_BITSTREAM_BUFFER_VER
NV_ENC_CREATE_BITSTREAM_BUFFER struct version.
Definition: nvEncodeAPI.h:991
uint32_t qpIntra
Definition: nvEncodeAPI.h:1049
tcuCtxDestroy_v2 * cuCtxDestroy
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1617
static const GUID NV_ENC_H264_PROFILE_HIGH_GUID
Definition: nvEncodeAPI.h:160
int32_t frameIntervalP
[in]: Specifies the GOP pattern as follows: frameIntervalP = 0: I, 1: IPP, 2: IBP, 3: IBBP If goplength is set to NVENC_INFINITE_GOPLENGTH frameIntervalP should be set to 1.
Definition: nvEncodeAPI.h:1290
NV_ENC_BUFFER_FORMAT bufferFmt
[in]: Specifies the input buffer format.
Definition: nvEncodeAPI.h:1508
#define NV_ENC_CONFIG_VER
macro for constructing the version field of _NV_ENC_CONFIG
Definition: nvEncodeAPI.h:1303
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1656
PNVENCINITIALIZEENCODER nvEncInitializeEncoder
[out]: Client should access NvEncInitializeEncoder() API through this pointer.
Definition: nvEncodeAPI.h:3164
int nb_surfaces
Definition: nvenc.h:110
int aud
Definition: nvenc.h:156
uint32_t enablePTD
[in]: Set this to 1 to enable the Picture Type Decision is be taken by the NvEncodeAPI interface...
Definition: nvEncodeAPI.h:1322
int cqp
Definition: nvenc.h:161
#define av_freep(p)
#define AV_CODEC_ID_H265
Definition: avcodec.h:395
static av_cold void set_lossless(AVCodecContext *avctx)
Definition: nvenc.c:611
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1562
uint32_t outputAUD
[in]: Set to 1 to write access unit delimiter syntax in bitstream
Definition: nvEncodeAPI.h:1160
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
Definition: fifo.c:63
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:170
uint32_t enableMinQP
[in]: Set this to 1 if minimum QP used for rate control.
Definition: nvEncodeAPI.h:1064
PNVENCUNLOCKBITSTREAM nvEncUnlockBitstream
[out]: Client should access NvEncUnlockBitstream() API through this pointer.
Definition: nvEncodeAPI.h:3171
#define FFSWAP(type, a, b)
Definition: common.h:99
#define NV_ENC_BUFFER_FORMAT_YUV444_PL
Definition: nvEncodeAPI.h:326
uint32_t encodeHeight
[in]: Specifies the encode height.
Definition: nvEncodeAPI.h:1316
uint32_t enableNonRefP
[in]: Set this to 1 to enable automatic insertion of non-reference P-frames (no effect if enablePTD=0...
Definition: nvEncodeAPI.h:1074
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2249
uint16_t targetQuality
[in]: Target CQ (Constant Quality) level for VBR mode (range 0-51 with 0-automatic) ...
Definition: nvEncodeAPI.h:1083
int tier
Definition: nvenc.h:138
#define NV_ENC_LOCK_INPUT_BUFFER_VER
Macro for constructing the version field of _NV_ENC_LOCK_INPUT_BUFFER.
Definition: nvEncodeAPI.h:1608
void * spsppsBuffer
[in]: Specifies bitstream header pointer of size NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.
Definition: nvEncodeAPI.h:1684
tcuDeviceGet * cuDeviceGet
uint32_t videoFormat
[in]: Specifies the source video format(as defined in Annex E of the ITU-T Specification).
Definition: nvEncodeAPI.h:1102
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:215
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1634
uint32_t version
[in]: Client should pass NV_ENCODE_API_FUNCTION_LIST_VER.
Definition: nvEncodeAPI.h:3151
This indicates that the encoder has not been initialized with NvEncInitializeEncoder() or that initia...
Definition: nvEncodeAPI.h:446
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:946
NV_ENC_OUTPUT_PTR output_surface
Definition: nvenc.h:44
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1650
uint32_t disableSPSPPS
[in]: Set to 1 to disable writing of Sequence and Picture parameter info in bitstream ...
Definition: nvEncodeAPI.h:1161
for(j=16;j >0;--j)
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
Predicted.
Definition: avutil.h:275
static void nvenc_map_preset(NvencContext *ctx)
Definition: nvenc.c:490
This indicates that device passed to the API call is no longer available and needs to be reinitialize...
Definition: nvEncodeAPI.h:409
int zerolatency
Definition: nvenc.h:151
This indicates that no encode capable devices were detected.
Definition: nvEncodeAPI.h:385
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:330
NVENCSTATUS
Error Codes.
Definition: nvEncodeAPI.h:375
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:2732
Maximum number of B-Frames supported.
Definition: nvEncodeAPI.h:651
This indicates that NvEncMapInputResource() API failed to map the client provided input resource...
Definition: nvEncodeAPI.h:477
const char * name
Definition: opengl_enc.c:103
NV_ENC_CODEC_CONFIG encodeCodecConfig
[in]: Specifies the codec specific config parameters through this union.
Definition: nvEncodeAPI.h:1297
This indicates that the API call failed because it was unable to allocate enough memory to perform th...
Definition: nvEncodeAPI.h:438
uint32_t version
[in]: Struct version.
Definition: nvEncodeAPI.h:1597
Adaptive Transform 8x8 mode should be used.
Definition: nvEncodeAPI.h:607