Add H.264 inference session recording and replay

This commit is contained in:
zmv
2026-09-24 15:05:44 +08:00
parent 0192fccbf0
commit daab1db58f
17 changed files with 532 additions and 10 deletions
+3
View File
@@ -4,6 +4,7 @@
#include <memory>
#include <optional>
#include <string>
#include <nlohmann/json.hpp>
namespace cms {
struct CameraConfig {
@@ -13,6 +14,8 @@ struct CameraConfig {
struct CapturedFrame {
CaptureMetadata metadata;
std::shared_ptr<const BgrImage> image;
// Present only for offline replay; keeps original timestamps and context.
std::shared_ptr<const nlohmann::json> replay_record;
};
// The capture thread exclusively owns read(); requestStop() is thread safe.
class Camera {
+2
View File
@@ -7,8 +7,10 @@
namespace cms {
struct PipelineConfig {
static constexpr char const* session_variant="inference-only";
CameraConfig camera;
OutputOptions output;
std::filesystem::path record_session,replay_session;
std::filesystem::path engines,door_mask;
double detector_confidence{0.30};
int max_people{3};
+38
View File
@@ -0,0 +1,38 @@
#pragma once
#include "camera.hpp"
#include "frame_result.hpp"
#include <nlohmann/json.hpp>
#include <filesystem>
#include <fstream>
#include <opencv2/videoio.hpp>
namespace cms {
struct PipelineConfig;
// H.264/MP4 plus a matching frame index and per-frame inference records.
// finish() flushes the encoder and marks the session replayable.
class SessionWriter {
public:
explicit SessionWriter(PipelineConfig const& config);
void write(FrameResult const& result, nlohmann::json const& stages,
nlohmann::json const* source = nullptr);
void finish();
private:
std::filesystem::path directory_;
std::ofstream index_;
cv::VideoWriter video_;
int width_{},height_{};
std::uint64_t count_{};
bool finished_{};
};
class SessionReader {
public:
explicit SessionReader(PipelineConfig& config);
std::optional<CapturedFrame> read();
private:
std::filesystem::path directory_;
std::ifstream index_;
cv::VideoCapture video_;
int width_{},height_{};
std::uint64_t count_{},lastFrame_{},expectedCount_{};
};
}