標籤:key 視頻流 name dia video 擷取 流操作 show 播放器
import cv2 import threadingimport win32gui,win32con class Producer(threading.Thread): """docstring for ClassName""" def __init__(self,str_rtsp): super(Producer, self).__init__() self.str_rtsp = str_rtsp self.play = True #通過cv2中的類擷取視頻流操作對象cap self.cap = cv2.VideoCapture(self.str_rtsp) #調用cv2方法擷取cap的視訊框架(幀:每秒多少張圖片) fps = self.cap.get(cv2.CAP_PROP_FPS) print(fps) #擷取cap視頻流的每幀大小 size = (int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))) print(size) #定義編碼格式mpge-4 fourcc = cv2.VideoWriter_fourcc(‘M‘, ‘P‘, ‘4‘, ‘2‘) #定義視頻檔案輸入對象 self.outVideo = cv2.VideoWriter(‘saveDir.avi‘,fourcc,fps,size) cv2.namedWindow("cap video",0); def run(self): print(‘in producer‘) while True: ret,image = self.cap.read() if (ret == True): if win32gui.FindWindow(None,‘cap video‘): cv2.imshow(‘cap video‘,image) self.outVideo.write(image) else: self.outVideo.release() self.cap.release() cv2.destroyAllWindows() break cv2.waitKey(1) if cv2.waitKey(1) & 0xFF == ord(‘q‘): self.outVideo.release() self.cap.release() cv2.destroyAllWindows() break # continue if __name__ == ‘__main__‘: print(‘run program‘) rtsp_str=‘http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8‘ #中央一套 producer = Producer(rtsp_str) producer.start()
CCTV1高清:http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8
CCTV3高清:http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8
CCTV5高清:http://ivi.bupt.edu.cn/hls/cctv5hd.m3u8
CCTV5+高清:http://ivi.bupt.edu.cn/hls/cctv5phd.m3u8
CCTV6高清:http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8 參考資料:80433063
python基礎===基於cv2的播放器