How to use start and stop buttons to save video in app designer?
4 views (last 30 days)
Show older comments
Jessica West
on 30 Oct 2023
Answered: Jessica West
on 31 Oct 2023
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?
1 Comment
Image Analyst
on 31 Oct 2023
If you have any more questions, then attach your .mlapp file with the paperclip icon after you read this:
Accepted Answer
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!