Screen capture program in C or C++ and Linux [dupl

2019-03-04 07:36发布

问题:

This question already has an answer here:

  • Fastest method for screen capturing on Linux 8 answers

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.

回答1:

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.



标签: c++ c screenshot