MPEG-4 is not lossless, at least it's not with the way VideoWriter
uses it here.
Try setting the profile
argument to 'Archival'
when creating the VideoWriter
(i.e. writerObj = VideoWriter(filename,profile)
);
profile
String enclosed in single quotation marks that describes the type of file to create. Specifying a profile sets default values for video properties such as
VideoCompressionMethod
. Possible values:
'Archival'
Motion JPEG 2000 file with lossless compression
'Motion JPEG AVI'
Compressed AVI file using Motion JPEG codec
'Motion JPEG 2000'
Compressed Motion JPEG 2000 file
'MPEG-4'
Compressed MPEG-4 file with H.264 encoding (systems with Windows 7 or Mac OS X 10.7 and later)
'Uncompressed AVI'
Uncompressed AVI file with RGB24 video
However, 'Archival'
will give a huge file, while 'MPEG-4'
will give the best compression-quality compromise, if your system supports H.264 encoding. For the lossy compression methods (e.g. 'MPEG-4'
or 'Motion JPEG AVI'
), using a higher Quality
setting will help the quality, but the pixel values will not be the same not matter high how the quality is set.
Note that with lossless compression, the Quality
option is not used.
NOTE: To count the number of different pixels without a loop:
count = sum(x(:)==y(:))