2

I am looking for a program to capture screen in Linux using C or Cpp. can someone help with giving a skeleton structure or program what can help me.

Thanks and Regards.

jww
  • 97,681
  • 90
  • 411
  • 885
Pferd
  • 49
  • 1
  • 1
  • 8

1 Answers1

2

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.

nurettin
  • 11,090
  • 5
  • 65
  • 85
  • That looks good. I tried using external libraries but couldnt find a perfect program. are there any sample programs that use third party api to capture screen shot? – Pferd Jun 05 '13 at 06:45
  • It worked http://stackoverflow.com/questions/15507788/making-a-screenshot-using-xlib-and-cairo-libs-fail – Pferd Jun 05 '13 at 07:50