-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmpv-tweaks.mdx
More file actions
477 lines (331 loc) · 13.5 KB
/
Copy pathmpv-tweaks.mdx
File metadata and controls
477 lines (331 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
---
title: 配一下 mpv
date: 2023-08-08T01:48:26+08:00
image: https://raw.githubusercontent.com/mpv-player/mpv.io/426aa6b9d64d1866b93b63f1ec40cacb891a1869/source/images/mpv-logo-128.png
tags:
- mpv
- Arch Linux
- 经验分享
---
mpv 是一款 ~~神似 vim 的~~ 媒体播放器,就是说第一眼有点劝退,配置项很多,但如果能花点时间进行配置还是挺香的,而且可以写脚本实现各种功能。
<Excerpt />
自从开始用 Linux 后我一直用的是 vlc,但总感觉有点捞(,最明显的是在暂停继续 / 快进后退时,经常会卡几秒,而且不是卡住不动而是边放边卡,感觉非常神秘,不知道能不能修,反正我之前简单搜过没修好。而 mpv 默认就没有这样的问题,早就想用了,但之前被它简陋的 UI 以及复杂的配置劝退了,拖到现在才入坑。
<Card type="warn">
我是 [Arch Linux](https://archlinux.org/) + [i3](https://i3wm.org/) + [nnn](https://github.com/jarun/nnn) 用户,下面有一些配置可能不适用于其他用户。
</Card>
完整配置:[ouuan/dotfiles/.config/mpv](https://github.com/ouuan/dotfiles/tree/master/.config/mpv)
## 入坑
### 参考资料
- [mpv - ArchWiki](https://wiki.archlinux.org/title/Mpv)
- `/usr/share/doc/mpv/`
- [Reference Manual - mpv.io](https://mpv.io/manual/stable/) (`man mpv`)
- <span class="heimu">Google</span>
- <span class="heimu">ChatGPT</span>
### 配置文件
- `~/.config/mpv/mpv.conf`: 主配置文件
- `~/.config/mpv/input.conf`: key binding 配置
- `~/.config/mpv/scripts/`: 脚本,放里面就会运行
- `~/.config/mpv/script-opts/`: 脚本的配置,例如 `~/.config/mpv/script-opts/osc.conf`
- `/usr/share/mpv/scripts/`: 一些自带的脚本,可以 symlink 到 `~/.config/mpv/scripts/`
有个冷知识 (?) 可以注意一下:
> Every *flag* option has a *no-flag* counterpart, e.g. the opposite of the `--fs` option is `--no-fs`. `--fs=yes` is same as `--fs`, `--fs=no` is the same as `--no-fs`.
## 输出
其实我不是很懂这些,但这两天进行各种尝试的感觉是,~~少配点吧,默认挺好的(~~
### 输出质量
```ini
profile=gpu-hq
profile=vo-gpu-high
[vo-gpu-high]
vo=gpu
scale=ewa_lanczossharp
cscale=ewa_lanczossharp
video-sync=display-resample
interpolation=yes
tscale=oversample
[vo-gpu-low]
vo=gpu
scale=spline36
cscale=spline36
video-sync=display-resample
interpolation=no
```
参考 [High quality configurations - mpv - ArchWiki](https://wiki.archlinux.org/title/Mpv#High_quality_configurations)。
`scale` 和 `cscale` 是用于 upscale,片源分辨率低于显示器才有用,虽然 `ewa_lanczossharp` 性能开销较大,但只用于低分辨率就还好。和 `spline36` 在视觉上的差异几乎没有,性能不够就别用,性能够的话用不用都行。
interpolation 可以参考 [Interpolation · mpv Wiki](https://github.com/mpv-player/mpv/wiki/Interpolation),`tscale=oversample` 不会造成 “soap opera effect”(如果用 SVP 就可能会有)。可以找个人物动作之类的片段开 A-B loop 对比(
如果播放一些高码率视频,可能会性能不够,所以可以两个 profile 切换。
### gpu-next
```ini
[vo-gpu-next]
vo=gpu-next
scale=spline36
cscale=spline36
video-sync=audio
interpolation=no
```
这个最直接的作用是可以读取 Dolby Vision metadata,不会出现颜色错误之类的。(可以用 [4K Dolby Vision video test](https://www.demolandia.net/4k-video-test/dolby-vision/page-1.html) 测试。)
但还是不太稳定,`scale=ewa_lanczossharp` 可能会偶尔黑屏,`video-sync=display-resample` 会闪屏。
可以设个快捷键切换,需要 [`cycle-commands.lua`](https://github.com/CogentRedTester/mpv-scripts/blob/master/cycle-commands.lua)。
```
G script-message cycle-commands 'apply-profile vo-gpu-low ; show-text "vo gpu-low"' 'apply-profile vo-gpu-next ; show-text "vo gpu-next"' 'apply-profile vo-gpu-high ; show-text "vo gpu high"'
```
### 硬件解码
```ini
hwdec=auto-safe
```
`hwdec` 可以实测一下来看要不要开,之前我测的时候结果变化还挺大的,感觉主要是 CPU 连续工作一段时间性能会下降,而且不同视频效果也不同,可以设 key binding 控制开关,实时看 stats。
```
g cycle-values hwdec no auto-safe
i script-binding stats/display-stats-toggle
```
### 音量均衡
```ini
af=loudnorm
```
```
n cycle-values af "" loudnorm
```
以前听歌和看视频之间切换时经常要调音量,加上这个就好了。
## 快捷键
key binding 很看个人习惯,可以对着 `/usr/share/doc/mpv/input.conf` 修改。如果没啥习惯可以直接用默认的。
虽然感觉没太大参考价值,但是:[input.conf · ouuan/dotfiles](https://github.com/ouuan/dotfiles/blob/master/.config/mpv/input.conf)。
### 避免误触未知快捷键
```ini
no-input-default-bindings
```
这个可能会影响通过脚本设置快捷键,如果不想影响脚本可以 `no-input-builtin-bindings`。
### 右键菜单
[Thomas Carmichael / mpvcontextmenu · GitLab](https://gitlab.com/carmanaught/mpvcontextmenu)
把 `mpvcontextmenu` 文件夹放进 `scripts`。需要安装 `gjs`。
```
MBTN_RIGHT script-message mpv_context_menu_gtk
```
调整字体:
```ini
# script-opts/menu-engine.conf
fontFace=monospace
fontSize=15
```
它附带了通过 GUI 打开文件的功能:(需要安装 `kdialog` 或 `zenity`)
```ini
# script-opts/gui-dialogs.conf
dialogPref=kdialog
```
```
o script-binding add_subtitle_dialog
O script-binding add_audio_dialog
Ctrl+o script-binding add_files_dialog
Ctrl+O script-binding append_files_dialog
```
### 快进
长按 <kbd>→</kbd> 快进。
[`fast-forward.lua`](https://github.com/ouuan/dotfiles/blob/master/.config/mpv/scripts/fast-forward.lua)
```
RIGHT script-binding fast-forward
```
### ~~每根毛都看得清清楚楚~~
用鼠标放大、拖拽画面。
[`mpv-image-viewer/scripts/image-positioning.lua`](https://github.com/occivink/mpv-image-viewer/blob/master/scripts/image-positioning.lua)
```
Ctrl+WHEEL_UP script-message cursor-centric-zoom 0.1
Ctrl+WHEEL_DOWN script-message cursor-centric-zoom -0.1
Ctrl+MBTN_LEFT script-binding drag-to-pan
r script-message rotate-video 90
R script-message rotate-video -90
```
```ini
no-window-dragging # for drag-to-pan
```
### 选择 track
裸的 mpv 添加 / 选择 track 很不方便,有了 `mpvcontextmenu` 就好很多了,但我在发现它之前就自己写了两个脚本,现在有了它就把添加文件的删了,但选择 track 还是保留下来。
顺便还会在打开文件时检测当前是否是双声道,如果不是(例如是环绕声)则弹出音轨选择。
[`select-track.lua`](https://github.com/ouuan/dotfiles/blob/master/.config/mpv/scripts/select-track.lua)
```
t script-binding select-subtitle
T script-binding select-audio
Ctrl+t script-binding select-video
```
### 重置设置
我这里只重置了会被我的 key binding 修改的设置。
```
Ctrl+0 apply-profile reset-all ; show-text 已重置所有设置
```
```ini
[reset-all]
profile-desc="重置所有设置"
volume=100
mute=no
speed=1
brightness=0
video-zoom=0
video-pan-x=0
video-pan-y=0
video-rotate=0
sub-visibility=yes
sub-scale=1
sub-pos=100
audio-delay=0
ab-loop-a=no
ab-loop-b=no
```
## 听歌
### 播放列表管理
[jonniek/mpv-playlistmanager: Mpv lua script to create and manage playlists](https://github.com/jonniek/mpv-playlistmanager)
```
P script-binding showplaylist
```
```ini
key_moveup=k UP
key_movedown=j DOWN
key_movepageup=Ctrl+u PGUP
key_movepagedown=Ctrl+d PGDWN
key_movebegin=^ 0 HOME
key_moveend=$ END
key_selectfile=d-d
key_unselectfile=p
key_playfile=l ENTER
key_removefile=x BS
key_closeplaylist=ESC P h
showamount=20
text_padding_y=15
curtain_opacity=0.3
style_ass_tags={\fs11}
slice_longfilenames=yes
slice_longfilenames_amount=120
```
~~其他都还好,这个 `dd` / `p` 确实太 Vim 了(~~
### 播放模式
我是觉得下面这几种播放模式比较常用(列表循环不太常用),而看视频时一般播完暂停比较好,作为默认。随机播放/单曲循环的时候一般不需要保存播放进度。
```ini
profile=playmode-pause
[playmode-pause]
profile-desc="播完暂停"
keep-open=always
loop-file=no
loop-playlist=inf
shuffle=no
save-position-on-quit
[playmode-shuffle]
profile-desc="随机播放"
keep-open=yes
loop-file=no
loop-playlist=inf
shuffle
no-save-position-on-quit
[playmode-loopfile]
profile-desc="单文件循环"
keep-open=yes
loop-file=inf
loop-playlist=inf
shuffle=no
no-save-position-on-quit
[playmode-playall]
profile-desc="顺序播放"
keep-open=yes
loop-file=no
loop-playlist=no
shuffle=no
save-position-on-quit
```
另外可以加一个 `no-keep-open-pause`,播完暂停时后退不会暂停。
快捷键切换:
```
p script-message cycle-commands "apply-profile playmode-shuffle ; playlist-shuffle ; show-text 随机播放" "apply-profile playmode-loopfile ; playlist-unshuffle ; show-text 单曲循环" "apply-profile playmode-playall ; playlist-unshuffle ; show-text 顺序播放" "apply-profile playmode-pause ; playlist-unshuffle ; show-text 播完暂停"
```
### playerctl
装了 [mpv-mpris](https://github.com/hoyon/mpv-mpris) 就可以用 [`playerctl`](https://github.com/altdesktop/playerctl) 了。
关闭所有 mpv:(当然 `killall` 也行就是比较暴力)
```bash
alias stopplay='playerctl -a -p mpv stop'
```
用 i3 的话,可以利用 playerctl 设快捷键,用 [`bumblebee-status` 的 `playerctl` module](https://bumblebee-status.readthedocs.io/en/main/modules.html#playerctl) 显示正在播放的媒体信息。
### 从命令行播放音乐
我一般都是用若干 alias 来从命令行播放音乐(所以很少在网易云上听(
```bash
play() {
stopplay >/dev/null 2>&1
bk mpv --profile=playmode-shuffle --no-video --no-resume-playback "$@"
}
alias playjp='play ~/Music/日本語の歌/'
...
```
其中 `bk` 是一个我用了很多年的小 trick:
```bash
bk_noalias() {
nohup "$@" </dev/null >/dev/null 2>/dev/null &
disown
}
alias bk='bk_noalias ' # alias 末尾空格可以继续接 alias
```
## 杂项
### OSC
显示总时长而非剩余时长:
```ini
# script-opts/osc.conf
timetotal=yes
```
全屏时移动鼠标显示 OSC,非全屏时一直显示且不遮挡画面:
```ini
# script-opts/osc.conf
# it does nothing when visibility is not always
boxvideo=yes
```
```ini
# mpv.conf
[osc-not-fullscreen]
profile-cond=not fullscreen
script-opts=osc-visibility=always
[osc-fullscreen]
profile-cond=fullscreen
script-opts=osc-visibility=auto
```
### autoload
打开一个文件时自动加载同目录下的其他文件。
```bash
ln -s /usr/share/mpv/scripts/autoload.lua ~/.config/mpv/scripts/
```
(其实 playlistmanager 也可以启用这个功能,只不过官方有维护 `autoload.lua` 就用官方的吧。)
### 自动找 track
模糊匹配字幕和音轨文件:(实际上也没有多 fuzzy,只是部分匹配而已)
```ini
sub-auto=fuzzy
audio-file-auto=fuzzy
```
### OSD
```ini
osd-on-seek=msg-bar
osd-playing-msg="File: ${filename}"
osd-duration=2000
```
快进后退的时候显示一下具体位置;切换文件时显示一下文件名;显示久一点。
### 截图
```ini
screenshot-directory=~/screenshots
screenshot-template="%F - %P - %#01n"
```
截图文件名是视频文件名 + 时间戳 + 版本(有了版本可以同一个位置截多张图,进行对比)。
### 暂停图标
试过在暂停的时候显示一个图标,后来还是觉得去掉好一点,改成了 `osd-msg cycle pause`。
想要的话可以参考 [@CogentRedTester - OSD-info when video is paused](https://github.com/mpv-player/mpv/issues/8155#issuecomment-707726802)。需要注意的是这里用到了 “⏸”,而 color emoji 会显示为乱码,只能用 monochrome emoji,可以装一个 Noto Emoji Monochrome 加在 fontconfig 里。
### 在线播放
mpv 使用了 yt-dlp,可以直接播放很多视频网站的视频/直播,yt-dlp 还可以直接从浏览器获取 Cookies:
```ini
ytdl-raw-options=cookies-from-browser=firefox
```
### WakaTime
[`wakatime.lua`](https://github.com/ouuan/dotfiles/blob/master/.config/mpv/scripts/wakatime.lua)
有点逆天,但是怎么不行呢((
本来是想着写个记录播放历史,但感觉有点肝不动,然后想到了 WakaTime(
和记录代码不用同一个账号就不会污染数据了,可以建个新文件夹作为 mpv 的 `WAKATIME_HOME`。
### 拆分 `mpv.conf`
配置都写在一起感觉最大的问题在于 profile 要写最底下,导致不能把不同板块的配置完全拆开。可以用 `include` 来拆成多个配置文件。
```ini
include=~~home/conf.d/output.conf
include=~~home/conf.d/playmode.conf
include=~~home/conf.d/osc.conf
...
```
注意 `~~home/` 是 mpv home,`~/` 才是 `$HOME`。
#### directory-specific config
[`exrc.lua`](https://github.com/ouuan/dotfiles/blob/master/.config/mpv/scripts/exrc.lua)(写得比较粗糙,能用就行(
mpv 提供了 [“File-specific Configuration Files”](https://mpv.io/manual/stable/#file-specific-configuration-files) 功能,但是它不安全。受 [More secure .exrc (.nvimrc) handling · Issue #20911 · neovim/neovim](https://github.com/neovim/neovim/issues/20911) 启发,可以在加载 exrc 前询问用户。
(我是学日语的时候听教材音频,想自动切成单曲循环。)