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.

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