DEV Community

Cover image for Python WebRTC basics with aiortc

Python WebRTC basics with aiortc

Yuichiro Tachibana (Tsuchiya) on February 12, 2021

Background Python is a very popular programming language, and one of the reasons is its Machine Learning, Image Processing, and Computer...
Collapse
 
zeeshaan profile image
Zeeshaan • Edited

It is also not starting to capture the video in your example program.
I'm also attaching the photo of your deployed example model not working.

Image: dev-to-uploads.s3.amazonaws.com/up...
Your link: share.streamlit.io/whitphx/streaml...

Collapse
 
whitphx profile image
Yuichiro Tachibana (Tsuchiya) • Edited

Since my example does not work, there seems something wrong in your environment. For example, network problems.
Are you using firewall software or being inside a office network which may drop WebRTC packets?

Apart from that, your app hosted on Sharing does not work in my env, where my app works on the other hand. It implies there may also be something wrong in your app code, but I can't find an exact reason.
However I found one thing; your app executes mask_image() in every execution, even when the WebCam mode is selected. What if it is modified not to be run when not necessary?

Collapse
 
zeeshaan profile image
Zeeshaan

I'm not using any firewall, And my app code is executing successfully on the local server, But It is not working on the Sharing Streamlit.

Does your app works on Sharing ? Because it in not working on any of my env.

Thread Thread
 
whitphx profile image
Yuichiro Tachibana (Tsuchiya)

Does your app works on Sharing ?

Yes. That's why I think there are something wrong in your environment.

Can you share the logs displayed in the browser's developer tool? Are there some errors?

Thread Thread
 
zeeshaan profile image
Zeeshaan

Sharing the log file please check.
Log File: dev-to-uploads.s3.amazonaws.com/up...

I'm asking you to please look into my code.
Github Code: github.com/zeeshaan28/Face-Mask-De...

I'm also sharing with you the log file of your example deployed on Sharing
File: dev-to-uploads.s3.amazonaws.com/up...

Collapse
 
zeeshaan profile image
Zeeshaan • Edited

I have created a face mask detector app that uses images or a webcam for detecting faces. The app works fine on a local server but when I deployed it on online streamlit sharing, the webcam is loading but it is not capturing. I tried deploying on Heroku, but the same problem persists.
I'm sharing the picture and my web app link. Please review and help me with it.

Image: dev-to-uploads.s3.amazonaws.com/up...
WEB APP Link: share.streamlit.io/zeeshaan28/face...

Collapse
 
mute profile image
bmox

When I run it on Local URL: localhost:8501 I have the option of selecting my device. But why am I trying it on Network url 192.168.1.127:8501 I'm unable to pick any device. It informs me a text "unavailable". I'm not going to attempt both URLat the same time. Could you please clarify what the issue is?

Collapse
 
whitphx profile image
Yuichiro Tachibana (Tsuchiya)

You need HTTPS when using media devices on hosts other than localhost. See dev.to/whitphx/build-a-web-based-r...

Collapse
 
momobami666 profile image
Momo • Edited

Can I ask a question sir, I just want to know if it is possible to have multiple cameras and each camera will pass frames to the python sever for image processing.
is this possible with aiortc? I hoping for your reply. sorry for my bad english.

Collapse
 
whitphx profile image
Yuichiro Tachibana (Tsuchiya)

I think it's possible.
You can just do the same thing for each camera input.

Collapse
 
zulfiquar15 profile image
Zulfiquar Ali

the model works just fine but then I get this error when I move from the camera and its intermittent.

2022-09-22 21:13:16.903 Error occurred in the WebRTC thread:
2022-09-22 21:13:16.904 Traceback (most recent call last):
2022-09-22 21:13:16.904 File "/home/user/.local/lib/python3.8/site-packages/streamlit_webrtc/process.py", line 108, in _run_worker_thread
2022-09-22 21:13:16.904 self._worker_thread()
2022-09-22 21:13:16.904 File "/home/user/.local/lib/python3.8/site-packages/streamlit_webrtc/process.py", line 196, in _worker_thread
2022-09-22 21:13:16.904 new_frames = finished.result()
2022-09-22 21:13:16.904 File "/home/user/.local/lib/python3.8/site-packages/streamlit_webrtc/models.py", line 115, in recv_queued
2022-09-22 21:13:16.904 return [self.recv(frames[-1])]
2022-09-22 21:13:16.904 File "/home/user/.local/lib/python3.8/site-packages/streamlit_webrtc/models.py", line 107, in recv
2022-09-22 21:13:16.904 return av.VideoFrame.from_ndarray(new_image, format="bgr24")
2022-09-22 21:13:16.904 File "av/video/frame.pyx", line 358, in av.video.frame.VideoFrame.from_ndarray
2022-09-22 21:13:16.904 File "av/utils.pyx", line 69, in av.utils.check_ndarray
2022-09-22 21:13:16.904 AttributeError: 'NoneType' object has no attribute 'dtype'

Please help me on this...
Thanks in advance...

Collapse
 
zeeshaan profile image
Zeeshaan

When the app is deployed on the server, The streamlit web_rtc fails to run. Can you help me with this?

Collapse
 
whitphx profile image
Yuichiro Tachibana (Tsuchiya)

Can you share the details?

Collapse
 
janaka1984 profile image
janaka1984

this is not working on chrome browser

Collapse
 
alha00005 profile image
alha00005

When I try to access it in chrome the page do not get loaded. I get this error site cant be reached :/

Collapse
 
rusydi101 profile image
rusydi_rudy

is it possible to use an ip camera?

Collapse
 
sargun_narula profile image
sargun123

Can u please explain how we can connect remote clients from other networks than in which server.py is running?