Skip to content

Commit cd3757d

Browse files
committed
✨ auto scale
1 parent 64a7d08 commit cd3757d

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/badapple/play.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ def play(
5656
open(video, 'rb').close()
5757
p = get_player(audio, player, video)
5858

59-
x = int(x)
60-
y = int(y)
61-
y += y & 1
62-
6359
capture = cv2.VideoCapture(video)
6460
width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
6561
width = int(width + 0.5)
@@ -73,9 +69,29 @@ def play(
7369
mo = max(int(0.5 + rate / fps), 1)
7470
clk = mo / rate
7571

72+
max_x, max_y = os.get_terminal_size()
73+
max_y = (max_y-1)*2
74+
75+
x = int(x)
76+
y = int(y)
77+
78+
if x > 0:
79+
if y == 0:
80+
y = int(height*x/width+0.5)
81+
else:
82+
if y == 0:
83+
x = min(max_x, int(width*max_y/height+0.5))
84+
y = min(max_y, int(height*max_x/width+0.5))
85+
86+
if y % 2:
87+
if y == max_y+1:
88+
y -= 1
89+
else:
90+
y += 1
91+
7692
print('[%d:%d %.2lfHz] -> [%d:%d %.2lfHz] %.3lfs' %
7793
(width, height, rate, x, y, rate / mo, duration), flush=True)
78-
# [1444:1080 29.97Hz] -> [76:54 9.99Hz] 232.065s
94+
# [1444:1080 29.97Hz] -> [72:54 9.99Hz] 232.065s
7995

8096
rewind, clear, console_size = get_func(need_clear)
8197
fnt = Font(font)
@@ -112,7 +128,7 @@ def play(
112128
rewind()
113129
clear()
114130
if not debug:
115-
console_size(x, y//2+1)
131+
# console_size(x, y//2+1)
116132
rewind()
117133
clear()
118134
timer.bg()

0 commit comments

Comments
 (0)