Record RTSP Camera stream with VideoCapture on Pi C++


I am trying to record a rtsp camera stream which is connected to my Pi via ethernet.
Using ffmpeg command in ssh with rtsp-link works fine.
Testing the code (cap = cv::VideoCapture(rtsplink)) it returns false for cap.isOpened().
I worked through several approaches and still cannot solve the problem.
Most possible solutions were:
ffmpeg license

also copying ffmpeg*.dll

Happy to hear from you and tell me if you need more details.


Well, VideoWriter is a class for writing wideos, not capturing (recording) them…

I accidentally wrote Writer in here but I use Capture in my Code. sry

yes, we do need a MRE.

you must ensure that ANYTHING you replace for privacy reasons MUST still cause the issue to be reproducible.

ideally you’d run an rtsp server that is reachable on the internet, so we can test. that may not be needed though.

Hi thanks for your response!

so the code:

void Camera::mainThread() {
cv::Mat myImage;
cv::VideoCapture cap(“rtsp://admin:password@”);
if (!cap.isOpened()) {
spdlog::info(“Camera not connected”);
} else {

the ffmpeg command I used in ssh:
ffmpeg -i rtsp://admin:password@ -c copy -map 0 -f segment -segment_time 5 -reset_timestamps 1 -segment_format mp4 /home/pi/anotherTest%08d.mp4

compiler on Pi is GCC
Camera used: Reolink RTC 410
I cloned the whole OpenCV to my CMAKE packages.

I also tried cv::VideoCapture cap(“rtsp://admin:password@”);

print cv::getBuildInformation() and check the Video I/O section. that’s build-time info. if the DLLs aren’t there at runtime, you’ll have more problems.

test that ffmpeg is available to OpenCV at runtime by trying to read a known good local video file, while forcing apiPreference=CAP_FFMPEG in the VideoCapture constructor