Borrar filtros
Borrar filtros

Saving Live video input to avi file

1 visualización (últimos 30 días)
Cordelia David
Cordelia David el 5 de Jun. de 2019
Editada: Cordelia David el 6 de Jun. de 2019
I'm having trouble recording frames from a live video and saving each frame to a playable avi file. I get the error "Operands to the || and && operators must be convertible to logical scalar values."
I'm using Matlab 2018a version, and the video input is using a frame grabber device with serial and cameralink connection.
% Specifies the Range of Interest
if exist('ROI','var') % Becomes True if the ROI variable was assigned in the function
CurROI = vid.ROIPosition; % Specifies Region of Interest(ROI) window
vid.ROIPosition = [max(0,ROI(1)),max(0,ROI(2)),min(ROI(3),CurROI(3)),min(ROI(4),CurROI(4))]; % Creates boundaries for ROI window
end
% Creates a video file from an array or file of images
diskLogger = VideoWriter(FileNameVideo,'Uncompressed AVI'); % VideoReader
diskLogger.FrameRate = 10; % Sets the framerate of the recorded and saved avi video file
set(vid,'Timeout',50);
% Starts the video
open(diskLogger);
preview(vid);
start(vid); % Triggers the acquisition of the live video
data = getdata(vid,vid.FramesAvailable,'uint8');
writeVideo(diskLogger,data)
implay(data);
%Close, stop, and end the video
close(diskLogger); % Closes the file the video was saved to
stop(vid); % Stops the triggering of the live camera feed
stoppreview(vid)
I had an earlier version that showed the same error.
for ii = 1:numFrames % Loops through each frame of the live camera feed saved
writeVideo(diskLogger, data(:,:,:,ii)); % writes each frame of the live feed to a video file
end
This replaced the writevideo line. IF there is any solution to this, I need it as soon as possible. Any ideas?
  7 comentarios
Cordelia David
Cordelia David el 6 de Jun. de 2019
Thank you Walter I'll give this a try!
Cordelia David
Cordelia David el 6 de Jun. de 2019
Editada: Cordelia David el 6 de Jun. de 2019
After implementing the manual trigger and wait period the software worked very well for some cameras, however sometimes I get the error
Error using imaqdevice/wait (line 120)
WAIT reached its timeout before OBJ stopped running.
Error in Video_File (line 46)
wait(vid,10); % Delays saving video so images have been acquired
Error in InitializationScript (line 57)
Video_File(vid, NumFrames, FileNameVideo, ROI ,Pattern); % Function will play and save the
live camera feed to an avi video file and delete from the Matlab workspace
I tried lengthening the wait time period or stopping the video before the wait command, but that doesn't seem to work. Is this a problem with the output of my camera, or with the code?
The code:
diskLogger = VideoWriter(FileNameVideo,'Uncompressed AVI');
diskLogger.FrameRate = 30; % Sets the framerate of the recorded and saved avi video file
set(vid,'Timeout',50);
open(diskLogger);
preview(vid); % Opens a window with a preview of the video
start(vid); % Starts the video
stoppreview(vid);
trigger(vid); % Triggers the acquisition of the live video
wait(vid,10); % Delays saving video so images have been acquired
data = getdata(vid,vid.FramesAcquired,'uint8');
writeVideo(diskLogger,data)
implay(data);
Edit: After reading information about the command wait() I realized I wasn't acquiring all images I had commanded the triggers to acquire because of a delay between when the camera started sending frames and my code started acquiring and saving it. To fix this, I simply added 100 frames to the number of frames the camera would send, so it was a little extra than what my code would acquire. There's probably a simpler and easier way to do this, but hey, it works.
Thank you for all the help and time @Walter Roberson, your answers helped immensely!

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by