Create a video from frames taken 5 by 5
Afficher commentaires plus anciens
Hello, I have this function to create a video:
function [video] = writeBufferToFinalVideo(buffer,fps)
video = VideoWriter('prueba','MPEG-4');
video.FrameRate = fps;
open(video)
for i = 1:size(buffer,4)
img = buffer(:,:,:,i);
img(img>1) = 1;
img(img<0) = 0;
writeVideo(video,img);
end
close(video);
end
This function have it has a dimension buffer as input
frameBuffer = zeros (height, width, numChannels, framesPerSymbol)
where framePerSymbol will be the number of frames that my symbol lasts. In my case this number equals 5, so I will have 5 frames.
The idea is that from a video I take 5 by 5 frames as a FIFO queue and once I fill the frame buffer, I decide whether I can encode it or not, and once decided I create a video with those frames (if I know has been able to encode or not). This is the code I run it on:
frameBuffer = zeros(height,width,numChannels,framesPerSymbol);
framesInBuffer = 0;
while hasFrame(videoObject)
frame = double(readFrame(videoObject));
frameBuffer = shiftBuffer(frameBuffer,frame);
% We update the framesInBuffer counter
framesInBuffer = framesInBuffer + 1;
if framesInBuffer > framesPerSymbol
framesInBuffer = framesPerSymbol;
bypassEncoding = false;
else
bypassEncoding = true;
end
if ~bypassEncoding
if canWeEncode(frameBuffer,alpha,threshold) % Frames with code
encodedBuffer = steganographicEncoding(frameBuffer,width,height,codeRows,codeCols,alpha,sigma);
writeBufferToFinalVideo(encodedBuffer,100);
else % Only Frames without code
writeFrameToFinalVideo(squeeze(frameBuffer(:,:,:,1)));
end
end
end
Finally you should get a video with the same length as the original. ShiftBuffer will be in charge of taking the frames from 5 to 5 as a FIFO queue.
2 commentaires
Geoff Hayes
le 20 Avr 2020
Alberto - what is your question? Or have you posted code that you think others would be interested in?
Alber
le 20 Avr 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Track Objects and Estimate Motion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!