From 4a2226451e141a6da53c777888db00c743ee8f48 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Tue, 8 Apr 2014 18:44:53 +0100 Subject: [PATCH 1/3] libx265: Use x265_param_parse to set the SAR Signed-off-by: Derek Buitenhuis --- libavcodec/libx265.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 77d0b03bee..94b08a713a 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -77,6 +77,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; x265_nal *nal; + char sar[10]; int sar_num, sar_den; int nnal; @@ -115,11 +116,11 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) av_reduce(&sar_num, &sar_den, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096); - ctx->params->vui.bEnableVuiParametersPresentFlag = 1; - ctx->params->vui.bEnableAspectRatioIdc = 1; - ctx->params->vui.aspectRatioIdc = 255; - ctx->params->vui.sarWidth = sar_num; - ctx->params->vui.sarHeight = sar_den; + snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den); + if (x265_param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) { + av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den); + return AVERROR_INVALIDDATA; + } if (x265_max_bit_depth == 8) ctx->params->internalBitDepth = 8; From cd0ac6f6e5c353cadf678d9f194868f7d846566b Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Thu, 10 Apr 2014 13:17:48 +0100 Subject: [PATCH 2/3] libx265: Use 16-bit SAR The spec says it is 16 bits. Signed-off-by: Derek Buitenhuis --- libavcodec/libx265.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 94b08a713a..223ec783bc 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -77,7 +77,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; x265_nal *nal; - char sar[10]; + char sar[12]; int sar_num, sar_den; int nnal; @@ -115,7 +115,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) av_reduce(&sar_num, &sar_den, avctx->sample_aspect_ratio.num, - avctx->sample_aspect_ratio.den, 4096); + avctx->sample_aspect_ratio.den, 65535); snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den); if (x265_param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) { av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den); From 25fbfeed98d2eaddda0885e0916a83085549bae6 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Thu, 10 Apr 2014 13:27:41 +0100 Subject: [PATCH 3/3] libx265: Only set the SAR if it is valid Signed-off-by: Derek Buitenhuis --- libavcodec/libx265.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 223ec783bc..41b1cda45c 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -113,13 +113,15 @@ 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, 65535); - snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den); - if (x265_param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) { - av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den); - return AVERROR_INVALIDDATA; + if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) { + av_reduce(&sar_num, &sar_den, + avctx->sample_aspect_ratio.num, + avctx->sample_aspect_ratio.den, 65535); + snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den); + if (x265_param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) { + av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den); + return AVERROR_INVALIDDATA; + } } if (x265_max_bit_depth == 8)