This post is for anyone using VPython to create animations. If you are having problems with lost/skipped frames when trying to capture the animations to video, here is a trick I’ve come up with to ensure every frame is reliably captured.
Use code such as the following:
# update this path to point to your browser's download directory
downloads_path = "~/Downloads"
downloads_path = os.path.expanduser(downloads_path)
frames = 300
for frame in range(frames):
scene.waitfor('draw_complete')
scene.capture("frame_%04d" % frame)
while not os.path.exists("%s/frame_%04d.png" % (downloads_path, frame)):
time.sleep(0.001)
# ... update objects for next timestep here ...
Once you have all the frames, you can construct a video, e.g.:
ffmpeg -r 30 -start_number 0 -i frame_%04d.png -c:v libx264rgb -pix_fmt rgb24 animation.mp4
Is it an awful hack? Yes! Is VPython itself an awful hack? Yes! Does it create nice physics animations with relatively little effort? Yes! Go forth and animate!

BETA