Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16595

LiveKit: Stream audio and video using python sdk

$
0
0

I am able to stream video but not audio using python sdk . Here is my code to connect to a room and play video (unfortunately no audio). What should I do to also include audio from my video.mp4

async def main(room: rtc.Room):    # get token and connect to room - not included    # publish a track    source = rtc.VideoSource(WIDTH, HEIGHT)    track = rtc.LocalVideoTrack.create_video_track("hue", source)    options = rtc.TrackPublishOptions()    options.source = rtc.TrackSource.SOURCE_CAMERA    publication = await room.local_participant.publish_track(track, options)    video_path = 'video.mp4'    await display_video(source, video_path)async def display_video(source: rtc.VideoSource, video_path: str):    cap = cv2.VideoCapture(video_path)    while cap.isOpened():        ret, frame = cap.read()        if not ret:            break        # Resize frame if necessary        frame = cv2.resize(frame, (WIDTH, HEIGHT))        # Convert BGR frame to RGBA format        rgba_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)        # Create a VideoFrame and capture it        frame_data = rgba_frame.tobytes()        frame = rtc.VideoFrame(WIDTH, HEIGHT, rtc.VideoBufferType.RGBA, frame_data)        source.capture_frame(frame)        await asyncio.sleep(1 / 30)  # Adjust sleep time for desired frame rate    cap.release()

Viewing all articles
Browse latest Browse all 16595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>