This gist shows how to extract motion from a video using the method described by Posy in https://www.youtube.com/watch?v=NSS6yAMZF78
To get the motion from a video by comparing each frame to the one 5 frames later:
./motionextractor.sh input.mp4 5 output.mp4
To compare to the first frame: