From patchwork Sun Aug 6 23:31:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sharpbai X-Patchwork-Id: 4645 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp2209778vsu; Sun, 6 Aug 2017 16:55:24 -0700 (PDT) X-Received: by 10.223.145.162 with SMTP id 31mr7485556wri.171.1502063724176; Sun, 06 Aug 2017 16:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502063724; cv=none; d=google.com; s=arc-20160816; b=Y1qaVbTbetZDqpqOcNuvcyHl0P16tj5l3wOIMXi+sdHkx9xBFWDXcEBJKjkzzugk3B T5X+si4T2XEEovZOKb8ihqUuL90qcATsAdW0WeYbHcwCR5mxXUxhgYlySAek8C4kIZq5 2ESi53eB3s+EP+iirLzymNZRrEVxAjcdo0WDxuZszB+Q5GqyF9Hv8NdWLI4b/O5sU7Ai ZtiGWWTAav8nysywpfmkwN4Ua8K1msaNCaTRN7Yo5N2J14JFO0B7eWpU+tghxT/+zuMo e3ftWgPd8krAVSEjwmcGVMdH5pVldqOwQyuvHxAtih/V8FbZWeibf7zJ+leaRHvra5CL Op2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=FRRv14O2MqAKMd+AuG2QJFc9Cvl9nu0DFGFmBnP+zwA=; b=VdU7dGTsxn+17in0GniuCI5UNubRCMlXQCWqppRvfJ/clUQLnxJqNg4V8rwd/qCS6s /BgiMeitMGgXAf1Kk51HZqs2uyhYHBLnfbLqZ3OwfAuk3zTNkGVWpRK5xXuPN3kR55FA osWlCeM4cgIQsm7uHjg6OI8+sFTBofTVb5Z6r6imV6dXJ1SXbF73qHBIAM3paWr0jlpx UYW3Xj8I2Tup0BHNmlXRr2Ta8cYjVGhEZQHpLGDvO+/DJ4v0hmaJDpjdapkxbBeZ0XJ2 u627jHeD/Lv0RdJtp99OlTgRQu6gQd6eeojLELoTxTe0XaF65RPm9dW6o6g6NwUY84VC CxKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=ZginjD5j; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j1si7776227wrd.349.2017.08.06.16.55.23; Sun, 06 Aug 2017 16:55:24 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=ZginjD5j; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 626DA6808E6; Mon, 7 Aug 2017 02:55:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A801D680416 for ; Mon, 7 Aug 2017 02:55:12 +0300 (EEST) Received: by mail-pf0-f196.google.com with SMTP id p13so7426601pfd.4 for ; Sun, 06 Aug 2017 16:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=MM7vyUplX7ClbnPuBMp9d4I1i5Lg268EpqR5hbytdY4=; b=ZginjD5jEhjyh0ONKx+tUEoWVjS5Wz5yJk7Mcv967yEIzU5FK7KicoicTi42SZS+MN REfpnH8xaODn8txtUT5vesM9y0deH/RappMzww0IcRy/ApmRgj9ZkIic1+SIv1aDa6Sh 9anIS9DZfenIy7OqwF5ukmLOsv8aacamdFQCmFojmKFwaPr9sJ4IDZPr+dO4fJQ3VuhL 5Epr5GJnwGWy+HVvbkPecZVzroAQ0dTWferdt47L3fm6SmnbNY6EoRdGZBIaY5rjtcDC jkeDve7WDfdkcZgBaD1t7MzmfGnjBH6Qgp15XYjjUBphnQcnCpYqooCwxgzXaQFW5DkE O4uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MM7vyUplX7ClbnPuBMp9d4I1i5Lg268EpqR5hbytdY4=; b=VgolY8gI0PazKukU2tEI+vNHELBLM0AqDRLRVhVz1HsPnRB3uwRMl8Bzv3lJ6qPRT/ rLRGueidNVb7rZrPnELCd9C/r1YTnEpB6aMCnJH1Z6c5T9xkfqmplfa4aEjFWU0tAvlo Ab12uGUlMDJ6xiN+VhBOQn8cUq//iW8+5Vufs9n623fI0vP+gj321dCgCbk9WlT3QQtf kKTGAG2oHxvdRL1OxIq2boKPij4NCj5tVwUfLc8WnbTKCigCpFJ5uEA2tN+n+zFsIOhw kZ5b+TGnZYRBE4fOXnD7Q510hUfIdbWB9FFeeuFksMuDNZVNAsghoKAqk8npsVYYmVWY EBeA== X-Gm-Message-State: AIVw110IknIqomEW2ZTsNYiED8iw73EYlWCIrQtw94uyYuPII/YRvIhl JeBH7S0L49IraYgRbKA= X-Received: by 10.84.217.70 with SMTP id e6mr12231686plj.414.1502062277149; Sun, 06 Aug 2017 16:31:17 -0700 (PDT) Received: from localhost.localdomain (li377-58.members.linode.com. [106.187.34.58]) by smtp.gmail.com with ESMTPSA id p10sm11567898pfk.103.2017.08.06.16.31.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 06 Aug 2017 16:31:16 -0700 (PDT) From: sharpbai To: ffmpeg-devel Date: Mon, 7 Aug 2017 07:31:03 +0800 Message-Id: <1502062263-24958-1-git-send-email-sharpbai@gmail.com> X-Mailer: git-send-email 2.2.1 Subject: [FFmpeg-devel] [PATCH] [PATCH] avdevice/avfoundation: add scaleFactor attribute for avfoundation 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 Cc: baitian , wangsiyuan , liyiren MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: sharpbai feature: add scaleFactor attribute for avfoundation added by: siyuan.wang@duobei.com added by: yiren.li@duobei.com --- doc/indevs.texi | 22 ++++++++++++++++++++++ libavdevice/avfoundation.m | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/doc/indevs.texi b/doc/indevs.texi index 09e3321..1ba71d7 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -139,6 +139,13 @@ Capture the mouse pointer. Default is 0. @item -capture_mouse_clicks Capture the screen mouse clicks. Default is 0. +@item -scale_factor +Scale factor for capture the screen. Set this property to scale the buffers +by a given factor. For example capturing a retina screen which resolution 2880x1800 +with a scale_factor of 0.5 (or 0.05) produces video buffers at 1440x900 (or 144x90). +This is useful for reducing captured file size and increasing performance +in capturing screen. Default is 1.0 (no scaling). + @end table @subsection Examples @@ -169,6 +176,21 @@ Record video from the system default video device using the pixel format bgr0 an $ ffmpeg -f avfoundation -pixel_format bgr0 -i "default:none" out.avi @end example +@item +Capture video from the first screen using the pixel format bgr0 and scaling in half size into out.avi. +First command use the avfoundation device command to enumerate all the available input devices including +screens ready to be captured: +@example +$ ffmpeg -f avfoundation -list_devices true -i "" +@end example +Once you've figured out the device index corresponding to the screen to be captured use, run the second +command with the correct screen device index to execute screen capture. For example on my mac the index +of "Screen Capture 0" is "1", I should replace @code{-i ""} with @code{-i "1"} in the second command. +@example +$ ffmpeg -f avfoundation -pixel_format bgr0 -scale_factor 0.5 -i "" out.avi +@end example + + @end itemize @section bktr diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index e2ddf47..1196cf3 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -96,6 +96,7 @@ typedef struct int capture_cursor; int capture_mouse_clicks; + float scale_factor; int list_devices; int video_device_index; @@ -735,6 +736,10 @@ static int avf_read_header(AVFormatContext *s) capture_screen_input.minFrameDuration = CMTimeMake(ctx->framerate.den, ctx->framerate.num); } + if (ctx->scale_factor > 0.0) { + capture_screen_input.scaleFactor = ctx->scale_factor; + } + #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 if (ctx->capture_cursor) { capture_screen_input.capturesCursor = YES; @@ -1025,6 +1030,7 @@ static const AVOption options[] = { { "video_size", "set video size", offsetof(AVFContext, width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, { "capture_cursor", "capture the screen cursor", offsetof(AVFContext, capture_cursor), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, { "capture_mouse_clicks", "capture the screen mouse clicks", offsetof(AVFContext, capture_mouse_clicks), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, + { "scale_factor", "scale screen factor range", offsetof(AVFContext, scale_factor), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 1.0, AV_OPT_FLAG_DECODING_PARAM }, { NULL }, };