diff --git a/build/bytetrack-counter b/build/bytetrack-counter index 79dc1e2..dfd9847 100755 Binary files a/build/bytetrack-counter and b/build/bytetrack-counter differ diff --git a/build/version.hpp b/build/version.hpp index d00ff13..902d53e 100644 --- a/build/version.hpp +++ b/build/version.hpp @@ -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; diff --git a/config.env.example b/config.env.example index 32fbbf2..0e67874 100644 --- a/config.env.example +++ b/config.env.example @@ -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 diff --git a/src/config.cpp b/src/config.cpp index 0a2f623..cfa8031 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -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); diff --git a/src/config.hpp b/src/config.hpp index 1ecaf51..423f73e 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index d145db0..39e2611 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -264,7 +264,9 @@ int main(int argc, char* argv[]) { w, h, static_cast(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); }); } diff --git a/src/video_writer.cpp b/src/video_writer.cpp index db3aa45..37fe326 100644 --- a/src/video_writer.cpp +++ b/src/video_writer.cpp @@ -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_)); diff --git a/src/video_writer.hpp b/src/video_writer.hpp index 6d67196..37463ef 100644 --- a/src/video_writer.hpp +++ b/src/video_writer.hpp @@ -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_;