File size: 1,298 Bytes
b5a56e1
df11c7f
9fdee07
df11c7f
c803588
df11c7f
 
 
 
 
 
c7f4ab1
9fdee07
dbd9537
c7f4ab1
df11c7f
9fdee07
 
 
 
df11c7f
 
 
 
 
 
dbd9537
df11c7f
 
 
 
 
0597779
df11c7f
dbd9537
df11c7f
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import streamlit as st
from streamlit_webrtc import webrtc_streamer, VideoTransformerBase
import av
import cv2

# Video Transformer Class for Rotating Stream
class RotatedVideoTransformer(VideoTransformerBase):
    def transform(self, frame):
        img = frame.to_ndarray(format="bgr24")
        rotated_img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)  # Rotate 90 degrees
        return av.VideoFrame.from_ndarray(rotated_img, format="bgr24")

# Streamlit UI
st.title("Live Webcam Streaming with Rotation")

# Text Input and Confirm Button
user_input = st.text_input("Enter some text:")
if st.button("Confirm"):
    st.write(f"You entered: {user_input}")

# WebRTC Connection Config with STUN Server
rtc_configuration = {
    "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
}

# Original Webcam Stream
st.subheader("Original Video Stream")
webrtc_streamer(
    key="original",
    media_stream_constraints={"video": True, "audio": False},
    rtc_configuration=rtc_configuration,  # Add STUN server
)

# Rotated Webcam Stream
st.subheader("Rotated Video Stream")
webrtc_streamer(
    key="rotated",
    video_transformer_factory=RotatedVideoTransformer,
    media_stream_constraints={"video": True, "audio": False},
    rtc_configuration=rtc_configuration,  # Add STUN server
)