roboflow / inference

A fast, easy-to-use, production-ready inference server for computer vision supporting deployment of many popular model architectures and fine-tuned models.
https://inference.roboflow.com
Other
1.3k stars 116 forks source link

Can I stream the video with bounding boxes as an RTSP stream to a server? #428

Closed rj-indro closed 4 months ago

rj-indro commented 4 months ago

Search before asking

Question

I have a model running that can detect doors. It consumes a RTSP stream for the video source then renders bounding boxes in a popup locally. I was wondering if it is possible to restream also as an RTSP stream to a server I already have set up.

I have looked into gstreamer and ffmpeg but I am not having much luck. Thanks!

Additional

No response

grzegorz-roboflow commented 4 months ago

Hi @rj-indro, inference does not deliver such functionality out of the box, however you could pipe annotated frames to ffmpeg which then can stream them back through RTSP.

import os

import cv2

os.mkfifo(path="/path/to/pipe")
pipe = open(file="/path/to/pipe", mode="wb", buffering=0)

# somewhere in your code, i.e. in custom_sink
# assuming frame was already scaled to known resolution, i.e. 1280x720
annotated_frame_bytes = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB).tobytes()
pipe.write(annotated_frame_bytes)

Then in another terminal:

# assuming 10 fps at source
ffmpeg -f rawvideo -video-size 1280x720 -r 10 -i /path/to/pipe -f flv rtsp://your_destination
grzegorz-roboflow commented 4 months ago

hi @rj-indro, I hope example above was helpful. I will close this issue but please feel free to reopen it if you have more questions.