path: root/player/command.c
diff options
authorwm4 <wm4@nowhere>2015-08-10 18:43:25 +0200
committerwm4 <wm4@nowhere>2015-08-10 18:48:45 +0200
commit031555fbe6cfdf6d0db3b0a5a316dd55efd75846 (patch)
tree478cf20c66af2f1a465dd9657b6131afa548a877 /player/command.c
parentfedaad8250b9c9e262da3cda2114ccf5b62703a3 (diff)
player: add display sync mode
If this mode is enabled, the player tries to strictly synchronize video to display refresh. It will adjust playback speed to match the display, so if you play 23.976 fps video on a 24 Hz screen, playback speed is increased by approximately 1/1000. Audio wll be resampled to keep up with playback. This is different from the default sync mode, which will sync video to audio, with the consequence that video might skip or repeat a frame once in a while to make video keep up with audio. This is still unpolished. There are some major problems as well; in particular, mkv VFR files won't work well. The reason is that Matroska is terrible and rounds timestamps to milliseconds. This makes it rather hard to guess the framerate of a section of video that is playing. We could probably fix this by just accepting jittery timestamps (instead of explicitly disabling the sync code in this case), but I'm not ready to accept such a solution yet. Another issue is that we are extremely reliant on OS video and audio APIs working in an expected manner, which of course is not too often the case. Consequently, the new sync mode is a bit fragile.
Diffstat (limited to 'player/command.c')
1 files changed, 32 insertions, 4 deletions
diff --git a/player/command.c b/player/command.c
index 486c7262b8..c64427f930 100644
--- a/player/command.c
+++ b/player/command.c
@@ -295,11 +295,26 @@ static int mp_property_av_speed_correction(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
char *type = prop->priv;
+ double val = 0;
switch (type[0]) {
- case 'a': return m_property_double_ro(action, arg, mpctx->speed_factor_a);
- case 'v': return m_property_double_ro(action, arg, mpctx->speed_factor_v);
+ case 'a': val = mpctx->speed_factor_a; break;
+ case 'v': val = mpctx->speed_factor_v; break;
+ default: abort();
- abort();
+ if (action == M_PROPERTY_PRINT) {
+ *(char **)arg = talloc_asprintf(NULL, "%+.05f%%", (val - 1) * 100);
+ return M_PROPERTY_OK;
+ }
+ return m_property_double_ro(action, arg, val);
+static int mp_property_display_sync_active(void *ctx, struct m_property *prop,
+ int action, void *arg)
+ MPContext *mpctx = ctx;
+ return m_property_flag_ro(action, arg, mpctx->display_sync_active);
/// filename with path (RO)
@@ -557,6 +572,16 @@ static int mp_property_vo_drop_frame_count(void *ctx, struct m_property *prop,
return m_property_int_ro(action, arg, vo_get_drop_count(mpctx->video_out));
+static int mp_property_vo_missed_frame_count(void *ctx, struct m_property *prop,
+ int action, void *arg)
+ MPContext *mpctx = ctx;
+ if (!mpctx->d_video)
+ return m_property_int_ro(action, arg, vo_get_missed_count(mpctx->video_out));
/// Current position in percent (RW)
static int mp_property_percent_pos(void *ctx, struct m_property *prop,
int action, void *arg)
@@ -3318,6 +3343,7 @@ static const struct m_property mp_properties[] = {
{"speed", mp_property_playback_speed},
{"audio-speed-correction", mp_property_av_speed_correction, .priv = "a"},
{"video-speed-correction", mp_property_av_speed_correction, .priv = "v"},
+ {"display-sync-active", mp_property_display_sync_active},
{"filename", mp_property_filename},
{"stream-open-filename", mp_property_stream_open_filename},
{"file-size", mp_property_file_size},
@@ -3335,6 +3361,7 @@ static const struct m_property mp_properties[] = {
{"total-avsync-change", mp_property_total_avsync_change},
{"drop-frame-count", mp_property_drop_frame_cnt},
{"vo-drop-frame-count", mp_property_vo_drop_frame_count},
+ {"vo-missed-frame-count", mp_property_vo_missed_frame_count},
{"percent-pos", mp_property_percent_pos},
{"time-start", mp_property_time_start},
{"time-pos", mp_property_time_pos},
@@ -3549,7 +3576,8 @@ static const char *const *const mp_event_property_change[] = {
E(MPV_EVENT_TICK, "time-pos", "stream-pos", "stream-time-pos", "avsync",
"percent-pos", "time-remaining", "playtime-remaining", "playback-time",
"estimated-vf-fps", "drop-frame-count", "vo-drop-frame-count",
- "total-avsync-change", "audio-speed-correction", "video-speed-correction"),
+ "total-avsync-change", "audio-speed-correction", "video-speed-correction",
+ "vo-missed-frame-count"),
E(MPV_EVENT_VIDEO_RECONFIG, "video-out-params", "video-params",
"video-format", "video-codec", "video-bitrate", "dwidth", "dheight",
"width", "height", "fps", "aspect", "vo-configured", "current-vo",