python基礎===基於cv2的播放器

來源:互聯網
上載者:User

標籤: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的播放器

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.