22 int main(
int argc,
char * argv[])
try 25 window app(1280, 720,
"RealSense Record and Playback Example");
29 bool recorded =
false;
30 bool recording =
false;
43 auto pipe = std::make_shared<rs2::pipeline>();
71 frames =
pipe->wait_for_frames();
93 pipe = std::make_shared<rs2::pipeline>();
95 cfg.enable_record_to_file(
"a.bag");
97 device =
pipe->get_active_profile().get_device();
114 ImGui::TextColored({ 255 / 255.f, 64 / 255.f, 54 / 255.f, 1 },
"Recording to file 'a.bag'");
129 pipe = std::make_shared<rs2::pipeline>();
131 device =
pipe->get_active_profile().get_device();
148 pipe = std::make_shared<rs2::pipeline>();
150 cfg.enable_device_from_file(
"a.bag");
152 device =
pipe->get_active_profile().get_device();
165 if (
pipe->poll_for_frames(&frames))
184 pipe = std::make_shared<rs2::pipeline>();
186 device =
pipe->get_active_profile().get_device();
206 catch (
const std::exception& e)
216 auto hhh = duration_cast<hours>(duration);
218 auto mm = duration_cast<minutes>(duration);
220 auto ss = duration_cast<seconds>(duration);
222 auto ms = duration_cast<milliseconds>(duration);
224 std::ostringstream
stream;
225 stream << std::setfill(
'0') << std::setw(hhh.count() >= 10 ? 2 : 1) << hhh.count() <<
':' <<
226 std::setfill(
'0') << std::setw(2) << mm.count() <<
':' <<
227 std::setfill(
'0') << std::setw(2) << ss.count();
236 double part = (1.0 *
progress) / playback_total_duration;
237 *seek_pos =
static_cast<int>(std::max(0.0,
std::min(part, 1.0)) * 100);
247 auto duration_db = std::chrono::duration_cast<std::chrono::duration<double, std::nano>>(playback.
get_duration());
248 auto single_percent = duration_db.count() / 100;
249 auto seek_time = std::chrono::duration<double, std::nano>((*seek_pos) * single_percent);
250 playback.
seek(std::chrono::duration_cast<std::chrono::nanoseconds>(seek_time));
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val)
void seek(std::chrono::nanoseconds time)
void render(const rs2::frame &frame, const rect &rect, float alpha=1.f)
IMGUI_API void SetCursorPos(const ImVec2 &local_pos)
void draw_seek_bar(rs2::playback &playback, int *seek_pos, float2 &location, float width)
GLint GLint GLsizei GLsizei GLsizei depth
GLsizei const GLchar *const * string
IMGUI_API bool SliderInt(const char *label, int *v, int v_min, int v_max, const char *display_format="%.0f", bool render_bg=false)
depth_frame get_depth_frame() const
const std::string & get_failed_args() const
rs2::frame process(rs2::frame frame) const override
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
int main(int argc, char *argv[])
IMGUI_API void PopStyleVar(int count=1)
bool ImGui_ImplGlfw_Init(GLFWwindow *window, bool install_callbacks)
IMGUI_API void SetNextWindowSize(const ImVec2 &size, ImGuiSetCond cond=0)
IMGUI_API void PushItemWidth(float item_width)
IMGUI_API void Text(const char *fmt,...) IM_PRINTFARGS(1)
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
uint64_t get_position() const
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4 &col)
std::chrono::duration< uint64_t, std::nano > nanoseconds
std::string pretty_time(std::chrono::nanoseconds duration)
void ImGui_ImplGlfw_NewFrame(float scale_factor)
IMGUI_API void PopItemWidth()
rs2_playback_status current_status() const
std::chrono::nanoseconds get_duration() const
static const textual_icon pause
const std::string & get_failed_function() const
IMGUI_API void PopStyleColor(int count=1)
IMGUI_API void TextColored(const ImVec4 &col, const char *fmt,...) IM_PRINTFARGS(2)