Python Basics = = = Cv2-based player

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.