1 Star 3 Fork 0

calvinlin/xdynawp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xdynawp.py 3.73 KB
一键复制 编辑 原始数据 按行查看 历史
calvinlin 提交于 2022-05-09 04:35 . update xdynawp.py.
#!/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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/calvin-lin/xdynawp.git
[email protected]:calvin-lin/xdynawp.git
calvin-lin
xdynawp
xdynawp
master

搜索帮助