Is there a way to process both video and audio in one callback?
luoweimeng opened this issue · 1 comments
luoweimeng commented
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 !!!
whitphx commented
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:
- Prepare a thread-safe data transmitting object, e.g.
data_queue = queue.Queue()
. - Push data from the audio callback, e.g.
data_queue.put(some_data)
- Get the queued data in the video callback
try: data_from_audio_callback = data_queue.get_nowait() except: data_from_audio_callback = None