forked from sharky5102/fbmatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbmplay.py
executable file
·67 lines (49 loc) · 1.99 KB
/
fbmplay.py
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
#!/usr/bin/env python3
import fbmatrix
import argparse
import time
import assembly.yuv420
from ffpyplayer.player import MediaPlayer
import numpy as np
from pyrr import Matrix44
def render():
global bytearray, player
global args
videoAspect = screenAspect = args.columns/args.rows
frame, val = player.get_frame()
if frame:
img, t = frame
data = img.to_bytearray()
size = img.get_size()
videoAspect = size[0]/size[1]
bytearray.setYUV420(data, size[0], size[1])
time.sleep(val)
M = np.eye(4, dtype=np.float32)
if not args.stretch:
if args.fit:
if screenAspect > videoAspect:
# Pillar box
M = M * Matrix44.from_scale( (1, screenAspect/videoAspect, 1, 1))
else:
# Letter box
M = M * Matrix44.from_scale( (videoAspect/screenAspect, 1, 1))
else:
if screenAspect > videoAspect:
# Pillar box
M = M * Matrix44.from_scale( (videoAspect/screenAspect, 1, 1))
else:
# Letter box
M = M * Matrix44.from_scale( (1, screenAspect/videoAspect, 1))
bytearray.setProjection(M)
bytearray.render()
import common
parser = argparse.ArgumentParser(description='Framebuffer RGB matrix player')
common.add_args(parser)
parser.add_argument('--fit', action='store_true', help='Fit the video as large as it can but maintaining aspect ratio. This means some part will be cut off')
parser.add_argument('--stretch', action='store_true', help='Stretch the video to fit the screen exactly, which means aspect ratio will not be preserved. I really hate it when people do this.')
parser.add_argument('videofile', help='Video to play')
args = parser.parse_args()
player = MediaPlayer(args.videofile, ff_opts={'out_fmt':'yuv420p'})
matrix = common.renderer_from_args(args)
bytearray = assembly.yuv420.bytearray(supersample = args.supersample)
matrix.run(render)