Question

I would like to extend my project on image watermarking to video, using prediction and sorting method.For that, in simple words, I want to process each frame, make some changes in the pixel values at sender side, reconstruct the video from the modified frames and want to revoke all those changes in pixels at the receiver side. My problem is that when the video is reconstructed after editing the frames the pixel values change again. i tested it with the code given below. ( i didnt make any modification to pixels, just read from the first video, write that frames to another video in same format and checked the pixel values of 1st frames of both videos)

readerobj = VideoReader('produce.mp4');
vidFrames = read(readerobj);
numFrames = get(readerobj, 'NumberOfFrames')

outputVideo = VideoWriter('produce_new','MPEG-4');
outputVideo.FrameRate = readerobj.FrameRate;
open(outputVideo);
q=1;
x=read(readerobj,q);
for q=1:numFrames
    frames=read(readerobj,q);
    frame_store=frames;
    writeVideo(outputVideo,frame_store); 
end

close(outputVideo);

readerobj = VideoReader('produce_new.mp4');
vidFrames = read(readerobj);
numFrames = get(readerobj, 'NumberOfFrames')
q=1;
y=read(readerobj,q);
count=0;

for i=1:size(x,1)
     for j=1:size(x,2)
          if x(i,j)~=y(i,j)
             count=count+1;
          end 
     end

end count

the value of count, which indicate the number of pixels underwent a change in value after video reconstruction is huge. In fact, for my code to work correctly, no pixel value should be changed. Is there a solution to this?

Was it helpful?

Solution

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(:))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top