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
507d95de
Commit
507d95de
authored
Feb 03, 2021
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容了mac部分崩溃问题
parent
f73d499d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
91 deletions
+128
-91
SDCard/picture/2021年02月01日--17时49分13秒_202__2.jpg
SDCard/picture/2021年02月01日--17时49分13秒_202__2.jpg
+0
-0
lib/service/StreamH264Flv.py
lib/service/StreamH264Flv.py
+75
-65
ui/CameraArea.py
ui/CameraArea.py
+52
-25
ui/globalParams.py
ui/globalParams.py
+1
-1
No files found.
SDCard/picture/2021年02月01日--17时49分13秒_202__2.jpg
deleted
100644 → 0
View file @
f73d499d
9.34 KB
lib/service/StreamH264Flv.py
View file @
507d95de
...
...
@@ -124,72 +124,79 @@ class StreamH264Flv():
self
.
isFileHead
=
0
timeStamp
=
0
self
.
timesStamp
=
timeStamp
with
open
(
self
.
videoPath
,
'rb'
)
as
fi
:
con
=
fi
.
read
(
self
.
readSize
)
data
=
con
.
hex
()
if
self
.
isFileHead
==
0
:
data
=
data
[
18
:]
self
.
isFileHead
=
1
else
:
data
=
data
while
con
:
if
self
.
isEndPush
!=
0
:
break
try
:
with
open
(
self
.
videoPath
,
'rb'
)
as
fi
:
con
=
fi
.
read
(
self
.
readSize
)
data
=
con
.
hex
()
if
self
.
isFileHead
==
0
:
data
=
data
[
18
:]
self
.
isFileHead
=
1
else
:
if
self
.
isSend
==
1
:
if
len
(
data
)
<
30
:
con
=
fi
.
read
(
self
.
readSize
)
data
=
data
+
con
.
hex
()
else
:
tagSize
=
self
.
getAVTagSize
(
data
)
if
len
(
data
)
<
(
tagSize
*
2
+
30
)
:
data
=
data
while
con
:
if
self
.
isEndPush
!=
0
:
break
else
:
if
self
.
isSend
==
1
:
if
len
(
data
)
<
30
:
con
=
fi
.
read
(
self
.
readSize
)
data
=
data
+
con
.
hex
()
else
:
tag
=
data
[:
tagSize
*
2
+
30
]
# flv tag
tagType
=
self
.
getTagType
(
tag
)
# flv tag 类型,是音频 还是视频
AVtag
=
tag
[
30
:]
# 音视频 tag
if
self
.
multiPushStatus
<
1
:
avTimeStamp
=
self
.
getAVTimeStamp
(
tag
)
#获取时间戳
timeStamp
=
avTimeStamp
self
.
timesStamp
=
timeStamp
tagSize
=
self
.
getAVTagSize
(
data
)
if
len
(
data
)
<
(
tagSize
*
2
+
30
):
con
=
fi
.
read
(
self
.
readSize
)
data
=
data
+
con
.
hex
()
else
:
avTimeStamp
=
self
.
getAVTimeStamp
(
tag
)
+
self
.
timeStampSeek
# 获取时间戳
timeStamp
=
avTimeStamp
self
.
timesStamp
=
timeStamp
if
avTimeStamp
>
100
:
if
self
.
isGetPlayUrl
==
0
:
self
.
getPlayUrl
(
self
.
mobile
,
self
.
channel
)
self
.
isGetPlayUrl
=
1
if
tagType
==
"08"
:
# 音频
AVdata
=
AVtag
[
4
:]
# 音频数据
if
self
.
isSendAudio
==
1
:
frameInfo
=
self
.
getAudioFrame
(
AVtag
)
tag
=
data
[:
tagSize
*
2
+
30
]
# flv tag
tagType
=
self
.
getTagType
(
tag
)
# flv tag 类型,是音频 还是视频
AVtag
=
tag
[
30
:]
# 音视频 tag
if
self
.
multiPushStatus
<
1
:
avTimeStamp
=
self
.
getAVTimeStamp
(
tag
)
#获取时间戳
timeStamp
=
avTimeStamp
self
.
timesStamp
=
timeStamp
else
:
avTimeStamp
=
self
.
getAVTimeStamp
(
tag
)
+
self
.
timeStampSeek
# 获取时间戳
timeStamp
=
avTimeStamp
self
.
timesStamp
=
timeStamp
if
avTimeStamp
>
100
:
if
self
.
isGetPlayUrl
==
0
:
self
.
getPlayUrl
(
self
.
mobile
,
self
.
channel
)
self
.
isGetPlayUrl
=
1
if
tagType
==
"08"
:
# 音频
AVdata
=
AVtag
[
4
:]
# 音频数据
if
self
.
isSendAudio
==
1
:
frameInfo
=
self
.
getAudioFrame
(
AVtag
)
for
frame
in
frameInfo
[
"frames"
]:
self
.
sendAudioFrame
(
frame
,
avTimeStamp
)
elif
tagType
==
"09"
:
# 视频
AVdata
=
AVtag
[
10
:]
# 视频数据
frameInfo
=
self
.
getVideoFrame
(
AVtag
)
for
frame
in
frameInfo
[
"frames"
]:
self
.
sendAudioFrame
(
frame
,
avTimeStamp
)
elif
tagType
==
"09"
:
# 视频
AVdata
=
AVtag
[
10
:]
# 视频数据
frameInfo
=
self
.
getVideoFrame
(
AVtag
)
for
frame
in
frameInfo
[
"frames"
]:
self
.
sendVideoFrame
(
frame
,
avTimeStamp
,
AVtag
)
elif
tagType
==
"12"
:
# 脚本
AVdata
=
AVtag
# 脚本数据
else
:
AVdata
=
AVtag
data
=
data
[(
tagSize
*
2
+
30
):]
else
:
time
.
sleep
(
1
)
self
.
pushStatusText
.
SetValue
(
"已连网"
)
timeCur
=
self
.
getCurTime
()
self
.
multiPushStatus
=
self
.
multiPushStatus
+
1
self
.
timeStampSeek
=
timeStamp
+
1000
self
.
logTextCtr
.
WriteText
(
timeCur
+
"视频推流结束,自动结束推流!
\n
"
)
if
self
.
autoClose
==
1
:
self
.
client
.
close
()
self
.
client
=
None
curTime
=
self
.
getCurTime
()
msgTxt
=
curTime
+
"视频推流结束,自动结束推流!(同时断开了连接)"
wx
.
CallAfter
(
pub
.
sendMessage
,
"closeMsg"
+
str
(
self
.
channel
),
msg
=
msgTxt
)
self
.
sendVideoFrame
(
frame
,
avTimeStamp
,
AVtag
)
elif
tagType
==
"12"
:
# 脚本
AVdata
=
AVtag
# 脚本数据
else
:
AVdata
=
AVtag
data
=
data
[(
tagSize
*
2
+
30
):]
else
:
time
.
sleep
(
1
)
self
.
pushStatusText
.
SetValue
(
"已连网"
)
timeCur
=
self
.
getCurTime
()
self
.
multiPushStatus
=
self
.
multiPushStatus
+
1
self
.
timeStampSeek
=
timeStamp
+
1000
self
.
logTextCtr
.
WriteText
(
timeCur
+
"视频推流结束,自动结束推流!
\n
"
)
if
self
.
autoClose
==
1
:
self
.
client
.
close
()
self
.
client
=
None
curTime
=
self
.
getCurTime
()
msgTxt
=
curTime
+
"视频推流结束,自动结束推流!(同时断开了连接)"
wx
.
CallAfter
(
pub
.
sendMessage
,
"closeMsg"
+
str
(
self
.
channel
),
msg
=
msgTxt
)
except
Exception
as
e
:
if
self
.
getOsName
()
==
"Windows"
:
traceback
.
print_exc
()
else
:
msgTxt
=
traceback
.
format_exc
()
wx
.
CallAfter
(
pub
.
sendMessage
,
"closeMsg"
+
str
(
self
.
channel
),
msg
=
msgTxt
)
####################################################
# 停止发送消息
...
...
@@ -248,14 +255,17 @@ class StreamH264Flv():
pkgs
=
self
.
protocal_1078
.
genPkgsByFrame
()
for
msg
in
pkgs
:
if
self
.
isOpenVideoLog
!=
0
:
# print("发送视频消息:" + msg)
msgTxt
=
"发送视频消息:"
+
msg
wx
.
CallAfter
(
pub
.
sendMessage
,
"showLog"
+
str
(
self
.
channel
),
msg
=
msgTxt
)
try
:
self
.
client
.
send
(
binascii
.
a2b_hex
(
msg
))
except
:
traceback
.
print_exc
()
print
(
msg
)
if
self
.
getOsName
()
==
"Windows"
:
traceback
.
print_exc
()
print
(
msg
)
else
:
msgTxt
=
traceback
.
format_exc
()
wx
.
CallAfter
(
pub
.
sendMessage
,
"closeMsg"
+
str
(
self
.
channel
),
msg
=
msgTxt
)
time
.
sleep
(
self
.
sendDur
)
####################################################
...
...
@@ -400,8 +410,8 @@ if __name__ == "__main__":
# obj.setMobile("142043390091")
obj
.
setMobile
(
"013146200000"
)
obj
.
setChannel
(
1
)
obj
.
setHost
(
"10.100.11.125"
)
#
obj.setHost("video-test.vandyo.com")
#
obj.setHost("10.100.11.125")
obj
.
setHost
(
"video-test.vandyo.com"
)
obj
.
setPort
(
1078
)
obj
.
setVideoPath
(
"../../flv/aaa3.flv"
)
obj
.
connectServer
()
...
...
ui/CameraArea.py
View file @
507d95de
...
...
@@ -311,7 +311,6 @@ class CameraArea():
timeCur
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
timeCur
=
"["
+
timeCur
+
"] "
return
timeCur
####################################################
# 获取当前时间(不加括号)
####################################################
...
...
@@ -321,6 +320,24 @@ class CameraArea():
timeCur
=
time
.
strftime
(
"
%
Y年
%
m月
%
d日--
%
H时
%
M分
%
S秒"
,
timeArray
)
timeCur
=
timeCur
return
timeCur
####################################################
# 获取当前日期
####################################################
def
getCurDate
(
self
):
timeCur
=
int
(
time
.
time
()
*
1000
)
timeArray
=
time
.
localtime
(
timeCur
/
1000
)
timeCur
=
time
.
strftime
(
"
%
Y
%
m
%
d"
,
timeArray
)
timeCur
=
timeCur
return
timeCur
####################################################
# 获取当前时间
####################################################
def
getCurTheTume
(
self
):
timeCur
=
int
(
time
.
time
()
*
1000
)
timeArray
=
time
.
localtime
(
timeCur
/
1000
)
timeCur
=
time
.
strftime
(
"
%
H
%
M
%
S"
,
timeArray
)
timeCur
=
timeCur
return
timeCur
####################################################
# 断网
...
...
@@ -353,7 +370,11 @@ class CameraArea():
try
:
self
.
pushObj
.
readFlvAndSend
()
except
:
traceback
.
print_exc
()
if
self
.
getOsName
()
==
"Windows"
:
traceback
.
print_exc
()
else
:
msgTxt
=
traceback
.
format_exc
()
wx
.
CallAfter
(
pub
.
sendMessage
,
"closeMsg"
+
str
(
self
.
channel
),
msg
=
msgTxt
)
####################################################
# 暂停推流
...
...
@@ -398,11 +419,19 @@ class CameraArea():
threadObj
=
threading
.
Thread
(
target
=
self
.
doStopPush
())
threadObj
.
start
()
def
doStopPush
(
self
):
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"推流停止!
\n
"
)
self
.
pushStatusText
.
SetValue
(
"连网"
)
self
.
pushObj
.
setIsEndPush
(
1
)
# self.pushObj = None
try
:
timeCur
=
self
.
getCurTime
()
self
.
logTextCtr
.
WriteText
(
timeCur
+
"推流停止!
\n
"
)
self
.
pushStatusText
.
SetValue
(
"连网"
)
self
.
pushObj
.
setIsEndPush
(
1
)
# self.pushObj = None
except
:
if
self
.
getOsName
()
==
"Windows"
:
traceback
.
print_exc
()
else
:
msgTxt
=
traceback
.
format_exc
()
wx
.
CallAfter
(
pub
.
sendMessage
,
"closeMsg"
+
str
(
self
.
channel
),
msg
=
msgTxt
)
traceback
.
print_exc
()
####################################################
...
...
@@ -614,23 +643,21 @@ class CameraArea():
if
self
.
pushObj
==
None
:
wx
.
CallAfter
(
pub
.
sendMessage
,
"showLog"
+
str
(
self
.
channel
),
msg
=
cutTime
+
"未推流,不可进行视频抓拍!"
)
else
:
capTime
=
self
.
pushObj
.
getTimeStamp
()
capTime
=
int
(
capTime
/
1000
)
capdur
=
12
# 要抓拍的视频时长
inFi
=
self
.
videoPathText
.
GetValue
()
videoLen
=
self
.
getVideoDur
(
inFi
)
curtimeO
=
self
.
getCurTimeO
()
curPath
=
globalParams
.
scriptPath
outFi
=
1
outFi
=
""
theDate
=
self
.
getCurDate
()
# 视频抓拍日期
theTime
=
self
.
getCurTheTume
()
# 视频抓拍时间
videoLen
=
self
.
getVideoDur
(
inFi
)
# 视频总时长
capTime
=
str
(
int
(
self
.
pushObj
.
getTimeStamp
()
/
1000
))
# 从第几秒开始截取的
if
cam
==
1
:
outFi
=
curPath
+
"/SDCard/
video/CAM_1/"
+
curtimeO
+
"_"
+
str
(
videoLen
)
+
"__"
+
str
(
capTime
)
+
".mp4"
outFi
=
curPath
+
"/SDCard/
picture/CAM_1/"
+
"VID"
+
str
(
videoLen
)
+
"_"
+
str
(
capTime
)
+
"_"
+
theDate
+
"_"
+
theTime
+
".mp4"
elif
cam
==
2
:
outFi
=
curPath
+
"/SDCard/
video/CAM_2/"
+
curtimeO
+
"_"
+
str
(
videoLen
)
+
"__"
+
str
(
capTime
)
+
".mp4"
outFi
=
curPath
+
"/SDCard/
picture/CAM_2/"
+
"VID"
+
str
(
videoLen
)
+
"_"
+
str
(
capTime
)
+
"_"
+
theDate
+
"_"
+
theTime
+
".mp4"
elif
cam
==
3
:
outFi
=
curPath
+
"/SDCard/video/CAM_3/"
+
curtimeO
+
"_"
+
str
(
videoLen
)
+
"__"
+
str
(
capTime
)
+
".mp4"
# outFi = curPath + "/SDCard/video/" + curtimeO + "_" + str(videoLen) + "__" + str(capTime) + ".mp4"
outFi
=
curPath
+
"/SDCard/picture/CAM_3/"
+
"VID"
+
str
(
videoLen
)
+
"_"
+
str
(
capTime
)
+
"_"
+
theDate
+
"_"
+
theTime
+
".mp4"
self
.
splitVideo
(
capTime
,
capdur
,
inFi
,
outFi
)
timeCur
=
int
(
time
.
time
())
self
.
uploadFile
(
cam
,
outFi
,
2
,
timeCur
)
ws
.
sendMsg
(
replyMsg
)
...
...
@@ -649,19 +676,19 @@ class CameraArea():
if
self
.
pushObj
==
None
:
wx
.
CallAfter
(
pub
.
sendMessage
,
"showLog"
+
str
(
self
.
channel
),
msg
=
cutTime
+
"未推流,不可进行图片抓拍!"
)
else
:
capTime
=
str
(
int
(
self
.
pushObj
.
getTimeStamp
()
/
1000
))
inFi
=
self
.
videoPathText
.
GetValue
()
curPath
=
globalParams
.
scriptPath
videoLen
=
self
.
getVideoDur
(
inFi
)
curtimeO
=
self
.
getCurTimeO
()
outFi
=
1
outFi
=
""
theDate
=
self
.
getCurDate
()
# 视频抓拍日期
theTime
=
self
.
getCurTheTume
()
# 视频抓拍时间
videoLen
=
self
.
getVideoDur
(
inFi
)
# 视频总时长
capTime
=
str
(
int
(
self
.
pushObj
.
getTimeStamp
()
/
1000
))
# 从第几秒开始截取的
if
cam
==
1
:
outFi
=
curPath
+
"/SDCard/picture/CAM_1/"
+
curtimeO
+
"_"
+
str
(
videoLen
)
+
"__"
+
str
(
capTime
)
+
".jpg"
outFi
=
curPath
+
"/SDCard/picture/CAM_1/"
+
"PIC"
+
str
(
videoLen
)
+
"_"
+
str
(
capTime
)
+
"_"
+
theDate
+
"_"
+
theTime
+
".jpg"
elif
cam
==
2
:
outFi
=
curPath
+
"/SDCard/picture/CAM_2/"
+
curtimeO
+
"_"
+
str
(
videoLen
)
+
"__"
+
str
(
capTime
)
+
".jpg"
outFi
=
curPath
+
"/SDCard/picture/CAM_2/"
+
"PIC"
+
str
(
videoLen
)
+
"_"
+
str
(
capTime
)
+
"_"
+
theDate
+
"_"
+
theTime
+
".jpg"
elif
cam
==
3
:
outFi
=
curPath
+
"/SDCard/picture/CAM_3/"
+
curtimeO
+
"_"
+
str
(
videoLen
)
+
"__"
+
str
(
capTime
)
+
".jpg"
# outFi = curPath + "/SDCard/picture/" + curtimeO + "_" + str(videoLen) + "__" + str(capTime) + ".jpg"
outFi
=
curPath
+
"/SDCard/picture/CAM_3/"
+
"PIC"
+
str
(
videoLen
)
+
"_"
+
str
(
capTime
)
+
"_"
+
theDate
+
"_"
+
theTime
+
".jpg"
m_command
=
[
"ffmpeg.exe"
,
"-i"
,
inFi
,
"-frames:v"
,
"1"
,
"-ss"
,
capTime
,
"-f"
,
"image2"
,
outFi
]
subprocess
.
run
(
m_command
)
...
...
ui/globalParams.py
View file @
507d95de
...
...
@@ -6,5 +6,5 @@ camera_2 = None # 相机2
camera_3
=
None
# 相机3
eventArea
=
None
# 事件发送对象
isLogRedirect
=
1
# 日志是否重定向到日志文本框 0: 不重定向 (用于调试) 1:重定向 (用于给别人用)
isLogRedirect
=
0
# 日志是否重定向到日志文本框 0: 不重定向 (用于调试) 1:重定向 (用于给别人用)
scriptPath
=
""
# 脚本执行的目录
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