Recording simultaneous video from 2 cameras

9 ビュー (過去 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 Center および File ExchangeMATLAB 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