ImportCv2ImportThreadingImportWin32gui,win32conclassProducer (Threading. Thread):"""docstring for ClassName""" def __init__(SELF,STR_RTSP): Super (Producer, self).__init__() self.str_rtsp=str_rtsp Self.play=True#get a video stream operand cap from a class in Cv2Self.cap =Cv2. Videocapture (SELF.STR_RTSP)#call the Cv2 method to get the video frame of the cap (frame: How many pictures per second)fps =Self.cap.get (Cv2. Cap_prop_fps)Print(fps)#get the CAP video stream per frame sizeSize =(int (self.cap.get (CV2). cap_prop_frame_width)), int (Self.cap.get (CV2). Cap_prop_frame_height )))Print(size)#defining the encoding format mpge-4FOURCC = Cv2. VIDEOWRITER_FOURCC ('M','P','4','2') #defining video File input objectsSelf.outvideo = Cv2. Videowriter ('Savedir.avi', Fourcc,fps,size) Cv2.namedwindow ("Cap Video", 0); defRun (self):Print('In producer') whileTrue:ret,image=Self.cap.read ()if(ret = =True):ifWin32gui. FindWindow (None,'Cap Video'): Cv2.imshow ('Cap Video', image) Self.outVideo.write (image)Else: Self.outVideo.release () self.cap.release () Cv2.destroya Llwindows () BreakCv2.waitkey (1) ifCv2.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 HD: http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8
CCTV3 HD: http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8
CCTV5 HD: http://ivi.bupt.edu.cn/hls/cctv5hd.m3u8
cctv5+ HD: http://ivi.bupt.edu.cn/hls/cctv5phd.m3u8
CCTV6 HD: http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8References:80433063
Python Basics = = = Cv2-based player