How to stream in webcam video?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hmilab_kevin

I was wondering if there is an easy way to stream in webcam video?

  1. On PC, stream in from the webcam on the device using the video player?

  2. On a Android build, stream in over the network using something like ffmpeg RTSP?

I checked some of the documentation and previous questions, it seems there is no built-in way?
There is something here Reddit - Dive into anything

I wonder if if anyone has any experience or could suggest an solution?
Thank you.

:bust_in_silhouette: Reply From: SteveSmith

AFAIK there’s nothing in Godot to play a stream. I use VLC, which I call from Godot. You can pass it params that hide its borders so it looks like part of the app.

thanks, you mean to invoke the VLC program from godot script?
I also want to modify some contents on the webcam video, e.g. draw some virtual objects on it.
Is there a way to still use godot to draw on the webcam video if we opened it using VLC?

hmilab_kevin | 2023-02-01 15:12

Yes, using OS.execute(). Unfortunately, you can’t then put anything over the top of it, as the VLC window will be on top of your Godot app.

SteveSmith | 2023-02-01 16:00

:bust_in_silhouette: Reply From: hmilab_kevin

I was able to implement a initial version of streaming webcam into godot by following

The idea is use python to open the webcam on a PC, and stream it as bytes on UDP.
Then on the godot, which runs at another PC or device, use UDP to receive the bytes and reconstruct the imagetexture.