代码拉取完成,页面将自动刷新
#!/usr/bin/python
import faulthandler
faulthandler.enable()
import argparse
import sys
import os
import time
import av
import threading
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from Xlib import X, display, Xutil,Xatom
from PIL import Image
import numpy as np
class Window(object):
def __init__(self, display,fname):
self.fname=fname
self.media=av.open(self.fname)
self.media_cont= self.media.decode(video=0)
self.d = display
self.objects = []
self.fps=int(self.media.streams.video[0].average_rate)
self.freams= self.media.streams.video[0].frames
self.screen = self.d.screen()
self.window = self.screen.root.create_window(
0, 0, self.screen.root.get_geometry().height, self.screen.root.get_geometry().width), 32,
self.screen.root_depth,
X.InputOutput,
X.CopyFromParent,
background_pixel = self.screen.black_pixel,
event_mask = (X.ExposureMask |
X.StructureNotifyMask |
X.ButtonPressMask |
X.ButtonReleaseMask |
X.Button1MotionMask),
colormap = X.CopyFromParent,
)
self.gc = self.window.create_gc(
foreground = self.screen.black_pixel,
background = self.screen.black_pixel,
)
wm_window_type = self.d.intern_atom('_NET_WM_WINDOW_TYPE')
wm_window_type_dock = self.d.intern_atom('_NET_WM_WINDOW_TYPE_DESKTOP')
self.window.change_property(wm_window_type, Xatom.ATOM, 32, [wm_window_type_dock], X.PropModeReplace)
self.WM_DELETE_WINDOW = self.d.intern_atom('WM_DELETE_WINDOW')
self.WM_PROTOCOLS = self.d.intern_atom('WM_PROTOCOLS')
self.window.set_wm_name('Xdynawp')
self.window.set_wm_icon_name('xdynawp.py')
self.window.set_wm_protocols([self.WM_DELETE_WINDOW])
self.window.set_wm_hints(flags = Xutil.StateHint,
initial_state = Xutil.NormalState)
self.window.set_wm_normal_hints(flags = (Xutil.PPosition | Xutil.PSize
| Xutil.PMinSize),
min_width = 20,
min_height = 20)
self.window.map()
def loop(self):
frame=next(self.media_cont)
pmap=self.window.create_pixmap(frame.width,frame.height, self.screen.root_depth)
while 1:
st=time.time()
try:
frame=next(self.media_cont).to_ndarray(format="rgb24")
except StopIteration:
self.media=av.open(self.fname)
self.media_cont= self.media.decode(video=0)
if frame.shape[0]>self.screen.root.get_geometry().height:
x=int((frame.shape[0]-self.screen.root.get_geometry().height)/2)
y=int((frame.shape[1]-self.screen.root.get_geometry().width)/4)
frame=frame[x:frame.shape[0]-x,y:frame.shape[1]-y]
i=Image.fromarray(frame)
pmap.put_pil_image(self.gc,0,0,i)
#pmap.put_image(self.gc,0,0, frame.shape[0],frame.shape[1],X.ZPixmap,32,0,Image.fromarray(frame).tobytes())
self.window.copy_area(self.gc, pmap, 0, 0,i.width,i.height, 0, 0)
if time.time()-st>0:
time.sleep(1/self.fps-time.time()-st>0)
e = self.d.sync()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("filename",help="Video file name")
args = parser.parse_args()
Window(display.Display(),args.filename).loop()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。