How to record multiple videos using the same webcam input video?

1 view (last 30 days)
%code start
background = imread('background.jpg');
motionThreshold = 200;
vid = videoinput('winvideo', 2, 'MJPG_1024x768');
set(vid, 'FrameRate','12');
triggerconfig(vid,'manual');
set( vid, 'FramesPerTrigger', 60 );
set(vid, 'LoggingMode', 'disk')
for c = 1 : 10
lognumber = int2str(c);
logname = strcat('log',lognumber);
frameLogFile = VideoWriter(logname,'Motion JPEG AVI');
vid.Disklogger = frameLogFile;
start(vid);
%motion detection part
while (getsnapshot(vid)-background) < motionThreshold
end
trigger(vid);
end
%end of code
Okay, so I am trying to do this project whereby I have a single webcam video input, and once there is motion detected, I want to record 5 seconds of video. So I am hoping that the camera can trigger and record a separate video every time there is new motion detected. But I am having some problems.
A few questions : 1. For webcams right, do they have a fixed or adjustable framerate? Or does it vary according to the image being captured?
2.About the disklogger function, I keep having an error that it cannot be executed if vid is running, is there a way to overcome this error?
3. If I use a manual trigger, and if I use start(vid), without triggering, does it mean vid is running but not logging? Does this mean that there is a video input, just that no video is actually getting recorded?
4. How do I get matlab to save the videos in the form 'log1','log2',etc.
5. Also, is it necessary to do start(vid) delete(vid) close(vid) for each iteration of c?
Sorry if I misunderstand some things, I am pretty new to matlab; thanks for the help!

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!