Coder Social home page Coder Social logo

ben-kerman / mpv-sub-scripts Goto Github PK

View Code? Open in Web Editor NEW
67.0 2.0 9.0 36 KB

Two mpv scripts for automatically pausing after each subtitle line and skipping intervals between subtitles.

Lua 100.00%
mpv-script language-learning condensed-audio subtitles

mpv-sub-scripts's Introduction

sub-pause

An mpv script that automatically pauses before and/or after each subtitle line. Mostly intended for language learning.

Key Bindings

  • (none): toggle auto-pause at start of line (toggle-start)
  • n: toggle auto-pause at end of line (toggle-end)
  • Alt+r: skip next pause (skip-next)
  • Ctrl+r: replay active/last line, always available (replay)

To use a key binding other than the defaults above add a line like the following to your input.conf (where X is the binding and <action_id> is the value in parentheses in the list above):

X script-binding sub_pause/<action_id>

sub-pause-toggle-start doesn't have a default binding and must be assigned manually.

If you want a binding for both replaying and skipping add a line like this:

Ctrl+Alt+SPACE script-binding sub-pause-replay; script-binding sub-pause-skip-next

sub_pause/ can be left out, however events triggered from bindings defined without it will be sent to all scripts, which can lead to conflicts if two scripts use the same action ID.

When using scoped actions, the script ID before / is derived from script's filename, with the extension removed and all characters except alphanumeric ASCII characters (A-Z, a-z, 0-9) replaced by _.

Configuration

Create a file at script-opts/sub_pause.conf in your mpv config directory:

# To set a value remove the leading # and modify it after the =.
# All values given here are defaults. Seconds can be decimal values.

# if set to 'yes', enable pausing at the start of each line by default
#default_start=no

# if set to 'yes', enable pausing at the end of each line by default
#default_end=no

# pause roughly this many seconds before the end of each line
# very low values can result in the line no longer being active after pausing
#end_delta=0.1

# if autopausing is enabled, hide subtitles while not paused
#hide_while_playing=no

# automatically resume playback this many seconds after autopausing
# no effect if less than or equal to zero
#unpause_time=0

# if unpause_time is set, prevent the next automatic unpause by pressing this key
# can be anything that would be an acceptable key binding in mpv's input.conf
#unpause_override=SPACE

# if set to 'yes' (the default), the previous line will be replayed after
# invoking `replay` if there is currently no active line
#replay_prev=yes

Known Issues

If there are multiple subtitles visible at the same time (e.g. one at the top and one at the bottom, or on-screen text with SubStation Alpha(ASS) subs) the script will only pause at the end of the last visible line. While it would be possible to fix this at least some of the time by saving every change in the subtitle end time this(in my opinion) doesn't justify the additional complexity considering how rare such situations are.


If you come across any other problems while using the script feel free to open a GitHub issue or send a pull request.

sub-skip

This script allows automatically skipping parts of a video that don't contain any subtitles. Skipping can be done either by speeding up playback while no subtitles are present or by seeking to the start of the next subtitle line, skipping the interval between lines entirely.

How To Use

The script works by briefly changing subtitle delay so that the next line starts at the current video/audio time, recording the difference between the original and shifted subtitle delay and then speeding up or seeking to the start of the next line (calculated from the difference).

This works best if mpv is forced to always demultiplex enough of the video for the next subtitle line to be almost always available by setting demuxer-readahead-secs to a value between 60-120 in mpv.conf. Alternatively, enabling cache for all videos with cache=yes also works.

If demuxer readahead or cache are not set explicitly it is possible for the next subtitle line to be unavailable even if it starts within the next few seconds. The script can deal with this but works best if one of the config entries from above is set.

Key Bindings

  • Ctrl+n: activate skipping (toggle)
  • Ctrl+Alt+n: toggle between speedup and seek skip (switch-mode)
  • Ctrl+Alt+[: decrease skip speed by 0.1 (decrease-speed)
  • Ctrl+Alt+]: increase skip speed by 0.1 (increase-speed)
  • Ctrl+Alt+-: decrease skip interval by 0.25s (decrease-interval)
  • Ctrl+Alt++: increase skip interval by 0.25s (increase-interval)

When changing the interval using the numpad +/- keys, it might be necessary to also press shift, even if it's not part of the binding.

As explained for sub-pause, additional bindings can be assigned in input.conf:

X script-binding sub_skip/<action_id>

Configuration

Create a file at script-opts/sub_skip.conf in your mpv config directory:

