当前位置:网站首页>实现离线文件推流成rtsp 2
实现离线文件推流成rtsp 2
2022-07-31 05:17:00 【'番茄炒蛋饭'】
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
实现离线文件推流成rtsp
1.安装ffmpeg
省略 前面写过
安装ffmpeg
2.进行搭建 rtsp 服务器
地址在自己的百度云 /脚本/rtsp服务脚本
1
解压 rtsp-simple-server_v0.17.17_linux_amd64.tar.gz
2 启动 rtsp 服务
执行 ./rtsp-simple-server
3.执行ffmpeg命令
# 将 本地front1.mp4 文件 推流成 本地服务 rtsp
ffmpeg -re -stream_loop -1 -i 20211102104550/front1.mp4 -c copy -f rtsp rtsp://localhost:8554/mystream2
4.启动脚本加载rtsp流
import cv2
import time
from queue import Queue
from threading import Thread
class VideoManager:
def __init__(self, videoPath, cam_type="none", rotate_type=False):
self.cap = cv2.VideoCapture(videoPath)
self.videoPath = videoPath
self.seq_length = 16
self.skip_num = 1
self.frame_buffer = Queue()
self.frame_idx = 0
self.cam_type = cam_type
self.rotate_type = rotate_type
def __iter__(self):
return self
def reset(self):
self.cap.release()
self.cap = cv2.VideoCapture(self.videoPath)
while not self.frame_buffer.empty():
self.frame_buffer.get()
return self.cap.isOpened()
def release(self):
self.cap.release()
def __next__(self):
was_read = True
frames = []
idx = 0
while was_read and len(frames) < self.seq_length:
was_read, frame = self.cap.read()
idx += 1
# 用于抽帧
if (idx - 1) % self.skip_num != 0:
continue
if self.rotate_type and self.cam_type == "top":
frame = frame[::-1, ::-1, :].copy()
# time.sleep(2e-2)
frames.append(frame)
if was_read:
self.frame_buffer.put(frame)
if self.frame_buffer.qsize() > self.seq_length:
self.frame_buffer.get()
if len(frames) > 0 and len(frames) < self.seq_length:
frames.clear()
while not (self.frame_buffer.empty()):
frames.append(self.frame_buffer.get())
was_read = True
if len(frames) == 0:
was_read = False
self.frame_idx += 1
return was_read, frames, self.frame_idx
def start(self):
return self
def videoReadMp4(cap_manager, videoFrameQueue): # 用MP4视频
ret = True
while ret:
# if videoFrameQueue.full():
# time.sleep(1e-3)
# continue
ret, frame, frame_id = next(cap_manager)
if not frame:
continue
frame = cv2.resize(frame[0], (960,540))
cv2.imshow('', frame)
cv2.waitKey(1)
# if ret:
# videoFrameQueue.put(frame)
else:
cap_manager.release()
# logger.info('视频检测完成')
print('检测完成')
# self.timeout_queue.put(self.flag)
# self.detectEnd()
if __name__ == '__main__':
# rtsp = r"C:\Users\caibaojun\Desktop\lldvideo\merge\new.mp4"
# rtsp = r"C:\Users\caibaojun\Desktop\lldvideo\merge\new3.avi"
rtsp = "rtsp://192.168.5.18:8554/mystream2"
videoFrameQueue = Queue()
cap_manager = VideoManager(rtsp, cam_type="front", rotate_type=False)
t = Thread(target=videoReadMp4, args=(cap_manager, videoFrameQueue))
t.start()
边栏推荐
- Pytorch学习笔记13——Basic_RNN
- DSPE-PEG-COOH CAS:1403744-37-5 磷脂-聚乙二醇-羧基脂质PEG共轭物
- 活体检测PatchNet学习笔记
- DingTalk Enterprise Internal-H5 Micro Application Development
- crontab timing operation
- RuntimeError: CUDA error: no kernel image is available for execution on the device问题记录
- Numpy常用函数
- Fluorescein-PEG-DSPE Phospholipid-Polyethylene Glycol-Fluorescein Fluorescent Phospholipid PEG Derivatives
- 应用usb_cam同时打开多个摄像头方法
- Tensorflow related list
猜你喜欢

CAS:1403744-37-5 DSPE-PEG-FA 科研实验用磷脂-聚乙二醇-叶酸

Detailed explanation of mysql transaction principle

CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research

mPEG-DMPE Methoxy-polyethylene glycol-bismyristyl phosphatidylethanolamine for stealth liposome formation

ROS之service编程的学习和理解

unicloud cloud development record

After unicloud is released, the applet prompts that the connection to the local debugging service failed. Please check whether the client and the host are under the same local area network.

DC-CDN学习笔记

CAS:474922-22-0 Maleimide-PEG-DSPE Phospholipid-Polyethylene Glycol-Maleimide Brief Description

mysql 事务原理详解
随机推荐
Virtual machine view port number process
Pytorch每日一练——预测泰坦尼克号船上的生存乘客
Attention based ASR(LAS)
CAS:474922-22-0 Maleimide-PEG-DSPE Phospholipid-Polyethylene Glycol-Maleimide Brief Description
OpenCV中的图像数据格式CV_8U定义
ROS之service编程的学习和理解
Talking about the understanding of CAP in distributed mode
Remote file xxx is mapped to the local path xxx and can‘t be found. You can continue debugging....
Wangeditor rich text editor to upload pictures and solve cross-domain problems
【Latex】TexLive+VScode+SumatraPDF 配置LaTex编辑环境
Numpy常用函数
拒绝采样小记
词向量——demo
DSPE-PEG-Biotin,CAS:385437-57-0,磷脂-聚乙二醇-生物素可延长循环半衰期
IDEA概述和安装及调试
Pytorch Daily Practice - Predicting Surviving Passengers on the Titanic
mPEG-DMPE Methoxy-polyethylene glycol-bismyristyl phosphatidylethanolamine for stealth liposome formation
四种常见的POST提交数据方式
CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research
Sourcery插件(自动提升代码质量)