Facebook
From Me, 2 Months ago, written in Plain Text.
This paste is a reply to Untitled from SMA - go back
Embed
Viewing differences between Untitled and Re: Untitled
import cv2
import pydub
import pydub.playback
#For Emid
# RTSP stream URL
rtsp_url = "rtsp://example.com/stream"

# Open the RTSP stream
cap = cv2.VideoCapture(rtsp_url)

# Check if the stream was opened successfully
if not cap.isOpened():
    print("Failed to open the RTSP stream")
    exit(1)

# Prepare an empty audio stream
audio_stream = pydub.AudioSegment.empty()

# Read and process the video frames
while True:
    # Read a frame from the stream
    ret, frame = cap.read()

    # Check if the frame was read successfully
    if not ret:
        print("Failed to read a frame from the RTSP stream")
        break

    # Extract audio data from the frame
    audio_data = frame.tobytes()

    # Convert the audio data to an AudioSegment
    audio_segment = pydub.AudioSegment(audio_data, frame_rate=44100, sample_width=2, channels=2)

    # Append the audio segment to the audio stream
    audio_stream += audio_segment

    # Play the audio stream
    pydub.playback.play(audio_stream)

    # Clear the audio stream
    audio_stream = pydub.AudioSegment.empty()

# Release resources
cap.release()
cv2.destroyAllWindows()
ffmpeg -i input.wav -f mp3 -ice_url "http://icecast_server:port/mount_point" -ice_name "Stream Name" -ice_genre "Genre" -ice_public 1 -ice_description "Stream Description" -ice_private 0 -ice_bitrate 128k -acodec libmp3lame -re -vn -y icecast_stream.mp3