Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
lishui
server
Commits
6db0af1a
提交
6db0af1a
authored
4月 23, 2025
作者:
李学军
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add rtsp to jpg
上级
95ed0a58
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
75 行增加
和
0 行删除
+75
-0
rtspweb.py
rtspweb.py
+71
-0
server.py
server.py
+4
-0
没有找到文件。
rtspweb.py
0 → 100644
浏览文件 @
6db0af1a
import
asyncio
import
websockets
from
websockets
import
exceptions
as
ws_exceptions
connected
=
set
()
async
def
handle_websocket
(
websocket
,
path
):
connected
.
add
(
websocket
)
try
:
await
websocket
.
wait_closed
()
finally
:
connected
.
remove
(
websocket
)
async
def
capture_and_send_frames
():
ffmpeg_cmd
=
[
'ffmpeg'
,
'-rtsp_transport'
,
'tcp'
,
'-i'
,
'rtsp://127.0.0.1:8554/stream0'
,
'-c:v'
,
'mjpeg'
,
'-q:v'
,
'2'
,
'-f'
,
'mjpeg'
,
'pipe:1'
]
process
=
await
asyncio
.
create_subprocess_exec
(
*
ffmpeg_cmd
,
stdout
=
asyncio
.
subprocess
.
PIPE
,
stderr
=
asyncio
.
subprocess
.
DEVNULL
)
buffer
=
b
''
try
:
while
True
:
data
=
await
process
.
stdout
.
read
(
4096
)
if
not
data
:
break
buffer
+=
data
while
True
:
start
=
buffer
.
find
(
b
'
\xff\xd8
'
)
if
start
==
-
1
:
break
end
=
buffer
.
find
(
b
'
\xff\xd9
'
,
start
)
if
end
==
-
1
:
break
end
+=
2
frame
=
buffer
[
start
:
end
]
buffer
=
buffer
[
end
:]
# Broadcast to all connected clients
for
ws
in
connected
.
copy
():
try
:
await
ws
.
send
(
frame
)
except
ws_exceptions
.
ConnectionClosed
:
connected
.
discard
(
ws
)
finally
:
process
.
terminate
()
await
process
.
wait
()
async
def
main
():
async
with
websockets
.
serve
(
handle_websocket
,
'0.0.0.0'
,
8765
):
await
capture_and_send_frames
()
if
__name__
==
'__main__'
:
try
:
asyncio
.
run
(
main
())
except
KeyboardInterrupt
:
print
(
"Server stopped."
)
\ No newline at end of file
server.py
浏览文件 @
6db0af1a
import
datetime
import
datetime
import
json
import
json
import
subprocess
from
flask
import
Flask
,
request
,
jsonify
,
make_response
from
flask
import
Flask
,
request
,
jsonify
,
make_response
from
flask_cors
import
CORS
from
flask_cors
import
CORS
import
os
import
os
...
@@ -8,9 +9,11 @@ import redis
...
@@ -8,9 +9,11 @@ import redis
from
flask_socketio
import
SocketIO
,
emit
from
flask_socketio
import
SocketIO
,
emit
import
couchdb
import
couchdb
# 步骤 1:创建 Server 对象
# 步骤 1:创建 Server 对象
server
=
couchdb
.
Server
(
'http://admin:M36j44l*.*@117.72.90.129:5984/'
)
# 替换为实际 IP/域名
server
=
couchdb
.
Server
(
'http://admin:M36j44l*.*@117.72.90.129:5984/'
)
# 替换为实际 IP/域名
# 步骤 2:添加用户名密码验证
# 步骤 2:添加用户名密码验证
# server.resource.http.add_credentials('admin', 'M36j44l*.*')
# server.resource.http.add_credentials('admin', 'M36j44l*.*')
...
@@ -47,6 +50,7 @@ socketio = SocketIO(app, cors_allowed_origins="*") # 允许跨域
...
@@ -47,6 +50,7 @@ socketio = SocketIO(app, cors_allowed_origins="*") # 允许跨域
# model = load_model() # 这里可以加载你的 PyTorch 模型
# model = load_model() # 这里可以加载你的 PyTorch 模型
@app.route
(
'/'
)
@app.route
(
'/'
)
def
index
():
def
index
():
return
"Welcome to Flask API"
return
"Welcome to Flask API"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论