Code Monkey home page Code Monkey logo

mpv-reload's Introduction

reload.lua

When an online video is stuck during buffering or got slow CDN source, restarting often helps. This script provides automatic reloading of videos that didn't have buffering progress for some time, keeping the current time position while preserving entries in the playlist. It also adds Ctrl+r keybinding to reload video manually.

Install

Mpv reads its configuration from MPV_HOME directory. On Unix it is ~/.config/mpv, see files section of the manual for the Windows configuration files.

To install the script, copy reload.lua to the MPV_HOME/scripts directory. To override default settings, create reload.conf file in the script-opts directory MPV_HOME/script-opts.

NOTE: config file name should match the name of the script.

For configuration example you can also check 4e6/dotfiles repo.

Settings

Default reload.conf settings:

# enable automatic reload on timeout
# when paused-for-cache event fired, we will wait
# paused_for_cache_timer_timeout sedonds and then reload the video
paused_for_cache_timer_enabled=yes

# checking paused_for_cache property interval in seconds,
# can not be less than 0.05 (50 ms)
paused_for_cache_timer_interval=1

# time in seconds to wait until reload
paused_for_cache_timer_timeout=10

# enable automatic reload based on demuxer cache
# if demuxer-cache-time property didn't change in demuxer_cache_timer_timeout
# time interval, the video will be reloaded as soon as demuxer cache depleated
demuxer_cache_timer_enabled=yes

# checking demuxer-cache-time property interval in seconds,
# can not be less than 0.05 (50 ms)
demuxer_cache_timer_interval=2

# if demuxer cache didn't receive any data during demuxer_cache_timer_timeout
# we decide that it has no progress and will reload the stream when
# paused_for_cache event happens
demuxer_cache_timer_timeout=20

# when the end-of-file is reached, reload the stream to check
# if there is more content available.
reload_eof_enabled=no

# keybinding to reload stream from current time position
# you can disable keybinding by setting it to empty value
# reload_key_binding=
reload_key_binding=Ctrl+r

Debugging

Debug messages will be printed to stdout with mpv command line option --msg-level='reload=debug'. You may also need to add the --no-msg-color option to make the debug logs visible if you are using a dark colorscheme in terminal.

mpv-reload's People

Contributors

4e6 avatar mauricioquintela avatar mesvam avatar woorst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpv-reload's Issues

Set a license

Hi!

I'm about to package this script in nixpkgs (so our users can easily pull it into their configuration) and saw there's no explicit license set for the repo.

Could you pick (a FOSS) one? Otherwise I'll have to treat it like unfree software, as far as the distro is concerned

Youtube session invalidation - simply exits instead of reloading

When a youtube video is left paused in mpv for a long time, the session becomes invalidated (naturally). However, when resumed and the cached amount is consumed, mpv simply exits as it thinks the EOF has been reached. The expected behaviour would be to reload the video from its original url.

The following error messages are the only ones which appear after the youtube session has been invalidated:

[ffmpeg] https: HTTP error 403 Forbidden
[ffmpeg] tls: The specified session has been invalidated for some reason.
[ffmpeg] https: Will reconnect at 95321392 in X second(s), error=Input/output error.

where X takes the value of 0, 1, 3, and 7.

Format code changes when twitch stream is ended

On twitch 720p-0 in VOD of current live stream is 720p30 in VOD after stream is ended. And 720p-1 is 720p60.
So, if i choose to watch "live" VOD with 720p-1 quality, and stream is ended, so when i reload it, video is quitting, because there is no such format code now, it's changed to 720p60.

external files are not connected

Hello, there is such a problem.
If I opened the video and pulled the subtitles to the player from another folder or they had a different name, then after reloading these subtitles do not remain, and are included that are stitched or have the name of the video itself, is there a way to solve this problem?

Youtube video stuttering after reload

Hi guys,

Thanks for the awesome workaround, I faced buffering issues for weeks.

The reload works fine, but after the reload my video stutters, it seems that my mpv.conf is not used after the reload.
Do you have a solution how mpv uses the mpv.conf after reload or an idea why the video stutters after reload, if normally the mpv.conf is used after reload?

Reloading based on demuxer-cache-time

Recently I revisited the docs and discovered demuxer-cache-time property:

Approximate time of video buffered in the demuxer, in seconds. Same as demuxer-cache-duration but returns the last timestamp of buffered data in demuxer.

Currently, reload is happening based on paused-for-cache timeout.
A better choice would be to reload the stream based on demuxer-cache-time.

The algorithm is:

IF demuxer-cache-time value didn't change in demuxer_cache_timeout time interval AND paused-for-cache is true THEN reload_resume()

It should work in the following situation:

  • demuxer has 60 seconds of playback cached
  • CDN stopped the stream uploading
  • a video is playing from the cache, but demuxer-cache-time value isn't changing
  • cache buffer is depleted, paused-for-cache event triggered
  • if demuxer-cache-time didn't change in last demuxer_cache_timeout then reload stream

The advantage is that it will reload the video as soon as the paused-for-cache event happened, without waiting for the paused_for_cache_timer_timeout timeout.
The algorithm should supplement the currently used one and have a separate timeout setting.

Stucked after reconnection

Hello there !

After disconnecting (or toggeling wireless connection by example), the script will reload the resources but mpv will stay "paused". I have to press space two time (one to actually pause, one to unpause) to play again.

Is it a known issue ?

Single reload sometimes leads to reloading in a loop

Issue

Right after the video is reloaded on a cache timeout, another reload might be triggered which leads to a sequence of reloads. This happens very rarely though.

Investigation

The bug is very hard to reproduce. The error is somewhere in the logic of demuxer_cache management, but I wasn't able to identify it by looking at the code.

It might be worth to rewrite the demuxer_cache management as an FSM. It will make the state and transitions explicit and most likely will fix the bug.

sending two SPACE keypresses might cause issues

Hi! First of all thanks for this useful script.

However I've experienced it breaking my visibility=always configuration in script-opts/osc.conf since it sends two spaces and space is mapped to toggling osc visibility. (in my config)
https://github.com/4e6/mpv-reload/blob/master/reload.lua#L378-L379

I know this issue is kinda specific to my setup, but I just wanted to mention it in case there is a better way to solve the problem. I resolved it in my setup by changing space to something different

Videos stuck reloading

Description of issue: Running mpv /path/to/videos-directory mpv loads and plays the videos fine. However, after about 5 minutes, even as soon as 2 minutes or just randomly, a video will load and get stuck loading. I can fast-forward the video and it starts playing again but if I leave it alone for long enough mpv will freeze entirely requiring a forced shutdown.

mpv version: 34.1 using the latest reload.lua

I did a lot of trouble shooting with my config, and checking all my scripts to see which one was causing this issue. I ran mpv --msg-level='reload=debug' --no-msg-color /path/to/videos-directory and got this error

statusline: AV: 00:00:29 / 00:00:29 (98%) A-V: -0.000412 Vb: 980 kbps Ab: 105 kbps
    reload: demuxer_cache.transition continue_stuck {"in_state_time" = 28, "name" = "stuck", "demuxer_cache_time" = 125.621}

This script works great for youtube so I'll use profiles to work around the issue with local videos for the time being.

Please let me know what other info would be helpful in fixing this issue and I will provide it. This is easily reproducible for me but I don't have a lot of experience debugging mpv or scripts so I'm not sure what is and is not relevant.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.