Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mirrorSimulator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李远洪
mirrorSimulator
Commits
41e4b06a
Commit
41e4b06a
authored
Jan 13, 2021
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加了首页websocket功能
parent
f6c46144
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
264 additions
and
10 deletions
+264
-10
lib/service/StreamH264Flv_bak.py
lib/service/StreamH264Flv_bak.py
+1
-1
lib/socket/ClientWebSocket.py
lib/socket/ClientWebSocket.py
+57
-1
ui/CameraArea.py
ui/CameraArea.py
+2
-2
ui/CodecArea.py
ui/CodecArea.py
+100
-2
ui/HomeArea.py
ui/HomeArea.py
+104
-4
No files found.
lib/service/StreamH264Flv_bak.py
View file @
41e4b06a
...
@@ -413,7 +413,7 @@ if __name__ == "__main__":
...
@@ -413,7 +413,7 @@ if __name__ == "__main__":
obj
.
setHost
(
"10.100.11.125"
)
obj
.
setHost
(
"10.100.11.125"
)
# obj.setHost("video-test.vandyo.com")
# obj.setHost("video-test.vandyo.com")
obj
.
setPort
(
1078
)
obj
.
setPort
(
1078
)
obj
.
setVideoPath
(
"../../flv/
bbb
3.flv"
)
obj
.
setVideoPath
(
"../../flv/
aaa
3.flv"
)
obj
.
connectServer
()
obj
.
connectServer
()
obj
.
readFlvAndSend
()
obj
.
readFlvAndSend
()
...
...
lib/socket/ClientWebSocket.py
View file @
41e4b06a
#coding: utf-8
#coding: utf-8
import
ssl
import
time
from
gevent
import
thread
import
websocket
class
ClientWebSocket
():
class
ClientWebSocket
():
def
__init__
(
self
):
def
__init__
(
self
):
pass
self
.
ws
=
None
# websocket 对象
\ No newline at end of file
self
.
wsUrl
=
"ws://api-test.vandyo.com/mirror/websocket/"
# webosocket 连接地址
self
.
wsCode
=
"868142043390091"
# 连接编号
self
.
isEnableTrace
=
0
# 是否显示websocket连接信息 0:否 1:是
def
setWsUrl
(
self
,
data
):
self
.
wsUrl
=
data
def
setWsCode
(
self
,
data
):
self
.
wsCode
=
data
def
getWs
(
self
):
return
self
.
ws
def
connect
(
self
):
if
self
.
isEnableTrace
==
1
:
websocket
.
enableTrace
(
True
)
self
.
ws
=
websocket
.
WebSocketApp
(
self
.
wsUrl
+
self
.
wsCode
,
on_open
=
self
.
on_open
,
on_message
=
self
.
on_message
,
on_error
=
self
.
on_error
,
on_close
=
self
.
on_close
)
self
.
ws
.
run_forever
()
def
on_message
(
self
,
message
):
print
(
"收到消息:"
+
message
)
def
on_error
(
self
,
error
):
print
(
error
)
def
on_close
(
self
):
print
(
"websocket 已经断开!!!"
)
def
on_open
(
self
):
print
(
"websocket 已连接......"
)
print
(
self
.
wsUrl
+
self
.
wsCode
)
##################################################
# 发送消息
##################################################
def
sendMsg
(
self
,
msg
):
self
.
ws
.
send
(
msg
)
##################################################
# 关闭websocket
##################################################
def
close
(
self
):
self
.
ws
.
close
()
if
__name__
==
"__main__"
:
ClientWebSocket
()
.
connect
()
ui/CameraArea.py
View file @
41e4b06a
...
@@ -153,9 +153,9 @@ class CameraArea():
...
@@ -153,9 +153,9 @@ class CameraArea():
# ctrArea.SetBackgroundColour("RED")
# ctrArea.SetBackgroundColour("RED")
ctrText
=
wx
.
StaticText
(
ctrArea
,
label
=
'控制:'
)
ctrText
=
wx
.
StaticText
(
ctrArea
,
label
=
'控制:'
)
ctrPanel
=
wx
.
Panel
(
ctrArea
,
style
=
wx
.
BORDER_SIMPLE
)
ctrPanel
=
wx
.
Panel
(
ctrArea
,
style
=
wx
.
BORDER_SIMPLE
)
c
onnect
Button
=
wx
.
Button
(
ctrPanel
,
label
=
"清空日志"
,
pos
=
(
5
,
5
))
c
learLog
Button
=
wx
.
Button
(
ctrPanel
,
label
=
"清空日志"
,
pos
=
(
5
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
clearLog
(
evt
),
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
clearLog
(
evt
),
c
onnect
Button
)
c
learLog
Button
)
isVideoLogOpenCombox
=
wx
.
ComboBox
(
ctrPanel
,
pos
=
(
90
,
5
),
choices
=
[
'视频日志(关)'
,
'视频日志(开)'
],
value
=
"视频日志(关)"
,
size
=
wx
.
Size
(
110
,
-
1
))
isVideoLogOpenCombox
=
wx
.
ComboBox
(
ctrPanel
,
pos
=
(
90
,
5
),
choices
=
[
'视频日志(关)'
,
'视频日志(开)'
],
value
=
"视频日志(关)"
,
size
=
wx
.
Size
(
110
,
-
1
))
self
.
frame
.
Bind
(
wx
.
EVT_COMBOBOX
,
lambda
evt
:
self
.
isVideoLogOpenChange
(
evt
),
self
.
frame
.
Bind
(
wx
.
EVT_COMBOBOX
,
lambda
evt
:
self
.
isVideoLogOpenChange
(
evt
),
isVideoLogOpenCombox
)
isVideoLogOpenCombox
)
...
...
ui/CodecArea.py
View file @
41e4b06a
#coding: utf-8
#coding: utf-8
import
os
import
subprocess
import
threading
import
wx
import
wx
...
@@ -6,6 +10,13 @@ class CodecArea():
...
@@ -6,6 +10,13 @@ class CodecArea():
def
__init__
(
self
,
frame
):
def
__init__
(
self
,
frame
):
self
.
frame
=
frame
self
.
frame
=
frame
self
.
mainPanel
=
None
self
.
mainPanel
=
None
self
.
codeCFileText
=
None
# 转码文件地址
self
.
saveFileText
=
None
# 要保存的文件地址
self
.
selectVcodecCombox
=
None
# 选择视频编码器
self
.
selectVresolutionCombox
=
None
# 选择分辨率
self
.
selectFrameRateCombox
=
None
# 选择帧率
self
.
selectAcodecCombox
=
None
# 选择音频编码器
#################################################
#################################################
# 创建一个顶级pannel
# 创建一个顶级pannel
...
@@ -14,9 +25,96 @@ class CodecArea():
...
@@ -14,9 +25,96 @@ class CodecArea():
self
.
mainPanel
=
wx
.
Panel
(
self
.
frame
)
self
.
mainPanel
=
wx
.
Panel
(
self
.
frame
)
boxSizer
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
boxSizer
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
topPanel
=
wx
.
Panel
(
self
.
mainPanel
)
topPanel
=
wx
.
Panel
(
self
.
mainPanel
)
topPanel
.
SetBackgroundColour
(
"YELLOW"
)
# topPanel.SetBackgroundColour("YELLOW")
fiPath
=
os
.
getcwd
()
+
"/flv/aaa3.flv"
wx
.
StaticText
(
topPanel
,
label
=
'转码文件:'
,
pos
=
(
10
,
10
))
self
.
codeCFileText
=
wx
.
TextCtrl
(
topPanel
,
pos
=
(
70
,
5
),
size
=
wx
.
Size
(
300
,
-
1
),
value
=
fiPath
)
selectCodecPathButton
=
wx
.
Button
(
topPanel
,
label
=
"选择视频文件"
,
pos
=
(
375
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
,
textCtr
=
self
.
codeCFileText
:
self
.
selectVideoFile
(
evt
,
textCtr
),
selectCodecPathButton
)
wx
.
StaticText
(
topPanel
,
label
=
'保存文件:'
,
pos
=
(
480
,
10
))
self
.
saveFileText
=
wx
.
TextCtrl
(
topPanel
,
pos
=
(
540
,
5
),
size
=
wx
.
Size
(
300
,
-
1
),
value
=
""
)
selectSavePathButton
=
wx
.
Button
(
topPanel
,
label
=
"选择目录"
,
pos
=
(
845
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
,
textCtr
=
self
.
saveFileText
:
self
.
saveVideoFile
(
evt
,
textCtr
),
selectSavePathButton
)
startCodecButton
=
wx
.
Button
(
topPanel
,
label
=
"开始转码"
,
pos
=
(
930
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
startCodec
(
evt
),
startCodecButton
)
wx
.
StaticText
(
topPanel
,
label
=
'视频编码器:'
,
pos
=
(
10
,
40
))
self
.
selectVcodecCombox
=
wx
.
ComboBox
(
topPanel
,
pos
=
(
90
,
35
),
choices
=
[
'libx264'
,
'copy'
],
value
=
"libx264"
,
size
=
wx
.
Size
(
100
,
-
1
))
wx
.
StaticText
(
topPanel
,
label
=
'视频分辨率:'
,
pos
=
(
200
,
40
))
self
.
selectVresolutionCombox
=
wx
.
ComboBox
(
topPanel
,
pos
=
(
280
,
35
),
choices
=
[
'1080x720'
,
'720x480'
,
'640x426'
,
'480x320'
,
'320x214'
],
value
=
"640x426"
,
size
=
wx
.
Size
(
80
,
-
1
))
wx
.
StaticText
(
topPanel
,
label
=
'视频帧率:'
,
pos
=
(
370
,
40
))
self
.
selectFrameRateCombox
=
wx
.
ComboBox
(
topPanel
,
pos
=
(
440
,
35
),
choices
=
[
'25'
,
'30'
],
value
=
"25"
,
size
=
wx
.
Size
(
70
,
-
1
))
wx
.
StaticText
(
topPanel
,
label
=
'音频编码器:'
,
pos
=
(
10
,
70
))
self
.
selectAcodecCombox
=
wx
.
ComboBox
(
topPanel
,
pos
=
(
90
,
65
),
choices
=
[
'aac'
,
'copy'
],
value
=
"aac"
,
size
=
wx
.
Size
(
100
,
-
1
))
bottomPanel
=
wx
.
Panel
(
self
.
mainPanel
)
bottomPanel
=
wx
.
Panel
(
self
.
mainPanel
)
boxSizer
.
Add
(
topPanel
,
1
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
boxSizer
.
Add
(
topPanel
,
1
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
boxSizer
.
Add
(
bottomPanel
,
2
,
flag
=
wx
.
EXPAND
|
wx
.
TOP
,
border
=
5
)
boxSizer
.
Add
(
bottomPanel
,
2
,
flag
=
wx
.
EXPAND
|
wx
.
TOP
,
border
=
5
)
self
.
mainPanel
.
SetSizer
(
boxSizer
)
self
.
mainPanel
.
SetSizer
(
boxSizer
)
return
self
.
mainPanel
return
self
.
mainPanel
#################################################
# 打开文件选择对话框
#################################################
def
selectVideoFile
(
self
,
evt
,
textCtr
):
wildcard
=
"Video file (*.flv;*.mp4;*.mkv;*.avi)|*.flv;*.mp4;*.mkv;*.avi"
dlg
=
wx
.
FileDialog
(
self
.
frame
,
message
=
"选择视频文件"
,
defaultDir
=
os
.
getcwd
(),
defaultFile
=
""
,
wildcard
=
wildcard
,
style
=
wx
.
FD_OPEN
|
wx
.
FD_CHANGE_DIR
|
wx
.
FD_FILE_MUST_EXIST
|
wx
.
FD_PREVIEW
)
if
dlg
.
ShowModal
()
==
wx
.
ID_OK
:
path
=
dlg
.
GetPath
()
textCtr
.
SetValue
(
path
)
dlg
.
Destroy
()
#################################################
# 打开文件选择对话框
#################################################
def
saveVideoFile
(
self
,
evt
,
textCtr
):
wildcard
=
"Video file (*.flv)|*.flv"
dlg
=
wx
.
FileDialog
(
self
.
frame
,
message
=
"保存文件"
,
defaultDir
=
os
.
getcwd
(),
defaultFile
=
""
,
wildcard
=
wildcard
,
style
=
wx
.
FD_SAVE
|
wx
.
FD_CHANGE_DIR
|
wx
.
FD_PREVIEW
)
if
dlg
.
ShowModal
()
==
wx
.
ID_OK
:
path
=
dlg
.
GetPath
()
textCtr
.
SetValue
(
path
)
dlg
.
Destroy
()
#################################################
# 开始转码
#################################################
def
startCodec
(
self
,
evt
):
srcVideo
=
self
.
codeCFileText
.
GetValue
()
dstFile
=
self
.
saveFileText
.
GetValue
()
if
dstFile
==
""
:
dstFile
=
srcVideo
[:
len
(
srcVideo
)
-
3
]
+
"flv"
vcodec
=
self
.
selectVcodecCombox
.
GetValue
()
vresolution
=
self
.
selectVresolutionCombox
.
GetValue
()
frameRate
=
self
.
selectFrameRateCombox
.
GetValue
()
acodec
=
self
.
selectAcodecCombox
.
GetValue
()
threadObj
=
threading
.
Thread
(
target
=
self
.
codec
,
args
=
(
srcVideo
,
vcodec
,
vresolution
,
frameRate
,
acodec
,
dstFile
,))
threadObj
.
start
()
def
codec
(
self
,
srcVideo
,
vcodec
,
vresolution
,
frameRate
,
acodec
,
dstFile
):
m_command
=
[
"ffmpeg.exe"
,
"-i"
,
srcVideo
,
"-vcodec"
,
vcodec
,
"-s"
,
vresolution
,
"-r"
,
frameRate
,
"-acodec"
,
acodec
,
dstFile
]
subprocess
.
run
(
m_command
)
ui/HomeArea.py
View file @
41e4b06a
#coding: utf-8
#coding: utf-8
import
sys
import
threading
import
wx
import
wx
from
lib.socket.ClientWebSocket
import
ClientWebSocket
class
HomeArea
():
class
HomeArea
():
def
__init__
(
self
,
frame
):
def
__init__
(
self
,
frame
):
self
.
frame
=
frame
self
.
frame
=
frame
self
.
wsUrl
=
"ws://api-test.vandyo.com/mirror/websocket/"
# webosocket 连接地址
self
.
devCode
=
"868142043390091"
# 设备id
self
.
ws
=
None
self
.
mainPanel
=
None
self
.
mainPanel
=
None
self
.
wsUrlText
=
None
# webSocket 连接地址文本框
self
.
devCodeText
=
None
# 设备号文本框
self
.
logTextCtr
=
None
# 日志显示框
def
setWsUrl
(
self
,
data
):
self
.
wsUrl
=
data
def
setDevCode
(
self
,
data
):
self
.
devCode
=
data
#################################################
#################################################
# 创建一个顶级pannel
# 创建一个顶级pannel
#################################################
#################################################
def
create
(
self
):
def
create
(
self
):
self
.
mainPanel
=
wx
.
Panel
(
self
.
frame
)
self
.
mainPanel
=
wx
.
Panel
(
self
.
frame
)
boxSizer
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
boxSizer
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
topPanel
=
wx
.
Panel
(
self
.
mainPanel
)
topPanel
=
self
.
getTopPanel
(
)
topPanel
.
SetBackgroundColour
(
"PINK"
)
bottomPanel
=
wx
.
Panel
(
self
.
mainPanel
)
bottomPanel
=
self
.
getBottomPanel
(
)
boxSizer
.
Add
(
topPanel
,
1
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
boxSizer
.
Add
(
topPanel
,
1
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
boxSizer
.
Add
(
bottomPanel
,
2
,
flag
=
wx
.
EXPAND
|
wx
.
TOP
,
border
=
5
)
boxSizer
.
Add
(
bottomPanel
,
2
,
flag
=
wx
.
EXPAND
|
wx
.
TOP
,
border
=
5
)
self
.
mainPanel
.
SetSizer
(
boxSizer
)
self
.
mainPanel
.
SetSizer
(
boxSizer
)
return
self
.
mainPanel
return
self
.
mainPanel
def
getTopPanel
(
self
):
topPanel
=
wx
.
Panel
(
self
.
mainPanel
)
# topPanel.SetBackgroundColour("PINK")
wx
.
StaticText
(
topPanel
,
label
=
'连接地址:'
,
pos
=
(
10
,
10
))
self
.
wsUrlText
=
wx
.
TextCtrl
(
topPanel
,
pos
=
(
70
,
5
),
size
=
wx
.
Size
(
355
,
-
1
),
value
=
self
.
wsUrl
)
wx
.
StaticText
(
topPanel
,
label
=
'设备 号:'
,
pos
=
(
430
,
10
))
self
.
devCodeText
=
wx
.
TextCtrl
(
topPanel
,
pos
=
(
485
,
5
),
size
=
wx
.
Size
(
120
,
-
1
),
value
=
self
.
devCode
)
setDevCodeButton
=
wx
.
Button
(
topPanel
,
label
=
"设置设备号"
,
pos
=
(
610
,
5
))
connectButton
=
wx
.
Button
(
topPanel
,
label
=
"连接设备"
,
pos
=
(
695
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
connect
(
evt
),
connectButton
)
disConnectButton
=
wx
.
Button
(
topPanel
,
label
=
"断开连接"
,
pos
=
(
775
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
disConnect
(
evt
),
disConnectButton
)
wx
.
StaticText
(
topPanel
,
label
=
'状态:'
,
pos
=
(
855
,
10
))
self
.
connectStatusText
=
wx
.
TextCtrl
(
topPanel
,
pos
=
(
895
,
5
),
size
=
wx
.
Size
(
80
,
-
1
),
value
=
"未连接"
,
style
=
wx
.
TE_READONLY
)
self
.
connectStatusText
.
SetForegroundColour
(
wx
.
RED
)
connectButton1
=
wx
.
Button
(
topPanel
,
label
=
"连接设备"
,
pos
=
(
695
,
100
))
return
topPanel
#################################################
# 获取底部pannel的内容
#################################################
def
getBottomPanel
(
self
):
bottomPanel
=
wx
.
Panel
(
self
.
mainPanel
)
boxSizer_bottom
=
wx
.
BoxSizer
(
wx
.
HORIZONTAL
)
logArea
=
wx
.
Panel
(
bottomPanel
)
logStaticText
=
wx
.
StaticText
(
logArea
,
label
=
'日志:'
)
self
.
logTextCtr
=
wx
.
TextCtrl
(
logArea
,
size
=
wx
.
Size
(
40
,
-
1
),
style
=
wx
.
TE_MULTILINE
)
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
boxSizer_logArea
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
boxSizer_logArea
.
Add
(
logStaticText
,
2
,
flag
=
wx
.
EXPAND
|
wx
.
TOP
,
border
=
10
)
boxSizer_logArea
.
Add
(
self
.
logTextCtr
,
100
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
logArea
.
SetSizer
(
boxSizer_logArea
)
ctrArea
=
wx
.
Panel
(
bottomPanel
)
ctrText
=
wx
.
StaticText
(
ctrArea
,
label
=
'控制:'
)
ctrPanel
=
wx
.
Panel
(
ctrArea
,
style
=
wx
.
BORDER_SIMPLE
)
clearLogButton
=
wx
.
Button
(
ctrPanel
,
label
=
"清空日志"
,
pos
=
(
5
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
clearLog
(
evt
),
clearLogButton
)
boxSizer_ctrArea
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
boxSizer_ctrArea
.
Add
(
ctrText
,
2
,
flag
=
wx
.
EXPAND
|
wx
.
TOP
,
border
=
10
)
boxSizer_ctrArea
.
Add
(
ctrPanel
,
100
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
ctrArea
.
SetSizer
(
boxSizer_ctrArea
)
boxSizer_bottom
.
Add
(
logArea
,
70
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
boxSizer_bottom
.
Add
(
ctrArea
,
30
,
flag
=
wx
.
EXPAND
|
wx
.
LEFT
,
border
=
10
)
bottomPanel
.
SetSizer
(
boxSizer_bottom
)
return
bottomPanel
#################################################
# 连接设备
#################################################
def
connect
(
self
,
evt
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
self
.
ws
=
ClientWebSocket
()
self
.
ws
.
setWsUrl
(
self
.
wsUrlText
.
GetValue
())
self
.
ws
.
setWsCode
(
self
.
devCodeText
.
GetValue
())
threadObj
=
threading
.
Thread
(
target
=
self
.
doConnect
,
args
=
())
threadObj
.
start
()
def
doConnect
(
self
):
self
.
ws
.
connect
()
#################################################
# 断开连接
#################################################
def
disConnect
(
self
,
evt
):
self
.
ws
.
close
()
#################################################
# 清空日志
#################################################
def
clearLog
(
self
,
evt
):
self
.
logTextCtr
.
SetValue
(
""
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment