Skip to content

Publish Video with BabyROS ​

SUMMARY

Publish Video with BabyROS streams live video using BabyROS as the communication layer. Two scripts share responsibility: a camera server that owns the hardware connection, and a client that controls streaming remotely via BabyROS topics. Optionally, an advanced client wraps capture and streaming behind a small helper class so the rest of your application talks to the camera entirely over BabyROS.

Available on: IDS, Webcam.

The Skill ​

The camera class registers BabyROS topics under a base path derived from its class name and name:

medulla/camera/<ClassName>/<name>

<ClassName> is the concrete camera class, for example IDSU336L0CX or Webcam. Every started stream publishes its frames as Image datatypes on the stream topic. Clients start and stop streaming either by publishing to the start_stream and stop_stream topics, or by sending start / stop requests to the stream_control server. Advanced clients can also call the connect and capture servers for remote control.

Example ​

IDS

Webcam

The camera server (camera_loop.py) runs in Terminal 1 — it connects to the hardware and keeps BabyROS nodes alive. The client (publish_video_example.py) runs in Terminal 2 — it starts the stream, subscribes to the stream topic to receive and log frames to Rerun, then stops the stream after 10 seconds. The IDS client uses the stream_control server; the Webcam client publishes to start_stream / stop_stream.

The Code ​

Camera Server (Terminal 1) ​

python
"""
Camera loop for the IDS camera.
"""
import time

from loguru import logger

from babyros import node
from telekinesis.medulla.cameras import ids


def main():
    camera = None
    try:
        camera = ids.IDSU336L0CX(name="my_ids_camera")
        camera.connect(serial_number="4108615854")
        camera.set_parameter("OutputPixelFormat", "RGB_8")
        camera.set_parameter("ExposureAuto", "Off")
        camera.set_parameter("ExposureTime", 30000.0)
        camera.set_parameter("AcquisitionFrameRate", 20.0)
        logger.info("Camera Server is running... Press Ctrl+C to stop.")
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        logger.info("Shutting down server...")
    finally:
        if camera is not None:
            camera.disconnect()
            node.SessionManager.delete()
        logger.info("Completed cleanup.")


if __name__ == "__main__":
    main()
python
"""
Camera loop for the Webcam.
"""
import time

from loguru import logger

from babyros import node
from telekinesis.medulla.cameras import webcam


def main():
    camera = None
    try:
        camera = webcam.Webcam(name="my_webcam_camera")
        camera.connect(camera_id=0)
        logger.info("Camera Server is running... Press Ctrl+C to stop.")
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        logger.info("Shutting down server...")
    finally:
        if camera is not None:
            camera.disconnect()
            node.SessionManager.delete()
        logger.info("Completed cleanup.")


if __name__ == "__main__":
    main()

BabyROS Client (Terminal 2) ​

python
"""
Stream live video from an IDS camera over BabyROS.
"""
import time

from loguru import logger
import rerun as rr

from babyros import node
from telekinesis import datatypes


def log_video(image: datatypes.Image) -> None:
    rr.log("Continuous_Image_Capture", rr.Image(image.to_numpy(copy=False)))


def main():
    rr.init("IDS_Example", spawn=True)

    name = "my_ids_camera"
    base_topic = f"medulla/camera/IDSU336L0CX/{name}"

    stream_client = node.Client(topic=f"{base_topic}/stream_control")
    video_subscriber = node.Subscriber(topic=f"{base_topic}/stream", callback=log_video)

    try:
        stream_client.request(
            data={
                "stream_type": datatypes.String("image"),
                "stream_command": datatypes.String("start"),
            }
        )
        time.sleep(10)
        stream_client.request(data={"stream_command": datatypes.String("stop")})
    except KeyboardInterrupt:
        logger.info("Shutting down.")
    finally:
        rr.disconnect()
        stream_client.delete()
        video_subscriber.delete()
        node.SessionManager.delete()
        logger.info("Completed cleanup.")


if __name__ == "__main__":
    main()
python
"""
Stream live video from a webcam over BabyROS.
"""
import time

from loguru import logger
import rerun as rr

from babyros import node
from telekinesis import datatypes


def log_video(image: datatypes.Image) -> None:
    rr.log("Continuous_Image_Capture", rr.Image(image.to_numpy()))


def main():
    rr.init("Webcam_Example", spawn=True)

    name = "my_webcam_camera"
    base_topic = f"medulla/camera/Webcam/{name}"

    start_video_stream_publisher = node.Publisher(topic=f"{base_topic}/start_stream")
    stop_video_stream_publisher = node.Publisher(topic=f"{base_topic}/stop_stream")
    video_subscriber = node.Subscriber(topic=f"{base_topic}/stream", callback=log_video)

    try:
        start_video_stream_publisher.publish(data={})
        time.sleep(10)
        stop_video_stream_publisher.publish(data={})
    except KeyboardInterrupt:
        logger.info("Shutting down.")
    finally:
        rr.disconnect()
        start_video_stream_publisher.delete()
        stop_video_stream_publisher.delete()
        video_subscriber.delete()
        node.SessionManager.delete()
        logger.info("Completed cleanup.")


if __name__ == "__main__":
    main()

Running the Example ​

Start the server first, then the client. Both must run from a terminal.

Terminal 1:

bash
python camera_loop.py

Wait for Camera Server is running... Press Ctrl+C to stop., then:

Terminal 2:

bash
python publish_video_example.py

Frames stream under Continuous_Image_Capture for 10 seconds. Press Ctrl+C in Terminal 1 to shut down the server.


