当前位置:网站首页>实现离线文件推流成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()
边栏推荐
- Learn how to get a database connection with JDBC
- 2021-09-30
- 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.
- DSPE-PEG-Azide DSPE-PED-N3 Phospholipid-Polyethylene Glycol-Azide Lipid PFG
- DC-CDN学习笔记
- ROS之service编程的学习和理解
- 用pytorch里的children方法自定义网络
- Software Testing Interview Questions 2021
- 钉钉H5微应用免登鉴权
- Research reagents Cholesterol-PEG-Maleimide, CLS-PEG-MAL, Cholesterol-PEG-Maleimide
猜你喜欢

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.

科研试剂Cholesterol-PEG-Maleimide,CLS-PEG-MAL,胆固醇-聚乙二醇-马来酰亚胺

Cholesterol-PEG-NHS NHS-PEG-CLS 胆固醇-聚乙二醇-活性酯可修饰小分子材料

使用 OpenCV 提取图像的 HOG、SURF 及 LBP 特征 (含代码)

2021年软件测试面试题大全

Pytorch Daily Practice - Predicting Surviving Passengers on the Titanic

UR3机器人雅克比矩阵

Pytorch常用函数

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

crontab的定时操作
随机推荐
数据预处理、特征工程和特征学习-摘抄
Cholesterol-PEG-Azide CLS-PEG-N3 Cholesterol-PEG-Azide MW:3400
unicloud cloud development record
IDEA控制台不能输入信息的解决方法
Cholesterol-PEG-Thiol CLS-PEG-SH 胆固醇-聚乙二醇-巯基
When solving background-size:cover, the picture is covered but not displayed completely?
cocos2d-x-3.2 image graying effect
Podspec verification dependency error problem pod lib lint , need to specify the source
Attention based ASR(LAS)
DSPE-PEG-Azide DSPE-PED-N3 Phospholipid-Polyethylene Glycol-Azide Lipid PFG
Redis-哈希
Redis-Hash
词向量——demo
MySQL free installation download and configuration tutorial
应用usb_cam同时打开多个摄像头方法
关于Iframe
DSPE-PEG-COOH CAS: 1403744-37-5 Phospholipid-polyethylene glycol-carboxy lipid PEG conjugate
pytorch模型微调finetuning训练image_dog(kaggle)
Talking about the understanding of CAP in distributed mode
wangeditor编辑器内容传至后台服务器存储