The methods described in this post are not available in other Plex clients apart from “Plex for Windows/Mac/Linux” and “Plex HTPC”
in this post:
- Pausing and stepping through a video, frame by frame
- Video zoom/crop
- Fine tune vertical position of subtitles
The internal AV engine in these players (called ‘MPV’) supports a lot of features which are not available in the Plex user interface.
Some of these features can be used, nonetheless by “circumventing” the Plex user interface and assigning keyboard buttons (or remote control buttons) to them.
The caveat is this: not all features can be accessed by this method. Some settings are pre-defined by the Plex player.
Some other features are only sensibly usable if the playback mode in Plex is “Direct Play”. (example: selecting audio tracks or subtitle tracks. On top of that, a track selection made in this way is not stored on the Plex server.)
Despite of the caveats, there are still some use cases which might be welcomed by some users. Here are those which have been figured out so far.
The contents of this article are largely based on the work of @German and @o_spring . A huge Thank You! to these users who shared their efforts in the forum here and here.
There are two methods:
- customized input maps (only available in Plex HTPC)
- custom player scripts in Lua (usable in both Plex for Windows/Mac/Linux and Plex HTPC)
The use of inputmaps is explained in this help article: https://support.plex.tv/articles/plex-htpc-input-maps/
The example keyboard.json
inputmap contains already a lot of useful examples on how to define buttons and key combinations. It is also important to know which buttons have already been assigned.
inputmaps are slightly easier to use.
They also enable you to use other non-keyboard input devices like remote controls or game controllers.
The use of Lua scripts only differs slightly.
They go into a subfolder named scripts
, which itself must be created in the main configuration folder of the Plex player. Start with the folder locations mentioned in here: https://support.plex.tv/articles/plex-htpc-input-maps/, but go upwards one or two levels – until you can see a file named mpv.conf.md
. This means you are in the right place.
The scripts
folder will be sitting next to the cache
, inputmaps
, and Logs
folders.
You create the scripts in a text-only editor (like e.g. notepad.exe
in Windows). Do not use a regular word processor like MS Word or the like. If your editor only writes .txt files, simply rename the file afterwards and swap the .txt
file name extension with .lua
.
The only difference between Plex HTPC and the Plex desktop app is that the main folder is named Plex
instead of Plex HTPC
(at least on Mac and Windows).
I haven’t figured out if non-keyboard devices can be used with the lua script method.
Here is how the folders look like on Windows
Plex HTPC:
Plex Desktop:
I’ve broken down all keycombos pertaining to one feature into a separate .lua
file.
You can put only one or several of these lua scripts at once in the scripts
folder – depending on which functionality you want to use.
Pausing and stepping through a video, frame by frame
The keys which are assigned are .
and ,
for stepping forth and back.
(Resuming normal playback may require pressing space
twice.)
inputmap method:
// single frame back and forth
"\\." : "mpv:frame-step",
"," : "mpv:frame-back-step",
the
.
requires “escaping” with double backslashes, because these inputmaps are parsed as regular expressions. The dot matches to anything in regex.
lua script method:
(suggested file name: stepping-keybinds.lua
)
function stepFwd()
mp.command("frame-step")
mp.osd_message("frame +1", 0.5)
end
function stepBack()
mp.command("frame-back-step")
mp.osd_message("frame -1", 0.5)
end
mp.add_forced_key_binding(".", "stepFwd", stepFwd)
mp.add_forced_key_binding(",", "stepBack", stepBack)
Video zoom/crop
inputmap method:
CTRL
++
zoom in
CTRL
+-
zoom out
CTRL
+*
cycle through default and 3 pre-defined zoom factors
CTRL
+0
reset zoom to default
//zoom controls
"Ctrl\\+\\+" : "mpv:add video-zoom 0.05",
"Ctrl\\+\\-" : "mpv:add video-zoom -0.05",
"Ctrl\\+\\*" : "mpv:cycle-values video-zoom 0 0.0574502 0.4025857 0.4269356",
"Ctrl\\+0" : "mpv:set video-zoom 0",
lua script method:
in its current state this uses different keys than the inputmap above.
please comment below if you have figured out how to use keyboard combos instead or how to implement the cycling through predefined zoom factors.
+
zoom in
-
zoom out
0
reset zoom to default
suggested file name: zoom-keybinds.lua
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function zoomAdd()
mp.command("add video-zoom +0.05")
zoom_level = mp.get_property("video-zoom")
zoom_level = round(zoom_level, 2)
mp.osd_message("Zoom: "..zoom_level, 0.5)
end
function zoomSub()
mp.command("add video-zoom -0.05")
zoom_level = mp.get_property("video-zoom")
zoom_level = round(zoom_level, 2)
mp.osd_message("Zoom: "..zoom_level, 0.5)
end
function zoomReset()
mp.command("set video-zoom 0")
mp.osd_message("Zoom reset")
end
mp.add_forced_key_binding("+", "zoomAdd", zoomAdd)
mp.add_forced_key_binding("-", "zoomSub", zoomSub)
mp.add_forced_key_binding("0", "zoomReset", zoomReset)
Fine tune vertical position of subtitles
Trying to mimic the default keycombo of the MPV standalone player, by using
r
subtitles up
R
subtitles down
inputmap method:
// refine subtitle position
"Shift\\+R" : "mpv:add sub-pos +1",
"R" : "mpv:add sub-pos -1",
lua script method:
suggested file name: subpos-keybinds.lua
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function subDown()
mp.command("add sub-pos +1")
sub_pos = mp.get_property("sub-pos")
sub_pos = round(sub_pos, 2)
mp.osd_message("subtitle position: "..sub_pos, 0.5)
end
function subUp()
mp.command("add sub-pos -1")
sub_pos = mp.get_property("sub-pos")
sub_pos = round(sub_pos, 2)
mp.osd_message("subtitle position: "..sub_pos, 0.5)
end
mp.add_forced_key_binding("R", "subDown", subDown)
mp.add_forced_key_binding("r", "subUp", subUp)
The mpv commands called by these keybindings are largely documented in here: mpv.io
Related information on customizations:
Here is another use for keybindings: An on-demand audio dynamics compressor for PMP and Plex HTPC
How to customize the appearance of subtitles in these players: Customizing Subtitle appearance in Plex Player for Windows/Mac/Linux and Plex HTPC and PMP
edit history:
2023-02-08 initial post
2023-02-09 subtitle position key assignments were swapped in the lua script
2023-04-05 corrected key assignment from _ to - in Zoom lua script