98 return Create(path, size, pixelFormat, Private::RecordingEngine::Create(settings));
124 return handle_.Handle();
135 metaData_ = metaData;
137 auto res = CVB_CALL_CAPI(Movie2SetImage(
Handle(), image.
Handle()));
138 if (res != CExports::CVC_E_OK)
139 Utilities::SystemInfo::ThrowLastError();
141 res = CVB_CALL_CAPI(Movie2AddFrame(
Handle()));
142 if (res != CExports::CVC_E_OK)
143 Utilities::SystemInfo::ThrowLastError();
150 CExports::Movie2StopRecording(
Handle());
154 Recorder(HandleGuard<Recorder> &&guard) noexcept
160 Recorder(Recorder &&other) noexcept
161 : handle_(std::move(other.handle_))
166 Private::RecordingEnginePtr engine)
167 : Recorder(std::
move(*CreateRecorder(size, pixelFormat, engine)))
171 ConfigureEngine(engine);
177 Private::RecordingEnginePtr engine)
179 return std::unique_ptr<Recorder>(
new Recorder(path, size, pixelFormat, engine));
183 Private::RecordingEnginePtr engine)
185 intptr_t dummyBuffer = 0;
193 HandleGuard<Recorder> guard(CExports::CreateMovie2RecorderEx(
194 static_cast<CExports::Movie2_RecordingEngine
>(engine->Settings().EngineType()), dummyImage->Handle()));
196 throw std::runtime_error(
"failed to create movie recorder");
198 return std::make_unique<Recorder>(std::move(guard));
201 void ConfigureEngine(Private::RecordingEnginePtr engine)
206 ConfigureDirectShowEngine();
208 ConfigureRawVideoEngine();
211 void ConfigureDirectShowEngine()
213 auto directShowEngine = std::dynamic_pointer_cast<Private::DirectShowEngine>(engine_);
214 const auto &settings = directShowEngine->Settings();
216 CVB_CALL_CAPI(Movie2SetSyncMode(
Handle(), CExports::Movie2_SyncAfterCopy));
217 CVB_CALL_CAPI(Movie2SetAcqMode(
Handle(), CExports::Movie2_AcqAddFrame));
218 CVB_CALL_CAPI(Movie2SetCompressorIndex(
Handle(),
static_cast<CExports::cvbval_t
>(settings.CodecIndex())));
219 CVB_CALL_CAPI(Movie2SetFrameRate(
Handle(), settings.FrameRate()));
220 CVB_CALL_CAPI(Movie2SetUseMetadata(
Handle(), (settings.UseMetaData()) ? 1 : 0));
222 if (settings.UseMetaData())
224 Internal::DoResCall([&]() {
225 CExports::pfMovie2ProvideMetaData metaDataCallback = [](CExports::MOVIE2RECORDER,
char *szMetaData,
226 CExports::cvbval_t BufferSize,
void *pUserData) {
227 if (szMetaData && BufferSize > 0)
229 auto recorder =
reinterpret_cast<Cvb::Movie2::Recorder *
>(pUserData);
230 auto metaData = recorder->metaData_;
232 std::string metaDataAscii(Internal::CastToAscii(metaData));
233 size_t charsToCopy = std::min(metaData.size(),
static_cast<std::size_t
>(BufferSize) - 1);
234 std::copy_n(metaDataAscii.begin(), charsToCopy, szMetaData);
235 szMetaData[charsToCopy] = 0;
239 CExports::cvbval_t dummy = 0;
240 return CVB_CALL_CAPI(Movie2RegisterMetaDataCallback(
Handle(), metaDataCallback,
this, dummy));
245 void ConfigureRawVideoEngine()
247 const auto &settings = engine_->Settings();
248 CVB_CALL_CAPI(Movie2SetSyncMode(
Handle(), CExports::Movie2_SyncAfterCopy));
249 CVB_CALL_CAPI(Movie2SetAcqMode(
Handle(), CExports::Movie2_AcqAddFrame));
250 Internal::DoResCall([&]() {
return CVB_CALL_CAPI(Movie2SetFrameRate(
Handle(), settings.FrameRate())); });
253 void Record(
const String &path)
255 auto res = CExports::Movie2SetTargetFileNameTyped(
Handle(), path.c_str());
256 if (res != CExports::CVC_E_OK)
257 Utilities::SystemInfo::ThrowLastError();
259 Internal::DoResCall([&]() {
return CVB_CALL_CAPI(Movie2StartRecording(
Handle())); });
263 HandleGuard<Recorder> handle_;
264 Private::RecordingEnginePtr engine_;
static std::unique_ptr< WrappedImage > FromRgbPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride, int planeStride)
Wraps, without copying, the given RGB pixel buffer in a CvbImage.
Definition decl_wrapped_image.hpp:81
static std::unique_ptr< WrappedImage > FromGreyPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride)
Wraps, without copying, the given monochrome pixel buffer in an image.
Definition decl_wrapped_image.hpp:46