forked from dsutanto/bytetrack-counter-cpp
Use batch_X_YYYYMMDD_HHMMSS.mp4 filename for exported recordings
This commit is contained in:
1 parent
37f98f243c
commit
31476d2fa7
3 files changed
+14
-12
No files matched your search
+11
-9
@@ -4,6 +4,7 @@
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
@@ -65,11 +66,15 @@ static std::string today_str() {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static std::string timestamp_str() {
|
||||
static std::string build_mp4_name(int batch_number, const std::string& counting_date) {
|
||||
std::string date_part = counting_date;
|
||||
date_part.erase(std::remove(date_part.begin(), date_part.end(), '-'), date_part.end());
|
||||
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
std::ostringstream ss;
|
||||
ss << std::put_time(std::localtime(&t), "%H%M%S");
|
||||
return ss.str();
|
||||
std::ostringstream name;
|
||||
name << "batch_" << batch_number << "_"
|
||||
<< date_part << "_"
|
||||
<< std::put_time(std::localtime(&t), "%H%M%S") << ".mp4";
|
||||
return name.str();
|
||||
}
|
||||
|
||||
void VideoBatchWriter::note_motion() {
|
||||
@@ -179,9 +184,7 @@ void VideoBatchWriter::stop_and_move(int batch_number) {
|
||||
std::string day_dir = output_dir_ + "/" + (current_date_.empty() ? today_str() : current_date_);
|
||||
ensure_dir(day_dir);
|
||||
|
||||
std::ostringstream name;
|
||||
name << "batch_" << batch_number << "_" << timestamp_str() << ".mp4";
|
||||
std::string dst = day_dir + "/" + name.str();
|
||||
std::string dst = day_dir + "/" + build_mp4_name(batch_number, current_date_);
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
@@ -208,8 +211,7 @@ void VideoBatchWriter::shutdown() {
|
||||
if (prev_state == CONFIRMED || prev_state == STOPPING) {
|
||||
std::string day_dir = output_dir_ + "/" + (current_date_.empty() ? today_str() : current_date_);
|
||||
ensure_dir(day_dir);
|
||||
std::string dst = day_dir + "/" +
|
||||
fs::path(src).filename().string();
|
||||
std::string dst = day_dir + "/" + build_mp4_name(current_batch_, current_date_);
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
|
||||
Reference in new issue
Block a user