From patchwork Wed Jan 20 16:31:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sgerwk-at-aol.com@ffmpeg.org X-Patchwork-Id: 25042 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6BA7D449C77 for ; Wed, 20 Jan 2021 18:33:47 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4BF696898A8; Wed, 20 Jan 2021 18:33:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sonic306-30.consmr.mail.bf2.yahoo.com (sonic306-30.consmr.mail.bf2.yahoo.com [74.6.132.229]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA13D6881EE for ; Wed, 20 Jan 2021 18:33:40 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1611160419; bh=hhLOqinKuB6QQLJVriiiCZAaW67LCL6u+Ll5dN8/x1A=; h=Date:From:Reply-To:To:Subject:References:From:Subject:Reply-To; b=CtFR7ZoH0HXlnFOeZmmw0Vf5IYP2zD0v2iu0TcTSz35h5aruwlvxy3s/VkCCb/axBF2hsbEvVQMKS6kgoJ1pHmLiR3ZoGPvOR+Y/SakN2Xyl91Po7dWCL5+iL9jv8hWeeldEjne4EB2xwFlBCEUITt0lWkeW2tJDl/P6+xhEbgezT15NRpSW+FWqBcVALKo0LPV8Bt7tCOlfQTif0N6+ULwUKIp6qWtApgWpRw1nUsjYZ+IdA+/XucGn2noLgigN2UTCqqGIuZb3q/YvnyZVK53D2KbkhYNUEI1XqEA/7ynOdMnUVnJpTKHDyP+Z99NHieiZYa6FeSGDxP+Ruv9TwQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1611160419; bh=HgGnwa31Tiv3eyCF9HV27WgDykugxHbJ2AE8k2D5y6W=; h=Date:From:To:Subject:From:Subject:Reply-To; b=W70ho/vTR8wL89nOCMOl0KSZIKhMPn9DAJOZ00+9LuhxKutIz7x5ZAKO8GY6SS9dw1adgqY/2V9Yuymjfgr4A/+ZACL0+yxiBDHidqbqquhYN6LGhuK6wVGW35giKWxipvjZO07u/MUcSvqmPM+28Vv6TTRhJ7swZJx0+8ZdnzNRxQwgvNNfs10qi2QntodS9CpNSPk4bg/71fQ6oRibRKeCovTbaBYNkoBNYzQW8KiJCGAk9zCJR7Q4i0fU3xSSE/B+wgbwR7mLgPI1LLmu39bXUHkrX+w1e3+OUCkWh4nJAx1/5Y3EZ9SRezRTdstWgA+l/0OHDpNrE/w9X1rbuA== X-YMail-OSG: rO_1MPUVM1kF0Tyin5COTXeuYQ7.RZ6rjXKVpYMkXnRGairoqrQKtL5a7pNcRD9 oG8mNszhQuqaw_vHWPSUNVJqr257MBdwNJW44XG5Wze5jxV9Wd6Bd7dJYD1CupJwDpIqeXo.gBQ1 p0vlEblcktJe8c.arzrN79rac8MoOzhlL4sVB7o7rUcOp0IBmWwz37CA.N48lAwu785c6YJYwQPR YkkZGSAebEGACfFZ55rBtgDGjFyXCiaavtTqPahOX.JUXAs1qCFyFniE.HHgaVx3PntbWz0KRvM8 caHHhz2ciLuQQArfH2ZdVhDlmX8psx9sZg9MHqCZ1_fdpPNq2EPi.30.AMMF7PGw4I60CPYqdbfO 0RqwSUw.41Vg5jnfgpz91dywPNv818GJlGrZTeGrVBplsuyz3E9ME5MBqPi04EpxC2AjCtZLgXgT GVlNntijz443TsG0Ev436nmvImRu2bKNwTz6s6t8TnWgewhlKliXeC_bSEP3c637hJiBCTkMt23D DXPMy0NHCMogOsT2R30w3AfPn7KqvCmvyohPVL8W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gd0pIujVtCAtklbU3hbw99cb7 Gr6sxQgNoiGZM9RaVLOc536bdWhUFh3wHMpEIXeCP5MUNIRVzb.1eXITPahIEfM7n9ghPU_ZsvHa jMJm6RB7sWAeNkUCS6K1fzLSYrpRMMrUstukEcjbKi3bxVqxTouiRgdtknwjpbwydY9lTZpAJms0 iST31y_OWKiZeD.OeK.5FZxbM4Ue.p1g4Khx4jwtNhcFk_5Wg6u0a2fMTVYfoDMWrvX5EiptMGS0 aThUKrTA9gFEfJ4If1b6bmyiChNwA2v4O93vXtOt.ayflXZ3l9NSlfmx02B9w.QoBU5TaUxD2bK8 n9CctOfH7wcWL4YPWxko9k1ElnIzeZXXm6VSza6BP1eWWCMMq8NeKfAO0yo9vO87_MRKpMCuwnXv I4OOtzz64YwEBZT2XZNz4hnxyBWIN98buOaJVn7F2I2l7jFG3Jv9qr62kXXFU0QQa9Pvp.mItvyv v5.iFwBgVep4lwC9ASGs8yiCpbeWQ7RpBeTN6qkByQqKxsLpCtsNfya6LupU56wpWJ.uz92M9nz6 0SHPwQoYncxn699GqIU9TWc9KkBU.ronFDbLU7oZ4LvZbCIb63b0IfY7uhosqyqEEHekg1bJVr3A HPoCYHcNBbALO66Wxl4dAtKdwR0N9XurqFiGYXaGHGY_3oNe5GOqvChTWT4cSFIO93LNXBE9UQaV vYDOrfgIH3MoXO3h9ila_8FrXq..cIvcj0lIb Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.bf2.yahoo.com with HTTP; Wed, 20 Jan 2021 16:33:39 +0000 Date: Wed, 20 Jan 2021 16:31:38 +0000 (UTC) From: sgerwk-at-aol.com@ffmpeg.org To: "ffmpeg-devel@ffmpeg.org" Message-ID: <942317827.2397172.1611160298506@mail.yahoo.com> MIME-Version: 1.0 References: <942317827.2397172.1611160298506.ref@mail.yahoo.com> X-Mailer: WebService/1.1.17501 aolwebmail Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36 OPR/73.0.3856.257 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] allow x11grab to capture a window instead of the whole screen X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Subject: [PATCH] allow x11grab to capture a window instead of the whole screen --- doc/indevs.texi | 3 +++ libavdevice/xcbgrab.c | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 3924d03..0738919 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -1564,6 +1564,9 @@ With @var{follow_mouse}: ffmpeg -f x11grab -follow_mouse centered -show_region 1 -framerate 25 -video_size cif -i :0.0 out.mpg @end example +@item window_id +Grab this window, instead of the whole screen. + @item video_size Set the video frame size. Default is the full desktop. diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c index 95bdc8a..6e4ef5d 100644 --- a/libavdevice/xcbgrab.c +++ b/libavdevice/xcbgrab.c @@ -60,6 +60,7 @@ typedef struct XCBGrabContext { AVRational time_base; int64_t frame_duration; + xcb_window_t window_id; int x, y; int width, height; int frame_size; @@ -82,6 +83,7 @@ typedef struct XCBGrabContext { #define OFFSET(x) offsetof(XCBGrabContext, x) #define D AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { + { "window_id", "Window to capture", OFFSET(window_id), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D }, { "x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D }, { "y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D }, { "grab_x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D }, @@ -157,7 +159,7 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt) XCBGrabContext *c = s->priv_data; xcb_get_image_cookie_t iq; xcb_get_image_reply_t *img; - xcb_drawable_t drawable = c->screen->root; + xcb_drawable_t drawable = c->window_id; xcb_generic_error_t *e = NULL; uint8_t *data; int length; @@ -267,7 +269,7 @@ static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt) XCBGrabContext *c = s->priv_data; xcb_shm_get_image_cookie_t iq; xcb_shm_get_image_reply_t *img; - xcb_drawable_t drawable = c->screen->root; + xcb_drawable_t drawable = c->window_id; xcb_generic_error_t *e = NULL; AVBufferRef *buf; xcb_shm_seg_t segment; @@ -566,7 +568,7 @@ static int create_stream(AVFormatContext *s) avpriv_set_pts_info(st, 64, 1, 1000000); - gc = xcb_get_geometry(c->conn, c->screen->root); + gc = xcb_get_geometry(c->conn, c->window_id); geo = xcb_get_geometry_reply(c->conn, gc, NULL); if (!geo) return AVERROR_EXTERNAL; @@ -745,7 +747,7 @@ static int select_region(AVFormatContext *s) press_position = (xcb_point_t){ press->event_x, press->event_y }; rectangle.x = press_position.x; rectangle.y = press_position.y; - xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle); + xcb_poly_rectangle(conn, c->window_id, gc, 1, &rectangle); was_pressed = 1; break; } @@ -754,14 +756,14 @@ static int select_region(AVFormatContext *s) xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)event; xcb_point_t cursor_position = { motion->event_x, motion->event_y }; - xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle); + xcb_poly_rectangle(conn, c->window_id, gc, 1, &rectangle); rectangle = rectangle_from_corners(&press_position, &cursor_position); - xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle); + xcb_poly_rectangle(conn, c->window_id, gc, 1, &rectangle); } break; } case XCB_BUTTON_RELEASE: { - xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle); + xcb_poly_rectangle(conn, c->window_id, gc, 1, &rectangle); done = 1; break; } @@ -825,6 +827,9 @@ static av_cold int xcbgrab_read_header(AVFormatContext *s) return AVERROR(EIO); } + if (c->window_id == 0) + c->window_id = c->screen->root; + if (c->select_region) { ret = select_region(s); if (ret < 0) {