Skip to content

Commit ad82151

Browse files
committed
Add --stop-on-last-frame command.
1 parent 6781cb5 commit ad82151

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

exporter/src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ struct Opt {
6060
#[clap(long = "skipframes", default_value = "0")]
6161
skipframes: u32,
6262

63+
/// Stops capturing frames once the root movie clip reaches its final frame.
64+
#[clap(long, action)]
65+
stop_on_last_frame: bool,
66+
6367
/// Don't show a progress bar
6468
#[clap(short, long, action)]
6569
silent: bool,
@@ -97,6 +101,7 @@ fn take_screenshot(
97101
progress: &Option<ProgressBar>,
98102
size: SizeOpt,
99103
force_play: bool,
104+
stop_on_last_frame: bool,
100105
) -> Result<Vec<RgbaImage>> {
101106
let movie = SwfMovie::from_path(swf_path, None).map_err(|e| anyhow!(e.to_string()))?;
102107

@@ -168,10 +173,23 @@ fn take_screenshot(
168173
if let Some(progress) = &progress {
169174
progress.inc(1);
170175
}
176+
177+
if stop_on_last_frame && is_root_movie_clip_at_end(&player) {
178+
break;
179+
}
171180
}
172181
Ok(result)
173182
}
174183

184+
fn is_root_movie_clip_at_end(player: &Arc<Mutex<Player>>) -> bool {
185+
player.lock().unwrap().mutate_with_update_context(|ctx| {
186+
ctx.stage
187+
.root_clip()
188+
.and_then(|root_clip| root_clip.as_movie_clip())
189+
.is_some_and(|movie_clip| movie_clip.current_frame() == movie_clip.total_frames())
190+
})
191+
}
192+
175193
fn force_root_clip_play(player: &Arc<Mutex<Player>>) {
176194
let mut player_guard = player.lock().unwrap();
177195

@@ -258,6 +276,7 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
258276
&progress,
259277
opt.size,
260278
opt.force_play,
279+
opt.stop_on_last_frame,
261280
)?;
262281

263282
if let Some(progress) = &progress {
@@ -352,6 +371,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
352371
&progress,
353372
opt.size,
354373
opt.force_play,
374+
opt.stop_on_last_frame,
355375
) {
356376
let mut relative_path = file
357377
.path()

0 commit comments

Comments
 (0)