summaryrefslogtreecommitdiffstats
path: root/sub/dec_sub.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-05 23:56:07 +0100
committerwm4 <wm4@nowhere>2015-12-05 23:56:07 +0100
commit04934e86dd154d1824253ba468c8f76eadc3076a (patch)
treef6b245f0951e72e35a61934e0a6d43aaaee88d30 /sub/dec_sub.c
parentff1eaea3e7f9ac2ab45b298326b96d256f487dc3 (diff)
downloadmpv-04934e86dd154d1824253ba468c8f76eadc3076a.tar.bz2
mpv-04934e86dd154d1824253ba468c8f76eadc3076a.tar.xz
sub: move --sub-fix-timing handling to renderer
Instead of messing with the subtitle packet timestamps, do it on output. We work on the libass event list. If there is an unwanted gap or overlap, we render the timestamp at another position where there is no gap or overlap. This is somewhat more robust, and even works with demuxed subs (to some degree - depends whether the subs are prefected soon enough). It's active even for native ASS subs. I wonder if this is a problem with extended type setting. If it is, the heuristic that tries to avoid interrupting such cases has to be improved. While it probably would be ideal to do this after the subtitle decoder, certain aspects are at least currently handled better in this place.
Diffstat (limited to 'sub/dec_sub.c')
-rw-r--r--sub/dec_sub.c34
1 files changed, 0 insertions, 34 deletions
diff --git a/sub/dec_sub.c b/sub/dec_sub.c
index a9267112f4..4372c0be91 100644
--- a/sub/dec_sub.c
+++ b/sub/dec_sub.c
@@ -346,37 +346,6 @@ static void multiply_timings(struct packet_list *subs, double factor)
}
}
-#define MS_TS(f_ts) ((long long)((f_ts) * 1000 + 0.5))
-
-// Remove overlaps and fill gaps between adjacent subtitle packets. This is done
-// by adjusting the duration of the earlier packet. If the gaps or overlap are
-// larger than the threshold, or if the durations are close to the threshold,
-// don't change the events.
-// The algorithm is maximally naive and doesn't work if there are multiple
-// overlapping lines. (It's not worth the trouble.)
-static void fix_overlaps_and_gaps(struct packet_list *subs)
-{
- double threshold = SUB_GAP_THRESHOLD;
- double keep = SUB_GAP_KEEP;
- for (int i = 0; i < subs->num_packets - 1; i++) {
- struct demux_packet *cur = subs->packets[i];
- struct demux_packet *next = subs->packets[i + 1];
- if (cur->pts != MP_NOPTS_VALUE && cur->duration > 0 &&
- next->pts != MP_NOPTS_VALUE && next->duration > 0)
- {
- double end = cur->pts + cur->duration;
- if (fabs(next->pts - end) <= threshold && cur->duration >= keep &&
- next->duration >= keep)
- {
- // Conceptually: cur->duration = next->pts - cur->pts;
- // But make sure the rounding and conversion to integers in
- // sd_ass.c can't produce overlaps.
- cur->duration = (MS_TS(next->pts) - MS_TS(cur->pts)) / 1000.0;
- }
- }
- }
-}
-
static void add_sub_list(struct dec_sub *sub, int at, struct packet_list *subs)
{
struct sd *sd = sub_get_last_sd(sub);
@@ -478,9 +447,6 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_stream *sh)
if (sub_speed != 1.0)
multiply_timings(subs, sub_speed);
- if (opts->sub_fix_timing)
- fix_overlaps_and_gaps(subs);
-
add_sub_list(sub, preprocess, subs);
pthread_mutex_unlock(&sub->lock);