Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
luoweimeng opened this issue Aug 7, 2023 · 1 comment
Open

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

luoweimeng opened this issue Aug 7, 2023 · 1 comment

Comments

@luoweimeng
Copy link

luoweimeng commented Aug 7, 2023

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
Copy link
Owner

whitphx commented Aug 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants