I am using some code to read a video and then write the video again to a file. I will do some manipulation before i write it, but for now lets say we only want to write it back to disk.
But the video i am writing, whatever setting i use for videowriter, i can never get the same size of video ( size increases in disk or changes, and it also changes in pixel values. I can get the exact same pixel values, but only when writing uncompressed avi and this is multiplying the file size of the written file )
My original video is jpeg compressed but i dont know any more details about it, so i will use here the default traffic.avi matlab video which is also compressed.
If i use option Uncompressed avi i will get exact same pixel values, but times x the original filesize. If i use Motion JPEG AVI i will get a bit bigger filesize than original and also no matching pixel values...
Is there a way to write video using VideoWriter and some combination of properties to get the exact same pixel values and exact same file size as the original input?
I cant believe that this cannot happen in matlab.
This is and example code i am using with a default matlab file ( avi file can be also find at toolbox - images -imdata to check the size if you want )
i use this function ( its an official example matlab function ) to read video and the code below to do what i am trying to do
function video = readVideo(filename)
vr = VideoReader(filename);
H = vr.Height;
W = vr.Width;
C = 3;
numFrames = floor(vr.Duration * vr.FrameRate);
video = zeros(H,W,C,numFrames);
i = 0;
i = i + 1;
video(:,:,:,i) = readFrame(vr);
if size(video,4) > i
video(:,:,:,i+1:end) = ;
Vptr = VideoReader('traffic.avi');
writer = VideoWriter('delete_me.avi', 'Motion JPEG AVI');
writer.FrameRate = Vptr.FrameRate;
frameCounter = 1;
thisFrame = readFrame(Vptr);
frameCounter = frameCounter + 1;
video = readVideo('traffic.avi');
video2 = readVideo('delete_me.avi');