python opencv VideoWriter results in invalid video file

Little did I know that OpenCV's VideoWriter could not handle saving into oddball-frame-sized video files. Python's not so verbose output doesn't help at all. Your program will still run fine like nothing wrong is happening, in the end it produces not-supposed-to-be file size like 578 kB or sth.

I bumped into similar SO articles [1, 2] which mentioned the case. I confirmed that VideoWriter works nicely when the frame dimensions (both height and width) is multiple of 8.