whitphx/streamlit-webrtc

Is there a way to process both video and audio in one callback?

luoweimeng opened this issue · 1 comments

I noticed there are video_frame_callback and audio_frame_callback in the Callbacks. Is there a way to deal with both video and audio in a single callback? My intention is to process the input audio, and transform it into a streaming video, is there any work-around to deal with that?

Thanks very much !!!

Unfortunately it's not supported to handle both types of input in a single callback due to WebRTC's nature that video and audio tracks are streamed separately and asynchronously.
To do what you described, you have to continue using 2 types of callbacks and write the "bridging" code.

I might be something like this, while I'm writing this without real coding/testing so I can't ensure it works:

  1. Prepare a thread-safe data transmitting object, e.g. data_queue = queue.Queue().
  2. Push data from the audio callback, e.g. data_queue.put(some_data)
  3. Get the queued data in the video callback
    try:
        data_from_audio_callback = data_queue.get_nowait()
    except:
        data_from_audio_callback = None