Skip to content

Commit

Permalink
options: add --sub-ass-colorspace option
Browse files Browse the repository at this point in the history
Option to control what colorspace subtitle should be converted to before
drawing them. Upstream ASS specification says that all subtitles should
be rendered with color primaries and transfer matching their associated
video.

This has certain limitations in the case of HDR/WCG content. See the
discussion in libass/libass#297.

To mitigate current situation add an option for users to control the
render target of subtitles.

This could be also accomplished with --blend-subtitles to some degree,
but I don't want to mux options that are not really clear to affect this
certain case.

See-Also: https://github.com/libass/libass/blob/649a7c2e1fc6f4188ea1a89968560715800b883d/libass/ass_types.h#L233-L237
See-Also: libass/libass#297
See-Also: mpv-player#13381
Fixes: mpv-player#13673
  • Loading branch information
kasper93 committed Mar 9, 2024
1 parent a56d8ff commit 3ee8d1b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Interface changes
- add `--border-background` option
- add `video-target-params` property
- add `hdr10plus` sub-parameter to `format` video filter
- add `--sub-ass-colorspace` option
--- mpv 0.37.0 ---
- `--save-position-on-quit` and its associated commands now store state files
in %LOCALAPPDATA% instead of %APPDATA% directory by default on Windows.
Expand Down
15 changes: 15 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,21 @@ Subtitles

Default: yes.

``--sub-ass-colorspace=<auto|video|sdr>``
Specify the RGB primaries and transfer function to use when rendering
ASS subtitles.

:auto: Follow the ASS specification. This is currently equivalent to
``video``. This behavior may change in the future. (default)
:video: Assume that ASS subtitles are in the video's colorspace. Match the
color primaries and transfer function of the ASS subtitles to those
of the associated video.
:sdr: Assume that ASS subtitles are SDR. Match them to the video's
colorspace in SDR mode. If the video is HDR/WCG, fall back to sRGB.

This option affects ``--vo=gpu-next``, ``--vo=gpu`` always assume sRGB
colorspace for subtitles.

``--sub-ass-vsfilter-aspect-compat=<yes|no>``
Stretch SSA/ASS subtitles when playing anamorphic videos for compatibility
with traditional VSFilter behavior. This switch has no effect when the
Expand Down
2 changes: 2 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ const struct m_sub_options mp_subtitle_sub_opts = {
{"sub-past-video-end", OPT_BOOL(sub_past_video_end)},
{"sub-ass-force-style", OPT_REPLACED("sub-ass-style-overrides")},
{"sub-lavc-o", OPT_KEYVALUELIST(sub_avopts)},
{"sub-ass-colorspace", OPT_CHOICE(ass_colorspace,
{"auto", 0}, {"video", 1}, {"sdr", 2})},
{0}
},
.size = sizeof(OPT_BASE_STRUCT),
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct mp_subtitle_opts {
bool sub_clear_on_seek;
int teletext_page;
bool sub_past_video_end;
int ass_colorspace;
char **sub_avopts;
};

Expand Down
17 changes: 15 additions & 2 deletions video/out/vo_gpu_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ struct priv {
struct m_config_cache *opts_cache;
struct m_config_cache *next_opts_cache;
struct gl_next_opts *next_opts;
struct m_config_cache *subtitle_opts_cache;
struct mp_subtitle_opts *subtitle_opts;
struct cache shader_cache, icc_cache;
struct mp_csp_equalizer_state *video_eq;
struct scaler_params scalers[SCALER_COUNT];
Expand Down Expand Up @@ -378,8 +380,15 @@ static void update_overlays(struct vo *vo, struct mp_osd_res res,
}
}
break;
case SUBBITMAP_LIBASS:
if (src && item->video_color_space)
case SUBBITMAP_LIBASS:;
bool video_color_space = item->video_color_space;
if (p->subtitle_opts->ass_colorspace == 2 &&
(pl_color_space_is_hdr(&src->params.color) ||
pl_color_primaries_is_wide_gamut(src->params.color.primaries)))
{
video_color_space = false;
}
if (src && video_color_space)
ol->color = src->params.color;
ol->mode = PL_OVERLAY_MONOCHROME;
ol->repr.alpha = PL_ALPHA_INDEPENDENT;
Expand Down Expand Up @@ -768,6 +777,8 @@ static void update_options(struct vo *vo)
if (changed)
update_render_options(vo);

m_config_cache_update(p->subtitle_opts_cache);

update_lut(p, &p->next_opts->lut);
pars->params.lut = p->next_opts->lut.lut;
pars->params.lut_type = p->next_opts->lut.type;
Expand Down Expand Up @@ -1820,6 +1831,8 @@ static int preinit(struct vo *vo)
p->opts_cache = m_config_cache_alloc(p, vo->global, &gl_video_conf);
p->next_opts_cache = m_config_cache_alloc(p, vo->global, &gl_next_conf);
p->next_opts = p->next_opts_cache->opts;
p->subtitle_opts_cache = m_config_cache_alloc(p, vo->global, &mp_subtitle_sub_opts);
p->subtitle_opts = p->subtitle_opts_cache->opts;
p->video_eq = mp_csp_equalizer_create(p, vo->global);
p->global = vo->global;
p->log = vo->log;
Expand Down

0 comments on commit 3ee8d1b

Please sign in to comment.