Commit 507d95de authored by liyuanhong's avatar liyuanhong

兼容了mac部分崩溃问题

parent f73d499d
...@@ -124,6 +124,7 @@ class StreamH264Flv(): ...@@ -124,6 +124,7 @@ class StreamH264Flv():
self.isFileHead = 0 self.isFileHead = 0
timeStamp = 0 timeStamp = 0
self.timesStamp = timeStamp self.timesStamp = timeStamp
try:
with open(self.videoPath, 'rb') as fi: with open(self.videoPath, 'rb') as fi:
con = fi.read(self.readSize) con = fi.read(self.readSize)
data = con.hex() data = con.hex()
...@@ -190,6 +191,12 @@ class StreamH264Flv(): ...@@ -190,6 +191,12 @@ class StreamH264Flv():
curTime = self.getCurTime() curTime = self.getCurTime()
msgTxt = curTime + "视频推流结束,自动结束推流!(同时断开了连接)" msgTxt = curTime + "视频推流结束,自动结束推流!(同时断开了连接)"
wx.CallAfter(pub.sendMessage, "closeMsg" + str(self.channel), msg=msgTxt) 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(): ...@@ -248,14 +255,17 @@ class StreamH264Flv():
pkgs = self.protocal_1078.genPkgsByFrame() pkgs = self.protocal_1078.genPkgsByFrame()
for msg in pkgs: for msg in pkgs:
if self.isOpenVideoLog != 0: if self.isOpenVideoLog != 0:
# print("发送视频消息:" + msg)
msgTxt = "发送视频消息:" + msg msgTxt = "发送视频消息:" + msg
wx.CallAfter(pub.sendMessage, "showLog" + str(self.channel), msg=msgTxt) wx.CallAfter(pub.sendMessage, "showLog" + str(self.channel), msg=msgTxt)
try: try:
self.client.send(binascii.a2b_hex(msg)) self.client.send(binascii.a2b_hex(msg))
except: except:
if self.getOsName() == "Windows":
traceback.print_exc() traceback.print_exc()
print(msg) print(msg)
else:
msgTxt = traceback.format_exc()
wx.CallAfter(pub.sendMessage, "closeMsg" + str(self.channel), msg=msgTxt)
time.sleep(self.sendDur) time.sleep(self.sendDur)
#################################################### ####################################################
...@@ -400,8 +410,8 @@ if __name__ == "__main__": ...@@ -400,8 +410,8 @@ if __name__ == "__main__":
# obj.setMobile("142043390091") # obj.setMobile("142043390091")
obj.setMobile("013146200000") obj.setMobile("013146200000")
obj.setChannel(1) obj.setChannel(1)
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/aaa3.flv") obj.setVideoPath("../../flv/aaa3.flv")
obj.connectServer() obj.connectServer()
......
...@@ -311,7 +311,6 @@ class CameraArea(): ...@@ -311,7 +311,6 @@ class CameraArea():
timeCur = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) timeCur = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
timeCur = "[" + timeCur + "] " timeCur = "[" + timeCur + "] "
return timeCur return timeCur
#################################################### ####################################################
# 获取当前时间(不加括号) # 获取当前时间(不加括号)
#################################################### ####################################################
...@@ -321,6 +320,24 @@ class CameraArea(): ...@@ -321,6 +320,24 @@ class CameraArea():
timeCur = time.strftime("%Y年%m月%d日--%H时%M分%S秒", timeArray) timeCur = time.strftime("%Y年%m月%d日--%H时%M分%S秒", timeArray)
timeCur = timeCur timeCur = timeCur
return 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(): ...@@ -353,7 +370,11 @@ class CameraArea():
try: try:
self.pushObj.readFlvAndSend() self.pushObj.readFlvAndSend()
except: except:
if self.getOsName() == "Windows":
traceback.print_exc() traceback.print_exc()
else:
msgTxt = traceback.format_exc()
wx.CallAfter(pub.sendMessage, "closeMsg" + str(self.channel), msg=msgTxt)
#################################################### ####################################################
# 暂停推流 # 暂停推流
...@@ -398,11 +419,19 @@ class CameraArea(): ...@@ -398,11 +419,19 @@ class CameraArea():
threadObj = threading.Thread(target=self.doStopPush()) threadObj = threading.Thread(target=self.doStopPush())
threadObj.start() threadObj.start()
def doStopPush(self): def doStopPush(self):
try:
timeCur = self.getCurTime() timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "推流停止!\n") self.logTextCtr.WriteText(timeCur + "推流停止!\n")
self.pushStatusText.SetValue("连网") self.pushStatusText.SetValue("连网")
self.pushObj.setIsEndPush(1) self.pushObj.setIsEndPush(1)
# self.pushObj = None # 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(): ...@@ -614,23 +643,21 @@ class CameraArea():
if self.pushObj == None: if self.pushObj == None:
wx.CallAfter(pub.sendMessage, "showLog" + str(self.channel), msg=cutTime + "未推流,不可进行视频抓拍!") wx.CallAfter(pub.sendMessage, "showLog" + str(self.channel), msg=cutTime + "未推流,不可进行视频抓拍!")
else: else:
capTime = self.pushObj.getTimeStamp()
capTime = int(capTime / 1000)
capdur = 12 # 要抓拍的视频时长 capdur = 12 # 要抓拍的视频时长
inFi = self.videoPathText.GetValue() inFi = self.videoPathText.GetValue()
videoLen = self.getVideoDur(inFi)
curtimeO = self.getCurTimeO()
curPath = globalParams.scriptPath 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: 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: 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: elif cam == 3:
outFi = curPath + "/SDCard/video/CAM_3/" + curtimeO + "_" + str(videoLen) + "__" + str(capTime) + ".mp4" outFi = curPath + "/SDCard/picture/CAM_3/" + "VID" + str(videoLen) + "_" + str(capTime) + "_" + theDate + "_" + theTime + ".mp4"
# outFi = curPath + "/SDCard/video/" + curtimeO + "_" + str(videoLen) + "__" + str(capTime) + ".mp4"
self.splitVideo(capTime, capdur,inFi, outFi) self.splitVideo(capTime, capdur,inFi, outFi)
timeCur = int(time.time()) timeCur = int(time.time())
self.uploadFile(cam, outFi, 2, timeCur) self.uploadFile(cam, outFi, 2, timeCur)
ws.sendMsg(replyMsg) ws.sendMsg(replyMsg)
...@@ -649,19 +676,19 @@ class CameraArea(): ...@@ -649,19 +676,19 @@ class CameraArea():
if self.pushObj == None: if self.pushObj == None:
wx.CallAfter(pub.sendMessage, "showLog" + str(self.channel), msg=cutTime + "未推流,不可进行图片抓拍!") wx.CallAfter(pub.sendMessage, "showLog" + str(self.channel), msg=cutTime + "未推流,不可进行图片抓拍!")
else: else:
capTime = str(int(self.pushObj.getTimeStamp() / 1000))
inFi = self.videoPathText.GetValue() inFi = self.videoPathText.GetValue()
curPath = globalParams.scriptPath curPath = globalParams.scriptPath
videoLen = self.getVideoDur(inFi) outFi = ""
curtimeO = self.getCurTimeO() theDate = self.getCurDate() # 视频抓拍日期
outFi = 1 theTime = self.getCurTheTume() # 视频抓拍时间
videoLen = self.getVideoDur(inFi) # 视频总时长
capTime = str(int(self.pushObj.getTimeStamp() / 1000)) # 从第几秒开始截取的
if cam == 1: 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: 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: elif cam == 3:
outFi = curPath + "/SDCard/picture/CAM_3/" + curtimeO + "_" + str(videoLen) + "__" + str(capTime) + ".jpg" outFi = curPath + "/SDCard/picture/CAM_3/" + "PIC" + str(videoLen) + "_" + str(capTime) + "_" + theDate + "_" + theTime + ".jpg"
# outFi = curPath + "/SDCard/picture/" + curtimeO + "_" + str(videoLen) + "__" + str(capTime) + ".jpg"
m_command = ["ffmpeg.exe", "-i", inFi, "-frames:v", "1", "-ss", capTime, "-f", "image2", outFi] m_command = ["ffmpeg.exe", "-i", inFi, "-frames:v", "1", "-ss", capTime, "-f", "image2", outFi]
subprocess.run(m_command) subprocess.run(m_command)
......
...@@ -6,5 +6,5 @@ camera_2 = None # 相机2 ...@@ -6,5 +6,5 @@ camera_2 = None # 相机2
camera_3 = None # 相机3 camera_3 = None # 相机3
eventArea = None # 事件发送对象 eventArea = None # 事件发送对象
isLogRedirect = 1 # 日志是否重定向到日志文本框 0: 不重定向 (用于调试) 1:重定向 (用于给别人用) isLogRedirect = 0 # 日志是否重定向到日志文本框 0: 不重定向 (用于调试) 1:重定向 (用于给别人用)
scriptPath = "" # 脚本执行的目录 scriptPath = "" # 脚本执行的目录
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment