mirror of
https://github.com/mpv-player/mpv
synced 2025-01-11 17:39:38 +00:00
video: honor the video's colormatrix and color range flags
If either of them is not defined, the old behavior is used: - the colormatrix is guessed based on resolution. - the color range is assumed to be tv aka limited range.
This commit is contained in:
parent
27262dec1b
commit
a1380f3945
@ -128,10 +128,16 @@ void get_detected_video_colorspace(struct sh_video *sh, struct mp_csp_details *c
|
||||
csp->levels_in = opts->requested_input_range;
|
||||
csp->levels_out = opts->requested_output_range;
|
||||
|
||||
if (csp->format == MP_CSP_AUTO)
|
||||
csp->format = sh->colorspace;
|
||||
if (csp->format == MP_CSP_AUTO)
|
||||
csp->format = mp_csp_guess_colorspace(vf->w, vf->h);
|
||||
|
||||
if (csp->levels_in == MP_CSP_LEVELS_AUTO)
|
||||
csp->levels_in = sh->color_range;
|
||||
if (csp->levels_in == MP_CSP_LEVELS_AUTO)
|
||||
csp->levels_in = MP_CSP_LEVELS_TV;
|
||||
|
||||
if (csp->levels_out == MP_CSP_LEVELS_AUTO)
|
||||
csp->levels_out = MP_CSP_LEVELS_PC;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "libmpdemux/demux_packet.h"
|
||||
#include "codec-cfg.h"
|
||||
#include "osdep/numcores.h"
|
||||
#include "libvo/csputils.h"
|
||||
|
||||
static const vd_info_t info = {
|
||||
"libavcodec video codecs",
|
||||
@ -463,6 +464,10 @@ static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt)
|
||||
};
|
||||
else
|
||||
supported_fmts = (const unsigned int[]){ctx->best_csp, 0xffffffff};
|
||||
|
||||
sh->colorspace = avcol_spc_to_mp_csp(avctx->colorspace);
|
||||
sh->color_range = avcol_range_to_mp_csp_levels(avctx->color_range);
|
||||
|
||||
if (!mpcodecs_config_vo2(sh, sh->disp_w, sh->disp_h, supported_fmts,
|
||||
ctx->best_csp))
|
||||
return -1;
|
||||
|
@ -147,6 +147,8 @@ typedef struct sh_video {
|
||||
float stream_aspect; // aspect ratio in media headers (DVD IFO files)
|
||||
int i_bps; // == bitrate (compressed bytes/sec)
|
||||
int disp_w, disp_h; // display size (filled by demuxer)
|
||||
int colorspace; // mp_csp
|
||||
int color_range; // mp_csp_levels
|
||||
// output driver/filters: (set by libmpcodecs core)
|
||||
unsigned int outfmt;
|
||||
unsigned int outfmtidx;
|
||||
|
@ -47,6 +47,37 @@ char * const mp_csp_equalizer_names[MP_CSP_EQ_COUNT] = {
|
||||
"gamma",
|
||||
};
|
||||
|
||||
enum mp_csp avcol_spc_to_mp_csp(enum AVColorSpace colorspace)
|
||||
{
|
||||
switch (colorspace) {
|
||||
case AVCOL_SPC_BT709:
|
||||
return MP_CSP_BT_709;
|
||||
break;
|
||||
case AVCOL_SPC_BT470BG:
|
||||
case AVCOL_SPC_SMPTE170M:
|
||||
return MP_CSP_BT_601;
|
||||
break;
|
||||
case AVCOL_SPC_SMPTE240M:
|
||||
return MP_CSP_SMPTE_240M;
|
||||
break;
|
||||
default:
|
||||
return MP_CSP_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
enum mp_csp_levels avcol_range_to_mp_csp_levels(enum AVColorRange range)
|
||||
{
|
||||
switch (range) {
|
||||
case AVCOL_RANGE_MPEG:
|
||||
return MP_CSP_LEVELS_TV;
|
||||
break;
|
||||
case AVCOL_RANGE_JPEG:
|
||||
return MP_CSP_LEVELS_PC;
|
||||
break;
|
||||
default:
|
||||
return MP_CSP_LEVELS_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
enum mp_csp mp_csp_guess_colorspace(int width, int height)
|
||||
{
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libavcodec/avcodec.h"
|
||||
|
||||
/* NOTE: the csp and levels AUTO values are converted to specific ones
|
||||
* above vf/vo level. At least vf_scale relies on all valid settings being
|
||||
@ -111,6 +112,10 @@ int mp_csp_equalizer_set(struct mp_csp_equalizer *eq, const char *property,
|
||||
int mp_csp_equalizer_get(struct mp_csp_equalizer *eq, const char *property,
|
||||
int *out_value);
|
||||
|
||||
enum mp_csp avcol_spc_to_mp_csp(enum AVColorSpace colorspace);
|
||||
|
||||
enum mp_csp_levels avcol_range_to_mp_csp_levels(enum AVColorRange range);
|
||||
|
||||
enum mp_csp mp_csp_guess_colorspace(int width, int height);
|
||||
|
||||
void mp_gen_gamma_map(unsigned char *map, int size, float gamma);
|
||||
|
Loading…
Reference in New Issue
Block a user