From 0869ff7e9d17cdcfbed65a8f25ce27002ec9b974 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 7 Jan 2016 00:48:22 +0100 Subject: [PATCH] avcodec/utils: Check bits_per_raw_sample on video encoder open Signed-off-by: Michael Niedermayer --- libavcodec/utils.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 4b4aea02bd6..63439bb8924 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1168,6 +1168,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code { int ret = 0; AVDictionary *tmp = NULL; + const AVPixFmtDescriptor *pixdesc; if (avcodec_is_open(avctx)) return 0; @@ -1453,6 +1454,13 @@ FF_ENABLE_DEPRECATION_WARNINGS goto free_and_end; } if(avctx->codec_type == AVMEDIA_TYPE_VIDEO) { + pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); + if ( avctx->bits_per_raw_sample < 0 + || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) { + av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n", + avctx->bits_per_raw_sample, pixdesc->comp[0].depth); + avctx->bits_per_raw_sample = pixdesc->comp[0].depth; + } if (avctx->width <= 0 || avctx->height <= 0) { av_log(avctx, AV_LOG_ERROR, "dimensions not set\n"); ret = AVERROR(EINVAL); -- 2.39.5