How to use start and stop buttons to save video in app designer?

4 views (last 30 days)
I am trying to create an app that will start recording video when the user presses 'start' and ends and saves the video when the user presses 'stop'.
Right now, the buisness part of my code looks a bit like this:
function StartCameraButtonPushed(app, event)
% preview video feed
app.vidObj = videoinput("winvideo", 1, "YUY2_1280x960");
app.vidObj.LoggingMode = 'disk';
vidImage = image(app.UIAxes,zeros(960,1280,3)); %If image resolution is 1280x960
preview(app.vidObj,vidImage);
end
% Button pushed function: StartRecordingButton
function StartRecordingButtonPushed(app, event)
app.vidWriteObj = VideoWriter('myVidFile.avi');
set(app.vidObj,'DiskLogger', app.vidWriteObj);
start(app.vidObj);
end
% Button pushed function: StopRecordingButton
function StopRecordingButtonPushed(app, event)
stop(app.vidObj);
app.vidWriteObj = get(app.vidObj, 'DiskLogger');
end
The video preview works, and 'myVidFile.avi' is created, but it is only one frame. What do I need to add besides the start() and stop() commands to make this work as intended?

Accepted Answer

Jessica West
Jessica West on 31 Oct 2023
Got it! Needed to add
app.vidObj.FramesPerTrigger = Inf;
and
recordedData = getdata(app.vidObj, app.vidObj.FramesAvailable);
See attached file for complete solution.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!