Hey Syed,
I understand that your query is to create a MATLAB App that lets you record a video while also showing you the preview of what is recorded within the app.
To achieve this, we can createa a private property that holds a webcam object. This object can then be used to both preview the video onto a UIAxes component while also being used by the Video Writer to write the video to video file.
The following code demonstrates this approach:
classdef recorder < matlab.apps.AppBase
properties (Access = public)
properties (Access = private)
isRecording logical = false
methods (Access = public)
function updateLiveFeed(app)
frame = snapshot(app.cam);
image(app.UIAxes, frame);
writeVideo(app.videoWriter, frame);
methods (Access = private)
app.timer = timer('ExecutionMode', 'fixedRate', 'Period', 1/60, ...
'TimerFcn', @(~,~) updateLiveFeed(app));
function RecordRecordButtonPushed(app, event)
app.RecordButton.Text = 'Stop';
app.videoWriter = VideoWriter('recordedVideo.avi');
app.RecordButton.Text = 'Record';
methods (Access = private)
The app interface should look as follows:
Once you record a video, you can see it show up in the same directory as the app:
You can refer to the documentation of Video Writer below:
Also, to use the webcam, ensure that you have MATLAB Support Package for USB Webcams Add On package installed. You can find the link to the Add On below: