You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.8KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVCODEC_NVENC_H
  19. #define AVCODEC_NVENC_H
  20. #include "compat/nvenc/nvEncodeAPI.h"
  21. #include "config.h"
  22. #include "compat/cuda/dynlink_loader.h"
  23. #include "libavutil/fifo.h"
  24. #include "libavutil/opt.h"
  25. #include "avcodec.h"
  26. #define MAX_REGISTERED_FRAMES 64
  27. typedef struct NvencSurface
  28. {
  29. NV_ENC_INPUT_PTR input_surface;
  30. AVFrame *in_ref;
  31. NV_ENC_MAP_INPUT_RESOURCE in_map;
  32. int reg_idx;
  33. int width;
  34. int height;
  35. int pitch;
  36. NV_ENC_OUTPUT_PTR output_surface;
  37. NV_ENC_BUFFER_FORMAT format;
  38. int size;
  39. int lockCount;
  40. } NvencSurface;
  41. typedef struct NvencDynLoadFunctions
  42. {
  43. CudaFunctions *cuda_dl;
  44. NvencFunctions *nvenc_dl;
  45. NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
  46. int nvenc_device_count;
  47. } NvencDynLoadFunctions;
  48. enum {
  49. PRESET_DEFAULT = 0,
  50. PRESET_SLOW,
  51. PRESET_MEDIUM,
  52. PRESET_FAST,
  53. PRESET_HP,
  54. PRESET_HQ,
  55. PRESET_BD ,
  56. PRESET_LOW_LATENCY_DEFAULT ,
  57. PRESET_LOW_LATENCY_HQ ,
  58. PRESET_LOW_LATENCY_HP,
  59. PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
  60. PRESET_LOSSLESS_HP,
  61. };
  62. enum {
  63. NV_ENC_H264_PROFILE_BASELINE,
  64. NV_ENC_H264_PROFILE_MAIN,
  65. NV_ENC_H264_PROFILE_HIGH,
  66. NV_ENC_H264_PROFILE_HIGH_444P,
  67. };
  68. enum {
  69. NV_ENC_HEVC_PROFILE_MAIN,
  70. NV_ENC_HEVC_PROFILE_MAIN_10,
  71. NV_ENC_HEVC_PROFILE_REXT,
  72. };
  73. enum {
  74. NVENC_LOWLATENCY = 1,
  75. NVENC_LOSSLESS = 2,
  76. NVENC_ONE_PASS = 4,
  77. NVENC_TWO_PASSES = 8,
  78. };
  79. enum {
  80. LIST_DEVICES = -2,
  81. ANY_DEVICE,
  82. };
  83. typedef struct NvencContext
  84. {
  85. AVClass *avclass;
  86. NvencDynLoadFunctions nvenc_dload_funcs;
  87. NV_ENC_INITIALIZE_PARAMS init_encode_params;
  88. NV_ENC_CONFIG encode_config;
  89. CUcontext cu_context;
  90. CUcontext cu_context_internal;
  91. int nb_surfaces;
  92. NvencSurface *surfaces;
  93. AVFifoBuffer *output_surface_queue;
  94. AVFifoBuffer *output_surface_ready_queue;
  95. AVFifoBuffer *timestamp_list;
  96. struct {
  97. CUdeviceptr ptr;
  98. NV_ENC_REGISTERED_PTR regptr;
  99. int mapped;
  100. } registered_frames[MAX_REGISTERED_FRAMES];
  101. int nb_registered_frames;
  102. /* the actual data pixel format, different from
  103. * AVCodecContext.pix_fmt when using hwaccel frames on input */
  104. enum AVPixelFormat data_pix_fmt;
  105. /* timestamps of the first two frames, for computing the first dts
  106. * when B-frames are present */
  107. int64_t initial_pts[2];
  108. int first_packet_output;
  109. void *nvencoder;
  110. int preset;
  111. int profile;
  112. int level;
  113. int tier;
  114. int rc;
  115. int cbr;
  116. int twopass;
  117. int device;
  118. int flags;
  119. int async_depth;
  120. int rc_lookahead;
  121. int aq;
  122. int no_scenecut;
  123. int forced_idr;
  124. int b_adapt;
  125. int temporal_aq;
  126. int zerolatency;
  127. int nonref_p;
  128. int strict_gop;
  129. int aq_strength;
  130. int quality;
  131. int aud;
  132. } NvencContext;
  133. int ff_nvenc_encode_init(AVCodecContext *avctx);
  134. int ff_nvenc_encode_close(AVCodecContext *avctx);
  135. int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  136. const AVFrame *frame, int *got_packet);
  137. extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
  138. #endif /* AVCODEC_NVENC_H */