From patchwork Tue Dec 12 13:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lena X-Patchwork-Id: 45092 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp3610232pzf; Tue, 12 Dec 2023 06:02:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIGiJz0w7WUktQeF/kh9iiakfn5GJ8YZYbeIedUbuHJKgfZvlv21IqifuTWyDfe6m/enVc X-Received: by 2002:a05:651c:b23:b0:2cb:2c27:593c with SMTP id b35-20020a05651c0b2300b002cb2c27593cmr1912288ljr.20.1702389777601; Tue, 12 Dec 2023 06:02:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702389777; cv=none; d=google.com; s=arc-20160816; b=pXXwgHCTm0gTJn+dENwxIpGzRrwlx76UQ3f36Xgqn/59roWswiAIJXjm65YG+q0ZRt +ie0GbgEX8wkb9axmlrHwiEFIvXY5Xp+Lq5cs+j/HvgRzVHBuhBNkWvO9mn9rRdAlOzj UzF9unObWRzXCzIJZQw4jBuzV3i9r4TdSfgyutMlVPeEJaFxKflO3rFJomBXrDri7cTi dXOy8UTZj9UXLabpEu6y9VVRyjwfat56/gVZ0TD1rwo/2iVntDFkRLb4ktzfsweg1278 uWiXu0aoYjIOwUzxHE3BoXt5/3yWIuZrG9MJhFVOdh0CAlLbhCKbpm4QiEt6vUwD33uR ot6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:delivered-to; bh=fGj0WyJ0ZuTThktzxd4NxUEoKlvHeljlHiAC/wzUbjo=; fh=unNFWMtKIBA8/LdzvbuVI+oNKix2hSYHISMMBvwJvu0=; b=svh+CyI5KBZzs9JgIV5g4uu6LHsHKVgOI0L7cDP5/2a3fsnd+2143CLrNyHIOctP4D AigO6tlHurNN79z/rt86/Z7CVp1DLn7I+lf6b7Sq8C7EAVI29wr+uoGh3/Uw7z0Ati6e W6TYNt/QjaZzZrP/eRLJvzE4OEEa1e+CkO1CJ8l7Cx77O6K6MUfi+12YYT6YuO9+4YsP aLDv4biaRVwbxd3ezDu70hcAtsKkSterUbY/QmLR+Hxe1R+T8NxBnTM0LulilrkYjs5z ekRcmaqh0GoyJSxLbF022GljOAm7VFxdkPCK06Nbj7Xx3IAeuY3iJq/HZuwt4kbhBV54 J5tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a15-20020a50c30f000000b0054cccbef037si4335761edb.349.2023.12.12.06.02.47; Tue, 12 Dec 2023 06:02:57 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0309E68D13B; Tue, 12 Dec 2023 16:02:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.nihil.gay (nihil.gay [157.90.242.5]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6862268D062 for ; Tue, 12 Dec 2023 16:02:37 +0200 (EET) Received: by mail.nihil.gay (Postfix, from userid 114) id E7AFC9D3EB; Tue, 12 Dec 2023 14:02:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on debian-4gb-fsn1-1 X-Spam-Status: No; tests=ALL_TRUSTED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED X-Spam-Score: -1.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. * See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block * for more information. * [URI: nihil.gay] * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's * domain * -0.0 T_SCC_BODY_TEXT_LINE No description available. Received: from localhost.localdomain (host-79-54-140-248.retail.telecomitalia.it [79.54.140.248]) (Authenticated sender: lena@nihil.gay) by mail.nihil.gay (Postfix) with ESMTPSA id 7C6D39D3E0; Tue, 12 Dec 2023 14:02:36 +0000 (UTC) To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Dec 2023 14:59:57 +0100 Message-ID: <20231212135956.20801-2-lena@nihil.gay> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] gdigrab: Allow capturing a window by its handle X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lena via ffmpeg-devel From: Lena Reply-To: FFmpeg development discussions and patches Cc: Lena , Stefano Sabatini , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yf0iLRctPMEk Added the change to the documentation and added error checking on `strtol`, according to the stdlib documentation. The documentation for `strtol` says that on error, 0 is returned. This makes it impossible to specify a window handle of 0 (the whole desktop), but that case is already covered by the "desktop" input filename, so it should be fine. x11grab can capture windows by their ID, but gdigrab can only capture windows by their names, internally calling FindWindowW to lookup its handle. This patch simply allows the user to specify a window handle directly. Signed-off-by: Lena --- doc/indevs.texi | 8 ++++++-- libavdevice/gdigrab.c | 13 ++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 863536a34d..6da0ccac62 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -722,7 +722,7 @@ Win32 GDI-based screen capture device. This device allows you to capture a region of the display on Windows. -There are two options for the input filename: +There are three options for the input filename: @example desktop @end example @@ -730,9 +730,13 @@ or @example title=@var{window_title} @end example +or +@example +hwnd=@var{window_hwnd} +@end example The first option will capture the entire desktop, or a fixed region of the -desktop. The second option will instead capture the contents of a single +desktop. The second and third options will instead capture the contents of a single window, regardless of its position on the screen. For example, to grab the entire desktop using @command{ffmpeg}: diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c index c069232472..f310d8f3d7 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -273,9 +273,20 @@ gdigrab_read_header(AVFormatContext *s1) } } else if (!strcmp(filename, "desktop")) { hwnd = NULL; + } else if (!strncmp(filename, "hwnd=", 5)) { + name = filename + 5; + + hwnd = strtol(name, NULL, 0); + + if (hwnd == NULL) { + av_log(s1, AV_LOG_ERROR, + "Invalid window handle.\n"); + ret = AVERROR(EINVAL); + goto error; + } } else { av_log(s1, AV_LOG_ERROR, - "Please use \"desktop\" or \"title=\" to specify your target.\n"); + "Please use \"desktop\", \"title=\" or \"hwnd=\" to specify your target.\n"); ret = AVERROR(EIO); goto error; }