python多路视频并行拉流代码

本文介绍如何使用Python结合ffmpeg实现多路视频流的并行拉取。通过读取rstp_urls.txt文件中的地址,video_save.py脚本能并行处理各个流,注意脚本中需调整rstp_list变量以匹配实际拉流路径。
摘要由CSDN通过智能技术生成

多路视频并行拉流代码思路:从多路地址(rstp_urls.txt)中进行并行拉流(video_save.py)。

  1. rstp_urls.txt主要是拉流的地址,参考内容如下:
http://10.10.47.181:10002/track
rtsp://172.0.8.25:9981/534/analysis
rtsp://guest:Guest123@172.1.0.84:554/h264/ch1/main/av_stream

http://10.10.47.181:10001/track
rtsp://172.0.8.30:9981/904/analysis
rtsp://guest:Guest123@172.1.0.83:554/h264/ch1/main/av_stream

http://10.10.47.182:10006/track
rtsp://172.0.8.22:9980/91/analysis
rtsp://guest:Guest123@172.1.33.13:554/h264/ch1/main/av_stream
  1. video_save.py应注意修改对应路径(rstp_list),参考代码如下:
'''
import sys
# sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')
sys.path.insert(0,'/home/ls/miniconda3/envs/yolo/lib/python3.8/site-packages')
import cv2
import time
import traceback

def test(rtsp_url):
    cap = cv2.VideoCapture(rtsp_url)
    if cap.isOpened():
        success, frame = cap.read()
        print('okokok')
    else:
        print("failed")
def pull_rtsp(rtsp_url, run_time=20, save_file=''):
    print("CAP_FFMPEG...")
    # save_file  += "_FFMPEG"
    videoWrite = False
    # cap = cv2.VideoCapture(rtsp_url, cv2.CAP_FFMPEG)
    cap = cv2.VideoCapture(rtsp_url, cv2.CAP_ANY)
    # cap = cv2.VideoCapture(rtsp_url, cv2.CAP_GSTREAMER)

    size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    # fps = int(cap.get(cv2.CAP_PROP_FPS))
    fps = 25
    print(f"video{
     size}, FPS:{
     fps}")

    # frame_time = time.time()
    # fourcc = cv2.VideoWriter_fourcc(*'XVID')
    # videoWrite = cv2.VideoWriter(f"{save_file+str(frame_time)}.avi", fourcc, fps, size)
    strf_style = "%Y%m%d_%H%M%S"
    frame_time = time.strftime(strf_style, time.localtime(time.time()))
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    print(save_file)
    videoWrite = cv2.VideoWriter(f"{
     save_file+'/'+str(frame_time)}.mp4", fourcc, fps, size)
    start_time = time.time()
    while (time.time() - start_time) < run_time:
        t 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值