How do I create a video mp4 output from the following code?
Show older comments
I am using Video Stabilization Using Point Feature Matching - MATLAB & Simulink (mathworks.com) code to stabilze a video. I am wanting to adapt it for my own use. The code uses the Computer Vision Toolbox video player, but I would like to have an mp4 output rather than just the MATLAB videoplayer that only works 20% of the time. Below is the code (Step 6 of the link) I want to change. I am not quite sure how to create an MP4 output.
% Reset the video source to the beginning of the file
read(hVideoSrc,1);
hVPlayer = vision.VideoPlayer; % Create video viewer
% Process all frames in the video
movMean = rgb2gray(im2single(readFrame(hVideoSrc)));
imgB = movMean;
imgBp = imgB;
correctedMean = imgBp;
ii = 2;
cumulativeTform = simtform2d;
while hasFrame(hVideoSrc) && ii < 10
% Read in new frame
imgA = imgB; % z^-1
imgAp = imgBp; % z^-1
imgB = rgb2gray(im2single(readFrame(hVideoSrc)));
movMean = movMean + imgB;
% Estimate transformation from frame A to frame B, and fit as an s-R-t
tformAffine = cvexEstStabilizationTform(imgA,imgB);
sRtTform = cvexTformToSRT(tformAffine);
cumulativeTform = simtform2d(cumulativeTform.A * sRtTform.A);
imgBp = imwarp(imgB,cumulativeTform,OutputView=imref2d(size(imgB)));
% Display as color composite with last corrected frame
step(hVPlayer,imfuse(imgAp,imgBp,ColorChannels='red-cyan'));
correctedMean = correctedMean + imgBp;
ii = ii+1;
end
correctedMean = correctedMean/(ii-2);
movMean = movMean/(ii-2);
% Here you call the release method on the objects to close any open files
% and release memory.
release(hVPlayer);
Accepted Answer
More Answers (0)
Categories
Find more on Detect, Extract, and Match Features in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!