Config mpv as a Better Player

Config mpv as a Better Player

缘由

产生这篇文章的原因是, 最近老灯从 X11 切 Wayland 了, 而 SMPlayer 又不工作了.

GNOME 官方的 Video 播放器也能凑合用. 但是老灯还是习惯 mpv 系列.

但是直接用 mpv 感觉还是不太习惯, 比如外挂字幕选择加载 mpv 貌似没有快捷键, 播放列表管理功能貌似也没有.

很快在 Github 上面找到一个神级脚本: https://github.com/darsain/uosc

还有一个堪称播放器级别的配置: https://github.com/thisisshihan/mpv-player-config-snad

mpv 配置目录

首先, 老灯机器上面甚至没有一个 mpv 的配置.

所以, 先找文档看看配置文件在哪?

在 Arch 上, mpv 系统全局配置目录在 /etc/mpv/

老灯看了下, 这个目录下面只有一个 encoding-profiles.conf文件

然后, 一般情况下, 标准的用户配置目录在 ~/.config/mpv , 当然还有一些特例, 比如:

The standard configuration directory. This can be overridden by environment variables, in ascending order:

1: If $XDG_CONFIG_HOME is set, then the derived configuration directory will be $XDG_CONFIG_HOME/mpv. 2: If $MPV_HOME is set, then the derived configuration directory will be $MPV_HOME.

If this directory, nor the original configuration directory (see below) do not exist, mpv tries to create this directory automatically.

主要用户配置文件: ~/.config/mpv/mpv.conf

主要的 key bindings 配置: ~/.config/mpv/input.conf

字体配置: ~/.config/mpv/fonts.conf

Fontconfig fonts.conf that is customized for mpv. You should include system fonts.conf in this file or mpv would not know about fonts that you already have in the system.

Only available when libass is built with fontconfig.

字体目录: ~/.config/mpv/fonts/

Font files in this directory are used by mpv/libass for subtitles. Useful if you do not want to install fonts to your system. Note that files in this directory are loaded into memory before being used by mpv. If you have a lot of fonts, consider using fonts.conf (see above) to include additional fonts, which is more memory-efficient.

脚本目录: ~/.config/mpv/scripts/

osc配置: ~/.config/mpv/script-opts/osc.conf

This is loaded by the OSC script. See the ON SCREEN CONTROLLER docs for details.

Other files in this directory are specific to the corresponding scripts as well, and the mpv core doesn't touch them.

uosc 安装

安装后的目录结构:

  ~/.config/mpv 
❯ tree
.
├── input.conf
├── mpv.conf
├── script-opts
│   └── uosc.conf
└── scripts
    └── uosc.lua

2 directories, 4 files

uosc is a replacement for the built in osc, so that has to be disabled first.

由于 uosc 实际上是内置 osc 功能的替代品, 因此内置的必须先禁用掉:

编辑 ~/.config/mpv/mpv.conf 加上:

# required so that the 2 UIs don't fight each other
osc=no
# uosc provides its own seeking/volume indicators, so you also don't need this
osd-bar=no
# uosc will draw its own window controls if you disable window border
border=no

下载脚本和脚本配置

curl -sSf --create-dirs -o $HOME/.config/mpv/scripts/uosc.lua \
https://raw.githubusercontent.com/darsain/uosc/master/uosc.lua

curl -sSf --create-dirs -o $HOME/.config/mpv/script-opts/uosc.conf \
https://raw.githubusercontent.com/darsain/uosc/master/uosc.conf

Keybindings 配置

编辑 ~/.config/mpv/input.conf 加上:

menu        script-binding uosc/menu
mbtn_right  script-binding uosc/menu
o           script-binding uosc/open-file          #! Open file
alt+s       script-binding uosc/load-subtitles     #! Load subtitles
S           script-binding uosc/subtitles          #! Select subtitles
A           script-binding uosc/audio              #! Select audio
ctrl+s      async screenshot                       #! Utils > Screenshot
P           script-binding uosc/playlist           #! Utils > Playlist
C           script-binding uosc/chapters           #! Utils > Chapters
#           script-binding uosc/open-config-directory #! Utils > Open config directory
#           set video-aspect-override "-1"         #! Aspect ratio > Default
#           set video-aspect-override "16:9"       #! Aspect ratio > 16:9
#           set video-aspect-override "4:3"        #! Aspect ratio > 4:3
#           set video-aspect-override "2.35:1"     #! Aspect ratio > 2.35:1
O           script-binding uosc/show-in-directory  #! Show in directory
esc         quit #! Quit
q           quit #!

这个键绑定老灯稍做了修改:

主要改动为:

ctrl+o      script-binding uosc/open-file          #! Open file
alt+o       script-binding uosc/show-in-directory  #! Show in directory

打开文件这两个操作老灯认为没有显示 osd 频繁, 因此 o 留给 osd toggle.

效果展示

选择视频文件打开:

内置字幕选择(支持方向键 和 vim hjkl 或 游戏党的 wasd):

utils 功能:

播放列表功能 (相应的快捷键见 input.conf ):

其它 mpv 内置快捷键

F8 Show the playlist and the current position in it (useful only if a UI window is used, broken on the terminal).

F9 Show the list of audio and subtitle streams (useful only if a UI window is used, broken on the terminal).

i and I Show/toggle an overlay displaying statistics about the currently playing file such as codec, framerate, number of dropped frames and so on. See STATS for more information.

del Cycle OSC visibility between never / auto (mouse-move) / always

` Show the console. (ESC closes it again. See CONSOLE.)

o (also P) Show progression bar, elapsed time and total duration on the OSD.

O Toggle OSD states between normal and playback time/duration.

v Toggle subtitle visibility.

j and J Cycle through the available subtitles.

z and Z Adjust subtitle delay by +/- 0.1 seconds. The x key does the same as Z currently, but use is discouraged.

9 and 0 Decrease/increase volume.

m Mute sound.

_ Cycle through the available video tracks.

#

Cycle through the available audio tracks.

f Toggle fullscreen (see also --fs).

ESC Exit fullscreen mode.

T Toggle stay-on-top (see also --ontop).

最后, 老灯折腾完的配置在这: https://github.com/ttys3/my-mpv-config

Refs

https://github.com/darsain/uosc

https://mpv.io/manual/master/#files

https://mpv.io/manual/master/#configuration-files

https://mpv.io/manual/master/#input-conf

https://github.com/mpv-player/mpv/blob/master/etc/input.conf

https://iamscum.wordpress.com/guides/videoplayback-guide/mpv-conf/

https://github.com/thisisshihan/mpv-player-config-snad

其它资源:

资源获取:

https://github.com/mpv-player/mpv/wiki/User-Scripts

https://github.com/topics/mpv-script?o=desc&s=stars

https://github.com/topics/mpv-config

老灯看到觉得不错的:

windows https://github.com/422658476/MPV-EASY-Player

windows https://github.com/hooke007/MPV_lazy

https://github.com/jonniek/mpv-playlistmanager

https://github.com/CogentRedTester/mpv-file-browser

https://github.com/maoiscat/mpv-osc-morden

https://github.com/hl2guide/better-mpv-config/blob/master/mpv.conf