python封装screenrecord成一个录屏工具,并输出gif图用到了moviepy
复制代码
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136#! /usr/bin/env python #coding=utf-8 # -*- coding: utf-8 -*- ########################################################################### ## Python code generated with wxFormBuilder (version Oct 8 2012) ## http://www.wxformbuilder.org/ ## ## PLEASE DO "NOT" EDIT THIS FILE! ########################################################################### import wx import wx.xrc import os from moviepy.editor import * ########################################################################### ## Class MyFrame1 ########################################################################### class MyFrame1 ( wx.Frame ): def __init__( self, parent ): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 385,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize ) bSizer2 = wx.BoxSizer( wx.VERTICAL ) self.m_button_start = wx.Button( self, wx.ID_ANY, u"开始录制", wx.DefaultPosition, wx.Size( 200,-1 ), 0 ) bSizer2.Add( self.m_button_start, 0, wx.ALL|wx.EXPAND, 5 ) self.m_button_stop = wx.Button( self, wx.ID_ANY, u"停止录制", wx.DefaultPosition, wx.Size( 200,-1 ), 0 ) bSizer2.Add( self.m_button_stop, 0, wx.EXPAND|wx.ALL, 5 ) self.m_scrolledWindow2 = wx.ScrolledWindow( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL ) self.m_scrolledWindow2.SetScrollRate( 5, 5 ) bSizer3 = wx.BoxSizer( wx.VERTICAL ) self.m_log = wx.StaticText( self.m_scrolledWindow2, wx.ID_ANY, u"日志输出", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_log.Wrap( -1 ) bSizer3.Add( self.m_log, 1, wx.ALL|wx.EXPAND, 5 ) self.m_scrolledWindow2.SetSizer( bSizer3 ) self.m_scrolledWindow2.Layout() bSizer3.Fit( self.m_scrolledWindow2 ) bSizer2.Add( self.m_scrolledWindow2, 1, wx.EXPAND |wx.ALL, 5 ) self.SetSizer( bSizer2 ) self.Layout() self.Centre( wx.BOTH ) self.m_button_start.Bind(wx.EVT_BUTTON, self.onStart) self.m_button_stop.Bind(wx.EVT_BUTTON, self.onStop) self.m_button_stop.Disable() self.log = u"日志输出窗口" self.adbpath = os.getcwd()+"\adb.exe" #print self.adbpath def __del__( self ): pass def onStart(self,event): import thread thread.start_new_thread(self.record,()) self.m_button_stop.Enable() self.m_button_start.Disable() def onStop(self,event): import subprocess self.p.terminate() self.log = self.log+u"已停止录制n" self.m_log.SetLabel(self.log) import thread thread.start_new_thread(self.copy2PC,()) self.m_button_stop.Disable() def copy2PC(self): import time import subprocess self.log = self.log + u"正在拷贝视频到PCn" self.m_log.SetLabel(self.log) time.sleep(3) self.p = subprocess.Popen(self.adbpath+" pull /sdcard/"+self.filename+".mp4 "+os.getcwd()+"\"+self.filename+".mp4", stderr=subprocess.PIPE, stdout=subprocess.PIPE) strout, strerr = self.p.communicate() if strerr.lower().find("kb/s") == -1: self.log = self.log + u"拷贝失败n" self.m_log.SetLabel(self.log + strerr +"n") self.m_button_start.Enable() return self.log = self.log + u"已拷贝到程序目录n" self.m_log.SetLabel(self.log) self.log = self.log + u"开始转换为gifn" self.m_log.SetLabel(self.log) ###开始转换为gif myclip = VideoFileClip(os.getcwd()+"\"+self.filename+".mp4") #print (myclip.fps) # prints for instance '30' myclip2 = myclip.subclip(0, int(myclip.end)) myclip2.write_gif(os.getcwd()+"\"+self.filename+".gif",fps=12) # the gif will have 12 fps self.log = self.log + u"gif转换完毕n" self.m_log.SetLabel(self.log) self.m_button_start.Enable() def record(self): import subprocess import datetime now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M') self.filename = u"Video_"+now cmd = self.adbpath+u" shell screenrecord --bit-rate 10000000 /sdcard/"+self.filename+".mp4" self.log = u"开始录制n文件保存在手机//sdcard/"+self.filename+".mp4n" self.m_log.SetLabel(self.log) self.p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) strout, strerr = self.p.communicate() if strerr != "": self.log = self.log + u"录制时出现错误:n"+strerr self.m_log.SetLabel(self.log) self.m_button_start.Enable() self.m_button_stop.Disable() #import gizeh #import moviepy.editor as mpy app = wx.App(False) mylog = MyFrame1(None) mylog.Show() app.MainLoop()
最后
以上就是无情飞机最近收集整理的关于python封装screenrecord成一个录屏工具,并输出gif图的全部内容,更多相关python封装screenrecord成一个录屏工具内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复