zoukankan      html  css  js  c++  java
  • python基础===基于cv2的播放器

    import cv2  
    import threading
    import 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
     
    参考资料:
    https://blog.csdn.net/jiadianyong12138/article/details/80433063
  • 相关阅读:
    Linear Regression Example
    三角函数画图(Python)
    机器学习算法笔记系列之深入理解主成分分析PCA-原理篇
    Boosted Trees 介绍
    Jacobian矩阵和Hessian矩阵
    使用插件pagehelper在mybatis中实现分页查询
    git常用操作
    Python远程视频监控
    FPGA选型
    英文Datasheet没那么难读
  • 原文地址:https://www.cnblogs.com/botoo/p/9577106.html
Copyright © 2011-2022 走看看