这是一个用于管理RTSP视频流拉取结果的HTTP服务器,提供查询和删除视频文件的功能。
cd /Users/wenhongquan/CLionProjects/jtjai_media
cmake --build cmake-build-debug --target jtjai_http_server
# 使用默认参数(输出目录:./output,端口:8080)
./cmake-build-debug/jtjai_http_server
# 指定输出目录
./cmake-build-debug/jtjai_http_server ./output
# 指定输出目录和端口
./cmake-build-debug/jtjai_http_server ./output 8080
./output
)8080
)请求
GET /api/timestamps
响应示例
{
"count": 3,
"timestamps": [
{
"timestamp": "20251010_163200",
"video_count": 2,
"total_size": 8385920
},
{
"timestamp": "20251010_163100",
"video_count": 2,
"total_size": 8385920
},
{
"timestamp": "20251010_163000",
"video_count": 2,
"total_size": 8385920
}
]
}
字段说明
count
: 时间戳目录总数timestamp
: 时间戳目录名称video_count
: 该目录下的视频数量total_size
: 该目录下所有视频的总大小(字节)请求
GET /api/videos
响应示例
{
"count": 6,
"videos": [
{
"filename": "test_stream1.mp4",
"full_path": "./output/20251010_163000/test_stream1.mp4",
"timestamp_dir": "20251010_163000",
"file_size": 1027405,
"created_time": "2025-10-10 16:30:26",
"stream_index": "1"
},
{
"filename": "test_stream2.mp4",
"full_path": "./output/20251010_163000/test_stream2.mp4",
"timestamp_dir": "20251010_163000",
"file_size": 7358515,
"created_time": "2025-10-10 16:30:26",
"stream_index": "2"
}
]
}
字段说明
filename
: 文件名full_path
: 完整路径timestamp_dir
: 所属时间戳目录file_size
: 文件大小(字节)created_time
: 创建时间stream_index
: 流索引(从文件名提取)请求
GET /api/videos?timestamp=20251010_163000
或者
GET /api/videos/20251010_163000
响应示例
{
"timestamp": "20251010_163000",
"count": 2,
"videos": [
{
"filename": "test_stream1.mp4",
"full_path": "./output/20251010_163000/test_stream1.mp4",
"timestamp_dir": "20251010_163000",
"file_size": 1027405,
"created_time": "2025-10-10 16:30:26",
"stream_index": "1"
}
]
}
请求
DELETE /api/video?path=./output/20251010_163000/test_stream1.mp4
响应示例(成功)
{
"success": true,
"path": "./output/20251010_163000/test_stream1.mp4",
"message": "文件删除成功"
}
响应示例(失败)
{
"success": false,
"path": "./output/20251010_163000/test_stream1.mp4",
"message": "文件删除失败"
}
安全限制
请求
DELETE /api/timestamp/20251010_163000
响应示例(成功)
{
"success": true,
"timestamp": "20251010_163000",
"path": "./output/20251010_163000",
"message": "目录删除成功"
}
响应示例(失败)
{
"success": false,
"timestamp": "20251010_163000",
"path": "./output/20251010_163000",
"message": "目录删除失败"
}
注意
所有错误响应都遵循以下格式:
{
"error": "错误类型",
"message": "详细错误信息"
}
400 Bad Request
: 请求参数错误403 Forbidden
: 无权访问或删除404 Not Found
: 请求的资源不存在500 Internal Server Error
: 服务器内部错误curl http://localhost:8080/api/timestamps
curl http://localhost:8080/api/videos
curl http://localhost:8080/api/videos/20251010_163000
curl -X DELETE "http://localhost:8080/api/video?path=./output/20251010_163000/test_stream1.mp4"
curl -X DELETE http://localhost:8080/api/timestamp/20251010_163000
// 列出所有视频
fetch('http://localhost:8080/api/videos')
.then(response => response.json())
.then(data => console.log(data));
// 删除视频
fetch('http://localhost:8080/api/video?path=./output/20251010_163000/test_stream1.mp4', {
method: 'DELETE'
})
.then(response => response.json())
.then(data => console.log(data));
import requests
# 列出所有视频
response = requests.get('http://localhost:8080/api/videos')
print(response.json())
# 删除视频
response = requests.delete('http://localhost:8080/api/video',
params={'path': './output/20251010_163000/test_stream1.mp4'})
print(response.json())
服务器支持跨域请求(CORS),可以从任何域的网页中调用API。
output/
├── 20251010_163000/ # 第1轮的输出
│ ├── test_stream1.mp4
│ ├── test_stream2.mp4
│ ├── rtsp_report.json
│ ├── report.txt
│ └── streams.csv
├── 20251010_163100/ # 第2轮的输出
│ ├── test_stream1.mp4
│ ├── test_stream2.mp4
│ ├── rtsp_report.json
│ ├── report.txt
│ └── streams.csv
└── 20251010_163200/ # 第3轮的输出
├── test_stream1.mp4
├── test_stream2.mp4
├── rtsp_report.json
├── report.txt
└── streams.csv
服务器会扫描输出目录下所有的时间戳子目录,并提供统一的查询和管理接口。