Add synced ZED SVO grid exporter

This commit is contained in:
2026-03-19 08:26:38 +00:00
parent 83171b415f
commit 2671ac7ba9
6 changed files with 2066 additions and 0 deletions
@@ -0,0 +1,117 @@
#pragma once
#include "cvmmap_streamer/config/runtime_config.hpp"
#include <cstdint>
#include <expected>
#include <filesystem>
#include <memory>
#include <string>
#include <string_view>
namespace cvmmap_streamer::zed_tools {
using cvmmap_streamer::CodecType;
using cvmmap_streamer::EncoderDeviceType;
inline constexpr std::uint32_t kDefaultGopSize = 30;
inline constexpr std::uint32_t kDefaultBFrames = 0;
inline constexpr int kDefaultQuality = 23;
inline constexpr std::uint64_t kNanosPerSecond = 1'000'000'000ull;
enum class PresetKind : std::uint8_t {
Fast,
Balanced,
Quality,
};
enum class TuneKind : std::uint8_t {
LowLatency,
Balanced,
};
struct EncodeTuning {
PresetKind preset{PresetKind::Fast};
TuneKind tune{TuneKind::LowLatency};
int quality{kDefaultQuality};
std::uint32_t gop{kDefaultGopSize};
std::uint32_t b_frames{kDefaultBFrames};
};
[[nodiscard]]
std::expected<CodecType, std::string> parse_codec(std::string_view raw);
[[nodiscard]]
std::expected<EncoderDeviceType, std::string> parse_encoder_device(std::string_view raw);
[[nodiscard]]
std::expected<PresetKind, std::string> parse_preset(std::string_view raw);
[[nodiscard]]
std::expected<TuneKind, std::string> parse_tune(std::string_view raw);
[[nodiscard]]
std::string_view codec_name(CodecType codec);
[[nodiscard]]
std::string_view preset_name(PresetKind preset);
[[nodiscard]]
std::string_view tune_name(TuneKind tune);
[[nodiscard]]
std::uint64_t frame_period_ns(float fps);
[[nodiscard]]
std::filesystem::path derive_output_path(const std::filesystem::path &input_path);
class ProgressBar {
public:
explicit ProgressBar(std::uint64_t total_frames);
~ProgressBar();
void update(std::uint64_t completed_frames);
void finish(std::uint64_t completed_frames, bool success);
private:
struct Impl;
std::unique_ptr<Impl> impl_{};
};
class Mp4Writer {
public:
Mp4Writer();
Mp4Writer(const Mp4Writer &) = delete;
Mp4Writer &operator=(const Mp4Writer &) = delete;
Mp4Writer(Mp4Writer &&) noexcept;
Mp4Writer &operator=(Mp4Writer &&) noexcept;
~Mp4Writer();
[[nodiscard]]
std::expected<void, std::string> open(
const std::filesystem::path &output_path,
CodecType codec,
EncoderDeviceType encoder_device,
std::uint32_t width,
std::uint32_t height,
float fps,
const EncodeTuning &tuning);
[[nodiscard]]
std::expected<void, std::string> write_bgr_frame(
const std::uint8_t *data,
std::size_t row_stride_bytes,
std::uint64_t relative_timestamp_ns);
[[nodiscard]]
std::expected<void, std::string> flush();
[[nodiscard]]
bool using_hardware() const;
private:
struct Impl;
std::unique_ptr<Impl> impl_{};
};
} // namespace cvmmap_streamer::zed_tools