Skip to content

Commit 7074706

Browse files
committed
Initial commit (full features, readme+license)
Creates thumbnails iteratively now, in multiple passes. This way the end of the file can be previewed quickly, without having to wait for all the thumbs from start to end to be generated. Also lots of other stuff. Should be robust, lest users prove me wrong.
1 parent 13f76d7 commit 7074706

File tree

12 files changed

+1105
-126
lines changed

12 files changed

+1105
-126
lines changed

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# `mpv_thumbnail_script.lua`
2+
3+
[![](docs/mpv_thumbnail_script.jpg "Thumbnail preview for Sintel (2010) 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.

cat_osc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"output" : "mpv_thumbnail_script_client_osc.lua",
33
"files" : [
4+
"src/license_blurb.lua",
5+
"<version>",
46
"lib/helpers.lua",
57
"src/options.lua",
68
"src/thumbnailer_shared.lua",
79
"src/patched_osc.lua"
810
],
11+
12+
"version_file" : "version.txt",
13+
"version_template_file" : "src/version.tmpl.lua",
14+
915
"header_prefix" : "--[ ",
1016
"header_suffix" : " ]--"
1117
}

cat_server.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"output" : "mpv_thumbnail_script_server.lua",
33
"files" : [
4+
"src/license_blurb.lua",
5+
"<version>",
46
"lib/helpers.lua",
57
"src/options.lua",
68
"src/thumbnailer_shared.lua",
79
"src/thumbnailer_server.lua"
810
],
11+
12+
"version_file" : "version.txt",
13+
"version_template_file" : "src/version.tmpl.lua",
14+
915
"header_prefix" : "--[ ",
1016
"header_suffix" : " ]--"
1117
}

docs/mpv_thumbnail_script.jpg

201 KB
Loading

src/license_blurb.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--[[
2+
Copyright (C) 2017 AMM
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
]]--

src/options.lua

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,38 @@ local thumbnailer_options = {
66
-- The thumbnail directory
77
cache_directory = join_paths(default_cache_base, "mpv_thumbs_cache"),
88

9+
-- Automatically generate the thumbnails on video load, without a keypress
910
autogenerate = true,
1011

12+
-- Only automatically thumbnail videos shorter than this (seconds)
13+
autogenerate_max_duration = 3600, -- 1 hour
14+
1115
-- Use mpv to generate thumbnail even if ffmpeg is found in PATH
16+
-- Note: mpv is a bit slower, but includes eg. subtitles in the previews!
1217
prefer_mpv = false,
1318

14-
-- Disable the built-in keybind ("T")
19+
-- Disable the built-in keybind ("T") to add your own
1520
disable_keybinds = false,
1621

17-
-- The maximum dimensions of the thumbnails
22+
-- The maximum dimensions of the thumbnails (pixels)
1823
thumbnail_width = 200,
1924
thumbnail_height = 200,
2025

21-
-- asd
26+
-- The thumbnail count target
27+
-- (This will result in a thumbnail every ~10 seconds for a 25 minute video)
2228
thumbnail_count = 150,
29+
30+
-- The above target count will be adjusted by the minimum and
31+
-- maximum time difference between thumbnails.
32+
-- The thumbnail_count will be used to calculate a target separation,
33+
-- and min/max_delta will be used to constrict it.
34+
35+
-- In other words, thumbnails will be:
36+
-- at least min_delta seconds apart (limiting the amount)
37+
-- at most max_delta seconds apart (raising the amount if needed)
2338
min_delta = 5,
24-
max_delta = 120,
39+
-- 120 seconds aka 2 minutes will add more thumbnails when the video is over 5 hours!
40+
max_delta = 90,
2541
}
2642

2743
read_options(thumbnailer_options, SCRIPT_NAME)

0 commit comments

Comments
 (0)