Skip to content

Commit 37a6b92

Browse files
committed
in middle
1 parent 136ac2a commit 37a6b92

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

include/pythonic/pythonicPrint.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ namespace pythonic
6666
render();
6767
}
6868

69+
// Force a render update (useful for indeterminate progress animation)
70+
void tick()
71+
{
72+
render();
73+
}
74+
6975
void finish()
7076
{
7177
_current_frame = _total_frames;
@@ -1128,15 +1134,17 @@ namespace pythonic
11281134
progress.update(0);
11291135

11301136
// Extract frames from video at the target fps
1131-
// We need to do this synchronously but show that something is happening
11321137
std::string extract_cmd = "ffmpeg -y -i \"" + actual_path + "\" -vf \"fps=" + fps_str + "\" \"" +
11331138
temp_dir + "/frame_%05d.png\" 2>/dev/null";
11341139

1135-
// Start extraction - this will block but progress bar shows activity
1136-
std::thread update_thread([&progress, &temp_dir, estimated_frames]()
1140+
// Atomic flag to signal extraction done
1141+
std::atomic<bool> extraction_done{false};
1142+
1143+
// Start progress update thread - this monitors frame extraction
1144+
std::thread update_thread([&progress, &temp_dir, estimated_frames, &extraction_done]()
11371145
{
11381146
// Periodically check extracted frame count and update progress
1139-
while (true)
1147+
while (!extraction_done.load())
11401148
{
11411149
size_t current = count_frames(temp_dir, "frame_");
11421150
if (current > 0)
@@ -1145,21 +1153,19 @@ namespace pythonic
11451153
progress.set_total(estimated_frames > 0 ? estimated_frames : current * 2);
11461154
progress.update(current);
11471155
}
1148-
std::this_thread::sleep_for(std::chrono::milliseconds(250));
1149-
1150-
// Check if extraction might be done
1151-
if (estimated_frames > 0 && current >= estimated_frames * 0.95)
1152-
break;
1153-
if (current > 1000 && count_frames(temp_dir, "frame_") == current)
1156+
else
11541157
{
1155-
// Frame count not changing, might be done
1156-
std::this_thread::sleep_for(std::chrono::milliseconds(500));
1157-
if (count_frames(temp_dir, "frame_") == current)
1158-
break;
1158+
// Still extracting first frames, render the spinner
1159+
progress.tick();
11591160
}
1161+
std::this_thread::sleep_for(std::chrono::milliseconds(250));
11601162
} });
11611163

1164+
// Run ffmpeg extraction (this blocks until done)
11621165
int result = std::system(extract_cmd.c_str());
1166+
1167+
// Signal update thread to stop and wait for it
1168+
extraction_done.store(true);
11631169
update_thread.join();
11641170

11651171
if (is_temp_video)

0 commit comments

Comments
 (0)