Minimize frame drops on resuming normal speed

Introduces slight a-v desynchronisation in speedup state, which is not
really noticeable. On resuming normalspeed a-v gets synchronized once
again.
This commit is contained in:
zenyd 2017-09-26 15:36:50 +02:00
parent bd746aa3dd
commit 5793184c2d
2 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,5 @@
## speed-transition ## speed-transition
This is a lua script for the mpv media player. The purpose of this script is to speed up the video if no subtitles are visible for a certain amount of (user configurable) time. It is inspired by [the speed-between-subs](https://gist.github.com/bitingsock/47c5ba6466c63c68bcf991dd376f1d18) script. This is a lua script for the mpv media player. The purpose of this script is to speed up the video if no subtitles are visible for a certain amount of (user configurable) time. It is inspired by the [speed-between-subs](https://gist.github.com/bitingsock/47c5ba6466c63c68bcf991dd376f1d18) script.
### How it works ### How it works
The script looks for the next subtitle and if it is ahead by 5 (default) seconds the video gets sped up and resumes normal playback just before the subtitle becomes visible. This is done to prevent audio glitches when speech starts. The script looks for the next subtitle and if it is ahead by 5 (default) seconds the video gets sped up and resumes normal playback just before the subtitle becomes visible. This is done to prevent audio glitches when speech starts.
@ -9,7 +9,9 @@ For the script to work it is necessary to have an appropriate 'text' subtitle se
If you want to use it with local files it is necessary to either have `--cache=yes` or `--demuxer-readahead-secs=10` options enabled in your config/cli. A value of `demuxer-readahead-secs>=10` is recommended. The same applies to `--cache-secs` option if it has been set. If you want to use it with local files it is necessary to either have `--cache=yes` or `--demuxer-readahead-secs=10` options enabled in your config/cli. A value of `demuxer-readahead-secs>=10` is recommended. The same applies to `--cache-secs` option if it has been set.
The script has sensible defaults, but if you want to change the `lookahead` value take care to not set it larger than what the buffers can provide. This applies to embedded subtitles and not external. The script works best in `video-sync=audio` mode (the default in mpv), because it will then be able to minimize frame drops on speed transition from high->normal. Stutter-free playback is the result.
Sensible defaults have been set, but if you want to change the `lookahead` value take care to not set it larger than what the buffers can provide. This applies to embedded subtitles and not external.
Key Bind|Effect Key Bind|Effect
--------|------ --------|------

View File

@ -18,6 +18,9 @@ end
function restore_normalspeed() function restore_normalspeed()
mp.set_property("speed", normalspeed) mp.set_property("speed", normalspeed)
if mp.get_property_native("video-sync") == "desync" then
mp.set_property("video-sync", "audio")
end
end end
function check_should_speedup() function check_should_speedup()
@ -78,6 +81,9 @@ function speed_transition(subtext, sub)
if sub == "" then if sub == "" then
nextsub, shouldspeedup = check_should_speedup() nextsub, shouldspeedup = check_should_speedup()
if shouldspeedup then if shouldspeedup then
if mp.get_property_native("video-sync") == "audio" then
mp.set_property("video-sync", "desync")
end
normalspeed = mp.get_property_native("speed") normalspeed = mp.get_property_native("speed")
mp.set_property("speed", speedup) mp.set_property("speed", speedup)
add_timers(nextsub) add_timers(nextsub)