# To set a value remove the leading # and modify it after the =.
# All values given here are defaults. Seconds can be decimal values.

# if set to 'yes', enable skipping by default
#default_state=no

# if set to 'yes', use seek mode by default
#seek_mode_default=no

# any interval between subtitle lines longer than this value in seconds will be skipped
#min_skip_interval=3

# what speed to use while skipping if not in seek mode
#speed_skip_speed=2.5

# how many seconds after the end of a line to wait for before starting to skip
#lead_in=0

# how many seconds before the start of the next line to stop skipping at
#lead_out=1

# how much to change skip speed by when invoking sub-skip-{de,in}crease-speed
#speed_skip_speed_delta=0.1

# how many seconds to change the minimum interval by when invoking sub-skip-{de,in}crease-interval
#min_skip_interval_delta=0.25

sub-skip is inspired by and partially based on speed-transition from https://github.com/zenyd/mpv-scripts, but rewritten from scratch.

mpv-sub-scripts's People

Contributors

artjomsr avatar ben-kerman avatar peldas 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

Watchers

 avatar  avatar

mpv-sub-scripts's Issues

Sub-Skip Keybindings

Would you be able to add keybindings so that you can change the lead-in/out times?
(Having to not ever open the the .lua to alter how you want it to work is just a nice convenience )

sub-skip: subtitle timeout

About 40% of the time I don't get the benefit of sub-skip because the subtitles are timed by a machine or timed poorly. It would be nice if there was an option to only allow subtitle duration to be a maximum of x seconds. For example, 7 seconds

something like sub-end = sub-start + min(x, sub-end - sub-start) where x = 7

zenyd/mpv-scripts#28

Config files problem !

I was trying to auto activate sub-skip, when I create a folder (script-opts) and conf file the script didn't work utterly. Could you please check it.

Also, you write "#default_state=no/yes",,, however, in the lua file "false/true". ?

[sub-pause] Rebinding key only works when sent to all clients (script can't be targeted)

Trying to rebind the sub-pause-toggle-end in input.conf only works when sent to all clients.

These work:
N script-binding sub-pause-toggle-end
N script-message sub-pause-toggle-end

These do not:
N script-binding sub-pause/sub-pause-toggle-end
N script-message-to sub-pause sub-pause-toggle-end

While I think it's quite unlikely that any other script would have a function specifically named sub-pause-toggle-end, it would probably still be good practice to implement support for this in order to prevent name conflicts.

Replay Last Sub

A heavenly feature would be replay last, any chance that'd be added? I tried doing it myself quickly but wouldn't function

Doesn't Stop Playback

Hello,
It looks like the script doesn't work with mpv 0.32.0. Occasionally it stops the playback, but in most cases there's no effect, despite availability of subtitles and activation of pausing functionality using "n" shortcut.
OS: Debian 11.

[sub-skip] skip music/ignore music lines

Similar to the option from speed-transition from zenyd, I just thought I'd suggest the option to ignore specific lines like โ™ชโ™ช so the music lines will also be skipped. I prefer sub-skip over speed-transition since sub-skip also fasts forward the audio while (as far as I could tell) speed-transition mutes when skipping, but anyways just a suggestion ๐Ÿ‘

Feature request: resume after X seconds in auto-pause

Hi, I really like the idea to auto pause my videos so I have the time to read the translation. Nonetheless, I think that it would be nice if I could set that after X amount of time the video could continue automatically.

script suddenly stopped working

it was working back around a few months ago but now when i tried to use it (pressing n) but nothing happens. i put all my script in
%AppData%\Roaming\mpv\scripts\sub_pause\sub-pause.lua

im assuming that n is the default key binding

other script are working fine

I'm using windows 10 mpv 0.35.1. i know that theres a new version but it was working before so its kinda weird its not working now.

any way i can debug where the issue lies?

thanks

[sub-pause] Make it work for .idx/.sub subtitles

Since .idx/.sub subtitles don't have the "sub-text" property, the current implementation doesn't work for them.
How about observing "sub-start" or "sub-end" instead of "sub-text"?
I tried a quick hack:

-		mp.observe_property("sub-text", "string", handle_sub_text_change)
+		mp.observe_property("sub-start", "string", handle_sub_text_change)

, and it did the job for me.

Possible to get it working on android?

I already tried pointing the script in my config file as like this.

Android mpv-android:

script=/storage/emulated/0//sub-skip.lua

Doesn't work. I changed the load config to true. Didn't work. How do I get it to work?

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.