Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5200

Beginners • Using a Raspberry Pi 5 to trigger USB cameras in OBS

$
0
0
I'm working on a project to improve the way my lab captures video, and I currently have a USB camera (https://www.amazon.com/Arducam-Computer ... LT8D&gQT=1), a raspberry pi 5, and a ttl adapter box so that the machine that runs the rest of our chambers can communicate with the pi. I wrote a python script using websocket to simultaneously trigger recordings in two separate instances of OBS on my windows laptop, and this works as expected. I managed to get OBS installed on the Pi, but I can't access the usb camera. Interestingly, if I open VLC, I can open the video feed, but it is all purple and green (driver issue?). I am also having issues getting the program to trigger recordings from OBS of even just my screen, with an AttributeError: 'NoneType' object has no attribute 'connected'.

Any help would be much appreciated!

Code:

from obswebsocket import obsws, requests# Configuration for multiple OBS instancesOBS_INSTANCES = [    {"host": "localhost", "port": 4455, "password": "Ks69zK8hQa2qqqDX", "scene": "Box 1"},    {"host": "localhost", "port": 4456, "password": "0dbphPn6KjkZw1UL", "scene": "Box 2"}]# OBS Recording Path (ensure all instances save to the same directory)recording_path = r"C:\Users\nickt\Videos" # Update to your desired path# Function to connect and control an OBS instancedef control_obs(instance, action="start"):    ws = obsws(instance["host"], instance["port"], instance["password"])    try:        ws.connect()        if action == "start":            ws.call(requests.StartRecording())            print(f"Recording started on OBS instance at port {instance['port']}")        elif action == "stop":            ws.call(requests.StopRecording())            print(f"Recording stopped on OBS instance at port {instance['port']}")    except Exception as e:        print(f"Error with OBS instance at port {instance['port']}: {e}")    finally:        ws.disconnect()# Start recordings on all instancesfor instance in OBS_INSTANCES:    control_obs(instance, action="start")# Stop recordings after some time (example: 10 seconds)import timetime.sleep(10)for instance in OBS_INSTANCES:    control_obs(instance, action="stop")

Statistics: Posted by gordonbc — Fri Jan 24, 2025 4:59 pm — Replies 0 — Views 21



Viewing all articles
Browse latest Browse all 5200

Trending Articles