mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-23 16:45:07 +03:00
cam: Add option to write raw frames to disk
Use the helper BufferWriter to optionally write frames to disk as they are captured. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
46ca8eeca0
commit
8b27416267
1 changed files with 23 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <libcamera/libcamera.h>
|
#include <libcamera/libcamera.h>
|
||||||
|
|
||||||
|
#include "buffer_writer.h"
|
||||||
#include "event_loop.h"
|
#include "event_loop.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
|
@ -21,10 +22,12 @@ using namespace libcamera;
|
||||||
OptionsParser::Options options;
|
OptionsParser::Options options;
|
||||||
std::shared_ptr<Camera> camera;
|
std::shared_ptr<Camera> camera;
|
||||||
EventLoop *loop;
|
EventLoop *loop;
|
||||||
|
BufferWriter *writer;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OptCamera = 'c',
|
OptCamera = 'c',
|
||||||
OptCapture = 'C',
|
OptCapture = 'C',
|
||||||
|
OptFile = 'F',
|
||||||
OptFormat = 'f',
|
OptFormat = 'f',
|
||||||
OptHelp = 'h',
|
OptHelp = 'h',
|
||||||
OptList = 'l',
|
OptList = 'l',
|
||||||
|
@ -52,6 +55,11 @@ static int parseOptions(int argc, char *argv[])
|
||||||
ArgumentRequired, "camera");
|
ArgumentRequired, "camera");
|
||||||
parser.addOption(OptCapture, OptionNone,
|
parser.addOption(OptCapture, OptionNone,
|
||||||
"Capture until interrupted by user", "capture");
|
"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,
|
parser.addOption(OptFormat, &formatKeyValue,
|
||||||
"Set format of the camera's first stream", "format");
|
"Set format of the camera's first stream", "format");
|
||||||
parser.addOption(OptHelp, OptionNone, "Display this help message",
|
parser.addOption(OptHelp, OptionNone, "Display this help message",
|
||||||
|
@ -113,6 +121,9 @@ static void requestComplete(Request *request, const std::map<Stream *, Buffer *>
|
||||||
<< " fps: " << std::fixed << std::setprecision(2) << fps
|
<< " fps: " << std::fixed << std::setprecision(2) << fps
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
if (writer)
|
||||||
|
writer->write(buffer);
|
||||||
|
|
||||||
request = camera->createRequest();
|
request = camera->createRequest();
|
||||||
if (!request) {
|
if (!request) {
|
||||||
std::cerr << "Can't create request" << std::endl;
|
std::cerr << "Can't create request" << std::endl;
|
||||||
|
@ -240,7 +251,19 @@ int main(int argc, char **argv)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.isSet(OptFile)) {
|
||||||
|
if (!options[OptFile].toString().empty())
|
||||||
|
writer = new BufferWriter(options[OptFile]);
|
||||||
|
else
|
||||||
|
writer = new BufferWriter();
|
||||||
|
}
|
||||||
|
|
||||||
capture();
|
capture();
|
||||||
|
|
||||||
|
if (options.isSet(OptFile)) {
|
||||||
|
delete writer;
|
||||||
|
writer = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (camera) {
|
if (camera) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue