@@ -60,6 +60,10 @@ pub 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 ,
@@ -89,6 +93,7 @@ pub struct Opt {
89
93
}
90
94
91
95
/// Captures a screenshot. The resulting image uses straight alpha
96
+ #[ allow( clippy:: too_many_arguments) ]
92
97
fn take_screenshot (
93
98
descriptors : Arc < Descriptors > ,
94
99
swf_path : & Path ,
@@ -97,6 +102,7 @@ fn take_screenshot(
97
102
progress : & Option < ProgressBar > ,
98
103
size : SizeOpt ,
99
104
force_play : bool ,
105
+ stop_on_last_frame : bool ,
100
106
) -> Result < Vec < RgbaImage > > {
101
107
let movie = SwfMovie :: from_path ( swf_path, None ) . map_err ( |e| anyhow ! ( e. to_string( ) ) ) ?;
102
108
@@ -168,10 +174,23 @@ fn take_screenshot(
168
174
if let Some ( progress) = & progress {
169
175
progress. inc ( 1 ) ;
170
176
}
177
+
178
+ if stop_on_last_frame && is_root_movie_clip_at_end ( & player) {
179
+ break ;
180
+ }
171
181
}
172
182
Ok ( result)
173
183
}
174
184
185
+ fn is_root_movie_clip_at_end ( player : & Arc < Mutex < Player > > ) -> bool {
186
+ player. lock ( ) . unwrap ( ) . mutate_with_update_context ( |ctx| {
187
+ ctx. stage
188
+ . root_clip ( )
189
+ . and_then ( |root_clip| root_clip. as_movie_clip ( ) )
190
+ . is_some_and ( |movie_clip| movie_clip. current_frame ( ) == movie_clip. total_frames ( ) )
191
+ } )
192
+ }
193
+
175
194
fn force_root_clip_play ( player : & Arc < Mutex < Player > > ) {
176
195
let mut player_guard = player. lock ( ) . unwrap ( ) ;
177
196
@@ -258,6 +277,7 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
258
277
& progress,
259
278
opt. size ,
260
279
opt. force_play ,
280
+ opt. stop_on_last_frame ,
261
281
) ?;
262
282
263
283
if let Some ( progress) = & progress {
@@ -352,6 +372,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
352
372
& progress,
353
373
opt. size ,
354
374
opt. force_play ,
375
+ opt. stop_on_last_frame ,
355
376
) {
356
377
let mut relative_path = file
357
378
. path ( )
0 commit comments