diff options
author | wm4 <wm4@nowhere> | 2015-04-23 19:35:15 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-04-23 19:37:02 +0200 |
commit | 90d7e51643273a14dfb9a4db622abb7da4e0aa5f (patch) | |
tree | 3001aff8d97622f092c813bc7f71cb967bd2a7b6 /demux | |
parent | e9ca0b1522a799e9d52e6aafc58fc316398f40b6 (diff) | |
download | mpv-90d7e51643273a14dfb9a4db622abb7da4e0aa5f.tar.bz2 mpv-90d7e51643273a14dfb9a4db622abb7da4e0aa5f.tar.xz |
demux_mkv: attempt to fix rounded timestamps
There is some potential for breakage. If it happens, this might have to
be disabled by default.
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux_mkv.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 4ae734cb5b..39b271e1b6 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <inttypes.h> #include <stdbool.h> +#include <math.h> #include <assert.h> #include <libavutil/common.h> @@ -190,6 +191,7 @@ struct demux_mkv_opts { int subtitle_preroll; double subtitle_preroll_secs; int probe_duration; + int fix_timestamps; }; const struct m_sub_options demux_mkv_conf = { @@ -198,11 +200,13 @@ const struct m_sub_options demux_mkv_conf = { OPT_DOUBLE("subtitle-preroll-secs", subtitle_preroll_secs, M_OPT_MIN, .min = 0), OPT_FLAG("probe-video-duration", probe_duration, 0), + OPT_FLAG("fix-timestamps", fix_timestamps, 0), {0} }, .size = sizeof(struct demux_mkv_opts), .defaults = &(const struct demux_mkv_opts){ .subtitle_preroll_secs = 1.0, + .fix_timestamps = 1, }, }; @@ -2327,6 +2331,19 @@ exit: return res; } +static double fix_timestamp(demuxer_t *demuxer, mkv_track_t *track, double ts) +{ + mkv_demuxer_t *mkv_d = demuxer->priv; + if (demuxer->opts->demux_mkv->fix_timestamps && track->default_duration > 0) { + // Assume that timestamps have been rounded to the timecode scale. + double quant = mkv_d->tc_scale / 1e9; + double rts = rint(ts / track->default_duration) * track->default_duration; + if (fabs(rts - ts) < quant) + ts = rts; + } + return ts; +} + static int handle_block(demuxer_t *demuxer, struct block_info *block_info) { mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; @@ -2349,7 +2366,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) return 0; } - current_pts = tc / 1e9 - track->codec_delay; + current_pts = fix_timestamp(demuxer, track, tc / 1e9) - track->codec_delay; if (track->type == MATROSKA_TRACK_AUDIO) { if (mkv_d->a_skip_to_keyframe) |