forked from dsutanto/bytetrack-counter-cpp
Force file sources to decode from frame 0; add first-frame diagnostics
OpenCV FFMPEG build buffer (CAP_PROP_BUFFERSIZE=1) on file sources was landing mid-file, so the first decoded frame could show an ~11s-later camera clock than the source's true frame 0. Gate BUFFERSIZE to live sources only and seek file sources to CAP_PROP_POS_FRAMES=0. Log pos_frames/pos_msec/frame_count/fps once on first successful read. SPEC: B1, V18, T20. AGENTS: capture setup notes.
This commit is contained in:
1 parent
ea370b0ffd
commit
90038da298
5 files changed
+31
-6
No files matched your search
+16
-1
@@ -41,7 +41,11 @@ static cv::VideoCapture open_capture(const std::string& source) {
|
||||
setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", g_config.rtsp_ffmpeg_options.c_str(), 1);
|
||||
}
|
||||
cv::VideoCapture cap(source, cv::CAP_FFMPEG);
|
||||
cap.set(cv::CAP_PROP_BUFFERSIZE, 1);
|
||||
if (is_live) {
|
||||
cap.set(cv::CAP_PROP_BUFFERSIZE, 1);
|
||||
} else {
|
||||
cap.set(cv::CAP_PROP_POS_FRAMES, 0);
|
||||
}
|
||||
return cap;
|
||||
}
|
||||
|
||||
@@ -291,6 +295,7 @@ int main(int argc, char* argv[]) {
|
||||
int reconnect_count = 0;
|
||||
bool blank_live_frame = false;
|
||||
bool paused = false;
|
||||
bool first_read_logged = false;
|
||||
|
||||
auto write_live_jpeg = [](const cv::Mat& out_frame, int quality) {
|
||||
try {
|
||||
@@ -335,6 +340,16 @@ int main(int argc, char* argv[]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!first_read_logged) {
|
||||
first_read_logged = true;
|
||||
std::cout << "[" << now_str() << "] [INFO] First frame decoded — "
|
||||
<< "pos_frames=" << cap.get(cv::CAP_PROP_POS_FRAMES)
|
||||
<< " pos_msec=" << cap.get(cv::CAP_PROP_POS_MSEC)
|
||||
<< " frame_count=" << cap.get(cv::CAP_PROP_FRAME_COUNT)
|
||||
<< " fps=" << cap.get(cv::CAP_PROP_FPS)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
auto elapsed_sec = std::chrono::duration<double>(
|
||||
std::chrono::steady_clock::now() - session_start).count();
|
||||
auto mono = std::chrono::steady_clock::now();
|
||||
|
||||
Reference in new issue
Block a user