Recording video from three webcams with app designer

조회 수: 35(최근 30일)
Genevieve Pounds
Genevieve Pounds 2021년 1월 26일
답변: Tatiana Leon 2021년 9월 5일
Hi All,
Posting again with more tags.
I am trying to create a simple MatLab app using the app designer. I have three USB webcams (named ANT, POST and MED) plugged into my laptop which have a resolution of 1080 x1920. The goal is to press a record button so a 5 second video records simultaneously from each camera at at least 25 fps.
I have posted the app and the 'push record button' callback code below:
I find the videos record and save to the current folder, however, the playback speed and duration of the videos is really variable and usually not 5 seconds.
Sometimes MatLab crashes and sends an error message that there is insufficient physical memory. My laptop has 16GB of RAM, however, having matlab open as well as running the app does use a lot.
I have tried packaging the app so it is a standalone .exe to use less RAM, however, this doesnt seem to work. Is this because without MatLab open, the app does not have a folder to store the output videos in? If so, how can I tell a standalone app to save files to a specific folder? would I have to add a browse folder box?
Also is the code incorrect? Do I need to set the individual properties of each video object? Or can a loop be used to make the code more succinct?
Any help much appreciated.
Many thanks.
The app looks like this:
My code for the properties and the record button pushed callback is:
properties (Access = private)
AntCam = videoinput('winvideo',2); % Description
PostCam = videoinput('winvideo',3); % Description
MedCam = videoinput('winvideo',4); % Description
% Button pushed function: RECORDButton
function RECORDButtonPushed(app, event)
%% Set Properties for Videoinput AntCam
app.AntCam.TimeOut = Inf;
app.AntCam.FrameGrabInterval = 1;
app.AntCam.LoggingMode = 'disk&memory';
app.AntCam.FramesPerTrigger = 1;
app.AntCam.TriggerRepeat = Inf;
app.AntCam.TimerPeriod = 5;
%% Set Properties for Videoinput PostCam
app.PostCam.TimeOut = Inf;
app.PostCam.FrameGrabInterval = 1;
app.PostCam.LoggingMode = 'disk&memory';
app.PostCam.FramesPerTrigger = 1;
app.PostCam.TriggerRepeat = Inf;
app.PostCam.TimerPeriod = 5;
%% Set Properties for Videoinput MedCam
app.MedCam.TimeOut = Inf;
app.MedCam.FrameGrabInterval = 1;
app.MedCam.LoggingMode = 'disk&memory';
app.MedCam.FramesPerTrigger = 1;
app.MedCam.TriggerRepeat = Inf;
app.MedCam.TimerPeriod = 5;
%% Construct VideoWriter objects and set Disk Logger Properties
vidWriterAnt = VideoWriter(([app.Date, app.Sample, app.Filename, 'ANT']),'MPEG-4');
vidWriterPost = VideoWriter(([app.Date, app.Sample, app.Filename,'POST']),'MPEG-4');
vidWriterMed = VideoWriter(([app.Date, app.Sample, app.Filename, 'MED']),'MPEG-4');
vidWriterAnt.Quality = 50;
vidWriterAnt.FrameRate = 25;
app.AntCam.DiskLogger = vidWriterAnt;
vidWriterPost.Quality = 50;
vidWriterPost.FrameRate = 25;
app.PostCam.DiskLogger = vidWriterPost;
vidWriterMed.Quality = 50;
vidWriterMed.FrameRate = 25;
app.MedCam.DiskLogger = vidWriterMed;
app.AntCam.TimerFcn = {'stop'};
app.PostCam.TimerFcn = {'stop'};
app.MedCam.TimerFcn = {'stop'};
clear app.AntCam
clear app.PostCam
clear app.MedCam
  댓글 수: 2
Genevieve Pounds
Genevieve Pounds 2021년 1월 27일
Hi Geoff,
Thankyou for your comment.
I tried the first camera with the code you posted above and it worked fine, thankyou.
I then added the second camera and the code ran, however, the second camera video filmed for 7 seconds rather than 5 seconds. In addition, the trigger for the two cameras was not simultaneous. It seems the first camera always triggers slightly before the second.
When adding the third camera, videos were logged from each device, however, MatLab crash reporter popped up after running the app and closed MatLab. Sometimes the videos from the second and third cameras recorded for ~20 seconds. However, the video for the first camera was around 5 seconds. The triggers were also slightly out of sync.
I found that running the code as a script rather than a MatLab app meant that MatLab did not crash but the same issues with video time/sync occured.
Is it possible that the cameras are struggling to reach the set framerate, therefore, the time of the video is being extended and the TimerFcn is being ignored, to compensate for that?
Many thanks,

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


Tatiana Leon
Tatiana Leon 2021년 9월 5일
I have a mistake
Undefined function 'videoinput' for input arguments of type 'char'.
Can somebody help me

Community Treasure Hunt

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

Start Hunting!

Translated by