Got tired of messing around with screen capture in X11 and thought I might as well add video encoding to my emulator.
Unfortunately I'm very much a beginner when it comes to video. What formats and/or libraries would you recommend? At the moment I could go with something lossless for further processing in e.g. ffmpeg, though I might as well make it a bit more general if it isn't too much work.
I would probably rip off dosbox's implementation of video logging and their palletized lossless format ZMBV.
Have a look at what gstreamer offers. It is one of the most popular libraries for encoding and decoding video, allowing you to decode from a file, encode to a file, redirect an encoded stream to a UDP stream, etc etc. It works with plugins allowing you to establish an entire pipeline (even from command line using gst-launch). It also works with audio as well, and contains as many formats as you can imagine.
A few months ago, I was working on NES-style games in Pygame to eventually be ported to the NES. What I did in those games was pipe RGB data from the rendering surface into FFmpeg, using the PNG codec, and output the audio separately.
I'm fond of the QuickTime (container) format; it's well-documented, supports variable-frame-rate video, largefile(>4GB) support, and is reasonably simple with CamStudio(lossless LZO) or PNG(lossless deflate) codec for video, and "twos"/raw for audio.
I'll look into gstreamer first. Having a choice between encodings and having formats available that work well with various filters applied would be nice. I'm guessing DOSBox's format is most suited for when you keep the native color range.
The most versatile choice is probably the ffmpeg library, but there's a hell of a learning curve to it. I've used it in a project before, and even simple decoding took a while to figure out. Like, a couple days. If you're just going to target Windows, check out the DirectShow or VFW APIs for encoding AVI files.
miker00lz wrote:
The most versatile choice is probably the ffmpeg library, but there's a hell of a learning curve to it. I've used it in a project before, and even simple decoding took a while to figure out. Like, a couple days. If you're just going to target Windows, check out the DirectShow or VFW APIs for encoding AVI files.
I did in fact go with libav/ffmpeg, and I agree that it has a learning curve to it. The kind of learning curve where you have to dig through cryptic source code because the devs couldn't be bothered to properly document their stuff.
In case someone wants to save themselves a lot of pain, the source code is at
https://github.com/ulfalizer/nesalizer/ ... /movie.cpp . With
-tune animation -crf 18 as is used there the resulting video is nearly indistinguishable from the emulator itself, which is very nice. For another slight boost in picture quality YUV444 is used over YUV422, though a caveat is that some video players don't seem to support it.