How to capture screen with ffmpeg:
Use the x11grab device:
ffmpeg -f x11grab -r 25 -s 1024x768 -i :0.0+100,200 output.flv
This will grab the image from desktop, starting with the upper-left
corner at (x=100, y=200) with the width and height of 1024x768.
If you need audio too, you can use alsa like this:
ffmpeg -f x11grab -r 25 -s 1024x768 -i :0.0+100,200 -f alsa -ac 2 -i
pulse output.flv
So you can simply place this in capture.sh
and run it from your code:
#include <cstdlib>
int main(){ std::system("./capture.sh"); }
If you have to do it without calling external utilities, you can use libffmpeg directly.