summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-05-23 03:48:51 +0200
committerwm4 <wm4@nowhere>2020-05-23 03:48:51 +0200
commit1826e69af215175ff602e01e76998db3759fc3ab (patch)
tree1fe40ec633e0f386031c739560990c9ee5bfce41
parentd62131d3aeda6f3b4c255ca06e70573433a8f16a (diff)
downloadmpv-1826e69af215175ff602e01e76998db3759fc3ab.tar.bz2
mpv-1826e69af215175ff602e01e76998db3759fc3ab.tar.xz
options: add option to control display-sync factor
Can be useful to force it to adapt to extreme speed changes, while a higher limit would just use a fraction closer to the original video speed. Probably useful for testing only.
-rw-r--r--DOCS/man/options.rst11
-rw-r--r--options/options.c2
-rw-r--r--options/options.h1
-rw-r--r--player/video.c7
4 files changed, 18 insertions, 3 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index 8118ea6ab0..370723aadb 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -6408,6 +6408,17 @@ Miscellaneous
:desync: Sync video according to system clock, and let audio play
on its own.
+``--video-sync-max-factor=<value>``
+ Maximum multiple for which to try to fit the video's FPS to the display's
+ FPS (default: 5).
+
+ For example, if this is set to 1, the video FPS is forced to an integer
+ multiple of the display FPS, as long as the speed change does not exceed
+ the value set by ``--video-sync-max-video-change``.
+
+ This is mostly for testing, and the option may be randomly changed in the
+ future without notice.
+
``--video-sync-max-video-change=<value>``
Maximum speed difference in percent that is applied to video with
``--video-sync=display-...`` (default: 1). Display sync mode will be
diff --git a/options/options.c b/options/options.c
index f32fec0cf9..08c9a7247f 100644
--- a/options/options.c
+++ b/options/options.c
@@ -692,6 +692,7 @@ static const m_option_t mp_opts[] = {
M_RANGE(0, 1)},
{"video-sync-adrop-size", OPT_DOUBLE(sync_audio_drop_size),
M_RANGE(0, 1)},
+ {"video-sync-max-factor", OPT_INT(sync_max_factor), M_RANGE(1, 10)},
{"hr-seek", OPT_CHOICE(hr_seek,
{"no", -1}, {"absolute", 0}, {"yes", 1}, {"always", 1}, {"default", 2})},
{"hr-seek-demuxer-offset", OPT_FLOAT(hr_seek_demuxer_offset)},
@@ -951,6 +952,7 @@ static const struct MPOpts mp_default_opts = {
.sync_max_video_change = 1,
.sync_max_audio_change = 0.125,
.sync_audio_drop_size = 0.020,
+ .sync_max_factor = 5,
.load_config = 1,
.position_resume = 1,
.autoload_files = 1,
diff --git a/options/options.h b/options/options.h
index db48135b1a..548edf70c3 100644
--- a/options/options.h
+++ b/options/options.h
@@ -206,6 +206,7 @@ typedef struct MPOpts {
double sync_max_video_change;
double sync_max_audio_change;
double sync_audio_drop_size;
+ int sync_max_factor;
int hr_seek;
float hr_seek_demuxer_offset;
int hr_seek_framedrop;
diff --git a/player/video.c b/player/video.c
index 630cdeffe4..5102ddf656 100644
--- a/player/video.c
+++ b/player/video.c
@@ -659,12 +659,12 @@ double calc_average_frame_duration(struct MPContext *mpctx)
// effective video FPS. If this is not possible, try to do it for multiples,
// which still leads to an improved end result.
// Both parameters are durations in seconds.
-static double calc_best_speed(double vsync, double frame)
+static double calc_best_speed(double vsync, double frame, int max_factor)
{
double ratio = frame / vsync;
double best_scale = -1;
double best_dev = INFINITY;
- for (int factor = 1; factor <= 5; factor++) {
+ for (int factor = 1; factor <= max_factor; factor++) {
double scale = ratio * factor / rint(ratio * factor);
double dev = fabs(scale - 1);
if (dev < best_dev) {
@@ -683,7 +683,8 @@ static double find_best_speed(struct MPContext *mpctx, double vsync)
double dur = mpctx->past_frames[n].approx_duration;
if (dur <= 0)
continue;
- total += calc_best_speed(vsync, dur / mpctx->opts->playback_speed);
+ total += calc_best_speed(vsync, dur / mpctx->opts->playback_speed,
+ mpctx->opts->sync_max_factor);
num++;
}
return num > 0 ? total / num : 1;