Add configurable recording quality (RECORD_CRF, RECORD_PRESET)

This commit is contained in:
proitlab committed 2026-08-07 23:12:40 +07:00
1 parent ef17a9105b
commit 30515086d3
8 files changed
+35 -7

No files matched your search

Binary file not shown.
+3 -3
View File
@@ -4,11 +4,11 @@
namespace version {
const std::string GIT_COMMIT = "37f98f24";
const std::string GIT_COMMIT = "ef17a910";
const std::string GIT_BRANCH = "main";
const std::string GIT_TAG = "";
const std::string BUILD_DATE = "2026-08-05";
const std::string BUILD_TIME = "00:25:19";
const std::string BUILD_DATE = "2026-08-07";
const std::string BUILD_TIME = "23:10:08";
const int BUILD_YEAR = 2026;
const bool BUILD_RKNN = 1;
+5
View File
@@ -142,6 +142,11 @@ RECORD_DELAY_SECONDS=10
RECORD_END_DELAY=1
# Days to keep recorded video folders (folders older than this deleted on startup)
RECORD_RETENTION_DAYS=3
# H.264 quality: lower CRF = higher quality (17-18 ~ visually lossless, 23 is ffmpeg default).
# Leave empty to use ffmpeg default.
RECORD_CRF=18
# x264 preset: slow = better compression/quality at higher CPU cost. Empty = default (medium).
RECORD_PRESET=slow
# Shared memory directory — used for video recording, live snapshots, and .reset trigger
# RECORD_SHM_DIR is an alias; SHM_DIR takes priority if both set
SHM_DIR=/dev/shm/bytetrack-counter
+3
View File
@@ -146,6 +146,9 @@ void AppConfig::load_from_env(const char* env_path) {
if (!reds_s.empty()) record_end_delay_seconds = std::stof(reds_s);
auto rret_s = get_env("RECORD_RETENTION_DAYS");
if (!rret_s.empty()) record_retention_days = std::stoi(rret_s);
auto rcrf_s = get_env("RECORD_CRF");
if (!rcrf_s.empty()) record_crf = std::stoi(rcrf_s);
record_preset = get_env("RECORD_PRESET", record_preset);
shm_dir = get_env("RECORD_SHM_DIR", shm_dir);
shm_dir = get_env("SHM_DIR", shm_dir);
+2
View File
@@ -64,6 +64,8 @@ struct AppConfig {
float record_delay_seconds = 10.0f;
float record_end_delay_seconds = 1.0f;
int record_retention_days = 3;
int record_crf = -1;
std::string record_preset;
std::string shm_dir = "/dev/shm/bytetrack-counter";
bool live_stream_enabled = false;
+3 -1
View File
@@ -264,7 +264,9 @@ int main(int argc, char* argv[]) {
w, h, static_cast<int>(fps_prop),
g_config.record_delay_seconds,
g_config.record_end_delay_seconds,
g_config.record_retention_days);
g_config.record_retention_days,
g_config.record_crf,
g_config.record_preset);
auto* vw = video_writer.get();
store.set_batch_closed_callback([vw](int bn, const std::string& date) { vw->on_batch_closed(bn, date); });
}
+14 -2
View File
@@ -16,11 +16,13 @@ VideoBatchWriter::VideoBatchWriter(const std::string& shm_dir,
int w, int h, int fps,
float delay_sec,
float end_delay_sec,
int retention_days)
int retention_days,
int crf,
const std::string& preset)
: shm_dir_(shm_dir), output_dir_(output_dir),
w_(w), h_(h), fps_(fps),
delay_sec_(delay_sec), end_delay_sec_(end_delay_sec),
retention_days_(retention_days)
retention_days_(retention_days), crf_(crf), preset_(preset)
{
ensure_dir(shm_dir_);
ensure_dir(output_dir_);
@@ -135,6 +137,16 @@ void VideoBatchWriter::start_recording() {
<< std::put_time(std::localtime(&t), "%Y%m%d_%H%M%S") << ".mp4";
current_path_ = shm_dir_ + "/" + name.str();
if (crf_ > 0 || !preset_.empty()) {
std::string opts;
if (crf_ > 0) opts += "crf;" + std::to_string(crf_);
if (!preset_.empty()) {
if (!opts.empty()) opts += "|";
opts += "preset;" + preset_;
}
setenv("OPENCV_FFMPEG_WRITE_OPTIONS", opts.c_str(), 1);
}
writer_.open(current_path_,
cv::VideoWriter::fourcc('a','v','c','1'),
fps_, cv::Size(w_, h_));
+5 -1
View File
@@ -10,7 +10,9 @@ public:
int w, int h, int fps,
float delay_sec,
float end_delay_sec,
int retention_days);
int retention_days,
int crf,
const std::string& preset);
~VideoBatchWriter();
@@ -35,6 +37,8 @@ private:
float delay_sec_;
float end_delay_sec_;
int retention_days_;
int crf_;
std::string preset_;
State state_ = IDLE;
std::chrono::steady_clock::time_point state_start_;