avcodec/libx265: ignore user set alpha x265-param

It makes no difference when the input has an alpha plane, and may end up in
crashes or undefined behavior if it doesn't.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2024-12-26 13:41:04 -03:00
parent 6ffbc22b53
commit 7e778586e7
2 changed files with 18 additions and 4 deletions

View file

@ -499,9 +499,9 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
size_t size = nal->size; size_t size = nal->size;
enum AVCodecID codec_id = ctx->codec->codec_id; enum AVCodecID codec_id = ctx->codec->codec_id;
if (codec_id == AV_CODEC_ID_HEVC && nal->nuh_layer_id > 0 && // if (codec_id == AV_CODEC_ID_HEVC && nal->nuh_layer_id > 0 &&
(nal->type < HEVC_NAL_VPS || nal->type > HEVC_NAL_PPS)) // (nal->type < HEVC_NAL_VPS || nal->type > HEVC_NAL_PPS))
continue; // continue;
// Remove trailing zeroes. // Remove trailing zeroes.
while (size > 0 && nal->data[size - 1] == 0) while (size > 0 && nal->data[size - 1] == 0)

View file

@ -505,8 +505,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
{ {
const AVDictionaryEntry *en = NULL; const AVDictionaryEntry *en = NULL;
while ((en = av_dict_iterate(ctx->x265_opts, en))) { while ((en = av_dict_iterate(ctx->x265_opts, en))) {
int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value); int parse_ret;
// ignore forced alpha option. The pixel format is all we need.
if (!strncmp(en->key, "alpha", 5)) {
if (desc->nb_components == 4) {
av_log(avctx, AV_LOG_WARNING,
"Ignoring redundant \"alpha\" option.\n");
continue;
}
av_log(avctx, AV_LOG_ERROR,
"Alpha encoding was requested through an unsupported "
"option when no alpha plane is present\n");
return AVERROR(EINVAL);
}
parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
switch (parse_ret) { switch (parse_ret) {
case X265_PARAM_BAD_NAME: case X265_PARAM_BAD_NAME:
av_log(avctx, AV_LOG_WARNING, av_log(avctx, AV_LOG_WARNING,