Recording jweb mediapipe video using script?

F_Dos's icon

I’m trying to record the camera input using jit.record while also using the jweb mediapipe module, but without success (I’m guessing only one destination can access the camera at a time).
Is there a way to record it to the computer using a script?

This post is a continuation of the previous post - after identifying the issue, I thought it would be better to open a new thread.

Source Audio's icon

look into ffmpeg suite

TFL's icon

As you noticed by yourself in your previous thread, you can definitely have the same camera used in [jweb] w/ mediapipe while recording it with [jit.grab] + [jit.record]. I just tested and it works, at least with one camera.

Your description of the problem seems more accurate in the previous thread:

I manage to make all 4 cameras work and also to record their output but then I cannot pass two of the camera via the jweb media pipe section. I'm getting an error

What is that error you get? Is it the same as that one?

F_Dos's icon

I'm sorry if not being clear.

I manage to make it work the following to scenarios:

1) recording all 4 cameras using jit.grab + jit.record - in this case I can't make the jweb mediapipe work. i'm getting error "Failed to acquire camera feed.."

2) recording 2 cameras using jit.grab + jit.record and using the other 2 cameras with the jweb mediapipe in order to do the eye tracking processing.

What I want to be able to make without success is to record all 4 camera as well to make eye tracking processing for 2 camera out of the 4 using the jweb mediapipe.

I hope this more clear of my situation.

What is that error you get? Is it the same as that one?


Yes

TFL's icon

That's indeed more clear! Sadly, I can't do further testing on my side since I only have one camera.

Could you try with just two cameras, both being recorded and used in mediapipe at the same time?

F_Dos's icon

Could you try with just two cameras, both being recorded and used in mediapipe at the same time?

Yes, but will do it only on Monday when will be in the place with the 4 cameras.

Rob Ramirez's icon

if on Windows, the OS prevents more than one application from accessing a single camera, which may be what you are experiencing. this is not unique to max or mediapipe, and i unfortunately do not know of any workarounds, except for duplicating feeds using Spout.

F_Dos's icon

if on Windows, the OS prevents more than one application from accessing a single camera, which may be what you are experiencing. this is not unique to max or mediapipe, and i unfortunately do not know of any workarounds, except for duplicating feeds using Spout.

Thanks for your answer. Yes I'm using Windows so it sounds that this is the problem I'm facing.

I will try source audio suggestion using "ffmpeg suite", or might will look as well to add recording into the js code (?) I asked chatgpt and this is an option he gave so I will look into that as well

F_Dos's icon

Could you try with just two cameras, both being recorded and used in mediapipe at the same time?

I just try it and it is not working..

F_Dos's icon

Another problem I encounter is that the long camera id is changing every time I restart the computer or disconnect and connect again the cameras. it is very difficult to make setup like that. Is there a way to change the camera name so it will be different for each camera and consistent?

Rob Ramirez's icon

are you talking about the jit.grab @uniqueid, or some mediapipe code related id? The jit.grab uniqueid should not be changing on restart. I can't say what the mediapipe source code is doing though.

F_Dos's icon

are you talking about the jit.grab @uniqueid, or some mediapipe code related id? The jit.grab uniqueid should not be changing on restart. I can't say what the mediapipe source code is doing though.

I'm talking about the mediapipe code related id.

I'm using max8 so no @unique id for me

TFL's icon

Ok, so the device ID in [jweb] is obtained from the MediaDeviceInfo API. It is clearly stated that:

It is un-guessable by other applications and unique to the origin of the calling application. It is reset when the user clears cookies (for Private Browsing, a different identifier is used that is not persisted across sessions).

I imagine there is no persistent cookie storing in [jweb] when the patch gets closed and re-opened, so the unique ids are reset as well.

This made me to assume that a cookie would be automatically created when media devices are checked for the first time, and that as a solution to your problem we could read that cookie, store it in a Max dict and restore it when we re-open the patch.

But sadly, when debugging the page, I see no cookie, no local storage, nothing.

So at this point my only suggestion is to try the nodejs-based version of mediapipe. I don't know much about how nodejs works and even less about electron (the framework that is used to run the mediapipe webpage in the node server), but hopefully it allows for persistent cookie storage.

Lysdexic provided node-for-Max examples for facemesh and handpose. If I remember correctly you actually need face-landmarker, so you'll probably need to adapt the code yourself to make it run the mediapipe model you want.

F_Dos's icon

Thanks for your kind help. Unfortunately I needed specific the eye and iris tracking so I'm not sure facemesh will help for me. Hopefully in the near future some new solution will come up for max

F_Dos's icon

The only thing I don’t understand is why I can’t use two cameras for eye-tracking (via jweb Mediapipe) and another two for regular video recording. I thought it was working — and it actually did work once or twice — but today when I ran it again, I got the same error message: “Failed to acquire camera feed …”

My guess is that it has something to do with the camera IDs changing each time, and sometimes this causes a conflict between jweb and jit.grab(?)

F_Dos's icon

Will give it one last chance - I noticed that the jweb choose the first camera in the list upon start . Is there a way to change that to select different camera when patch is load?

F_Dos's icon

Another thing noticed - JWEB won't open camera if jit.grab is opened before it

Rob Ramirez's icon
F_Dos's icon

Yes ok, I think thats it for the moment.. Thanks for all the kind help!