Advanced: Remote Camera Control with a Client Helper ​

The plain client only starts and stops streaming. To also capture single frames remotely, wrap the BabyROS nodes in a small client-side helper class. The example below targets the IDS server but the same pattern applies to any camera, since every camera registers the capture, stream, and stream_control topics.

The camera server (camera_loop.py) must be running first — see the Camera Server section above. Device parameters such as ExposureTime are set on the server side, before the loop starts.

python
"""
Capture a single image and stream live video over BabyROS via a client helper.
"""
import time

from loguru import logger
import rerun as rr
import numpy as np

from babyros import node
from telekinesis import datatypes


class IDSClient:
    """Helper class for communicating with the IDS camera over BabyROS."""

    def __init__(self, name: str) -> None:
        self._name = name
        self._base_topic = f"medulla/camera/IDSU336L0CX/{self._name}"

        self._capture_client = node.Client(topic=f"{self._base_topic}/capture")
        self._stream_client = node.Client(topic=f"{self._base_topic}/stream_control")

    def capture(self) -> np.ndarray:
        response = self._capture_client.request(
            data={"capture_type": datatypes.String("image")}
        )
        return response[0]["capture"].to_numpy()

    def start_stream(self) -> None:
        self._stream_client.request(
            data={
                "stream_type": datatypes.String("image"),
                "stream_command": datatypes.String("start"),
            }
        )

    def stop_stream(self) -> None:
        self._stream_client.request(data={"stream_command": datatypes.String("stop")})

    def delete(self) -> None:
        self._capture_client.delete()
        self._stream_client.delete()


def log_image(image: np.ndarray) -> None:
    rr.log("Single_Image_Capture", rr.Image(image))


def log_video(image: datatypes.Image) -> None:
    rr.log("Continuous_Image_Capture", rr.Image(image.to_numpy(copy=False)))


def main():
    rr.init("IDS_Example", spawn=True)

    camera = None
    video_subscriber = None
    try:
        name = "my_ids_camera"
        camera = IDSClient(name=name)
        base_topic = f"medulla/camera/IDSU336L0CX/{name}"

        video_subscriber = node.Subscriber(topic=f"{base_topic}/stream", callback=log_video)

        log_image(camera.capture())

        camera.start_stream()
        time.sleep(5)
        camera.stop_stream()
    except KeyboardInterrupt:
        logger.info("Shutting down.")
    finally:
        rr.disconnect()
        if camera is not None:
            camera.delete()
        if video_subscriber is not None:
            video_subscriber.delete()
        node.SessionManager.delete()
        logger.info("Cleanup complete.")


if __name__ == "__main__":
    main()

The constructor builds the base topic path from the camera class name and name — name must match exactly the name given to the server-side camera instance in camera_loop.py. It then creates a node.Client for each request-response interaction: /capture for single frames and /stream_control for starting and stopping the stream.

capture sends a request with capture_type set to "image", takes the first element of the response list (the server returns a list), and reads the capture field as an Image datatype, which is converted to a NumPy array with to_numpy(). start_stream and stop_stream send stream_command "start" / "stop" to /stream_control; the start request also names the stream_type. Frames arrive on the /stream topic. The video_subscriber is created before streaming starts to ensure no frames are missed in the window between start_stream and the first frame arriving.

The capture request also accepts "depth", "pointcloud", "rgbd", and "image_pointcloud" as capture_type for cameras that support them.

Run ​

Start camera_loop.py in Terminal 1 first, then:

bash
python advanced_example.py

A Rerun viewer opens showing the captured frame under Single_Image_Capture, followed by 5 seconds of video under Continuous_Image_Capture.

Parameter Configuration ​

ParameterTypeDefaultDescription
namestrrequiredCamera name given to the server-side camera instance. The client must reuse it unchanged to derive the same base topic (medulla/camera/Webcam/<name> or medulla/camera/IDSU336L0CX/<name>).
start_stream / stop_stream payloaddict{}The stream type defaults to "image" when the payload carries no stream_type, so an empty dict starts or stops the image stream.
stream_control request stream_commanddatatypes.Stringrequired"start" or "stop". Any other value is rejected by the server.
stream_control request stream_typedatatypes.String"image"Kind of stream to start: "image", "depth", "pointcloud", "rgbd", "image_pointcloud", or "stereo". Only the types the camera implements can be started.
capture request capture_typedatatypes.String"image"Kind of frame to capture: "image", "depth", "pointcloud", "rgbd", or "image_pointcloud".

Returns ​

TypeDescription
datatypes.ImageFrame delivered to the stream subscriber's callback. Convert it with image.to_numpy().
np.ndarraycapture() on the client helper returns the captured frame, converted from the capture field of the response.
Nonestart_stream() / stop_stream() on the client helper — nothing is returned.

Raises ​

ExceptionCondition
RuntimeErrorServer side — the camera skipped the frame for a one-shot capture request after a recoverable fault. Retry the request.
ValueErrorServer side — unknown capture_type or stream_type, or a stream_control request without a stream_command.

A started stream stops itself if the camera delivers no frame for an extended period, and disconnect() stops a running stream before releasing the device.

Where to Use the Skill ​

  • Distributed pipelines — keep the camera process pinned to the machine with USB access while running vision workloads on a different machine.
  • Multi-consumer streaming — multiple clients can subscribe to the same stream topic without duplicating hardware connections.
  • Remote capture — grab single frames from a control script while the camera server keeps the hardware connection open.