xcms_beixiaocai/004批量添加摄像头.py

61 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
import uuid
import os
import time
"""
批量向xcms中添加添加摄像头
"""
RSTP_URL = "rtsp://10.0.0.17:8554/camera_test/"
ADD_CAMERA_URL = "http://10.0.0.81:9001/open/addStream"
def add_camera(rtsp_path, nick_name, code ,method="POST"):
# code = uuid.uuid4().hex
# print(code)
data = {
"code": f"{code}",# 必填,摄像头编号(不能与已有摄像头编号重复)
"nickname": f"{nick_name}",#必填,名称
"pull_stream_type": 1, # 必填数值类型1:RTSP,2:RTMP,3:FVL,4:HLS,21:GB28181
"pull_stream_url": f"{rtsp_path}", # 必填,直播流地址
"pull_stream_ip":"10.0.0.17", # 必填摄像头IP
"pull_stream_port":8554, # 必填,数值类型,摄像头拉流服务对用的端口
# "camera_name":"", # 非必填,摄像头名称
# "camera_manufacturer":"", # 非必填,摄像头厂商
# "camera_device_id":"group1",# v4.638新增非必填摄像头所属分组编号默认不填写时等于code
# "remark":"", # 非必填,备注
# "onvif_username":"", # 非必填探测ONVIF username
# "onvif_password":"", # 非必填探测ONVIF password
"is_audio":0 # 必填数值类型0:静音 1:原始音频
}
headers = {
"Content-Type": "application/json",
"Safe":"aqxY9ps21fyhyKNRyYpGvJCTp1JBeGOM"
}
response = requests.post(ADD_CAMERA_URL, json=data, headers=headers)
response.raise_for_status()
response_data = response.json()
print(response_data["code"])
def main():
video_path = "/home/admin-root/haotian/康达瑞贝斯机器狗/data_video"
video_name_list = os.listdir(video_path)
for i, video_name in enumerate(video_name_list):
video_name = video_name.split(".")[0]
add_camera(RSTP_URL+video_name, video_name, f"t{i}")
time.sleep(0.2)
if __name__ == "__main__":
main()