mirror of
https://github.com/mpv-player/mpv
synced 2025-01-30 03:32:50 +00:00
sd_lavc: remove small gaps between subtitles
Just like with text subtitles. Move the magic constants to a common place too.
This commit is contained in:
parent
9a240dc82e
commit
ff1eaea3e7
@ -356,8 +356,8 @@ static void multiply_timings(struct packet_list *subs, double factor)
|
||||
// overlapping lines. (It's not worth the trouble.)
|
||||
static void fix_overlaps_and_gaps(struct packet_list *subs)
|
||||
{
|
||||
double threshold = 0.2; // up to 200 ms overlaps or gaps are removed
|
||||
double keep = threshold * 2;// don't change timings if durations are smaller
|
||||
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];
|
||||
|
5
sub/sd.h
5
sub/sd.h
@ -4,6 +4,11 @@
|
||||
#include "dec_sub.h"
|
||||
#include "demux/packet.h"
|
||||
|
||||
// up to 200 ms overlaps or gaps are removed
|
||||
#define SUB_GAP_THRESHOLD 0.2
|
||||
// don't change timings if durations are smaller
|
||||
#define SUB_GAP_KEEP 0.4
|
||||
|
||||
struct sd {
|
||||
struct mp_log *log;
|
||||
struct MPOpts *opts;
|
||||
|
@ -202,6 +202,9 @@ static void decode(struct sd *sd, struct demux_packet *packet)
|
||||
if (prev->endpts == MP_NOPTS_VALUE || prev->endpts > pts)
|
||||
prev->endpts = pts;
|
||||
|
||||
if (opts->sub_fix_timing && pts - prev->endpts <= SUB_GAP_THRESHOLD)
|
||||
prev->endpts = pts;
|
||||
|
||||
for (int n = 0; n < priv->num_seekpoints; n++) {
|
||||
if (priv->seekpoints[n].pts == prev->pts) {
|
||||
priv->seekpoints[n].endpts = prev->endpts;
|
||||
|
Loading…
Reference in New Issue
Block a user