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
49a92319
Commit
49a92319
authored
Jan 04, 2021
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了帧的预览
parent
11e5b4c7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
172 additions
and
44 deletions
+172
-44
lib/service/StreamH264Flv.py
lib/service/StreamH264Flv.py
+42
-33
ui/CameraArea.py
ui/CameraArea.py
+130
-11
No files found.
lib/service/StreamH264Flv.py
View file @
49a92319
...
...
@@ -24,6 +24,7 @@ class StreamH264Flv():
self
.
channel
=
1
# 频道号
self
.
isSendAudio
=
1
# 是否发送音频0:不发送 1:发送
self
.
isSend
=
0
# 是否发送消息 0:不发送 1:发送
self
.
isEndPush
=
0
# 是否结束推流 0:不结束 1:结束
# self.host = "10.100.11.125" # 开发环境
self
.
host
=
"10.100.12.3"
# 测试环境
...
...
@@ -51,6 +52,10 @@ class StreamH264Flv():
self
.
sendDur
=
data
def
setVideoPath
(
self
,
data
):
self
.
videoPath
=
data
def
setIsSend
(
self
,
data
):
self
.
isSend
=
data
def
setIsEndPush
(
self
,
data
):
self
.
isEndPush
=
data
####################################################
...
...
@@ -75,7 +80,8 @@ class StreamH264Flv():
# 读取flv文件,并发送 (h264编码,并且音频为aac编码格式)
####################################################
def
readFlvAndSend
(
self
):
self
.
isSend
=
1
self
.
isSend
=
1
# 控制暂停或继续推流
self
.
isEndPush
=
0
with
open
(
self
.
videoPath
,
'rb'
)
as
fi
:
con
=
fi
.
read
(
self
.
readSize
)
data
=
con
.
hex
()
...
...
@@ -85,6 +91,9 @@ class StreamH264Flv():
else
:
data
=
data
while
con
:
if
self
.
isEndPush
!=
0
:
break
else
:
if
self
.
isSend
==
1
:
if
len
(
data
)
<
30
:
con
=
fi
.
read
(
self
.
readSize
)
...
...
ui/CameraArea.py
View file @
49a92319
...
...
@@ -5,6 +5,8 @@ import sys
import
threading
import
time
import
traceback
import
platform
import
cv2
import
requests
import
wx
...
...
@@ -36,6 +38,7 @@ class CameraArea():
self
.
msgSendDurText
=
None
# 发送间隔文本框
self
.
audioCombox
=
None
# 音频开关按钮
self
.
videoPlayText
=
None
# 获取播放地址文本框
self
.
isShowFrame
=
0
# 是否展示帧预览画面 0:不显示 1:显示
def
setDevId
(
self
,
data
):
self
.
devId
=
data
...
...
@@ -70,7 +73,7 @@ class CameraArea():
paramView
=
wx
.
Panel
(
topPanel
)
wx
.
StaticText
(
paramView
,
label
=
'本地视频:'
,
pos
=
(
10
,
10
))
fiPath
=
os
.
getcwd
()
+
"
\\
flv
\\
aaa3.flv"
fiPath
=
os
.
getcwd
()
+
"
/flv/
aaa3.flv"
self
.
videoPathText
=
wx
.
TextCtrl
(
paramView
,
pos
=
(
70
,
5
),
size
=
wx
.
Size
(
300
,
-
1
),
value
=
fiPath
)
# 要推流的视频地址
selectPathButton
=
wx
.
Button
(
paramView
,
label
=
"选择视频文件"
,
pos
=
(
375
,
5
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
,
textCtr
=
self
.
videoPathText
:
self
.
selectVideoFile
(
evt
,
textCtr
),
...
...
@@ -93,9 +96,9 @@ class CameraArea():
self
.
audioCombox
=
wx
.
ComboBox
(
paramView
,
pos
=
(
240
,
125
),
choices
=
[
'开'
,
'关'
],
value
=
"开"
,
size
=
wx
.
Size
(
50
,
-
1
))
wx
.
StaticText
(
paramView
,
label
=
'播放地址:'
,
pos
=
(
10
,
190
))
self
.
videoPlayText
=
wx
.
TextCtrl
(
paramView
,
pos
=
(
70
,
185
),
size
=
wx
.
Size
(
350
,
-
1
))
# 视频播放地址
self
.
getPlayUrlButton
=
wx
.
Button
(
paramView
,
label
=
"获取播放地址"
,
pos
=
(
425
,
185
))
getPlayUrlButton
=
wx
.
Button
(
paramView
,
label
=
"获取播放地址"
,
pos
=
(
425
,
185
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
,
textCtr
=
self
.
videoPlayText
:
self
.
getPlayUrl
(
evt
,
textCtr
),
self
.
getPlayUrlButton
)
getPlayUrlButton
)
ctrView
=
wx
.
Panel
(
topPanel
,
style
=
wx
.
BORDER_SIMPLE
)
connectButton
=
wx
.
Button
(
ctrView
,
label
=
"1、连网"
,
pos
=
(
5
,
5
))
...
...
@@ -106,14 +109,20 @@ class CameraArea():
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
startPush
(
evt
),
startPushButton
)
pausePushButton
=
wx
.
Button
(
ctrView
,
label
=
"3、停止推流"
,
pos
=
(
5
,
35
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
pausePush
(
evt
),
pausePushButton
)
rePushButton
=
wx
.
Button
(
ctrView
,
label
=
"4、继续推流"
,
pos
=
(
120
,
35
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
continuePush
(
evt
),
rePushButton
)
stopPushButton
=
wx
.
Button
(
ctrView
,
label
=
"5、结束推流"
,
pos
=
(
5
,
65
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
stopPush
(
evt
),
stopPushButton
)
disConnectButton
=
wx
.
Button
(
ctrView
,
label
=
"6、断网"
,
pos
=
(
120
,
65
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
disConnect
(
evt
),
disConnectButton
)
playStreamVideoButton
=
wx
.
Button
(
ctrView
,
label
=
"播放流地址"
,
pos
=
(
5
,
95
))
showFrameButton
=
wx
.
Button
(
ctrView
,
label
=
"实时显示帧画面"
,
pos
=
(
120
,
95
))
# ctrView.SetBackgroundColour("PINK")
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
showFrame
(
evt
),
showFrameButton
)
StopPlayStreamVideoButton
=
wx
.
Button
(
ctrView
,
label
=
"停止播放"
,
pos
=
(
5
,
125
))
stopShowFrameButton
=
wx
.
Button
(
ctrView
,
label
=
"停止显示帧画面"
,
pos
=
(
120
,
125
))
self
.
frame
.
Bind
(
wx
.
EVT_BUTTON
,
lambda
evt
:
self
.
stopShowFrame
(
evt
),
stopShowFrameButton
)
boxSizer_1
=
wx
.
BoxSizer
(
wx
.
HORIZONTAL
)
boxSizer_1
.
Add
(
preView
,
1
,
flag
=
wx
.
EXPAND
|
wx
.
ALL
)
...
...
@@ -187,8 +196,7 @@ class CameraArea():
def
getPlayUrl
(
self
,
evt
,
textCtr
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
threadObj
=
threading
.
Thread
(
target
=
self
.
doGetPlayUrl
,
args
=
(
textCtr
,))
threadObj
=
threading
.
Thread
(
target
=
self
.
doGetPlayUrl
,
args
=
(
textCtr
,))
threadObj
.
start
()
####################################################
...
...
@@ -269,11 +277,14 @@ class CameraArea():
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
try
:
timeCur
=
self
.
getCurTime
()
if
self
.
pushObj
!=
None
:
threadObj
=
threading
.
Thread
(
target
=
self
.
pushStream
)
threadObj
.
start
()
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"推流成功!
\n
"
)
self
.
pushStatusText
.
SetValue
(
"推流中"
)
else
:
self
.
logTextCtr
.
WriteText
(
timeCur
+
"未连网!
\n
"
)
except
:
traceback
.
print_exc
()
def
pushStream
(
self
):
...
...
@@ -284,6 +295,55 @@ class CameraArea():
except
:
traceback
.
print_exc
()
####################################################
# 暂停推流
####################################################
def
pausePush
(
self
,
evt
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
threadObj
=
threading
.
Thread
(
target
=
self
.
doPausePush
())
threadObj
.
start
()
def
doPausePush
(
self
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"暂停推流!
\n
"
)
self
.
pushStatusText
.
SetValue
(
"推流暂停"
)
self
.
pushObj
.
setIsSend
(
0
)
####################################################
# 继续推流
####################################################
def
continuePush
(
self
,
evt
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
threadObj
=
threading
.
Thread
(
target
=
self
.
doContinuePush
())
threadObj
.
start
()
def
doContinuePush
(
self
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"继续推流!
\n
"
)
self
.
pushStatusText
.
SetValue
(
"推流中"
)
self
.
pushObj
.
setIsSend
(
1
)
####################################################
# 停止推流
####################################################
def
stopPush
(
self
,
evt
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
threadObj
=
threading
.
Thread
(
target
=
self
.
doStopPush
())
threadObj
.
start
()
def
doStopPush
(
self
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"推流停止!
\n
"
)
self
.
pushStatusText
.
SetValue
(
"连网"
)
self
.
pushObj
.
setIsEndPush
(
1
)
self
.
pushObj
=
None
####################################################
# 清空日志
...
...
@@ -291,3 +351,62 @@ class CameraArea():
def
clearLog
(
self
,
evt
):
self
.
logTextCtr
.
SetValue
(
""
)
####################################################
# 获取操作系统名字
####################################################
def
getOsName
(
self
):
osName
=
platform
.
system
()
return
osName
####################################################
# 实时显示帧画面
####################################################
def
showFrame
(
self
,
evt
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
threadObj
=
threading
.
Thread
(
target
=
self
.
doShowFrame
())
threadObj
.
start
()
def
doShowFrame
(
self
):
self
.
isShowFrame
=
1
devId
=
self
.
devIdText
.
GetValue
()
channel
=
self
.
channelText
.
GetValue
()
res
=
requests
.
post
(
self
.
getGetPlayUrl
,
data
=
json
.
dumps
({
'devId'
:
devId
,
'chan'
:
str
(
channel
)}))
.
text
res
=
json
.
loads
(
res
)
pullUrl
=
res
[
"data"
][
"url"
]
cap
=
cv2
.
VideoCapture
(
pullUrl
)
try
:
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"帧预览开始!
\n
"
)
while
(
cap
.
isOpened
()):
if
self
.
isShowFrame
==
1
:
ret
,
frame
=
cap
.
read
()
if
ret
==
False
:
break
cv2
.
imshow
(
"video"
,
frame
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
else
:
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"帧预览停止!
\n
"
)
break
cap
.
release
()
cv2
.
destroyAllWindows
()
except
:
traceback
.
print_exc
()
####################################################
# 停止显示帧画面
####################################################
def
stopShowFrame
(
self
,
evt
):
sys
.
stdout
=
self
.
logTextCtr
sys
.
stderr
=
self
.
logTextCtr
threadObj
=
threading
.
Thread
(
target
=
self
.
stopDoShowFrame
())
threadObj
.
start
()
def
stopDoShowFrame
(
self
):
self
.
isShowFrame
=
0
####################################################
# 播放视频地址
###################################################
def
playFrame
(
self
):
pass
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