1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-10-06 05:47:18 +02:00

avformat/demux: don't overwrite container level color information if set

If the information is coded at the container level, then that's what should be
exported. The user will still have access to values coded at the bitstream
level by firing a decoder.

Fixes issue #20121

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2025-08-05 14:49:03 -03:00
parent 95850f339e
commit 9b709532d5
3 changed files with 44 additions and 3 deletions

View File

@@ -2509,6 +2509,47 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *
return 0;
}
static int parameters_from_context(AVFormatContext *ic, AVCodecParameters *par,
const AVCodecContext *avctx)
{
AVCodecParameters *par_tmp;
int ret;
par_tmp = avcodec_parameters_alloc();
if (!par_tmp)
return AVERROR(ENOMEM);
ret = avcodec_parameters_copy(par_tmp, par);
if (ret < 0)
goto fail;
ret = avcodec_parameters_from_context(par, avctx);
if (ret < 0)
goto fail;
/* Restore some values if they are signaled at the container level
* given they may have been replaced by codec level values as read
* internally by avformat_find_stream_info().
*/
if (par_tmp->color_range != AVCOL_RANGE_UNSPECIFIED)
par->color_range = par_tmp->color_range;
if (par_tmp->color_primaries != AVCOL_PRI_UNSPECIFIED ||
par_tmp->color_trc != AVCOL_TRC_UNSPECIFIED ||
par_tmp->color_space != AVCOL_SPC_UNSPECIFIED) {
par->color_primaries = par_tmp->color_primaries;
par->color_trc = par_tmp->color_trc;
par->color_space = par_tmp->color_space;
}
if (par_tmp->chroma_location != AVCHROMA_LOC_UNSPECIFIED)
par->chroma_location = par_tmp->chroma_location;
ret = 0;
fail:
avcodec_parameters_free(&par_tmp);
return ret;
}
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
{
FFFormatContext *const si = ffformatcontext(ic);
@@ -3034,7 +3075,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
FFStream *const sti = ffstream(st);
if (sti->avctx_inited) {
ret = avcodec_parameters_from_context(st->codecpar, sti->avctx);
ret = parameters_from_context(ic, st->codecpar, sti->avctx);
if (ret < 0)
goto find_stream_info_err;

View File

@@ -32,7 +32,7 @@
#include "version_major.h"
#define LIBAVFORMAT_VERSION_MINOR 6
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \

View File

@@ -1,6 +1,6 @@
#extradata 0: 46, 0x6fed1203
#extradata 1: 26, 0x5e13070a
#extradata 2: 12, 0x044800b1
#extradata 2: 12, 0x044200af
#extradata 3: 27, 0x5f3604aa
#extradata 4: 17, 0x1d8a047e
#extradata 5: 34, 0x2b7301d1