Periodically I’ve been seeing the 346.47 driver hang when playing video on a GTX 980. Everything freezes for a good 10 seconds or so, then resume for an instant, then freeze up again. This shows up in the kernel log when this happens:
I thought so too, and tried disabling acceleration and using a different video mode but I was still getting issues with VLC, however, a lot less frequently.
Maybe the same problem as mine: https://devtalk.nvidia.com/default/topic/825049/linux/compiz-crash-with-recent-nvidia-drivers/
Before compiz crash I got video freeze for a few second and a xid 31 error like yours.
Perhaps you can try the 331.113 release which is AFAIK the latest version that does not exhibit the problem. This can eventually give some clues to the nvidia guys about this problem which is now more than one year old.