ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
MKVWriter.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <k4a/k4a.h>
11 #include <k4arecord/playback.h>
12 #include <k4arecord/record.h>
13 
15 
16 namespace cloudViewer {
17 namespace io {
18 
19 using namespace cloudViewer;
20 
21 MKVWriter::MKVWriter() : handle_(nullptr) {}
22 
23 bool MKVWriter::Open(const std::string &filename,
24  const _k4a_device_configuration_t &config,
25  k4a_device_t device) {
26  if (IsOpened()) {
27  Close();
28  }
29 
30  if (K4A_RESULT_SUCCEEDED != k4a_plugin::k4a_record_create(filename.c_str(),
31  device, config,
32  &handle_)) {
33  utility::LogWarning("Unable to open file {}", filename);
34  return false;
35  }
36 
37  return true;
38 }
39 
40 bool MKVWriter::IsOpened() { return handle_ != nullptr; }
41 
42 bool MKVWriter::SetMetadata(const MKVMetadata &metadata) {
43  metadata_ = metadata;
44 
45  if (K4A_RESULT_SUCCEEDED != k4a_plugin::k4a_record_write_header(handle_)) {
46  utility::LogWarning("Unable to write header");
47  return false;
48  }
49  return true;
50 }
51 
53  if (K4A_RESULT_SUCCEEDED != k4a_plugin::k4a_record_flush(handle_)) {
54  utility::LogWarning("Unable to flush before writing");
55  }
57 }
58 
59 bool MKVWriter::NextFrame(k4a_capture_t capture) {
60  if (!IsOpened()) {
61  utility::LogWarning("Null file handler. Please call Open().");
62  return false;
63  }
64 
65  if (K4A_RESULT_SUCCEEDED !=
66  k4a_plugin::k4a_record_write_capture(handle_, capture)) {
67  utility::LogWarning("Unable to write frame to mkv.");
68  return false;
69  }
70 
71  return true;
72 }
73 } // namespace io
74 } // namespace cloudViewer
std::string filename
bool SetMetadata(const MKVMetadata &metadata)
Definition: MKVWriter.cpp:42
bool NextFrame(_k4a_capture_t *)
Definition: MKVWriter.cpp:59
bool Open(const std::string &filename, const _k4a_device_configuration_t &config, _k4a_device_t *device)
Definition: MKVWriter.cpp:23
#define LogWarning(...)
Definition: Logging.h:72
k4a_result_t k4a_record_write_header(k4a_record_t recording_handle)
Definition: K4aPlugin.cpp:216
k4a_result_t k4a_record_flush(k4a_record_t recording_handle)
Definition: K4aPlugin.cpp:238
k4a_result_t k4a_record_create(const char *path, k4a_device_t device, const k4a_device_configuration_t device_config, k4a_record_t *recording_handle)
Definition: K4aPlugin.cpp:194
k4a_result_t k4a_record_write_capture(k4a_record_t recording_handle, k4a_capture_t capture_handle)
Definition: K4aPlugin.cpp:224
void k4a_record_close(k4a_record_t recording_handle)
Definition: K4aPlugin.cpp:244
Generic file read and write utility for python interface.