Recording simultaneous video from 2 cameras

조회 수: 6 (최근 30일)
Frederik Vogel
Frederik Vogel 2023년 10월 23일
댓글: Frederik Vogel 2023년 11월 15일
For a project i need to record 2 IP cam video streams and wonder on how to accomplish that since the image aquisition explorer only allows me to use one camera at a time.
Cheers!

답변 (1개)

Saffan
Saffan 2023년 10월 30일
Hi Frederik,
I understand that your goal is to simultaneously record two video streams from two separate IP cameras. This can be achieved using the “ipcam” function, which facilitates the acquisition of video data from IP cameras.
Here is a code snippet that demonstrates this:
% Create the ipcam objects
cam1 = ipcam('address1');
cam2 = ipcam('address2');
% Capture one frame to get its size
frame1 = snapshot(cam1);
frame2 = snapshot(cam2);
[frameHeight1, frameWidth1, ~] = size(frame1);
[frameHeight2, frameWidth2, ~] = size(frame2);
% Create video writer objects
outputVideo1 = VideoWriter('cam1.avi');
outputVideo2 = VideoWriter('cam2.avi');
open(outputVideo1);
open(outputVideo2);
duration = 100;
tic;
while toc < duration
writeVideo(outputVideo1, snapshot(cam1));
writeVideo(outputVideo2, snapshot(cam2));
end
% Close the video writer objects
close(outputVideo1);
close(outputVideo2);
Please refer to the following documentation for more information:
Hope this helps!
  댓글 수: 2
Frederik Vogel
Frederik Vogel 2023년 11월 15일
Hey Saffan!
first of all thank you for your response. Because i am adressing my cams slightly different this is the code i get
% Create the ipcam objects
cam1 = videoinput("gentl", 1, "BayerBG8");
cam2 = videoinput("gentl", 2, "Mono8");
% Capture one frame to get its size
frame1 = getsnapshot(cam1);
frame2 = getsnapshot(cam2);
[frameHeight1, frameWidth1, ~] = size(frame1);
[frameHeight2, frameWidth2, ~] = size(frame2);
% Create video writer objects
outputVideo1 = VideoWriter('cam1.avi');
outputVideo2 = VideoWriter('cam2.avi');
open(outputVideo1);
open(outputVideo2);
duration = 100;
tic;
while toc < duration
writeVideo(outputVideo1, getsnapshot(cam1));
writeVideo(outputVideo2, getsnapshot(cam2));
end
% Close the video writer objects
close(outputVideo1);
close(outputVideo2);
sadly this does not seem to work as the files created did not work as an avi video. also matlab gave me a warning for every single frame
Warning: No video frames were written to this file. The file may be invalid.
Warning: No video frames were written to this file. The file may be invalid.
Also i do not quite understand the difference between snapshot and getsnapshot.
I hope my response is somewhat helpful.
Thank you in advance!
Frederik Vogel
Frederik Vogel 2023년 11월 15일
PS: i need the gentl adapter for my cameras to work for some obscure reason

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for IP Cameras에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by