Clear Filters
Clear Filters

Recording simultaneous video from 2 cameras

9 views (last 30 days)
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!

Answers (1)

Saffan
Saffan on 30 Oct 2023
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 Comments
Frederik Vogel
Frederik Vogel on 15 Nov 2023
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 on 15 Nov 2023
PS: i need the gentl adapter for my cameras to work for some obscure reason

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!