Write a YUV4MPEG2 file or standard output, and then use ffmpeg to encode it for something reasonable. YUV4MPEG is an uncompressed format, and it's ridiculously simple, especially if you use non-interlaced 4: 4: 4.
Alternatively, use Motion JPEG , which is basically a collection of JPEG frames in a container. Many (though not all) video players can play MJPEG directly. I am sure that you already have access to the JPEG encoder, so traversing multiple JPEG frames into the MJPEG stream is relatively simple.
source share