From patchwork Sun Dec 17 17:29:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lena X-Patchwork-Id: 45194 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp6916009pzf; Sun, 17 Dec 2023 09:36:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IED4TWHaA8WJNXfyWlTUCeKRGW67NzUNJzRHsEINMdB/qZYm1uI9SiuiEApX8WoGZY6aT2I X-Received: by 2002:a50:8ad3:0:b0:553:5357:96f2 with SMTP id k19-20020a508ad3000000b00553535796f2mr60832edk.31.1702834614037; Sun, 17 Dec 2023 09:36:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702834614; cv=none; d=google.com; s=arc-20160816; b=Yn/pj/8XbgSw/dOC++f/e1vIJL4yhiGdQDxPRGiHq3SRIkZyMacKoTmSIwjJbDXUQ7 RAsXrzbu6+2Z1yq55DFBVokC6wPYdacQOLbtrb8LKS9hbr47WfqbDY14CekzXQhm59sh 7kp/z+JQUr3VBpr3XYRwt/nUovAy3MHmfRR8JORrVZLjFmrWqx50NVOsT8APfxnMaJCA LQD4TPQmBEyyHowC8lB+3UVkZEWjM3NWAbu7DBqSLE7K6efL3bjth3WpXSPiaxZEyY9E 8t9E7dp++DRejLbhdjIDEJoy5T+X0aLTW2r6zZ/ERyouVBH+QUhnjzH3m9Hku3cnnfs6 nlhg== 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=5kD2bhTKIpQ04wuLg8xwH//KsY6mk4FhkWwCNaRKHd8=; fh=2RdUZ4q5S+1mIU42r1+PaH9j9WTQxFChEFG1R/gadzg=; b=kU+Q7vFnIIMdcv86GysUwrpjw2X6ePisdr2SR4Awbhqny9zqcm3DzRoz7Hf1DODiZ4 A/zi3Ka35U4OREItIFY/ncc0mstZ657fB85Qzs59Mv02u3HQaBwKj/rhtfWj/ZwJkOlS CFi8QNmckMVti29fgda3YZnU03UHGrT6QbRh7zs9fK4fUnlf1mTHjdmdDldSRec4++e0 MPsCxILrbVkPPQpPhS+AnRrrJHyNeL+K6HriQbs9XzH0TjOZDaKzL9d6gqFVqpzU8/Ur W9ZnVz6n6RSJ4VimTp6Zr9ujYB+TJCXJPheaXlierIutpLhdqRJvki+j7CBj7T0AexIF m1VA== 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 f15-20020a50d54f000000b0055340e62760si402884edj.505.2023.12.17.09.36.53; Sun, 17 Dec 2023 09:36:54 -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 E0FFC68D157; Sun, 17 Dec 2023 19:36:49 +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 1A5D568CC39 for ; Sun, 17 Dec 2023 19:36:44 +0200 (EET) Received: by mail.nihil.gay (Postfix, from userid 114) id DB0C79D3ED; Sun, 17 Dec 2023 17:36:42 +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.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.1 DKIM_VALID Message has at least one valid DKIM or DK signature * 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.0 T_SCC_BODY_TEXT_LINE No description available. Received: from localhost.localdomain (host-82-52-80-11.retail.telecomitalia.it [82.52.80.11]) (Authenticated sender: lena@nihil.gay) by mail.nihil.gay (Postfix) with ESMTPSA id 6BD5C9D34A; Sun, 17 Dec 2023 17:36:42 +0000 (UTC) To: ffmpeg-devel@ffmpeg.org Date: Sun, 17 Dec 2023 18:29:33 +0100 Message-ID: <20231217172932.60614-2-lena@nihil.gay> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4] 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 , Remi Denis-Courmont Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0pNdBvMVyZWf Added more context in the error message and did a final test that it all works. Thanks for the smooth patch submission process! 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 | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 863536a34d..a0c684f545 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: +Amongst options for the imput filenames are such elements as: @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..aa909a9392 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -273,9 +273,22 @@ gdigrab_read_header(AVFormatContext *s1) } } else if (!strcmp(filename, "desktop")) { hwnd = NULL; + } else if (!strncmp(filename, "hwnd=", 5)) { + name = filename + 5; + char *p; + + hwnd = strtol(name, &p, 0); + + if (p == NULL || p == name || p[0] == '\0') + { + av_log(s1, AV_LOG_ERROR, + "Invalid window handle '%s', must be an valid integer.\n", name); + 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; }