Spaces:
Sleeping
Sleeping
Merge pull request #5 from MSU-AI/working-app-with-video-and-audio
Browse files- .vscode/settings.json +5 -0
- app/surveillance.py +41 -0
.vscode/settings.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cSpell.words": [
|
3 |
+
"ndarray"
|
4 |
+
]
|
5 |
+
}
|
app/surveillance.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import av
|
3 |
+
import streamlit as st
|
4 |
+
from streamlit_webrtc import WebRtcMode, webrtc_streamer
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
st.set_page_config(page_title='Surveillance')
|
8 |
+
|
9 |
+
with st.sidebar:
|
10 |
+
st.write('# Settings')
|
11 |
+
display_settings = {
|
12 |
+
'mirror': st.checkbox('mirror'),
|
13 |
+
'echo': st.checkbox('echo'),
|
14 |
+
}
|
15 |
+
|
16 |
+
def audio_frame_callback(frame: av.AudioFrame) -> av.AudioFrame:
|
17 |
+
sound = frame.to_ndarray()
|
18 |
+
|
19 |
+
# sound logic
|
20 |
+
|
21 |
+
result_sound = sound if display_settings['echo'] else np.zeros_like(sound)
|
22 |
+
result_frame = av.AudioFrame.from_ndarray(result_sound, layout=frame.layout.name)
|
23 |
+
result_frame.sample_rate = frame.sample_rate
|
24 |
+
return result_frame
|
25 |
+
|
26 |
+
def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
27 |
+
image = frame.to_ndarray(format='bgr24')
|
28 |
+
|
29 |
+
mirrored = image[:,::-1,:] if display_settings['mirror'] else image
|
30 |
+
|
31 |
+
# image logic
|
32 |
+
|
33 |
+
return av.VideoFrame.from_ndarray(mirrored, format='bgr24')
|
34 |
+
|
35 |
+
streamer = webrtc_streamer(
|
36 |
+
key='surveillance',
|
37 |
+
mode=WebRtcMode.SENDRECV,
|
38 |
+
audio_frame_callback=audio_frame_callback,
|
39 |
+
video_frame_callback=video_frame_callback,
|
40 |
+
async_processing=True,
|
41 |
+
)
|