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.
This commit is contained in:
wm4 2020-05-23 03:48:51 +02:00
parent d62131d3ae
commit 1826e69af2
4 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -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,

View File

@ -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;

View File

@ -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;