From 8b27416267a8c14cda97f6511c2f3e0c0d42caf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 28 Jan 2019 01:18:39 +0100 Subject: cam: Add option to write raw frames to disk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(+) (limited to 'src/cam') diff --git a/src/cam/main.cpp b/src/cam/main.cpp index ec5040e1..9b67ab75 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) { -- cgit v1.2.1