@@ -60,6 +60,10 @@ struct Opt {
60
60
#[ clap( long = "skipframes" , default_value = "0" ) ]
61
61
skipframes : u32 ,
62
62
63
+ /// Stops capturing frames once the root movie clip reaches its final frame.
64
+ #[ clap( long, action) ]
65
+ stop_on_last_frame : bool ,
66
+
63
67
/// Don't show a progress bar
64
68
#[ clap( short, long, action) ]
65
69
silent : bool ,
@@ -97,6 +101,7 @@ fn take_screenshot(
97
101
progress : & Option < ProgressBar > ,
98
102
size : SizeOpt ,
99
103
force_play : bool ,
104
+ stop_on_last_frame : bool ,
100
105
) -> Result < Vec < RgbaImage > > {
101
106
let movie = SwfMovie :: from_path ( swf_path, None ) . map_err ( |e| anyhow ! ( e. to_string( ) ) ) ?;
102
107
@@ -168,10 +173,23 @@ fn take_screenshot(
168
173
if let Some ( progress) = & progress {
169
174
progress. inc ( 1 ) ;
170
175
}
176
+
177
+ if stop_on_last_frame && is_root_movie_clip_at_end ( & player) {
178
+ break ;
179
+ }
171
180
}
172
181
Ok ( result)
173
182
}
174
183
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
+
175
193
fn force_root_clip_play ( player : & Arc < Mutex < Player > > ) {
176
194
let mut player_guard = player. lock ( ) . unwrap ( ) ;
177
195
@@ -258,6 +276,7 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
258
276
& progress,
259
277
opt. size ,
260
278
opt. force_play ,
279
+ opt. stop_on_last_frame ,
261
280
) ?;
262
281
263
282
if let Some ( progress) = & progress {
@@ -352,6 +371,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
352
371
& progress,
353
372
opt. size ,
354
373
opt. force_play ,
374
+ opt. stop_on_last_frame ,
355
375
) {
356
376
let mut relative_path = file
357
377
. path ( )
0 commit comments