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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

软件测试技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值