I found this snippet in C and that can easily be done in FPC too:
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
int main() {
av_register_all();
AVFormatContext *pFormatCtx = avformat_alloc_context();
AVOutputFormat *pOutputFmt = av_guess_format(NULL, "output.mp4", NULL);
pFormatCtx->oformat = pOutputFmt;
// Open the output file
if (avio_open(&pFormatCtx->pb, "output.mp4", AVIO_FLAG_WRITE) < 0) {
return -1;
}
// Add video stream, set codec parameters, etc.
// ...
// Write frames
// ...
// Clean up
av_write_trailer(pFormatCtx);
avio_close(pFormatCtx->pb);
avformat_free_context(pFormatCtx);
return 0;
}
Of course it takes some more setup, but would work.
I *think* libffmpeg takes care of its own thread, but it has been some time ago since I used it.
I would try and capture the screen as the last part of an OnPaint event, not a timer, but you can combine it with a timer.
You can also simply pipe to ffmpeg, of course.