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.

573 lines
19KB

  1. /*
  2. * libx265 encoder
  3. *
  4. * Copyright (c) 2013-2014 Derek Buitenhuis
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #if defined(_MSC_VER)
  23. #define X265_API_IMPORTS 1
  24. #endif
  25. #include <x265.h>
  26. #include <float.h>
  27. #include "libavutil/internal.h"
  28. #include "libavutil/common.h"
  29. #include "libavutil/opt.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "avcodec.h"
  32. #include "internal.h"
  33. typedef struct libx265Context {
  34. const AVClass *class;
  35. x265_encoder *encoder;
  36. x265_param *params;
  37. const x265_api *api;
  38. float crf;
  39. int forced_idr;
  40. char *preset;
  41. char *tune;
  42. char *profile;
  43. char *x265_opts;
  44. /**
  45. * If the encoder does not support ROI then warn the first time we
  46. * encounter a frame with ROI side data.
  47. */
  48. int roi_warned;
  49. } libx265Context;
  50. static int is_keyframe(NalUnitType naltype)
  51. {
  52. switch (naltype) {
  53. case NAL_UNIT_CODED_SLICE_BLA_W_LP:
  54. case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
  55. case NAL_UNIT_CODED_SLICE_BLA_N_LP:
  56. case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
  57. case NAL_UNIT_CODED_SLICE_IDR_N_LP:
  58. case NAL_UNIT_CODED_SLICE_CRA:
  59. return 1;
  60. default:
  61. return 0;
  62. }
  63. }
  64. static av_cold int libx265_encode_close(AVCodecContext *avctx)
  65. {
  66. libx265Context *ctx = avctx->priv_data;
  67. ctx->api->param_free(ctx->params);
  68. if (ctx->encoder)
  69. ctx->api->encoder_close(ctx->encoder);
  70. return 0;
  71. }
  72. static av_cold int libx265_encode_init(AVCodecContext *avctx)
  73. {
  74. libx265Context *ctx = avctx->priv_data;
  75. AVCPBProperties *cpb_props = NULL;
  76. ctx->api = x265_api_get(av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth);
  77. if (!ctx->api)
  78. ctx->api = x265_api_get(0);
  79. ctx->params = ctx->api->param_alloc();
  80. if (!ctx->params) {
  81. av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param structure.\n");
  82. return AVERROR(ENOMEM);
  83. }
  84. if (ctx->api->param_default_preset(ctx->params, ctx->preset, ctx->tune) < 0) {
  85. int i;
  86. av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", ctx->preset, ctx->tune);
  87. av_log(avctx, AV_LOG_INFO, "Possible presets:");
  88. for (i = 0; x265_preset_names[i]; i++)
  89. av_log(avctx, AV_LOG_INFO, " %s", x265_preset_names[i]);
  90. av_log(avctx, AV_LOG_INFO, "\n");
  91. av_log(avctx, AV_LOG_INFO, "Possible tunes:");
  92. for (i = 0; x265_tune_names[i]; i++)
  93. av_log(avctx, AV_LOG_INFO, " %s", x265_tune_names[i]);
  94. av_log(avctx, AV_LOG_INFO, "\n");
  95. return AVERROR(EINVAL);
  96. }
  97. ctx->params->frameNumThreads = avctx->thread_count;
  98. if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
  99. ctx->params->fpsNum = avctx->framerate.num;
  100. ctx->params->fpsDenom = avctx->framerate.den;
  101. } else {
  102. ctx->params->fpsNum = avctx->time_base.den;
  103. ctx->params->fpsDenom = avctx->time_base.num * avctx->ticks_per_frame;
  104. }
  105. ctx->params->sourceWidth = avctx->width;
  106. ctx->params->sourceHeight = avctx->height;
  107. ctx->params->bEnablePsnr = !!(avctx->flags & AV_CODEC_FLAG_PSNR);
  108. ctx->params->bOpenGOP = !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
  109. /* Tune the CTU size based on input resolution. */
  110. if (ctx->params->sourceWidth < 64 || ctx->params->sourceHeight < 64)
  111. ctx->params->maxCUSize = 32;
  112. if (ctx->params->sourceWidth < 32 || ctx->params->sourceHeight < 32)
  113. ctx->params->maxCUSize = 16;
  114. if (ctx->params->sourceWidth < 16 || ctx->params->sourceHeight < 16) {
  115. av_log(avctx, AV_LOG_ERROR, "Image size is too small (%dx%d).\n",
  116. ctx->params->sourceWidth, ctx->params->sourceHeight);
  117. return AVERROR(EINVAL);
  118. }
  119. ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1;
  120. ctx->params->vui.bEnableVideoFullRangeFlag = avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
  121. avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
  122. avctx->pix_fmt == AV_PIX_FMT_YUVJ444P ||
  123. avctx->color_range == AVCOL_RANGE_JPEG;
  124. if ((avctx->color_primaries <= AVCOL_PRI_SMPTE432 &&
  125. avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
  126. (avctx->color_trc <= AVCOL_TRC_ARIB_STD_B67 &&
  127. avctx->color_trc != AVCOL_TRC_UNSPECIFIED) ||
  128. (avctx->colorspace <= AVCOL_SPC_ICTCP &&
  129. avctx->colorspace != AVCOL_SPC_UNSPECIFIED)) {
  130. ctx->params->vui.bEnableColorDescriptionPresentFlag = 1;
  131. // x265 validates the parameters internally
  132. ctx->params->vui.colorPrimaries = avctx->color_primaries;
  133. ctx->params->vui.transferCharacteristics = avctx->color_trc;
  134. ctx->params->vui.matrixCoeffs = avctx->colorspace;
  135. }
  136. if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) {
  137. char sar[12];
  138. int sar_num, sar_den;
  139. av_reduce(&sar_num, &sar_den,
  140. avctx->sample_aspect_ratio.num,
  141. avctx->sample_aspect_ratio.den, 65535);
  142. snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den);
  143. if (ctx->api->param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) {
  144. av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den);
  145. return AVERROR_INVALIDDATA;
  146. }
  147. }
  148. switch (avctx->pix_fmt) {
  149. case AV_PIX_FMT_YUV420P:
  150. case AV_PIX_FMT_YUV420P10:
  151. case AV_PIX_FMT_YUV420P12:
  152. ctx->params->internalCsp = X265_CSP_I420;
  153. break;
  154. case AV_PIX_FMT_YUV422P:
  155. case AV_PIX_FMT_YUV422P10:
  156. case AV_PIX_FMT_YUV422P12:
  157. ctx->params->internalCsp = X265_CSP_I422;
  158. break;
  159. case AV_PIX_FMT_GBRP:
  160. case AV_PIX_FMT_GBRP10:
  161. case AV_PIX_FMT_GBRP12:
  162. ctx->params->vui.matrixCoeffs = AVCOL_SPC_RGB;
  163. ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1;
  164. ctx->params->vui.bEnableColorDescriptionPresentFlag = 1;
  165. case AV_PIX_FMT_YUV444P:
  166. case AV_PIX_FMT_YUV444P10:
  167. case AV_PIX_FMT_YUV444P12:
  168. ctx->params->internalCsp = X265_CSP_I444;
  169. break;
  170. case AV_PIX_FMT_GRAY8:
  171. case AV_PIX_FMT_GRAY10:
  172. case AV_PIX_FMT_GRAY12:
  173. if (ctx->api->api_build_number < 85) {
  174. av_log(avctx, AV_LOG_ERROR,
  175. "libx265 version is %d, must be at least 85 for gray encoding.\n",
  176. ctx->api->api_build_number);
  177. return AVERROR_INVALIDDATA;
  178. }
  179. ctx->params->internalCsp = X265_CSP_I400;
  180. break;
  181. }
  182. if (ctx->crf >= 0) {
  183. char crf[6];
  184. snprintf(crf, sizeof(crf), "%2.2f", ctx->crf);
  185. if (ctx->api->param_parse(ctx->params, "crf", crf) == X265_PARAM_BAD_VALUE) {
  186. av_log(avctx, AV_LOG_ERROR, "Invalid crf: %2.2f.\n", ctx->crf);
  187. return AVERROR(EINVAL);
  188. }
  189. } else if (avctx->bit_rate > 0) {
  190. ctx->params->rc.bitrate = avctx->bit_rate / 1000;
  191. ctx->params->rc.rateControlMode = X265_RC_ABR;
  192. }
  193. ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000;
  194. ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate / 1000;
  195. cpb_props = ff_add_cpb_side_data(avctx);
  196. if (!cpb_props)
  197. return AVERROR(ENOMEM);
  198. cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000;
  199. cpb_props->max_bitrate = ctx->params->rc.vbvMaxBitrate * 1000;
  200. cpb_props->avg_bitrate = ctx->params->rc.bitrate * 1000;
  201. if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
  202. ctx->params->bRepeatHeaders = 1;
  203. if (ctx->x265_opts) {
  204. AVDictionary *dict = NULL;
  205. AVDictionaryEntry *en = NULL;
  206. if (!av_dict_parse_string(&dict, ctx->x265_opts, "=", ":", 0)) {
  207. while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) {
  208. int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
  209. switch (parse_ret) {
  210. case X265_PARAM_BAD_NAME:
  211. av_log(avctx, AV_LOG_WARNING,
  212. "Unknown option: %s.\n", en->key);
  213. break;
  214. case X265_PARAM_BAD_VALUE:
  215. av_log(avctx, AV_LOG_WARNING,
  216. "Invalid value for %s: %s.\n", en->key, en->value);
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. av_dict_free(&dict);
  223. }
  224. }
  225. if (ctx->params->rc.vbvBufferSize && avctx->rc_initial_buffer_occupancy > 1000 &&
  226. ctx->params->rc.vbvBufferInit == 0.9) {
  227. ctx->params->rc.vbvBufferInit = (float)avctx->rc_initial_buffer_occupancy / 1000;
  228. }
  229. if (ctx->profile) {
  230. if (ctx->api->param_apply_profile(ctx->params, ctx->profile) < 0) {
  231. int i;
  232. av_log(avctx, AV_LOG_ERROR, "Invalid or incompatible profile set: %s.\n", ctx->profile);
  233. av_log(avctx, AV_LOG_INFO, "Possible profiles:");
  234. for (i = 0; x265_profile_names[i]; i++)
  235. av_log(avctx, AV_LOG_INFO, " %s", x265_profile_names[i]);
  236. av_log(avctx, AV_LOG_INFO, "\n");
  237. return AVERROR(EINVAL);
  238. }
  239. }
  240. ctx->encoder = ctx->api->encoder_open(ctx->params);
  241. if (!ctx->encoder) {
  242. av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");
  243. libx265_encode_close(avctx);
  244. return AVERROR_INVALIDDATA;
  245. }
  246. if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
  247. x265_nal *nal;
  248. int nnal;
  249. avctx->extradata_size = ctx->api->encoder_headers(ctx->encoder, &nal, &nnal);
  250. if (avctx->extradata_size <= 0) {
  251. av_log(avctx, AV_LOG_ERROR, "Cannot encode headers.\n");
  252. libx265_encode_close(avctx);
  253. return AVERROR_INVALIDDATA;
  254. }
  255. avctx->extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
  256. if (!avctx->extradata) {
  257. av_log(avctx, AV_LOG_ERROR,
  258. "Cannot allocate HEVC header of size %d.\n", avctx->extradata_size);
  259. libx265_encode_close(avctx);
  260. return AVERROR(ENOMEM);
  261. }
  262. memcpy(avctx->extradata, nal[0].payload, avctx->extradata_size);
  263. }
  264. return 0;
  265. }
  266. static av_cold int libx265_encode_set_roi(libx265Context *ctx, const AVFrame *frame, x265_picture* pic)
  267. {
  268. AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_REGIONS_OF_INTEREST);
  269. if (sd) {
  270. if (ctx->params->rc.aqMode == X265_AQ_NONE) {
  271. if (!ctx->roi_warned) {
  272. ctx->roi_warned = 1;
  273. av_log(ctx, AV_LOG_WARNING, "Adaptive quantization must be enabled to use ROI encoding, skipping ROI.\n");
  274. }
  275. } else {
  276. /* 8x8 block when qg-size is 8, 16*16 block otherwise. */
  277. int mb_size = (ctx->params->rc.qgSize == 8) ? 8 : 16;
  278. int mbx = (frame->width + mb_size - 1) / mb_size;
  279. int mby = (frame->height + mb_size - 1) / mb_size;
  280. int qp_range = 51 + 6 * (pic->bitDepth - 8);
  281. int nb_rois;
  282. const AVRegionOfInterest *roi;
  283. uint32_t roi_size;
  284. float *qoffsets; /* will be freed after encode is called. */
  285. roi = (const AVRegionOfInterest*)sd->data;
  286. roi_size = roi->self_size;
  287. if (!roi_size || sd->size % roi_size != 0) {
  288. av_log(ctx, AV_LOG_ERROR, "Invalid AVRegionOfInterest.self_size.\n");
  289. return AVERROR(EINVAL);
  290. }
  291. nb_rois = sd->size / roi_size;
  292. qoffsets = av_mallocz_array(mbx * mby, sizeof(*qoffsets));
  293. if (!qoffsets)
  294. return AVERROR(ENOMEM);
  295. // This list must be iterated in reverse because the first
  296. // region in the list applies when regions overlap.
  297. for (int i = nb_rois - 1; i >= 0; i--) {
  298. int startx, endx, starty, endy;
  299. float qoffset;
  300. roi = (const AVRegionOfInterest*)(sd->data + roi_size * i);
  301. starty = FFMIN(mby, roi->top / mb_size);
  302. endy = FFMIN(mby, (roi->bottom + mb_size - 1)/ mb_size);
  303. startx = FFMIN(mbx, roi->left / mb_size);
  304. endx = FFMIN(mbx, (roi->right + mb_size - 1)/ mb_size);
  305. if (roi->qoffset.den == 0) {
  306. av_free(qoffsets);
  307. av_log(ctx, AV_LOG_ERROR, "AVRegionOfInterest.qoffset.den must not be zero.\n");
  308. return AVERROR(EINVAL);
  309. }
  310. qoffset = roi->qoffset.num * 1.0f / roi->qoffset.den;
  311. qoffset = av_clipf(qoffset * qp_range, -qp_range, +qp_range);
  312. for (int y = starty; y < endy; y++)
  313. for (int x = startx; x < endx; x++)
  314. qoffsets[x + y*mbx] = qoffset;
  315. }
  316. pic->quantOffsets = qoffsets;
  317. }
  318. }
  319. return 0;
  320. }
  321. static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  322. const AVFrame *pic, int *got_packet)
  323. {
  324. libx265Context *ctx = avctx->priv_data;
  325. x265_picture x265pic;
  326. x265_picture x265pic_out = { 0 };
  327. x265_nal *nal;
  328. uint8_t *dst;
  329. int payload = 0;
  330. int nnal;
  331. int ret;
  332. int i;
  333. ctx->api->picture_init(ctx->params, &x265pic);
  334. if (pic) {
  335. for (i = 0; i < 3; i++) {
  336. x265pic.planes[i] = pic->data[i];
  337. x265pic.stride[i] = pic->linesize[i];
  338. }
  339. x265pic.pts = pic->pts;
  340. x265pic.bitDepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
  341. x265pic.sliceType = pic->pict_type == AV_PICTURE_TYPE_I ?
  342. (ctx->forced_idr ? X265_TYPE_IDR : X265_TYPE_I) :
  343. pic->pict_type == AV_PICTURE_TYPE_P ? X265_TYPE_P :
  344. pic->pict_type == AV_PICTURE_TYPE_B ? X265_TYPE_B :
  345. X265_TYPE_AUTO;
  346. ret = libx265_encode_set_roi(ctx, pic, &x265pic);
  347. if (ret < 0)
  348. return ret;
  349. }
  350. ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
  351. pic ? &x265pic : NULL, &x265pic_out);
  352. av_freep(&x265pic.quantOffsets);
  353. if (ret < 0)
  354. return AVERROR_EXTERNAL;
  355. if (!nnal)
  356. return 0;
  357. for (i = 0; i < nnal; i++)
  358. payload += nal[i].sizeBytes;
  359. ret = ff_alloc_packet2(avctx, pkt, payload, payload);
  360. if (ret < 0) {
  361. av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
  362. return ret;
  363. }
  364. dst = pkt->data;
  365. for (i = 0; i < nnal; i++) {
  366. memcpy(dst, nal[i].payload, nal[i].sizeBytes);
  367. dst += nal[i].sizeBytes;
  368. if (is_keyframe(nal[i].type))
  369. pkt->flags |= AV_PKT_FLAG_KEY;
  370. }
  371. pkt->pts = x265pic_out.pts;
  372. pkt->dts = x265pic_out.dts;
  373. #if FF_API_CODED_FRAME
  374. FF_DISABLE_DEPRECATION_WARNINGS
  375. switch (x265pic_out.sliceType) {
  376. case X265_TYPE_IDR:
  377. case X265_TYPE_I:
  378. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
  379. break;
  380. case X265_TYPE_P:
  381. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;
  382. break;
  383. case X265_TYPE_B:
  384. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B;
  385. break;
  386. }
  387. FF_ENABLE_DEPRECATION_WARNINGS
  388. #endif
  389. #if X265_BUILD >= 130
  390. if (x265pic_out.sliceType == X265_TYPE_B)
  391. #else
  392. if (x265pic_out.frameData.sliceType == 'b')
  393. #endif
  394. pkt->flags |= AV_PKT_FLAG_DISPOSABLE;
  395. *got_packet = 1;
  396. return 0;
  397. }
  398. static const enum AVPixelFormat x265_csp_eight[] = {
  399. AV_PIX_FMT_YUV420P,
  400. AV_PIX_FMT_YUVJ420P,
  401. AV_PIX_FMT_YUV422P,
  402. AV_PIX_FMT_YUVJ422P,
  403. AV_PIX_FMT_YUV444P,
  404. AV_PIX_FMT_YUVJ444P,
  405. AV_PIX_FMT_GBRP,
  406. AV_PIX_FMT_GRAY8,
  407. AV_PIX_FMT_NONE
  408. };
  409. static const enum AVPixelFormat x265_csp_ten[] = {
  410. AV_PIX_FMT_YUV420P,
  411. AV_PIX_FMT_YUVJ420P,
  412. AV_PIX_FMT_YUV422P,
  413. AV_PIX_FMT_YUVJ422P,
  414. AV_PIX_FMT_YUV444P,
  415. AV_PIX_FMT_YUVJ444P,
  416. AV_PIX_FMT_GBRP,
  417. AV_PIX_FMT_YUV420P10,
  418. AV_PIX_FMT_YUV422P10,
  419. AV_PIX_FMT_YUV444P10,
  420. AV_PIX_FMT_GBRP10,
  421. AV_PIX_FMT_GRAY8,
  422. AV_PIX_FMT_GRAY10,
  423. AV_PIX_FMT_NONE
  424. };
  425. static const enum AVPixelFormat x265_csp_twelve[] = {
  426. AV_PIX_FMT_YUV420P,
  427. AV_PIX_FMT_YUVJ420P,
  428. AV_PIX_FMT_YUV422P,
  429. AV_PIX_FMT_YUVJ422P,
  430. AV_PIX_FMT_YUV444P,
  431. AV_PIX_FMT_YUVJ444P,
  432. AV_PIX_FMT_GBRP,
  433. AV_PIX_FMT_YUV420P10,
  434. AV_PIX_FMT_YUV422P10,
  435. AV_PIX_FMT_YUV444P10,
  436. AV_PIX_FMT_GBRP10,
  437. AV_PIX_FMT_YUV420P12,
  438. AV_PIX_FMT_YUV422P12,
  439. AV_PIX_FMT_YUV444P12,
  440. AV_PIX_FMT_GBRP12,
  441. AV_PIX_FMT_GRAY8,
  442. AV_PIX_FMT_GRAY10,
  443. AV_PIX_FMT_GRAY12,
  444. AV_PIX_FMT_NONE
  445. };
  446. static av_cold void libx265_encode_init_csp(AVCodec *codec)
  447. {
  448. if (x265_api_get(12))
  449. codec->pix_fmts = x265_csp_twelve;
  450. else if (x265_api_get(10))
  451. codec->pix_fmts = x265_csp_ten;
  452. else if (x265_api_get(8))
  453. codec->pix_fmts = x265_csp_eight;
  454. }
  455. #define OFFSET(x) offsetof(libx265Context, x)
  456. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  457. static const AVOption options[] = {
  458. { "crf", "set the x265 crf", OFFSET(crf), AV_OPT_TYPE_FLOAT, { .dbl = -1 }, -1, FLT_MAX, VE },
  459. { "forced-idr", "if forcing keyframes, force them as IDR frames", OFFSET(forced_idr),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
  460. { "preset", "set the x265 preset", OFFSET(preset), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
  461. { "tune", "set the x265 tune parameter", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
  462. { "profile", "set the x265 profile", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
  463. { "x265-params", "set the x265 configuration using a :-separated list of key=value parameters", OFFSET(x265_opts), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
  464. { NULL }
  465. };
  466. static const AVClass class = {
  467. .class_name = "libx265",
  468. .item_name = av_default_item_name,
  469. .option = options,
  470. .version = LIBAVUTIL_VERSION_INT,
  471. };
  472. static const AVCodecDefault x265_defaults[] = {
  473. { "b", "0" },
  474. { NULL },
  475. };
  476. AVCodec ff_libx265_encoder = {
  477. .name = "libx265",
  478. .long_name = NULL_IF_CONFIG_SMALL("libx265 H.265 / HEVC"),
  479. .type = AVMEDIA_TYPE_VIDEO,
  480. .id = AV_CODEC_ID_HEVC,
  481. .init = libx265_encode_init,
  482. .init_static_data = libx265_encode_init_csp,
  483. .encode2 = libx265_encode_frame,
  484. .close = libx265_encode_close,
  485. .priv_data_size = sizeof(libx265Context),
  486. .priv_class = &class,
  487. .defaults = x265_defaults,
  488. .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
  489. .wrapper_name = "libx265",
  490. };