1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-11 04:01:31 +00:00

sub: clear subtitle list when crossing timeline boundary

When crossing timeline boundaries (such as switching to a new segment or
chapter with ordered chapters), clear the internal text subtitle list.
This breaks the sub-seek command, but is otherwise not too harmful.
Fixes Sub-OC-test-final7.mkv. (The internal text subtitle list is
basically a cache to make subtitles show up at the right time when
seeking back.)

I suspect this was caused by 76fcef61. The sample file times subtitles
slightly before the video frame when it should show up. This is to avoid
problems with subtitles showing up a frame later than intended. It also
means that a subtitle which is supposed to show up on the start of a
timeline part boundary actually might first be shown in a different
part. Since we now manipulate the packet timestamps, instead of
manipulating timestamps after the subtitle decoder, this means this
subtitle event would have 2 timestamps, which our code of course does
not handle.

If the two parts come one after another, this would actually work (since
the subtitle would have the same timestamps in the old and new part),
but it breaks if the new part (which follows the old part in the
physical file) is has a completely different start time in the timeline.

Essentially, the trick used to time subtitles correctly is incompatible
with the way we cache subtitles (to make them survive seeks).

The simple solution is just clearing the cached subtitles when crossing
chapter boundaries.
This commit is contained in:
wm4 2015-12-25 12:28:01 +01:00
parent 940007cbf9
commit 6d9cb89333
3 changed files with 19 additions and 4 deletions

View File

@ -336,6 +336,12 @@ bool timeline_switch_to_time(struct MPContext *mpctx, double pts)
track->type,
track->user_tid - 1);
}
if (track->type == STREAM_SUB && track->stream) {
struct dec_sub *dec = track->stream->sub->dec_sub;
if (dec)
sub_control(dec, SD_CTRL_CLEAR, NULL);
}
}
}

View File

@ -22,6 +22,7 @@ enum sd_ctrl {
SD_CTRL_SET_VIDEO_PARAMS,
SD_CTRL_GET_RESOLUTION,
SD_CTRL_SET_TOP,
SD_CTRL_CLEAR,
};
struct dec_sub *sub_create(struct mpv_global *global);

View File

@ -510,13 +510,18 @@ static void fill_plaintext(struct sd *sd, double pts)
track->styles[track->default_style].Alignment = ctx->on_top ? 6 : 2;
}
static void clear(struct sd *sd)
{
struct sd_ass_priv *ctx = sd->priv;
ass_flush_events(ctx->ass_track);
ctx->num_seen_packets = 0;
}
static void reset(struct sd *sd)
{
struct sd_ass_priv *ctx = sd->priv;
if (sd->opts->sub_clear_on_seek) {
ass_flush_events(ctx->ass_track);
ctx->num_seen_packets = 0;
}
if (sd->opts->sub_clear_on_seek)
clear(sd);
if (ctx->converter)
lavc_conv_reset(ctx->converter);
}
@ -549,6 +554,9 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg)
case SD_CTRL_SET_TOP:
ctx->on_top = *(bool *)arg;
return CONTROL_OK;
case SD_CTRL_CLEAR:
clear(sd);
return CONTROL_OK;
default:
return CONTROL_UNKNOWN;
}