# Record RTSP Camera stream with VideoCapture on Pi C++

**URL:** <https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885>\
**Category:** C++\
**Tags:** raspberrypi, rtsp\
**Created:** [November 9, 2022, 8:26am UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885 "2022-11-09T08:26:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![convolut](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@convolut](https://forum.opencv.org/u/convolut)\
**Post date:** [November 9, 2022, 8:26am UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885/1 "2022-11-09T08:26:32Z")

</div>

Hey,

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](https://stackoverflow.com/questions/30230223/how-to-build-a-portable-program-by-visual-studio)

or  
[also copying ffmpeg\*.dll](https://stackoverflow.com/questions/62288640/cant-grab-frames-from-an-ip-camera-rtsp-with-a-c-dll-using-opencv-3-4-5?rq=1)

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

Cheers

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [November 9, 2022, 9:34am UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885/2 "2022-11-09T09:34:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![convolut](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@convolut](https://forum.opencv.org/u/convolut)\
**Post date:** [November 9, 2022, 9:49am UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885/3 "2022-11-09T09:49:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [November 9, 2022, 6:58pm UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885/4 "2022-11-09T18:58:53Z")

</div>

yes, we do need a [MRE](https://stackoverflow.com/help/minimal-reproducible-example).

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.

---

<div class="post-metadata">

**Author:** ![convolut](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@convolut](https://forum.opencv.org/u/convolut)\
**Post date:** [November 10, 2022, 9:19am UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885/5 "2022-11-10T09:19:43Z")

</div>

Hi thanks for your response!

so the code:

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

the ffmpeg command I used in ssh:  
ffmpeg -i rtsp://admin:password@172.16.1.150:554/h264Preview\_01\_main -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.

---

<div class="post-metadata">

**Author:** ![convolut](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@convolut](https://forum.opencv.org/u/convolut)\
**Post date:** [November 16, 2022, 8:29am UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885/6 "2022-11-16T08:29:32Z")

</div>

I also tried cv::VideoCapture cap(“rtsp://admin:password@172.16.1.150:554/h264Preview\_01\_main”);

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [November 16, 2022, 10:45am UTC](https://forum.opencv.org/t/record-rtsp-camera-stream-with-videocapture-on-pi-c/10885/7 "2022-11-16T10:45:37Z")

</div>

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
