tags:

views:

142

answers:

3

Hi,

I created a video recorder which stores recording to a file. I would like to implement a method which would read the file each second, compare the current file with the old value (1 second older) and write the difference to a separate file.

I would be very thankful if anyone could explain how to do that or write a simple example. I guess there has to be a thread which compares the new value with the old one by calling a custom method compareFiles(File currentFile, File oldFile) on a given period of time. The old file could also be saved as a temporary file and the current file at the original path could be compared with temporary file.

Any suggestion about the improvement of the described logic is more than welcome!

A: 

You will have too many different data for video file because of having non-perfect (physically non-perfect) camera. I doubt you could use general DIFF algos for video stream comparing.

FractalizeR
A: 

it sounds like you are trying to do motion detection. the basic idea is to extract the pixels from two frames, so you get:

int p1[],p2[];

then, convert them to gray scale, and then you substract one from the other:

int diff[] = new int[pixels1.length];
for(int i=0;i<pixels1.length;i++) diff[i] = Math.abs(p1[i] - p2[i]);

the thing is, that due to jpeg compression etc, two subsequent images will not be identical even if nothing changed. so you want to look for pixels greater than some threshold. if you found them you have motion.

this approach will not work if your camera is moving because then you all have motion in all pixels.

Omry
A: 

You should take a look at how http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome does this things. The noise will be a BIG problem if you try to do a simple "one-to-ne" diff...

Quamis