|
| 1 | +# `mpv_thumbnail_script.lua` |
| 2 | + |
| 3 | +[ on mpv's seekbar")](https://www.youtube.com/watch?v=a9cmt176WDI) |
| 4 | +[*Click the image or here to see the script in action*](https://www.youtube.com/watch?v=a9cmt176WDI) |
| 5 | + |
| 6 | +---- |
| 7 | + |
| 8 | +## What is it? |
| 9 | + |
| 10 | +`mpv_thumbnail_script.lua` is a script/replacement OSC for [mpv](https://github.com/mpv-player/mpv) to display preview thumbnails when hovering over the seekbar, without any external dependencies[<sup>1</sup>](#footnotes), cross-platform-ly[<sup>2</sup>](#footnotes)! |
| 11 | + |
| 12 | +The script supports all four built-in OSC layouts, [as seen in this Youtube video](https://www.youtube.com/watch?v=WsfWmO41p8A). |
| 13 | +The script will also do multiple passes over the video, generating thumbnails with increasing frequency until the target is reached. |
| 14 | +This allows you to preview the end of the file before every thumbnail has been generated. |
| 15 | + |
| 16 | +## How do I install it? |
| 17 | + |
| 18 | +Grab both the `mpv_thumbnail_script_server.lua` and `mpv_thumbnail_script_client_osc.lua` from the [releases page](https://github.com/TheAMM/mpv_thumbnail_script/releases) (or [see below](#development) how to "build" (concatenate) it yourself) and place them both to your mpv's `scripts` directory. (**Note!** Also see Configuration below) |
| 19 | + |
| 20 | +For example: |
| 21 | + * Linux/Unix/Mac: `~/.config/mpv/scripts/mpv_thumbnail_script_server.lua` & `~/.config/mpv/scripts/mpv_thumbnail_script_client_osc.lua` |
| 22 | + * Windows: `%APPDATA%\Roaming\mpv\scripts\mpv_thumbnail_script_server.lua` & `%APPDATA%\Roaming\mpv\scripts\mpv_thumbnail_script_client_osc.lua` |
| 23 | + |
| 24 | +See the [Files section](https://mpv.io/manual/master/#files) in mpv's manual for more info. |
| 25 | + |
| 26 | +The script can also use FFmpeg for faster thumbnail generation, which is highly recommended. |
| 27 | +Just make sure `ffmpeg[.exe]` is in your `PATH`. |
| 28 | + |
| 29 | +## How do I use it? |
| 30 | + |
| 31 | +Just open a file and hover over the seekbar! |
| 32 | +Although by default, videos over an hour will require you to press the `T` (that's `shift+t`) keybind. |
| 33 | +You may change this duration check in the configuration (`autogenerate_max_duration`). |
| 34 | + |
| 35 | +**Also of note:** the script does not manage the thumbnails in any way, you should clear the directory from time to time. |
| 36 | + |
| 37 | +## Configuration |
| 38 | + |
| 39 | +**Note!** Because this script replaces the built-in OSC, you will have to set `osc=no` in your mpv's [main config file](https://mpv.io/manual/master/#files). |
| 40 | + |
| 41 | +Create a file called `mpv_thumbnail_script.conf` inside your mpv's `lua-settings` directory to adjust the script's options. |
| 42 | + |
| 43 | +For example: |
| 44 | + * Linux/Unix/Mac: `~/.config/mpv/lua-settings/mpv_thumbnail_script.conf` |
| 45 | + * Windows: `%APPDATA%\Roaming\mpv\lua-settings\mpv_thumbnail_script.conf` |
| 46 | + |
| 47 | +See the [Files section](https://mpv.io/manual/master/#files) in mpv's manual for more info. |
| 48 | + |
| 49 | +In this file you may set the following options: |
| 50 | +```ini |
| 51 | +# The thumbnail cache directory. |
| 52 | +# On Windows this defaults to %TEMP%\mpv_thumbs_cache, |
| 53 | +# and on other platforms to /tmp/mpv_thumbs_cache. |
| 54 | +# The directory will be created automatically, but must be writeable! |
| 55 | +cache_directory=/tmp/my_mpv_thumbnails |
| 56 | + |
| 57 | +# Whether to generate thumbnails automatically on video load, without a keypress |
| 58 | +# Defaults to yes |
| 59 | +autogenerate=[yes/no] |
| 60 | + |
| 61 | +# Only automatically thumbnail videos shorter than this (in seconds) |
| 62 | +# You will have to press T (or your own keybind) to enable the thumbnail previews |
| 63 | +# Set to 0 to disable the check, ie. thumbnail videos no matter how long they are |
| 64 | +# Defaults to 3600 (one hour) |
| 65 | +autogenerate_max_duration=3600 |
| 66 | + |
| 67 | +# Use mpv to generate thumbnail even if ffmpeg is found in PATH |
| 68 | +# It's better to use ffmpeg, but the choice is yours |
| 69 | +# Defaults to no |
| 70 | +prefer_mpv=[yes/no] |
| 71 | + |
| 72 | +# Enable to disable the built-in keybind ("T") to add your own, see after the block |
| 73 | +disable_keybinds=[yes/no] |
| 74 | + |
| 75 | +# The maximum dimensions of the thumbnails, in pixels |
| 76 | +# Defaults to 200 and 200 |
| 77 | +thumbnail_width=200 |
| 78 | +thumbnail_height=200 |
| 79 | + |
| 80 | +# The thumbnail count target |
| 81 | +# (This will result in a thumbnail every ~10 seconds for a 25 minute video) |
| 82 | +thumbnail_count=150 |
| 83 | + |
| 84 | +# The above target count will be adjusted by the minimum and |
| 85 | +# maximum time difference between thumbnails. |
| 86 | +# The thumbnail_count will be used to calculate a target separation, |
| 87 | +# and min/max_delta will be used to constrict it. |
| 88 | + |
| 89 | +# In other words, thumbnails will be: |
| 90 | +# - at least min_delta seconds apart (limiting the amount) |
| 91 | +# - at most max_delta seconds apart (raising the amount if needed) |
| 92 | +# Defaults to 5 and 90, values are seconds |
| 93 | +min_delta=5 |
| 94 | +max_delta=90 |
| 95 | +# 120 seconds aka 2 minutes will add more thumbnails only when the video is over 5 hours long! |
| 96 | +``` |
| 97 | + |
| 98 | +With `disable_keybind=yes`, you can add your own keybind to [`input.conf`](https://mpv.io/manual/master/#input-conf) with `script-binding generate-thumbnails`, for example: |
| 99 | +```ini |
| 100 | +shift+alt+s script-binding generate-thumbnails |
| 101 | +``` |
| 102 | + |
| 103 | +## Development |
| 104 | + |
| 105 | +Included in the repository is the `concat_files.py` tool I use for automatically concatenating files upon their change, and also mapping changes to the output file back to the source files. It's really handy on stack traces when mpv gives you a line and column on the output file - no need to hunt down the right place in the source files! |
| 106 | + |
| 107 | +The script requires Python 3, so install that. Nothing more, though. Call it with `concat_files.py cat_osc.json`. |
| 108 | + |
| 109 | +You may also, of course, just `cat` the files together yourself. See the [`cat_osc.json`](cat_osc.json)/[`cat_server.json`](cat_server.json) for the order. |
| 110 | + |
| 111 | +### Donation |
| 112 | + |
| 113 | +If you *really* get a kick out of this (weirdo), you can [paypal me](https://www.paypal.me/TheAMM) or send bitcoins to `1K9FH7J3YuC9EnQjjDZJtM4EFUudHQr52d`. Just having the option there, is all. |
| 114 | + |
| 115 | +#### Footnotes |
| 116 | +<sup>1</sup>You *may* need to add `mpv[.exe]` to your `PATH` (and *will* have to add `ffmpeg[.exe]` if you want faster generation). |
| 117 | + |
| 118 | +<sup>2</sup>Developed & tested on Windows and Linux (Ubuntu), but it *should* work on Mac and whatnot as well, if <sup>1</sup> has been taken care of. |
0 commit comments