---- a/libavcodec/libx265.c 2017-12-10 14:35:08.000000000 -0700
-+++ b/libavcodec/libx265.c 2018-02-08 16:57:46.028108824 -0700
-@@ -45,6 +45,7 @@
- int forced_idr;
- char *preset;
- char *tune;
-+ char *profile;
- char *x265_opts;
- } libx265Context;
-
-@@ -114,11 +115,11 @@
- ctx->params->sourceHeight = avctx->height;
- ctx->params->bEnablePsnr = !!(avctx->flags & AV_CODEC_FLAG_PSNR);
-
-- if ((avctx->color_primaries <= AVCOL_PRI_BT2020 &&
-+ if ((avctx->color_primaries <= AVCOL_PRI_SMPTE432 &&
- avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
-- (avctx->color_trc <= AVCOL_TRC_BT2020_12 &&
-+ (avctx->color_trc <= AVCOL_TRC_ARIB_STD_B67 &&
- avctx->color_trc != AVCOL_TRC_UNSPECIFIED) ||
-- (avctx->colorspace <= AVCOL_SPC_BT2020_CL &&
-+ (avctx->colorspace <= AVCOL_SPC_ICTCP &&
- avctx->colorspace != AVCOL_SPC_UNSPECIFIED)) {
-
- ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1;
-@@ -220,6 +221,18 @@
- }
- }
-
-+ if (ctx->profile) {
-+ if (ctx->api->param_apply_profile(ctx->params, ctx->profile) < 0) {
-+ int i;
-+ av_log(avctx, AV_LOG_ERROR, "Invalid or incompatible profile set: %s.\n", ctx->profile);
-+ av_log(avctx, AV_LOG_INFO, "Possible profiles:");
-+ for (i = 0; x265_profile_names[i]; i++)
-+ av_log(avctx, AV_LOG_INFO, " %s", x265_profile_names[i]);
-+ av_log(avctx, AV_LOG_INFO, "\n");
-+ return AVERROR(EINVAL);
-+ }
-+ }
-+
- ctx->encoder = ctx->api->encoder_open(ctx->params);
- if (!ctx->encoder) {
- av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");
-@@ -294,7 +307,7 @@
- for (i = 0; i < nnal; i++)
- payload += nal[i].sizeBytes;
-
-- ret = ff_alloc_packet(pkt, payload);
-+ ret = ff_alloc_packet2(avctx, pkt, payload, payload);
- if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
- return ret;
-@@ -392,6 +412,7 @@
- { "forced-idr", "if forcing keyframes, force them as IDR frames", OFFSET(forced_idr),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
- { "preset", "set the x265 preset", OFFSET(preset), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
- { "tune", "set the x265 tune parameter", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
-+ { "profile", "set the x265 profile", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
- { "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 },
- { NULL }
- };