-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathauto_scaling.lua
178 lines (155 loc) · 6.37 KB
/
auto_scaling.lua
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
--[[
Disable video scaling if video is slightly smaller than window size.
For example, your monitor is 1920x1080, the video is 1920x816 (2.35:1 aspect ratio), scaling is disabled.
The "window-scale" will be set to 1 and "border" set to "no" if the video is within range,
this is to simplify how the script functions.
Edit the script settings at line ~35.
https://github.com/kevinlekiller/mpv_scripts
--]]
--[[
Copyright (C) 2016-2017 kevinlekiller
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
https://www.gnu.org/licenses/gpl-2.0.html
--]]
-----------------------------------------------------------------------------------------------------------------------------------
------------------------------------------- Start of user settings ----------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------
local settings = {
-- Width of your monitor's resolution in pixels.
width = 1920,
-- Height of your monitor's resolution in pixels.
height = 1080,
-- How much smaller can a video be to the window size before enabling scaling?
-- For example, the video is 1860x1020, window size is 1920x1080, 1920*0.93=1786, 1080*0.93=1004,
-- the video is larger than 1786x1004 so scaling is turned off.
deviation = 0.93,
osd = {
-- Enable OSD?
enabled = false,
-- How much time in seconds will the OSD message be on screen.
time = 5,
-- Keyboard key to print OSD message.
key = ";"
},
-- Add debug to OSD messages?
debug = false
}
-----------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------- End of user settings -----------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------
local global = {
scale = nil,
osd = {
start = mp.get_property_osd("osd-ass-cc/0"),
stop = mp.get_property_osd("osd-ass-cc/1")
},
debug = ""
}
function main()
global.debug = ""
global.scale = check_scaling()
if (global.scale ~= nil) then
if (global.scale == "yes") then
mp.set_property("border", "no")
mp.set_property("window-scale", 1)
end
mp.set_property("video-unscaled", global.scale)
end
end
function osd()
if (settings.osd.enabled == true and global.scale ~= nil) then
local string = global.osd.start .. "{\\b1}Scaling disabled:{\\b0}\\h" .. global.scale .. "\\N"
if (settings.debug == true) then
string = string .. "{\\b1}Debug:{\\b0}\\h" .. global.debug .. "\\N"
end
mp.osd_message(string .. global.osd.stop, settings.osd.time);
end
end
if (settings.osd.enabled == true) then
mp.add_key_binding(settings.osd.key, "auto-scaling_osd", osd, {repeatable=true})
end
function check_scaling()
-- Get video dimensions.
local video = {
width = mp.get_property("video-out-params/dw"),
height = mp.get_property("video-out-params/dh")
}
-- Get window size.
local window = {
width = tonumber(settings.width),
height = tonumber(settings.height),
}
local error = "nil property unavailable"
if (video.width == error or video.height == error) then
global.debug = "Unable to get video dimensions."
return nil
end
video.width = tonumber(video.width)
video.height = tonumber(video.height)
if (window.width == nil or video.width == nil) then
global.debug = "Unable to get video or window dimensions."
return nil
end
-- Minimum acceptable values.
local min = {
width = (window.width * settings.deviation),
height = (window.height * settings.deviation)
}
if (settings.debug == true) then
global.debug = "Video (" .. video.width .. "x" .. video.height .. ") is "
end
-- Video is bigger than monitor.
if (video.width > window.width or video.height > window.height) then
if (settings.debug == true) then
global.debug = (
global.debug .. "larger than window size (" ..
window.width .. "x" .. window.height .."), enable scaling."
)
end
return "no"
end
-- Video width is within acceptable range.
if (video.width >= min.width) then
if (settings.debug == true) then
global.debug = (
global.debug .. "within acceptable width range of (" ..
min.width .. " - " .. window.width .. "), disable scaling."
)
end
return "yes"
end
-- Video height is within acceptable range.
if (video.height >= min.height) then
if (settings.debug == true) then
global.debug = (
global.debug .. "within acceptable height range of (" ..
min.height .. " - " .. window.height .. "), disable scaling."
)
end
return "yes"
end
-- Video height and width are under acceptable range. Enable scaling.
if (settings.debug == true) then
global.debug = (
global.debug ..
"under acceptable range of thresholds (" .. min.width ..
"x" .. min.height .. ") and window size (" ..
window.width .. "x" .. window.height .. "), enable scaling."
)
end
return "no"
end
mp.register_event("file-loaded", main)
mp.register_event("video-reconfig", main)
mp.observe_property("window-scale", "native", main)
mp.observe_property("fullscreen", "native", main)