Hello, I have this function to create a video:
function = 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);endclose(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 endend
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.
Best Answer