matroskadec_haali: Export colorspace info in the mastering data struct
This commit is contained in:
parent
45a01c82b0
commit
024cbd0507
|
@ -1065,28 +1065,41 @@ static int mkv_parse_video_color(AVStream *st, TrackInfo *info)
|
|||
info->AV.Video.Colour.MasteringMetadata.PrimaryBChromaticityX > 0 && info->AV.Video.Colour.MasteringMetadata.PrimaryBChromaticityY > 0 &&
|
||||
info->AV.Video.Colour.MasteringMetadata.WhitePointChromaticityX > 0 && info->AV.Video.Colour.MasteringMetadata.WhitePointChromaticityY > 0;
|
||||
const int has_mastering_luminance = info->AV.Video.Colour.MasteringMetadata.LuminanceMax > 0;
|
||||
int has_colorspace = 0;
|
||||
|
||||
if (info->AV.Video.Colour.MatrixCoefficients != AVCOL_SPC_RESERVED)
|
||||
if (info->AV.Video.Colour.MatrixCoefficients != AVCOL_SPC_RESERVED &&
|
||||
info->AV.Video.Colour.MatrixCoefficients != AVCOL_SPC_UNSPECIFIED) {
|
||||
st->codecpar->color_space = info->AV.Video.Colour.MatrixCoefficients;
|
||||
has_colorspace = 1;
|
||||
}
|
||||
if (info->AV.Video.Colour.Primaries != AVCOL_PRI_RESERVED &&
|
||||
info->AV.Video.Colour.Primaries != AVCOL_PRI_RESERVED0)
|
||||
info->AV.Video.Colour.Primaries != AVCOL_PRI_RESERVED0 &&
|
||||
info->AV.Video.Colour.Primaries != AVCOL_PRI_UNSPECIFIED) {
|
||||
st->codecpar->color_primaries = info->AV.Video.Colour.Primaries;
|
||||
has_colorspace = 1;
|
||||
}
|
||||
if (info->AV.Video.Colour.TransferCharacteristics != AVCOL_TRC_RESERVED &&
|
||||
info->AV.Video.Colour.TransferCharacteristics != AVCOL_TRC_RESERVED0)
|
||||
info->AV.Video.Colour.TransferCharacteristics != AVCOL_TRC_RESERVED0 &&
|
||||
info->AV.Video.Colour.TransferCharacteristics != AVCOL_TRC_UNSPECIFIED) {
|
||||
st->codecpar->color_trc = info->AV.Video.Colour.TransferCharacteristics;
|
||||
has_colorspace = 1;
|
||||
}
|
||||
if (info->AV.Video.Colour.Range != AVCOL_RANGE_UNSPECIFIED &&
|
||||
info->AV.Video.Colour.Range <= AVCOL_RANGE_JPEG)
|
||||
info->AV.Video.Colour.Range <= AVCOL_RANGE_JPEG) {
|
||||
st->codecpar->color_range = info->AV.Video.Colour.Range;
|
||||
has_colorspace = 1;
|
||||
}
|
||||
if (info->AV.Video.Colour.ChromaSitingHorz != MATROSKA_COLOUR_CHROMASITINGHORZ_UNDETERMINED &&
|
||||
info->AV.Video.Colour.ChromaSitingVert != MATROSKA_COLOUR_CHROMASITINGVERT_UNDETERMINED &&
|
||||
info->AV.Video.Colour.ChromaSitingHorz < MATROSKA_COLOUR_CHROMASITINGHORZ_NB &&
|
||||
info->AV.Video.Colour.ChromaSitingHorz < MATROSKA_COLOUR_CHROMASITINGHORZ_NB &&
|
||||
info->AV.Video.Colour.ChromaSitingVert < MATROSKA_COLOUR_CHROMASITINGVERT_NB) {
|
||||
st->codecpar->chroma_location =
|
||||
avcodec_chroma_pos_to_enum((info->AV.Video.Colour.ChromaSitingHorz - 1) << 7,
|
||||
(info->AV.Video.Colour.ChromaSitingVert - 1) << 7);
|
||||
has_colorspace = 1;
|
||||
}
|
||||
|
||||
if (has_mastering_primaries || has_mastering_luminance) {
|
||||
if (has_mastering_primaries || has_mastering_luminance || has_colorspace) {
|
||||
// Use similar rationals as other standards.
|
||||
const int chroma_den = 50000;
|
||||
const int luma_den = 10000;
|
||||
|
@ -1124,6 +1137,15 @@ static int mkv_parse_video_color(AVStream *st, TrackInfo *info)
|
|||
round(info->AV.Video.Colour.MasteringMetadata.LuminanceMin * luma_den), luma_den);
|
||||
metadata->has_luminance = 1;
|
||||
}
|
||||
if (has_colorspace) {
|
||||
// set color properties in the metadata, so it can be differentiated from any codec data
|
||||
metadata->color_range = st->codecpar->color_range;
|
||||
metadata->color_primaries = st->codecpar->color_primaries;
|
||||
metadata->color_trc = st->codecpar->color_trc;
|
||||
metadata->colorspace = st->codecpar->color_space;
|
||||
metadata->chroma_location = st->codecpar->chroma_location;
|
||||
metadata->has_colorspace = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -56,6 +56,30 @@ typedef struct AVMasteringDisplayMetadata {
|
|||
*/
|
||||
AVRational max_luminance;
|
||||
|
||||
/**
|
||||
* MPEG vs JPEG YUV range.
|
||||
* It must be accessed using av_frame_get_color_range() and
|
||||
* av_frame_set_color_range().
|
||||
* - encoding: Set by user
|
||||
* - decoding: Set by libavcodec
|
||||
*/
|
||||
enum AVColorRange color_range;
|
||||
|
||||
enum AVColorPrimaries color_primaries;
|
||||
|
||||
enum AVColorTransferCharacteristic color_trc;
|
||||
|
||||
/**
|
||||
* YUV colorspace type.
|
||||
* It must be accessed using av_frame_get_colorspace() and
|
||||
* av_frame_set_colorspace().
|
||||
* - encoding: Set by user
|
||||
* - decoding: Set by libavcodec
|
||||
*/
|
||||
enum AVColorSpace colorspace;
|
||||
|
||||
enum AVChromaLocation chroma_location;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the display primaries (and white point) are set.
|
||||
*/
|
||||
|
@ -66,6 +90,10 @@ typedef struct AVMasteringDisplayMetadata {
|
|||
*/
|
||||
int has_luminance;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the color_range, color_primaries, color_trc, colorspace and chroma_location have been set
|
||||
*/
|
||||
int has_colorspace;
|
||||
} AVMasteringDisplayMetadata;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue