X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Flibx265.c;h=2370601ed78fd713104447ddbed8bb5f71acdedf;hb=f5d1d1e4667ba346ea7e0f97e6d2756bc9d4abde;hp=01833d99d670d3a3fe57f3d16aa5fef45c2030ec;hpb=d3736471948cd06851f6b3aef352ef285b7c6480;p=ffmpeg diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 01833d99d67..2370601ed78 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -29,6 +29,10 @@ #include "avcodec.h" #include "internal.h" +#if defined(_MSC_VER) +#define X265_API_IMPORTS 1 +#endif + typedef struct libx265Context { const AVClass *class; @@ -77,10 +81,20 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) libx265Context *ctx = avctx->priv_data; x265_nal *nal; uint8_t *buf; + int sar_num, sar_den; int nnal; int ret; int i; + if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL && + !av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_w && + !av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_h) { + av_log(avctx, AV_LOG_ERROR, + "4:4:4 support is not fully defined for HEVC yet. " + "Set -strict experimental to encode anyway.\n"); + return AVERROR(ENOSYS); + } + avctx->coded_frame = av_frame_alloc(); if (!avctx->coded_frame) { av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); @@ -104,11 +118,31 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) ctx->params->sourceWidth = avctx->width; ctx->params->sourceHeight = avctx->height; + av_reduce(&sar_num, &sar_den, + avctx->sample_aspect_ratio.num, + avctx->sample_aspect_ratio.den, 4096); + ctx->params->bEnableVuiParametersPresentFlag = 1; + ctx->params->bEnableAspectRatioIdc = 1; + ctx->params->aspectRatioIdc = 255; + ctx->params->sarWidth = sar_num; + ctx->params->sarHeight = sar_den; + if (x265_max_bit_depth == 8) ctx->params->internalBitDepth = 8; else if (x265_max_bit_depth == 12) ctx->params->internalBitDepth = 10; + switch (avctx->pix_fmt) { + case AV_PIX_FMT_YUV420P: + case AV_PIX_FMT_YUV420P10: + ctx->params->internalCsp = X265_CSP_I420; + break; + case AV_PIX_FMT_YUV444P: + case AV_PIX_FMT_YUV444P10: + ctx->params->internalCsp = X265_CSP_I444; + break; + } + if (avctx->bit_rate > 0) { ctx->params->rc.bitrate = avctx->bit_rate / 1000; ctx->params->rc.rateControlMode = X265_RC_ABR; @@ -201,7 +235,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, ret = x265_encoder_encode(ctx->encoder, &nal, &nnal, pic ? &x265pic : NULL, &x265pic_out); if (ret < 0) - return AVERROR_UNKNOWN; + return AVERROR_EXTERNAL; if (!nnal) return 0; @@ -243,12 +277,15 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, static const enum AVPixelFormat x265_csp_eight[] = { AV_PIX_FMT_YUV420P, + AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE }; static const enum AVPixelFormat x265_csp_twelve[] = { AV_PIX_FMT_YUV420P, + AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV420P10, + AV_PIX_FMT_YUV444P10, AV_PIX_FMT_NONE };