From d470766000250ada785da3513dc7a476447e7e73 Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Sat, 28 Oct 2023 15:54:43 +0300 Subject: sub: add --sub-stretch-durations option Stretch a subtitle duration so it ends when the next one starts. Should help with subtitles which erroneously have zero durations. I found such a subrip substitles stream in the wild. Signed-off-by: Mohammad AlSaleh --- DOCS/man/options.rst | 8 ++++++++ options/options.c | 1 + options/options.h | 1 + sub/sd_ass.c | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 42399509ae..d8f55f4cd1 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2648,6 +2648,14 @@ Subtitles particular subtitles in mkv files) are always assumed to be UTF-8. +``--sub-stretch-durations=`` + Stretch a subtitle duration so it ends when the next one starts. + Should help with subtitles which erroneously have zero durations. + + .. note:: + + Only applies to text subtitles. + ``--sub-fix-timing=`` Adjust subtitle timing is to remove minor gaps or overlaps between subtitles (if the difference is smaller than 210 ms, the gap or overlap diff --git a/options/options.c b/options/options.c index b217d10e56..36d59e2f4b 100644 --- a/options/options.c +++ b/options/options.c @@ -291,6 +291,7 @@ const struct m_sub_options mp_subtitle_sub_opts = { {"stretch-image-subs-to-screen", OPT_BOOL(stretch_image_subs)}, {"image-subs-video-resolution", OPT_BOOL(image_subs_video_res)}, {"sub-fix-timing", OPT_BOOL(sub_fix_timing)}, + {"sub-stretch-durations", OPT_BOOL(sub_stretch_durations)}, {"sub-pos", OPT_FLOAT(sub_pos), M_RANGE(0.0, 150.0)}, {"sub-gauss", OPT_FLOAT(sub_gauss), M_RANGE(0.0, 3.0)}, {"sub-gray", OPT_BOOL(sub_gray)}, diff --git a/options/options.h b/options/options.h index 3c730cebf5..aa071b28f6 100644 --- a/options/options.h +++ b/options/options.h @@ -93,6 +93,7 @@ struct mp_subtitle_opts { bool stretch_image_subs; bool image_subs_video_res; bool sub_fix_timing; + bool sub_stretch_durations; bool sub_scale_by_window; bool sub_scale_with_window; bool ass_scale_with_window; diff --git a/sub/sd_ass.c b/sub/sd_ass.c index bbf3218f49..6742f6f658 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -341,7 +341,8 @@ static void decode(struct sd *sd, struct demux_packet *packet) double sub_duration = 0; char **r = lavc_conv_decode(ctx->converter, packet, &sub_pts, &sub_duration); - if (packet->duration < 0 || sub_duration == UINT32_MAX) { + if (sd->opts->sub_stretch_durations || + packet->duration < 0 || sub_duration == UINT32_MAX) { if (!ctx->duration_unknown) { MP_WARN(sd, "Subtitle with unknown duration.\n"); ctx->duration_unknown = true; -- cgit v1.2.3