| 13 | using namespace dlib; |
| 14 | |
| 15 | int main() |
| 16 | try |
| 17 | { |
| 18 | const auto demuxers = ffmpeg::list_demuxers(); |
| 19 | const bool screen_grab_available = std::find(begin(demuxers), end(demuxers), "x11grab") != demuxers.end(); |
| 20 | |
| 21 | if (screen_grab_available) |
| 22 | { |
| 23 | ffmpeg::demuxer::args args; |
| 24 | args.filepath = ""; |
| 25 | args.input_format = "x11grab"; |
| 26 | |
| 27 | ffmpeg::demuxer cap(args); |
| 28 | if (!cap.is_open() || !cap.video_enabled()) |
| 29 | { |
| 30 | printf("Failed to open demuxer for screen grab\n"); |
| 31 | return EXIT_FAILURE; |
| 32 | } |
| 33 | |
| 34 | image_window win; |
| 35 | |
| 36 | ffmpeg::frame frame; |
| 37 | array2d<rgb_pixel> img; |
| 38 | |
| 39 | while (cap.read(frame)) |
| 40 | { |
| 41 | convert(frame, img); |
| 42 | win.set_image(img); |
| 43 | } |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | printf("Sorry your installation of ffmpeg doesn't support screen grab\n"); |
| 48 | } |
| 49 | |
| 50 | return EXIT_SUCCESS; |
| 51 | } |
| 52 | catch (const std::exception& e) |
| 53 | { |
| 54 | printf("%s\n", e.what()); |
| 55 | return EXIT_FAILURE; |
| 56 | } |