1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-18 04:51:52 +00:00

video: Include better heuristics for guessing primaries

These consult the vertical resolution, matching against 576 for
PAL and 480/486 for NTSC. The documentation has also been updated.

Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
Niklas Haas 2014-04-02 00:40:36 +02:00 committed by wm4
parent fbd35caef8
commit 664f8e9832
4 changed files with 36 additions and 6 deletions

View File

@ -585,12 +585,21 @@ OPTIONS
management, for example ``opengl`` with the ``srgb`` or ``icc-profile``
suboptions set.
If this option is set to ``auto`` (which is the default), the video's
primaries flag will be used. If that flag is unset, the color space will
be selected automatically, using the following heuristics: If the
``--colormatrix`` is set or determined as BT.2020 or BT.709, the
corresponding primaries are used. Otherwise, if the video height is
exactly 576 (PAL), BT.601-625 is used. If it's exactly 480 or 486 (NTSC),
BT.601-525 is used. If the video resolution is anything else, BT.709 is
used.
Available primaries are:
:auto: automatic selection (default)
:BT.601-525: ITU-R BT.601 (SD) 525-line systems (NTSC)
:BT.601-525: ITU-R BT.601 (SD) 525-line systems (NTSC, SMPTE-C)
:BT.601-625: ITU-R BT.601 (SD) 625-line systems (PAL, SECAM)
:BT.709: ITU-R BT.709 (HD)
:BT.709: ITU-R BT.709 (HD) (same primaries as sRGB)
:BT.2020: ITU-R BT.2020 (UHD)
``--config-dir=<path>``

View File

@ -160,6 +160,25 @@ enum mp_csp mp_csp_guess_colorspace(int width, int height)
return width >= 1280 || height > 576 ? MP_CSP_BT_709 : MP_CSP_BT_601;
}
enum mp_csp_prim mp_csp_guess_primaries(int width, int height)
{
// HD content
if (width >= 1280 || height > 576)
return MP_CSP_PRIM_BT_709;
switch (height) {
case 576: // Typical PAL content, including anamorphic/squared
return MP_CSP_PRIM_BT_601_625;
case 480: // Typical NTSC content, including squared
case 486: // NTSC Pro or anamorphic NTSC
return MP_CSP_PRIM_BT_601_525;
default: // No good metric, just pick BT.709 to minimize damage
return MP_CSP_PRIM_BT_709;
}
}
enum mp_chroma_location avchroma_location_to_mp(int avloc)
{
switch (avloc) {

View File

@ -180,6 +180,7 @@ int mp_csp_levels_to_avcol_range(enum mp_csp_levels range);
int mp_csp_prim_to_avcol_pri(enum mp_csp_prim prim);
enum mp_csp mp_csp_guess_colorspace(int width, int height);
enum mp_csp_prim mp_csp_guess_primaries(int width, int height);
enum mp_chroma_location avchroma_location_to_mp(int avloc);
int mp_chroma_location_to_av(enum mp_chroma_location mploc);

View File

@ -537,14 +537,15 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
if (params->colorlevels == MP_CSP_LEVELS_AUTO)
params->colorlevels = MP_CSP_LEVELS_TV;
if (params->primaries == MP_CSP_PRIM_AUTO) {
// We assume BT.709 primaries for all untagged BT.609/BT.709
// content, because it offers the minimal deviation from all three,
// including both NTSC and PAL/SECAM.
// Guess based on the colormatrix as a first priority
if (params->colorspace == MP_CSP_BT_2020_NC ||
params->colorspace == MP_CSP_BT_2020_C) {
params->primaries = MP_CSP_PRIM_BT_2020;
} else {
} else if (params->colorspace == MP_CSP_BT_709) {
params->primaries = MP_CSP_PRIM_BT_709;
} else {
// Ambiguous colormatrix for BT.601, guess based on res
params->primaries = mp_csp_guess_primaries(params->w, params->h);
}
}
} else if (fmt.flags & MP_IMGFLAG_RGB) {