Hacker News new | ask | show | jobs
by darkteflon 1242 days ago
So, if I write a script that takes screenshots of my desktop every minute or so, are there any tools out there I could use to “de-dupe” based on some arbitrary threshold of similarity to existing screenshots? I imagine it would be quite straightforward for identical screenshots, but what about stuff that’s just “mostly unchanged”?
5 comments

A very low tech approach would be to create a video from the screenshots, and let the video codecs do this for you. Av1/x265 are quite mature in detecting differences between frames.
I agree that's not a bad starting point, but it should be possible to do a lot better than this because a screenshot will often be very similar to an earlier one that's not the previous one. For example, repeatedly switching between a few views. Video codecs are optimized for (a) streams that rarely go back to an earlier pattern, (b) minimal ongoing memory usage, and (c) realtime decompression, so they aren't going for quite the same use case.
Even h264, which is way over a decade old, can reference frames that are further back than the last one. And it supports lossless. Now the only thing to research is if those two features can be used together and how many frames back it can reference.
See my other post here: https://news.ycombinator.com/item?id=34566857

I wrote a DB for PNG files which deduplicates PNG blocks (only exact matchs): https://github.com/albertz/png-db

I imagine that compressing the screenshots daily with something like gzip would do the magic for screenshots. A lot of the image would be repeated anyway, task bar, active windows, background, etc.

A good question would be if you screenshot your screen twice in a very small time, how much of the binary would be the same? Are the tools and PNG reproducible enough to dedupe most of the second file on gzip?

I've had a lot of success using the pixelmatch library for image comparison / deduping

https://github.com/mapbox/pixelmatch

Thank you, that looks perfect.

> “pixelmatch is around 150 lines of code, has no dependencies…”

* Except hundreds of megabytes of Node.js
Recording the whole screen using H.264 or similar at a low frame rate might be easier.