RTD_APP / app.py
Raumkommander's picture
Update app.py
a737070 verified
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 Configuration with STUN + TURN Server
rtc_configuration = {
"iceServers": [
{"urls": ["stun:stun.l.google.com:19302"]}, # Google STUN Server
{
"urls": "turn:turn.nordvpn.com:1194", # Free TURN server (NordVPN)
"username": "random_username",
"credential": "random_password"
}
]
}
# Original Webcam Stream
st.subheader("Original Video Stream")
webrtc_streamer(
key="original",
media_stream_constraints={"video": True, "audio": False},
rtc_configuration=rtc_configuration, # Use STUN + TURN
)
# 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, # Use STUN + TURN
)