Enter values into a FIFO array

14 views (last 30 days)
Alber
Alber on 20 Apr 2020
Edited: Alber on 22 Apr 2020
Hello,
I have an array called
frameBuffer = zeros (height, width, numChannels, framesPerSymbol);
and a video. The parameters of the frameBuffer are height, width, number of color channels and framesPerSymbol, which will be the number of frames that my symbol lasts.My goal is to insert frames of the video in the array as if it were a FIFO queue, that is, if framesPerSymbol is 5:
F = frames E = empty
1) E E E E E
2) F E E E E
3) F F E E E
4) F F F E E
5) F F F F E
6) F F F F F
Thanks in advance.

Accepted Answer

Mehmed Saad
Mehmed Saad on 20 Apr 2020
Edited: Mehmed Saad on 20 Apr 2020
I think you are trying to save last five frames in a buffer, but a for loop is not required for that purpose
frameBuffer=zeros (height, width, numChannels, framesPerSymbol);
framesInBuffer = 0;
While loop
while hasFrame(videoObject)
frame = double(readFrame(videoObject));
I made a change here
frameBuffer = shiftBuffer(frameBuffer,frame);
framesInBuffer = framesInBuffer + 1;
if framesInBuffer > framesPerSymbol
framesInBuffer = framesPerSymbol;
bypassEncoding = false;
else
bypassEncoding = true;
end
if ~bypassEncoding
if canWeEncode(frameBuffer,alpha,threshold)
encodedBuffer = steganographicEncoding(frameBuffer,width,height,codeRows,codeCols,alpha,sigma);
writeBufferToFinalVideo(encodedBuffer,100);
else
writeFrameToFinalVideo(squeeze(frameBuffer(:,:,:,1)));
end
end
end
and a change here
function frameBuffer = shiftBuffer (frameBuffer,frame)
frameBuffer = circshift(frameBuffer,1,4);
frameBuffer(:,:,:,1) = frame;
end
  1 Comment
Alber
Alber on 20 Apr 2020
Edited: Alber on 20 Apr 2020
Yes, my idea is that when the buffer is full, to see if I can encode and after this is done it will take me another 5 frames, so until I complete all the frames of the video and can you explain this part?
function frameBuffer = shiftBuffer (frameBuffer,frame)
frameBuffer = circshift(frameBuffer,1,4);
frameBuffer(:,:,:,1) = frame;
end
I want to take 5 frames, I encode (the whole loop below) and I will take another 5, like this until I complete all the frames of the video.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!