Video and image writing in Rust

I'm a relative beginner in rust looking to build some kind of pixel colour based cellular automata and I am having difficulties deciding which libraries to use as there are many different graphics libraries and video/image libraries. I would just like to be able to manipulate an array of pixels, possibly display and then write them to a video + a final image. Are there any specific libraries which would be recommended for me to use?

The image crate provides a basic pixel array you can read and write, and also saving/loading image files, and resizing (which will be useful to make “chunky” pixels for interactive viewing of the CA).

softbuffer provides a way to put pixels on screen — it's not directly compatible with image but writing conversions is easy with std's slice and iterator tools. Also take a look at the libraries that softbuffer's introduction compares itself with.

1 Like

Thanks, those libraries seem great. Do you know any libraries I can use for joining the images into a video?

I don't know of an obviously good option. I'm interested in the question myself, but haven't got to really trying things out. Some things from my list:

  • The image family of crates supports writing animated GIFs and PNGs, which might be fine if you want to write out a few CA frames, but aren't very compressed.
  • I've been meaning to check out rav1e.
  • There are crates with bindings to ffmpeg, but then you have to deal with depending on a complex C library.

Also, you could write out a GIF or collection of separate images, then use a separate tool (such as command line ffmpeg) to reencode them into a video format.

1 Like