OpenShot Library | libopenshot
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
CameraCaptureReader.h
Go to the documentation of this file.
1
8
9
// Copyright (c) 2008-2026 OpenShot Studios, LLC
10
//
11
// SPDX-License-Identifier: LGPL-3.0-or-later
12
13
#ifndef OPENSHOT_CAMERACAPTUREREADER_H
14
#define OPENSHOT_CAMERACAPTUREREADER_H
15
16
#include "
AudioDevices.h
"
17
#include "
ScreenCaptureReader.h
"
18
19
#include <memory>
20
#include <vector>
21
22
namespace
openshot
23
{
24
enum
CameraCaptureBackend
25
{
26
CAMERA_CAPTURE_AUTO
= 0,
27
CAMERA_CAPTURE_V4L2
= 1,
28
CAMERA_CAPTURE_WINDOWS_DSHOW
= 2,
29
CAMERA_CAPTURE_MAC_AVFOUNDATION
= 3
30
};
31
33
struct
CameraCaptureMode
34
{
35
int
width
= 0;
36
int
height
= 0;
37
openshot::Fraction
fps
=
openshot::Fraction
(0, 1);
38
std::string
input_format
;
39
};
40
41
struct
CameraCaptureSettings
42
{
43
CameraCaptureBackend
backend
=
CAMERA_CAPTURE_AUTO
;
44
std::string
device
=
"/dev/video0"
;
45
int
width
= 1280;
46
int
height
= 720;
47
openshot::Fraction
fps
=
openshot::Fraction
(30, 1);
48
std::map<std::string, std::string>
options
;
49
};
50
51
class
CameraCaptureReader
:
public
ReaderBase
52
{
53
public
:
54
explicit
CameraCaptureReader
(
const
CameraCaptureSettings
& settings);
55
~CameraCaptureReader
()
override
;
56
57
void
Close
()
override
;
59
void
RequestClose
();
60
CacheBase
*
GetCache
()
override
{
return
NULL; };
61
std::shared_ptr<openshot::Frame>
GetFrame
(int64_t number)
override
;
62
bool
IsOpen
()
override
{
return
reader && reader->IsOpen(); };
63
std::string
Name
()
override
{
return
"CameraCaptureReader"
; };
64
std::string
Json
()
const override
;
65
void
SetJson
(
const
std::string value)
override
;
66
Json::Value
JsonValue
()
const override
;
67
void
SetJsonValue
(
const
Json::Value root)
override
;
68
void
Open
()
override
;
69
70
openshot::CaptureReaderStats
GetStats
()
const
;
71
CameraCaptureSettings
GetSettings
()
const
{
return
settings; };
72
static
bool
IsBackendSupported
(
CameraCaptureBackend
backend);
73
static
CameraCaptureBackend
DefaultBackend
();
74
static
AudioDeviceList
GetDeviceNames
(
CameraCaptureBackend
backend =
CAMERA_CAPTURE_AUTO
);
75
79
static
std::vector<CameraCaptureMode>
GetDeviceModes
(
80
const
std::string& device,
CameraCaptureBackend
backend =
CAMERA_CAPTURE_AUTO
);
81
82
private
:
83
void
ValidateSettings()
const
;
84
ScreenCaptureSettings
ToDeviceSettings()
const
;
85
void
RebuildReader();
86
87
CameraCaptureSettings
settings;
88
std::unique_ptr<ScreenCaptureReader> reader;
89
};
90
}
91
92
#endif
AudioDevices.h
Header file for Audio Device Info struct.
ScreenCaptureReader.h
Header file for live screen capture readers.
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition
CacheBase.h:35
openshot::CameraCaptureReader::Open
void Open() override
Open the reader (and start consuming resources, such as images or video files).
Definition
CameraCaptureReader.cpp:302
openshot::CameraCaptureReader::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition
CameraCaptureReader.cpp:338
openshot::CameraCaptureReader::Close
void Close() override
Close the reader (and any resources it was consuming).
Definition
CameraCaptureReader.cpp:309
openshot::CameraCaptureReader::IsBackendSupported
static bool IsBackendSupported(CameraCaptureBackend backend)
Definition
CameraCaptureReader.cpp:145
openshot::CameraCaptureReader::GetDeviceNames
static AudioDeviceList GetDeviceNames(CameraCaptureBackend backend=CAMERA_CAPTURE_AUTO)
Definition
CameraCaptureReader.cpp:172
openshot::CameraCaptureReader::RequestClose
void RequestClose()
Request cancellation without releasing camera resources on the caller's thread.
Definition
CameraCaptureReader.cpp:316
openshot::CameraCaptureReader::CameraCaptureReader
CameraCaptureReader(const CameraCaptureSettings &settings)
Definition
CameraCaptureReader.cpp:129
openshot::CameraCaptureReader::Json
std::string Json() const override
Generate JSON string of this object.
Definition
CameraCaptureReader.cpp:333
openshot::CameraCaptureReader::GetCache
CacheBase * GetCache() override
Get the cache object used by this reader (note: not all readers use cache).
Definition
CameraCaptureReader.h:60
openshot::CameraCaptureReader::GetStats
openshot::CaptureReaderStats GetStats() const
Definition
CameraCaptureReader.cpp:323
openshot::CameraCaptureReader::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t number) override
Definition
CameraCaptureReader.cpp:328
openshot::CameraCaptureReader::GetDeviceModes
static std::vector< CameraCaptureMode > GetDeviceModes(const std::string &device, CameraCaptureBackend backend=CAMERA_CAPTURE_AUTO)
Definition
CameraCaptureReader.cpp:227
openshot::CameraCaptureReader::Name
std::string Name() override
Return the type name of the class.
Definition
CameraCaptureReader.h:63
openshot::CameraCaptureReader::~CameraCaptureReader
~CameraCaptureReader() override
Definition
CameraCaptureReader.cpp:140
openshot::CameraCaptureReader::DefaultBackend
static CameraCaptureBackend DefaultBackend()
Definition
CameraCaptureReader.cpp:159
openshot::CameraCaptureReader::IsOpen
bool IsOpen() override
Determine if reader is open or closed.
Definition
CameraCaptureReader.h:62
openshot::CameraCaptureReader::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition
CameraCaptureReader.cpp:355
openshot::CameraCaptureReader::GetSettings
CameraCaptureSettings GetSettings() const
Definition
CameraCaptureReader.h:71
openshot::CameraCaptureReader::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition
CameraCaptureReader.cpp:364
openshot::Fraction
This class represents a fraction.
Definition
Fraction.h:30
openshot::ReaderBase::ReaderBase
ReaderBase()
Constructor for the base reader, where many things are initialized.
Definition
ReaderBase.cpp:27
openshot
This namespace is the default namespace for all code in the openshot library.
Definition
AnimatedCurve.h:24
openshot::AudioDeviceList
std::vector< std::pair< std::string, std::string > > AudioDeviceList
Definition
AudioDevices.h:42
openshot::CameraCaptureBackend
CameraCaptureBackend
Definition
CameraCaptureReader.h:25
openshot::CAMERA_CAPTURE_AUTO
@ CAMERA_CAPTURE_AUTO
Definition
CameraCaptureReader.h:26
openshot::CAMERA_CAPTURE_WINDOWS_DSHOW
@ CAMERA_CAPTURE_WINDOWS_DSHOW
Definition
CameraCaptureReader.h:28
openshot::CAMERA_CAPTURE_V4L2
@ CAMERA_CAPTURE_V4L2
Definition
CameraCaptureReader.h:27
openshot::CAMERA_CAPTURE_MAC_AVFOUNDATION
@ CAMERA_CAPTURE_MAC_AVFOUNDATION
Definition
CameraCaptureReader.h:29
openshot::CameraCaptureMode
A supported capture combination, with an FFmpeg input format name.
Definition
CameraCaptureReader.h:34
openshot::CameraCaptureMode::height
int height
Definition
CameraCaptureReader.h:36
openshot::CameraCaptureMode::fps
openshot::Fraction fps
Definition
CameraCaptureReader.h:37
openshot::CameraCaptureMode::input_format
std::string input_format
Definition
CameraCaptureReader.h:38
openshot::CameraCaptureMode::width
int width
Definition
CameraCaptureReader.h:35
openshot::CameraCaptureSettings
Definition
CameraCaptureReader.h:42
openshot::CameraCaptureSettings::width
int width
Definition
CameraCaptureReader.h:45
openshot::CameraCaptureSettings::device
std::string device
Definition
CameraCaptureReader.h:44
openshot::CameraCaptureSettings::options
std::map< std::string, std::string > options
Definition
CameraCaptureReader.h:48
openshot::CameraCaptureSettings::height
int height
Definition
CameraCaptureReader.h:46
openshot::CameraCaptureSettings::fps
openshot::Fraction fps
Definition
CameraCaptureReader.h:47
openshot::CameraCaptureSettings::backend
CameraCaptureBackend backend
Definition
CameraCaptureReader.h:43
openshot::CaptureReaderStats
Definition
ScreenCaptureReader.h:55
openshot::ScreenCaptureSettings
Definition
ScreenCaptureReader.h:37
CameraCaptureReader.h
Generated by
1.17.0