From patchwork Wed Feb 6 06:08:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 542 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A27461047 for ; Wed, 6 Feb 2019 07:08:30 +0100 (CET) Received: from pendragon.ideasonboard.com (d51A4137F.access.telenet.be [81.164.19.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A999C41 for ; Wed, 6 Feb 2019 07:08:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549433309; bh=NB6qFUY2NGlMoTYBWRvhf3ofIxPgq9TkA0jR21AHXBs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=aLvBMQ67/j+1JkTRkJ6SJw28HDgqW4vVeCiSK9EtNc83WxRE8mkadxf2CFlWKDprq zEAKbE/F8N/VhezQcMnBXU09HhCOkrQPvsQNH/Y5slbrBAFfXlCwYzwFCuMEyVCYWm iYrNc4s3yTprv9Ha7t2f4FJWAC1tF4VZNOUfyIfg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Feb 2019 08:08:18 +0200 Message-Id: <20190206060818.13907-28-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> References: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 27/27] cam: Add option to write raw frames to disk X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Feb 2019 06:08:30 -0000 From: Niklas Söderlund Use the helper BufferWriter to optionally write frames to disk as they are captured. Signed-off-by: Niklas Söderlund Signed-off-by: Jacopo Mondi Signed-off-by: Kieran Bingham Signed-off-by: Laurent Pinchart --- src/cam/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index ec5040e19935..9b67ab75a6a1 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -13,6 +13,7 @@ #include +#include "buffer_writer.h" #include "event_loop.h" #include "options.h" @@ -21,10 +22,12 @@ using namespace libcamera; OptionsParser::Options options; std::shared_ptr camera; EventLoop *loop; +BufferWriter *writer; enum { OptCamera = 'c', OptCapture = 'C', + OptFile = 'F', OptFormat = 'f', OptHelp = 'h', OptList = 'l', @@ -52,6 +55,11 @@ static int parseOptions(int argc, char *argv[]) ArgumentRequired, "camera"); parser.addOption(OptCapture, OptionNone, "Capture until interrupted by user", "capture"); + parser.addOption(OptFile, OptionString, + "Write captured frames to disk\n" + "The first '#' character in the file name is expanded to the frame sequence number.\n" + "The default file name is 'frame-#.bin'.", + "file", ArgumentOptional, "filename"); parser.addOption(OptFormat, &formatKeyValue, "Set format of the camera's first stream", "format"); parser.addOption(OptHelp, OptionNone, "Display this help message", @@ -113,6 +121,9 @@ static void requestComplete(Request *request, const std::map << " fps: " << std::fixed << std::setprecision(2) << fps << std::endl; + if (writer) + writer->write(buffer); + request = camera->createRequest(); if (!request) { std::cerr << "Can't create request" << std::endl; @@ -240,7 +251,19 @@ int main(int argc, char **argv) goto out; } + if (options.isSet(OptFile)) { + if (!options[OptFile].toString().empty()) + writer = new BufferWriter(options[OptFile]); + else + writer = new BufferWriter(); + } + capture(); + + if (options.isSet(OptFile)) { + delete writer; + writer = nullptr; + } } if (camera) {