LWN.net Logo

motion detection is not as easy as it should be

motion detection is not as easy as it should be

Posted Oct 25, 2012 11:24 UTC (Thu) by njs (guest, #40338)
In reply to: motion detection is not as easy as it should be by amtota
Parent article: Wayland and Weston 1.0 released

The X server may or may not know about scrolling (it depends on which APIs the client is using), and the interface to expose this would be a nightmare... plus scrolling is an extremely trivial sort of motion to detect (integer number of pixels with absolutely unchanged contents). Why not just write some motion detection code?

Both sides of the connection have the old window contents available (though the server may not keep it in memory right now). A cheap-but-effective algorithm would be: Break this into fixed size chunks (say 16x16 pixels), discard solid-color ones, and hash the remaining with a rolling hash. When you get a new region to send, first run the rolling hash over this region to see if there are any matches. If so, align the new data with the matching old data, subtract, and send the offset + the difference (which will be highly compressible). Then the client inverts this to reconstruct. This will be effective even if some parts of the region are changing at the same time they scroll, new bits of the window are scrolling onto screen, etc., and the computational overhead would still be absolutely swamped by gzip, never mind vpx/x264.


(Log in to post comments)

motion detection is not as easy as it should be

Posted Oct 25, 2012 15:34 UTC (Thu) by renox (subscriber, #23785) [Link]

>Why not just write some motion detection code?

Because the more complex compression you do, the more latency you add..

motion detection is not as easy as it should be

Posted Oct 25, 2012 19:33 UTC (Thu) by njs (guest, #40338) [Link]

Yes, that's why I made a point of describing an algorithm that should only add a tiny amount of overhead on top of the existing gzip cost, and less than the super-fancy video encoders that are already used? Detecting simple scrolling is really not complicated.

motion detection is not as easy as it should be

Posted Oct 25, 2012 19:51 UTC (Thu) by hoegsberg (guest, #57768) [Link]

Yeah, and we're working on more or less the exact rolling hash idea you described. It was kinda weird to see you describe the same approach here... It's still work in progress, but there's a few PNGs here that shows the current status: http://people.freedesktop.org/~krh/rolling-hash/

With just a few MULs per pixel, we can detect if a 32x32 blocks starting at that pixel appears in the previous frame. This should basically be as good as any scrolling/copyarea hint we could've gotten from X or a toolkit, and it detects duplicate blocks in may cases where applications don't scroll but just re-render (like resizing). And of course this technique applies to both fullscreen remote display or per-window remote display.

motion detection is not as easy as it should be

Posted Oct 25, 2012 21:07 UTC (Thu) by njs (guest, #40338) [Link]

Hah, awesome. Well, I guess it's the obvious thing to try...

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds