flask直播流 截图

python 复制代码
class VideoCapture:
    def __init__(self, name):
        self.cap = cv2.VideoCapture(name)
        self.q = queue.Queue()
        t = threading.Thread(target=self._reader)
        t.daemon = True
        t.start()
    # 帧可用时立即读取帧,只保留最新的帧
    def _reader(self):
        while True:
            ret, frame = self.cap.read()
            if not ret:
                break
            if not self.q.empty():
                try:
                    self.q.get_nowait()  # 删除上一个(未处理的)帧
                except queue.Empty:
                    pass
            self.q.put(frame)
    def read(self):
        return self.q.get()
python 复制代码
@app.route('/ZL00132/front',methods=["GET"])
def index():

    # vehicle = request.args.get('vehicle')
    # direction = request.args.get('direction')

    # 直播流URL
    # stream_url = 'http://127.0.0.1:8096/z/live/'+vehicle+'/'+direction+'.flv'
    # 尝试打开直播流

    # 检查直播流是否成功打开
    # if not cap.isOpened():
    #     print("Error: Could not open video stream.")
    #     exit()
    # frame_count = 0  # 用于给截图命名的计数器
    stimestamp = time.time()
    while True:
            # 读取一帧
            frame = cap.read()
            now = datetime.datetime.now()
            date_str = now.strftime("%Y-%m-%d-%H:%M:%S")
            filename = f'/home/zhanyuan/static/{date_str}.jpg'
            cv2.imwrite(filename, frame)
            date_str1 = now.strftime("%Y-%m-%d-%H-%M-%S")
            etimestamp = time.time()
            print(f"文件 :{filename} 时间:{date_str1} 时间差: {etimestamp - stimestamp}")
            if etimestamp - stimestamp > 0.01:
                break
    url = f"http://127.0.0.1:10800/static/{date_str}.jpg"
    etimestamp1 = time.time()
    print(f"时间差: {etimestamp1 - stimestamp}")
    return f"{url}"
相关推荐
hai4058717 分钟前
Spring Boot中的响应与分层解耦架构
spring boot·后端·架构
鸽芷咕1 小时前
【Python报错已解决】ModuleNotFoundError: No module named ‘paddle‘
开发语言·python·机器学习·bug·paddle
子午1 小时前
动物识别系统Python+卷积神经网络算法+TensorFlow+人工智能+图像识别+计算机毕业设计项目
人工智能·python·cnn
风等雨归期1 小时前
【python】【绘制小程序】动态爱心绘制
开发语言·python·小程序
yanglamei19621 小时前
基于GIKT深度知识追踪模型的习题推荐系统源代码+数据库+使用说明,后端采用flask,前端采用vue
前端·数据库·flask
Adolf_19932 小时前
Flask-JWT-Extended登录验证, 不用自定义
后端·python·flask
冯宝宝^2 小时前
基于mongodb+flask(Python)+vue的实验室器材管理系统
vue.js·python·flask
friklogff2 小时前
【无标题】云端之C#:全面解析6种云服务提供商的SDK
开发语言·flask·c#
叫我:松哥2 小时前
基于Python flask的医院管理学院,医生能够增加/删除/修改/删除病人的数据信息,有可视化分析
javascript·后端·python·mysql·信息可视化·flask·bootstrap
海里真的有鱼2 小时前
Spring Boot 项目中整合 RabbitMQ,使用死信队列(Dead Letter Exchange, DLX)实现延迟队列功能
开发语言·后端·rabbitmq