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
+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_{};
};
}