|
@@ -71,7 +71,7 @@ parser.add_option("", "--title", dest="title",default="SCREEN",
|
|
|
|
|
|
|
|
|
|
|
|
|
import numpy
|
|
import numpy
|
|
|
-
|
|
|
|
|
|
|
+QUIT = 0
|
|
|
|
|
|
|
|
for o in dir(options):
|
|
for o in dir(options):
|
|
|
if "_" in o:
|
|
if "_" in o:
|
|
@@ -184,6 +184,110 @@ def _cam_cfg_new(fn):
|
|
|
f.write("\n".join(txt))
|
|
f.write("\n".join(txt))
|
|
|
f.close()
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+def VideoMeta():
|
|
|
|
|
+ out = {}
|
|
|
|
|
+ out["run"] = 1
|
|
|
|
|
+ out["x"] = 0
|
|
|
|
|
+ out["y"] = 0
|
|
|
|
|
+ out["ang"] = 0
|
|
|
|
|
+ out["scale"] = 0
|
|
|
|
|
+ out["fname"] = "xxx.mp4"
|
|
|
|
|
+ out["fpath"] = "xxx.mp4"
|
|
|
|
|
+
|
|
|
|
|
+class VideoPlayer(): # concept / mokup
|
|
|
|
|
+ def __init__():
|
|
|
|
|
+ self.data = VideoMeta()
|
|
|
|
|
+ def play(self):
|
|
|
|
|
+ pass
|
|
|
|
|
+ def pause(self):
|
|
|
|
|
+ pass
|
|
|
|
|
+ def reset(self):
|
|
|
|
|
+ pass
|
|
|
|
|
+ def select(self):
|
|
|
|
|
+ pass
|
|
|
|
|
+ def draw(self):
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+def _rescale_frame_by_width(frame, width):
|
|
|
|
|
+ #print(type(frame)) #np array
|
|
|
|
|
+ height = int(frame.shape[0]/frame.shape[1] * width )
|
|
|
|
|
+ dim = (width, height)
|
|
|
|
|
+ #return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
|
|
|
|
|
+ return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
|
|
|
|
|
+
|
|
|
|
|
+def _rescale_frame_by_procent(frame, percent=75):
|
|
|
|
|
+ #print(type(frame))
|
|
|
|
|
+ width = int(frame.shape[1] * percent/ 100)
|
|
|
|
|
+ height = int(frame.shape[0] * percent/ 100)
|
|
|
|
|
+ dim = (width, height)
|
|
|
|
|
+ return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
|
|
|
|
|
+
|
|
|
|
|
+def _moveImage(img,x=0,y=0,shape=None):
|
|
|
|
|
+ #print(type(img)) #np.array
|
|
|
|
|
+ # Creating a translation matrix
|
|
|
|
|
+ np = numpy
|
|
|
|
|
+ translation_matrix = np.float32([ [1,0,x], [0,1,y] ])
|
|
|
|
|
+
|
|
|
|
|
+ if shape is None:
|
|
|
|
|
+ num_cols,num_rows = img.shape[1::-1]
|
|
|
|
|
+ else:
|
|
|
|
|
+ num_cols,num_rows = shape #[1::-1]
|
|
|
|
|
+ # Image translation
|
|
|
|
|
+ frame = cv2.warpAffine(img, translation_matrix, (num_cols,num_rows))
|
|
|
|
|
+ return frame
|
|
|
|
|
+
|
|
|
|
|
+def _rotateImage(image, angle):
|
|
|
|
|
+ #print(type(image)) # nm.array
|
|
|
|
|
+ if angle in [0,360]:
|
|
|
|
|
+ pass#return image
|
|
|
|
|
+ try:
|
|
|
|
|
+ #print("EE",image.shape)
|
|
|
|
|
+ #print("EE",dir(image))
|
|
|
|
|
+ shape = list(image.shape[1::-1])
|
|
|
|
|
+ bg_shape = shape[:]
|
|
|
|
|
+
|
|
|
|
|
+ delta_x = 0 # + nach rechts
|
|
|
|
|
+ delta_y = 0 # + nach unten
|
|
|
|
|
+ r = []
|
|
|
|
|
+ r.extend(list(range(0-3,0+3)))
|
|
|
|
|
+ r.extend(list(range(180-3,180+3)))
|
|
|
|
|
+ r.extend(list(range(360-3,360+3)))
|
|
|
|
|
+
|
|
|
|
|
+ r2 = []
|
|
|
|
|
+ r2.extend(list(range(90-3,90+3)))
|
|
|
|
|
+ r2.extend(list(range(270-3,270+3)))
|
|
|
|
|
+ if angle in r:
|
|
|
|
|
+ pass
|
|
|
|
|
+ elif 0:#angle in r2:
|
|
|
|
|
+ bg_shape = bg_shape[::-1]
|
|
|
|
|
+ delta_y = -65 #shape[1]/2 # # + nach unten
|
|
|
|
|
+ delta_x = 30 #shape[1]/2 # # + nach unten
|
|
|
|
|
+
|
|
|
|
|
+ delta_y -= bg_shape[1]/2 - 20
|
|
|
|
|
+ delta_x = bg_shape[0]/2 - 10
|
|
|
|
|
+
|
|
|
|
|
+ pass
|
|
|
|
|
+ else:
|
|
|
|
|
+ if shape[0] > shape[1]:
|
|
|
|
|
+ # landscape video
|
|
|
|
|
+ bg_shape = (shape[0],shape[0])
|
|
|
|
|
+ delta_y = (shape[0]-shape[1])/2
|
|
|
|
|
+ else:
|
|
|
|
|
+ # portrait video
|
|
|
|
|
+ bg_shape = (shape[1],shape[1])
|
|
|
|
|
+ delta_x = (shape[1]-shape[0])/2
|
|
|
|
|
+
|
|
|
|
|
+ center = (shape[0]/2+delta_x,shape[1]/2+delta_y)
|
|
|
|
|
+ image = _moveImage(image,x=delta_x,y=delta_y,shape=bg_shape)
|
|
|
|
|
+
|
|
|
|
|
+ bg_shape = tuple(bg_shape) # exception ... if angle 0 no tuple !!!
|
|
|
|
|
+ rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
|
|
|
|
|
+ frame = cv2.warpAffine(image, rot_mat, bg_shape ) #,flags=cv2.INTER_LINEAR)
|
|
|
|
|
+ return frame
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ raise(e)
|
|
|
|
|
+
|
|
|
def _cam_cfg():
|
|
def _cam_cfg():
|
|
|
fn = HOME+'/LibreLight/video_in.txt'
|
|
fn = HOME+'/LibreLight/video_in.txt'
|
|
|
if not os.path.isfile(fn):
|
|
if not os.path.isfile(fn):
|
|
@@ -209,6 +313,58 @@ def _cam_cfg():
|
|
|
|
|
|
|
|
return cfg
|
|
return cfg
|
|
|
|
|
|
|
|
|
|
+def _open_cam(obj):
|
|
|
|
|
+ # LIVE VIDEO INPUT UVC DEVICE
|
|
|
|
|
+ cfg = _cam_cfg()
|
|
|
|
|
+ print("III",cfg)
|
|
|
|
|
+
|
|
|
|
|
+ res = "HD"
|
|
|
|
|
+ #res = "4K"
|
|
|
|
|
+ #res = ""
|
|
|
|
|
+
|
|
|
|
|
+ if res == "HD":
|
|
|
|
|
+ # HD
|
|
|
|
|
+ w = 1920
|
|
|
|
|
+ h = 1080
|
|
|
|
|
+ elif res == "4K":
|
|
|
|
|
+ # 4K
|
|
|
|
|
+ w = 3840
|
|
|
|
|
+ h = 2160
|
|
|
|
|
+ else:
|
|
|
|
|
+
|
|
|
|
|
+ # LOW
|
|
|
|
|
+ w = 1280
|
|
|
|
|
+ h = 720
|
|
|
|
|
+ d = 0 # VIDEO INPUT DEV
|
|
|
|
|
+
|
|
|
|
|
+ for c in cfg:
|
|
|
|
|
+ try:
|
|
|
|
|
+ if c.startswith("d"):
|
|
|
|
|
+ d = int(c[1:])
|
|
|
|
|
+ if c.startswith("h"):
|
|
|
|
|
+ h = int(c[1:])
|
|
|
|
|
+ if c.startswith("w"):
|
|
|
|
|
+ w = int(c[1:])
|
|
|
|
|
+ if c.startswith("video"):
|
|
|
|
|
+ d = int(c[-1])
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ cprint("Exception", "cam_cfg 878",e,color="red")
|
|
|
|
|
+
|
|
|
|
|
+ df = "video{}".format(d)
|
|
|
|
|
+ if obj._stop:
|
|
|
|
|
+ df += "_stop"
|
|
|
|
|
+ elif os.path.exists("/dev/{}".format(df)):
|
|
|
|
|
+ obj.Rcap = cv2.VideoCapture(d)
|
|
|
|
|
+ obj.Rcap.set(cv2.CAP_PROP_FRAME_WIDTH, w)
|
|
|
|
|
+ obj.Rcap.set(cv2.CAP_PROP_FRAME_HEIGHT, h)
|
|
|
|
|
+ else:
|
|
|
|
|
+ #obj.Rcap = None
|
|
|
|
|
+ #obj.end = 1
|
|
|
|
|
+ df += "_error"
|
|
|
|
|
+
|
|
|
|
|
+ if obj.fname.startswith("cam_"):
|
|
|
|
|
+ obj.fname = "cam_{}".format(df)
|
|
|
|
|
+
|
|
|
class PixelMedia():
|
|
class PixelMedia():
|
|
|
|
|
|
|
|
def __init__(self,dmx=None,_id=None):
|
|
def __init__(self,dmx=None,_id=None):
|
|
@@ -291,62 +447,7 @@ class PixelMedia():
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
cprint("PixelMedia.select_video()",dmx_value,e,color="red")
|
|
cprint("PixelMedia.select_video()",dmx_value,e,color="red")
|
|
|
|
|
|
|
|
- def close_cap():
|
|
|
|
|
- print(dir(self.Rcap)) # = cv2.VideoCapture(self.fpath+self.fname)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- def _open_cam(self):
|
|
|
|
|
- # LIVE VIDEO INPUT UVC DEVICE
|
|
|
|
|
- cfg = _cam_cfg()
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- res = "HD"
|
|
|
|
|
- #res = "4K"
|
|
|
|
|
- #res = ""
|
|
|
|
|
-
|
|
|
|
|
- if res == "HD":
|
|
|
|
|
- # HD
|
|
|
|
|
- w = 1920
|
|
|
|
|
- h = 1080
|
|
|
|
|
- elif res == "4K":
|
|
|
|
|
- # 4K
|
|
|
|
|
- w = 3840
|
|
|
|
|
- h = 2160
|
|
|
|
|
- else:
|
|
|
|
|
-
|
|
|
|
|
- # LOW
|
|
|
|
|
- w = 1280
|
|
|
|
|
- h = 720
|
|
|
|
|
- d = 0 # VIDEO INPUT DEV
|
|
|
|
|
-
|
|
|
|
|
- for c in cfg:
|
|
|
|
|
- try:
|
|
|
|
|
- if c.startswith("d"):
|
|
|
|
|
- d = int(c[1:])
|
|
|
|
|
- if c.startswith("h"):
|
|
|
|
|
- h = int(c[1:])
|
|
|
|
|
- if c.startswith("w"):
|
|
|
|
|
- w = int(c[1:])
|
|
|
|
|
- if c.startswith("video"):
|
|
|
|
|
- d = int(c[-1])
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- cprint("Exception", "cam_cfg 878",e,color="red")
|
|
|
|
|
-
|
|
|
|
|
- df = "video{}".format(d)
|
|
|
|
|
- if self._stop:
|
|
|
|
|
- df += "_stop"
|
|
|
|
|
- elif os.path.exists("/dev/{}".format(df)):
|
|
|
|
|
- self.Rcap = cv2.VideoCapture(d)
|
|
|
|
|
- self.Rcap.set(cv2.CAP_PROP_FRAME_WIDTH, w)
|
|
|
|
|
- self.Rcap.set(cv2.CAP_PROP_FRAME_HEIGHT, h)
|
|
|
|
|
- else:
|
|
|
|
|
- #self.Rcap = None
|
|
|
|
|
- #self.end = 1
|
|
|
|
|
- df += "_error"
|
|
|
|
|
|
|
|
|
|
- if self.fname.startswith("cam_"):
|
|
|
|
|
- self.fname = "cam_{}".format(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _init(self):
|
|
def _init(self):
|
|
@@ -355,7 +456,7 @@ class PixelMedia():
|
|
|
|
|
|
|
|
if not os.path.isfile(self.fpath+self.fname):
|
|
if not os.path.isfile(self.fpath+self.fname):
|
|
|
print()
|
|
print()
|
|
|
- print("video file does not exits !! >",self.fpath,self.fname)
|
|
|
|
|
|
|
+ cprint("video file does not exits !! >",self.fpath,self.fname,color="red")
|
|
|
print()
|
|
print()
|
|
|
#exit()
|
|
#exit()
|
|
|
|
|
|
|
@@ -371,12 +472,13 @@ class PixelMedia():
|
|
|
self.img_meta = create_img_meta()
|
|
self.img_meta = create_img_meta()
|
|
|
self.img_meta["_fpath"] = self.fpath
|
|
self.img_meta["_fpath"] = self.fpath
|
|
|
self.img_meta["fname"] = self.fname
|
|
self.img_meta["fname"] = self.fname
|
|
|
|
|
+
|
|
|
img_open(self.img_meta)
|
|
img_open(self.img_meta)
|
|
|
- self.buffer = [1,2,3]
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ self.buffer = [1,2,3]
|
|
|
|
|
+ return # STOP
|
|
|
|
|
|
|
|
if self.fname.startswith("cam_"):
|
|
if self.fname.startswith("cam_"):
|
|
|
- self._open_cam()
|
|
|
|
|
|
|
+ _open_cam(obj=self)
|
|
|
self.img_meta = {}
|
|
self.img_meta = {}
|
|
|
else:
|
|
else:
|
|
|
self.Rcap = cv2.VideoCapture(self.fpath+self.fname, cv2.CAP_FFMPEG)
|
|
self.Rcap = cv2.VideoCapture(self.fpath+self.fname, cv2.CAP_FFMPEG)
|
|
@@ -389,7 +491,7 @@ class PixelMedia():
|
|
|
|
|
|
|
|
#self.Rfvs = FileVideoStream(self.fpath+self.fname).start()
|
|
#self.Rfvs = FileVideoStream(self.fpath+self.fname).start()
|
|
|
self.Rsuccess = 1
|
|
self.Rsuccess = 1
|
|
|
- self._read()
|
|
|
|
|
|
|
+ self.read()
|
|
|
|
|
|
|
|
def _del(self):
|
|
def _del(self):
|
|
|
if self.img_meta:
|
|
if self.img_meta:
|
|
@@ -406,7 +508,7 @@ class PixelMedia():
|
|
|
gc.collect()
|
|
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
- def _read(self):
|
|
|
|
|
|
|
+ def read(self):
|
|
|
if self.img_meta:
|
|
if self.img_meta:
|
|
|
return
|
|
return
|
|
|
success = self.Rsuccess
|
|
success = self.Rsuccess
|
|
@@ -435,10 +537,10 @@ class PixelMedia():
|
|
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
|
if self.fname.startswith("cam_"):
|
|
if self.fname.startswith("cam_"):
|
|
|
pass
|
|
pass
|
|
|
- #img = self.rescale_frame2(img, 1200)
|
|
|
|
|
|
|
+ #img = _rescale_frame_by_width(img, 1200)
|
|
|
else:
|
|
else:
|
|
|
- img = self.rescale_frame2(img, 200)
|
|
|
|
|
- #img = self.rescale_frame2(img, 1200)
|
|
|
|
|
|
|
+ img = _rescale_frame_by_width(img, 200)
|
|
|
|
|
+ #img = _rescale_frame_by_width(img, 1200)
|
|
|
|
|
|
|
|
|
|
|
|
|
# store frame into buffer list
|
|
# store frame into buffer list
|
|
@@ -457,8 +559,6 @@ class PixelMedia():
|
|
|
self.success = 1
|
|
self.success = 1
|
|
|
return ok
|
|
return ok
|
|
|
|
|
|
|
|
- def read(self):
|
|
|
|
|
- pass
|
|
|
|
|
|
|
|
|
|
def prev(self):
|
|
def prev(self):
|
|
|
self.pos -= 1
|
|
self.pos -= 1
|
|
@@ -468,87 +568,12 @@ class PixelMedia():
|
|
|
self.pos = len(self.buffer)-1
|
|
self.pos = len(self.buffer)-1
|
|
|
self.im = self.buffer[int(self.pos)]
|
|
self.im = self.buffer[int(self.pos)]
|
|
|
|
|
|
|
|
- def rotateImage(self,image, angle):
|
|
|
|
|
|
|
+ def _rotateImage(self,image, angle):
|
|
|
if self.img_meta:
|
|
if self.img_meta:
|
|
|
return
|
|
return
|
|
|
- if angle in [0,360]:
|
|
|
|
|
- pass#return image
|
|
|
|
|
- try:
|
|
|
|
|
- #print("EE",image.shape)
|
|
|
|
|
- #print("EE",dir(image))
|
|
|
|
|
- shape = list(image.shape[1::-1])
|
|
|
|
|
- bg_shape = shape[:]
|
|
|
|
|
-
|
|
|
|
|
- delta_x = 0 # + nach rechts
|
|
|
|
|
- delta_y = 0 # + nach unten
|
|
|
|
|
- r = []
|
|
|
|
|
- r.extend(list(range(0-3,0+3)))
|
|
|
|
|
- r.extend(list(range(180-3,180+3)))
|
|
|
|
|
- r.extend(list(range(360-3,360+3)))
|
|
|
|
|
-
|
|
|
|
|
- r2 = []
|
|
|
|
|
- r2.extend(list(range(90-3,90+3)))
|
|
|
|
|
- r2.extend(list(range(270-3,270+3)))
|
|
|
|
|
- if angle in r:
|
|
|
|
|
- pass
|
|
|
|
|
- elif 0:#angle in r2:
|
|
|
|
|
- bg_shape = bg_shape[::-1]
|
|
|
|
|
- delta_y = -65 #shape[1]/2 # # + nach unten
|
|
|
|
|
- delta_x = 30 #shape[1]/2 # # + nach unten
|
|
|
|
|
|
|
+ return _rotateImage(image, angle)
|
|
|
|
|
|
|
|
- delta_y -= bg_shape[1]/2 - 20
|
|
|
|
|
- delta_x = bg_shape[0]/2 - 10
|
|
|
|
|
|
|
|
|
|
- pass
|
|
|
|
|
- else:
|
|
|
|
|
- if shape[0] > shape[1]:
|
|
|
|
|
- # landscape video
|
|
|
|
|
- bg_shape = (shape[0],shape[0])
|
|
|
|
|
- delta_y = (shape[0]-shape[1])/2
|
|
|
|
|
- else:
|
|
|
|
|
- # portrait video
|
|
|
|
|
- bg_shape = (shape[1],shape[1])
|
|
|
|
|
- delta_x = (shape[1]-shape[0])/2
|
|
|
|
|
-
|
|
|
|
|
- center = (shape[0]/2+delta_x,shape[1]/2+delta_y)
|
|
|
|
|
- image = self.moveImage(image,x=delta_x,y=delta_y,shape=bg_shape)
|
|
|
|
|
-
|
|
|
|
|
- bg_shape = tuple(bg_shape) # exception ... if angle 0 no tuple !!!
|
|
|
|
|
- rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
|
|
|
|
|
- frame = cv2.warpAffine(image, rot_mat, bg_shape ) #,flags=cv2.INTER_LINEAR)
|
|
|
|
|
- return frame
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- raise(e)
|
|
|
|
|
- def moveImage(self,img,x=0,y=0,shape=None):
|
|
|
|
|
- if self.img_meta:
|
|
|
|
|
- return
|
|
|
|
|
- # Creating a translation matrix
|
|
|
|
|
- np = numpy
|
|
|
|
|
- translation_matrix = np.float32([ [1,0,x], [0,1,y] ])
|
|
|
|
|
-
|
|
|
|
|
- if shape is None:
|
|
|
|
|
- num_cols,num_rows = img.shape[1::-1]
|
|
|
|
|
- else:
|
|
|
|
|
- num_cols,num_rows = shape #[1::-1]
|
|
|
|
|
- # Image translation
|
|
|
|
|
- frame = cv2.warpAffine(img, translation_matrix, (num_cols,num_rows))
|
|
|
|
|
- return frame
|
|
|
|
|
-
|
|
|
|
|
- def rescale_frame2(self,frame, width):
|
|
|
|
|
- if self.img_meta:
|
|
|
|
|
- return
|
|
|
|
|
- height = int(frame.shape[0]/frame.shape[1] * width )
|
|
|
|
|
- dim = (width, height)
|
|
|
|
|
- #return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
|
|
|
|
|
- return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
|
|
|
|
|
-
|
|
|
|
|
- def rescale_frame(self,frame, percent=75):
|
|
|
|
|
- if self.img_meta:
|
|
|
|
|
- return
|
|
|
|
|
- width = int(frame.shape[1] * percent/ 100)
|
|
|
|
|
- height = int(frame.shape[0] * percent/ 100)
|
|
|
|
|
- dim = (width, height)
|
|
|
|
|
- return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
|
|
|
|
|
|
|
|
|
|
def pause(self):
|
|
def pause(self):
|
|
|
if self.img_meta:
|
|
if self.img_meta:
|
|
@@ -600,10 +625,10 @@ class PixelMedia():
|
|
|
if self.img is None:
|
|
if self.img is None:
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- self.img = self.rescale_frame(self.img, percent=self.scale)
|
|
|
|
|
|
|
+ self.img = _rescale_frame_by_procent(self.img, percent=self.scale)
|
|
|
|
|
|
|
|
# rotate frame BUG: x,y offset ??? !!!
|
|
# rotate frame BUG: x,y offset ??? !!!
|
|
|
- self.img = self.rotateImage(self.img, self.angle)
|
|
|
|
|
|
|
+ self.img = self._rotateImage(self.img, self.angle)
|
|
|
self.shape = self.img.shape[1::-1]
|
|
self.shape = self.img.shape[1::-1]
|
|
|
|
|
|
|
|
if len(self.buffer) % 100 == 0:
|
|
if len(self.buffer) % 100 == 0:
|
|
@@ -624,7 +649,7 @@ class PixelMedia():
|
|
|
except AttributeError as e:
|
|
except AttributeError as e:
|
|
|
time.sleep(.05)
|
|
time.sleep(.05)
|
|
|
#if self.init_count % 100 == 0:
|
|
#if self.init_count % 100 == 0:
|
|
|
- print("except 776",e)
|
|
|
|
|
|
|
+ cprint("except 776",e,color="red")
|
|
|
#self.init()
|
|
#self.init()
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
cprint("except 756",e,color="red")
|
|
cprint("except 756",e,color="red")
|
|
@@ -713,40 +738,58 @@ class PixelMedia():
|
|
|
else:
|
|
else:
|
|
|
wn.blit(self.im, (int(self.x-xx/2), int(self.y-yy/2)))
|
|
wn.blit(self.im, (int(self.x-xx/2), int(self.y-yy/2)))
|
|
|
|
|
|
|
|
- def overlay(self,wn=None,mode="x"):
|
|
|
|
|
- # overlay
|
|
|
|
|
|
|
+ def get_meta(self):
|
|
|
|
|
+ out = {}
|
|
|
|
|
+ mode="x"
|
|
|
|
|
+ if self._run:
|
|
|
|
|
+ mode = "run"
|
|
|
|
|
+ else:
|
|
|
|
|
+ mode = "pause"
|
|
|
|
|
|
|
|
- pygame.draw.rect(wn,[255,200,0],[5,MAIN_SIZE[1]-(self._id+1)*35,300,28])
|
|
|
|
|
- font15 = pygame.font.SysFont("freemonobold",17)
|
|
|
|
|
|
|
+ out["frames"] = len(self.buffer)
|
|
|
|
|
+ out["mode"] = mode
|
|
|
|
|
+ out["fname"] = self.fname
|
|
|
|
|
+ out["scale"] =self.scale
|
|
|
|
|
+ out["fps"] = int(self.fps)
|
|
|
|
|
+ out["pos"] = self.pos
|
|
|
|
|
+ out["dim"] = self.dim
|
|
|
|
|
+ out["run"] = self._run
|
|
|
|
|
+ out["cur"] = 0
|
|
|
|
|
+ if self.fps > 0: # check if div zerro
|
|
|
|
|
+ out["cur"] = (self.pos/self.fps)
|
|
|
|
|
+ out["x"] = self.x
|
|
|
|
|
+ out["y"] = self.y
|
|
|
|
|
+ out["id"] = self._id
|
|
|
|
|
+ out["nr"] = self._media_nr
|
|
|
|
|
+ out["pz"] = 0
|
|
|
|
|
+
|
|
|
|
|
+ return out
|
|
|
|
|
|
|
|
- pz = 0
|
|
|
|
|
|
|
+ def _overlay_text(self):
|
|
|
|
|
+ meta = self.get_meta()
|
|
|
|
|
|
|
|
- if self.end:
|
|
|
|
|
- rgb = [ 100,255,100]
|
|
|
|
|
- else:
|
|
|
|
|
- rgb = [255,100,0]
|
|
|
|
|
- pygame.draw.rect(wn,rgb,[220,MAIN_SIZE[1]-(self._id+1)*35,260,13])
|
|
|
|
|
|
|
+ keys = ["fps","pos","frames","cur","pz","x","y","scale","dim"]
|
|
|
|
|
+ _line = create_format_line(meta,keys)
|
|
|
|
|
|
|
|
- _line = "error no _line"
|
|
|
|
|
- _line ="FPS:{} F:{:05} von {:05} sec:{:0.02f} von {:0.02f} POS:{:#}:{:#} z:{:#} d:{:#}"
|
|
|
|
|
- if self.fps == 0: # check if div zerro
|
|
|
|
|
- _line = _line.format(self.fps,int(self.pos),len(self.buffer),(-1),pz ,self.x,self.y,self.scale,self.dim)
|
|
|
|
|
- else:
|
|
|
|
|
- pz = (len(self.buffer)/self.fps)
|
|
|
|
|
- _line = _line.format(self.fps,int(self.pos),len(self.buffer),(self.pos/self.fps),pz ,self.x,self.y,self.scale,self.dim)
|
|
|
|
|
|
|
+ keys= ["id","nr","mode","fname"]
|
|
|
|
|
+ _line2 = create_format_line(meta,keys)
|
|
|
|
|
+
|
|
|
|
|
+ return [_line,_line2]
|
|
|
|
|
|
|
|
- fr = font15.render(_line ,1, (0,0,0))
|
|
|
|
|
- wn.blit(fr,(10,MAIN_SIZE[1]-(self._id+1)*35))
|
|
|
|
|
|
|
|
|
|
- if self._run:
|
|
|
|
|
- mode = "run"
|
|
|
|
|
|
|
+def create_format_line(meta,keys):
|
|
|
|
|
+ _line = []
|
|
|
|
|
+ for k in keys:
|
|
|
|
|
+ v=meta.get(k,"-")
|
|
|
|
|
+ _line.append(str(k))
|
|
|
|
|
+ _line.append(":")
|
|
|
|
|
+ if type(v) is float:
|
|
|
|
|
+ _line.append("{:0.02f}".format(v))
|
|
|
else:
|
|
else:
|
|
|
- mode = "pause"
|
|
|
|
|
- fr = font15.render(" {} {} >:{} ".format(self._id+1,self._media_nr,mode) ,1, (0,0,0))
|
|
|
|
|
- wn.blit(fr,(3,MAIN_SIZE[1]-(self._id+1)*35+15))
|
|
|
|
|
-
|
|
|
|
|
- fr = font15.render("{}".format(self.fname) ,1, (0,0,0))
|
|
|
|
|
- wn.blit(fr,(70,MAIN_SIZE[1]-(self._id+1)*35+15))
|
|
|
|
|
|
|
+ _line.append(str(v))
|
|
|
|
|
+ _line.append(" ")
|
|
|
|
|
+ _line = "".join(_line)
|
|
|
|
|
+ return _line
|
|
|
|
|
|
|
|
PixelMedia = PixelMedia
|
|
PixelMedia = PixelMedia
|
|
|
|
|
|
|
@@ -795,7 +838,7 @@ def loop_videoplayer():
|
|
|
ok = 0
|
|
ok = 0
|
|
|
for i in _videoplayer: #.append( PixelMedia(cdmx,_id=_vid) )
|
|
for i in _videoplayer: #.append( PixelMedia(cdmx,_id=_vid) )
|
|
|
try:
|
|
try:
|
|
|
- r = i._read() # read next frame from file
|
|
|
|
|
|
|
+ r = i.read() # read next frame from file
|
|
|
if r:
|
|
if r:
|
|
|
ok = 1
|
|
ok = 1
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -806,6 +849,9 @@ def loop_videoplayer():
|
|
|
else:
|
|
else:
|
|
|
time.sleep(0.005)
|
|
time.sleep(0.005)
|
|
|
|
|
|
|
|
|
|
+ if QUIT:
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
thread.start_new_thread(loop_videoplayer,())
|
|
thread.start_new_thread(loop_videoplayer,())
|
|
|
# ===== ======
|
|
# ===== ======
|
|
|
|
|
|
|
@@ -831,7 +877,7 @@ def loop2_videoplayer():
|
|
|
j =0
|
|
j =0
|
|
|
for i in _videoplayer: #.append( PixelMedia(cdmx,_id=_vid) )
|
|
for i in _videoplayer: #.append( PixelMedia(cdmx,_id=_vid) )
|
|
|
try:
|
|
try:
|
|
|
- r = i._read() # read next frame from file
|
|
|
|
|
|
|
+ r = i.read() # read next frame from file
|
|
|
if r:
|
|
if r:
|
|
|
print(j,len(videoplayer2),i,len(i.buffer))
|
|
print(j,len(videoplayer2),i,len(i.buffer))
|
|
|
ok = 1
|
|
ok = 1
|
|
@@ -902,7 +948,7 @@ try:
|
|
|
if options.XX:
|
|
if options.XX:
|
|
|
pass#_x2 = int(options.XX)
|
|
pass#_x2 = int(options.XX)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print( "Exc",options.mode,e)
|
|
|
|
|
|
|
+ cprint( "Exc",options.mode,e,color="red")
|
|
|
|
|
|
|
|
print("_x2 , -X",_x2)
|
|
print("_x2 , -X",_x2)
|
|
|
# ===== GUI =========
|
|
# ===== GUI =========
|
|
@@ -919,7 +965,7 @@ if options.win_pos:
|
|
|
WIN_POS = '%i,%i' % (int(win_pos[0]),int(win_pos[1]) )
|
|
WIN_POS = '%i,%i' % (int(win_pos[0]),int(win_pos[1]) )
|
|
|
os.environ['SDL_VIDEO_WINDOW_POS'] = WIN_POS
|
|
os.environ['SDL_VIDEO_WINDOW_POS'] = WIN_POS
|
|
|
except Excetpion as e:
|
|
except Excetpion as e:
|
|
|
- print("win_pos",win_pos,e)
|
|
|
|
|
|
|
+ cprint("win_pos",win_pos,e,color="red")
|
|
|
|
|
|
|
|
|
|
|
|
|
os.environ['SDL_VIDEO_CENTERED'] = '0'
|
|
os.environ['SDL_VIDEO_CENTERED'] = '0'
|
|
@@ -1009,7 +1055,7 @@ try:
|
|
|
MAIN_SIZE=(wx,wy+pm_wy)
|
|
MAIN_SIZE=(wx,wy+pm_wy)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print("Exception:",e)
|
|
|
|
|
|
|
+ cprint("Exception:",e,color="red")
|
|
|
|
|
|
|
|
CFG_IN["w"] = CFG_BLOCK["size"] * CFG_BLOCK["h-count"]
|
|
CFG_IN["w"] = CFG_BLOCK["size"] * CFG_BLOCK["h-count"]
|
|
|
CFG_IN["h"] = CFG_BLOCK["size"] * CFG_BLOCK["v-count"]
|
|
CFG_IN["h"] = CFG_BLOCK["size"] * CFG_BLOCK["v-count"]
|
|
@@ -1366,13 +1412,15 @@ def event():
|
|
|
if event.type == pygame.VIDEORESIZE:
|
|
if event.type == pygame.VIDEORESIZE:
|
|
|
window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
|
|
window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(e)
|
|
|
|
|
|
|
+ cprint(e,color="red")
|
|
|
|
|
|
|
|
if event.type==pygame.QUIT:
|
|
if event.type==pygame.QUIT:
|
|
|
- print("QUIT")
|
|
|
|
|
|
|
+ global QUIT
|
|
|
|
|
+ QUIT = 1
|
|
|
|
|
+ cprint("QUIT",color="red")
|
|
|
running=False
|
|
running=False
|
|
|
#time.sleep(1)
|
|
#time.sleep(1)
|
|
|
- sys.exit()
|
|
|
|
|
|
|
+ #sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
fps = 0
|
|
fps = 0
|
|
@@ -1392,17 +1440,31 @@ if options.videoplayer:
|
|
|
vplay2=t[1]
|
|
vplay2=t[1]
|
|
|
except:pass
|
|
except:pass
|
|
|
|
|
|
|
|
-def draw_overlay():
|
|
|
|
|
- global fps,fps2
|
|
|
|
|
|
|
+
|
|
|
|
|
+def output_mask(): # oben
|
|
|
|
|
+ RGB = [0,0,50]
|
|
|
|
|
+ #RGB = [120,0,0] # test
|
|
|
|
|
+ start = 0
|
|
|
# oben
|
|
# oben
|
|
|
- pygame.draw.rect(window,[0,0,50],[0,0,MAIN_SIZE[0],57]) # background
|
|
|
|
|
- pygame.draw.rect(window,[0,0,50],[0,215,MAIN_SIZE[0],15]) # background
|
|
|
|
|
|
|
+ pygame.draw.rect(window,RGB,[0,start,MAIN_SIZE[0]+200,57]) # background
|
|
|
|
|
+ # unten
|
|
|
|
|
+ pygame.draw.rect(window,RGB,[0,start+192,MAIN_SIZE[0]+200,35]) # background
|
|
|
|
|
+ # links
|
|
|
|
|
+ pygame.draw.rect(window,RGB,[0,start+0,35,235]) # background
|
|
|
|
|
+
|
|
|
|
|
+def input_mask(): # unten
|
|
|
|
|
+ RGB = [0,0,50]
|
|
|
|
|
+ #RGB = [120,0,110] # test
|
|
|
|
|
+ start = 227
|
|
|
|
|
+ # oben
|
|
|
|
|
+ pygame.draw.rect(window,RGB,[0,start,MAIN_SIZE[0]+200,7]) # background
|
|
|
# links
|
|
# links
|
|
|
- pygame.draw.rect(window,[0,0,50],[0,50,35,400]) # background
|
|
|
|
|
- # mitte
|
|
|
|
|
- pygame.draw.rect(window,[0,0,50],[0,398,MAIN_SIZE[0],98]) # background
|
|
|
|
|
|
|
+ pygame.draw.rect(window,RGB,[0,start,35,200]) # background
|
|
|
# unten
|
|
# unten
|
|
|
- pygame.draw.rect(window,[0,0,50],[330,398+98,MAIN_SIZE[0],98]) # background
|
|
|
|
|
|
|
+ pygame.draw.rect(window,RGB,[0,start+173,MAIN_SIZE[0]+200,198]) # background
|
|
|
|
|
+
|
|
|
|
|
+def draw_main_overlay():
|
|
|
|
|
+ global fps,fps2
|
|
|
fr = font15.render("DMX-FPS: {}".format(fps) ,1, (200,0,255))
|
|
fr = font15.render("DMX-FPS: {}".format(fps) ,1, (200,0,255))
|
|
|
window.blit(fr,(10,2))
|
|
window.blit(fr,(10,2))
|
|
|
|
|
|
|
@@ -2106,7 +2168,48 @@ class FADE():
|
|
|
def next(self):
|
|
def next(self):
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
-def draw_video(VIDEO):
|
|
|
|
|
|
|
+def video_overlay_draw(wn=None,lines=["line1","line2"],i=0):
|
|
|
|
|
+ # overlay
|
|
|
|
|
+
|
|
|
|
|
+ pygame.draw.rect(wn,[255,200,0],[5,MAIN_SIZE[1]-(i+1)*35,380,28])
|
|
|
|
|
+ font15 = pygame.font.SysFont("freemonobold",17)
|
|
|
|
|
+
|
|
|
|
|
+ rgb = [255,100,0]
|
|
|
|
|
+ pygame.draw.rect(wn,rgb,[5,MAIN_SIZE[1]-(i+1)*35,200,13])
|
|
|
|
|
+
|
|
|
|
|
+ _line = lines[0]
|
|
|
|
|
+ fr = font15.render(_line ,1, (0,0,0))
|
|
|
|
|
+ wn.blit(fr,(10,MAIN_SIZE[1]-(i+1)*35))
|
|
|
|
|
+
|
|
|
|
|
+ _line = lines[1]
|
|
|
|
|
+ fr = font15.render(_line ,1, (0,0,0))
|
|
|
|
|
+ wn.blit(fr,(10,MAIN_SIZE[1]-(i+1)*35+15))
|
|
|
|
|
+
|
|
|
|
|
+ #_line = lines[2]
|
|
|
|
|
+ #fr = font15.render(_line ,1, (0,0,0))
|
|
|
|
|
+ #wn.blit(fr,(75,MAIN_SIZE[1]-(i+1)*35+15))
|
|
|
|
|
+
|
|
|
|
|
+def draw_all_video_overlay(VIDEO):
|
|
|
|
|
+ global videplayer
|
|
|
|
|
+ i=0
|
|
|
|
|
+ for count in VIDEO:
|
|
|
|
|
+ video1 = videoplayer[i]
|
|
|
|
|
+ #video1.overlay_draw(window,"run") # old
|
|
|
|
|
+ lines = video1._overlay_text()
|
|
|
|
|
+
|
|
|
|
|
+ video_overlay_draw(wn=window,lines=lines,i=i)
|
|
|
|
|
+ i += 1
|
|
|
|
|
+
|
|
|
|
|
+def del_all_video():
|
|
|
|
|
+ global videplayer
|
|
|
|
|
+ i = 0
|
|
|
|
|
+ print()
|
|
|
|
|
+ cprint("del_all_video")
|
|
|
|
|
+ for video in videoplayer:
|
|
|
|
|
+ cprint("- del video",video)
|
|
|
|
|
+ video._del()
|
|
|
|
|
+
|
|
|
|
|
+def draw_all_video(VIDEO):
|
|
|
global videplayer
|
|
global videplayer
|
|
|
i = 0
|
|
i = 0
|
|
|
|
|
|
|
@@ -2209,11 +2312,6 @@ def draw_video(VIDEO):
|
|
|
i+=1
|
|
i+=1
|
|
|
|
|
|
|
|
|
|
|
|
|
- i=0
|
|
|
|
|
- for count in VIDEO:
|
|
|
|
|
- video1 = videoplayer[i]
|
|
|
|
|
- video1.overlay(window,"run")
|
|
|
|
|
- i += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2516,6 +2614,8 @@ def dmx_loop():
|
|
|
dmx_raw()
|
|
dmx_raw()
|
|
|
time.sleep(1/40) # fast high cpu
|
|
time.sleep(1/40) # fast high cpu
|
|
|
#time.sleep(1/25)
|
|
#time.sleep(1/25)
|
|
|
|
|
+ if QUIT:
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
dmx_raw()
|
|
dmx_raw()
|
|
|
|
|
|
|
@@ -2763,15 +2863,15 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
if VIDEO:
|
|
if VIDEO:
|
|
|
- draw_video(VIDEO)
|
|
|
|
|
|
|
+ draw_all_video(VIDEO)
|
|
|
|
|
+ #draw_all_video_overlay(VIDEO)
|
|
|
#img_draw(img_meta_a)
|
|
#img_draw(img_meta_a)
|
|
|
|
|
|
|
|
if options.countdown:
|
|
if options.countdown:
|
|
|
draw_counter(COUNTER)
|
|
draw_counter(COUNTER)
|
|
|
|
|
|
|
|
|
|
|
|
|
- pygame.draw.rect(window,[5,5,5],[0,60,MAIN_SIZE[0],p*9]) # background
|
|
|
|
|
- draw_overlay()
|
|
|
|
|
|
|
+ #pygame.draw.rect(window,[5,5,5],[0,60,MAIN_SIZE[0],p*9]) # background
|
|
|
pointer.draw(0,pm_wy) #wy
|
|
pointer.draw(0,pm_wy) #wy
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2796,14 +2896,19 @@ def main():
|
|
|
draw_kachel_nr()
|
|
draw_kachel_nr()
|
|
|
|
|
|
|
|
|
|
|
|
|
- GRID_A1_DIM()
|
|
|
|
|
- GRID_A2_DIM()
|
|
|
|
|
|
|
|
|
|
- draw_overlay()
|
|
|
|
|
- pointer.draw(0,pm_wy) #wy
|
|
|
|
|
|
|
|
|
|
|
|
+ output_mask() # mask background
|
|
|
|
|
+ input_mask() # mask background
|
|
|
|
|
|
|
|
|
|
+ GRID_A1_DIM() # overlay
|
|
|
|
|
+ GRID_A2_DIM() # overlay
|
|
|
|
|
|
|
|
|
|
+ if VIDEO:
|
|
|
|
|
+ draw_all_video_overlay(VIDEO)
|
|
|
|
|
+
|
|
|
|
|
+ draw_main_overlay()
|
|
|
|
|
+ pointer.draw(0,pm_wy) #wy
|
|
|
pygame.display.flip()
|
|
pygame.display.flip()
|
|
|
clock.tick(25)
|
|
clock.tick(25)
|
|
|
|
|
|
|
@@ -2813,4 +2918,7 @@ def main():
|
|
|
frame2 += 1
|
|
frame2 += 1
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
- main()
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ main()
|
|
|
|
|
+ finally:
|
|
|
|
|
+ del_all_video()
|