How to make movies with VMD, imagemagick and ffmpeg

Export frames in VMD after the molecule is setup and looking pretty. The following will produce 360 frames for a full rotation around the Y axis at fixed 720p resolution using Tachyon as external renderer. This must be installed first via sudo apt install tachyon. By default the renderer does not support JPEG output.

set i 0;
while {$i < 360} {
  rotate y by 1
  set d [format "%04d" $i]
  render Tachyon out.dat tachyon %s -res 1280 720 -aasamples 2 -mediumshade %s -format PNG -o out_$d.png
  incr i

Be sure to render in the resolution you want your GIF or movie to be in the end. Otherwise you loose quality or ffmpeg will not accept certain aspect ratios (you will have to pad with black pixels and you don't want that!)

Assembling the frames into a GIF with imagemagick:

convert -quality 5 -loop 0 -delay 5 out_%04d.png animation.gif

The quality option did not change my results visibly (no idea if this is working as intended). The -loop 0 parameter controls how often the animation is repeated. If your animation is large and you want to be nice to users of old PCs, limit this to a couple of times, because the CPU will have to flip through all the frames indefinitively with 0. Experiment with delay based on how many frames you have for the speed of the animation.

Creating a short movie from the same frames using ffmpeg:

ffmpeg -i out_%04d.png -vcodec libx264 -preset slow -crf 22 -r 15 -threads 0 video.mp4

-i out_%04d.png are your rendered frames with four digids and leading zeros. vcodec libx264 uses x264 for H.264 encoding (which has wide spread compatibility). -preset slow controls the encoding speed and results in better quality/compression ratio during encoding. -crf 22 is a measure of quality; 23 is an accepted default, with smaller values resulting in less loss of information and 51 decreases the image quality to a artifact riddled pulp. -r 15 controls the framerate; if you do not want to produce too many frames due to space or computing time reduce this value, to slow down your video. -threads 0 gives you all the CPUs you have available. And video.mp4 is evidently the generated output file.