-
-
Couldn't load subscription status.
- Fork 926
exporter: Add Support for Full Auto-Export, End-on-Last-Frame Logic, and Prevent --force-play Looping #20896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
57b8426
beb8ca0
5775f79
8f8dc5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,8 @@ struct Opt { | |
| #[clap(name = "output")] | ||
| output_path: Option<PathBuf>, | ||
|
|
||
| /// Number of frames to capture per file | ||
| /// Number of frames to capture per file. | ||
| /// If set to 0, all frames in the SWF's main timeline will be captured | ||
| #[clap(short = 'f', long = "frames", default_value = "1")] | ||
| frames: u32, | ||
|
|
||
|
|
@@ -123,7 +124,16 @@ fn take_screenshot( | |
| .build(); | ||
|
|
||
| let mut result = Vec::new(); | ||
| let totalframes = frames + skipframes; | ||
| let totalframes = if frames == 0 { | ||
| player.lock().unwrap().mutate_with_update_context(|ctx| { | ||
| ctx.stage | ||
| .root_clip() | ||
| .and_then(|root_clip| root_clip.as_movie_clip()) | ||
| .map_or(1, |movie_clip| movie_clip.total_frames() as u32) | ||
| }) | ||
| } else { | ||
| frames + skipframes | ||
| }; | ||
|
|
||
| for i in 0..totalframes { | ||
| if let Some(progress) = &progress { | ||
|
|
@@ -168,23 +178,28 @@ fn take_screenshot( | |
| if let Some(progress) = &progress { | ||
| progress.inc(1); | ||
| } | ||
|
|
||
| if is_root_movie_clip_at_end(&player) { | ||
| break; | ||
| } | ||
|
Comment on lines
+182
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will break some animations, it has to be another CLI option There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made a new cli command and raised under #20929 |
||
| } | ||
| Ok(result) | ||
| } | ||
|
|
||
| fn force_root_clip_play(player: &Arc<Mutex<Player>>) { | ||
| let mut player_guard = player.lock().unwrap(); | ||
|
|
||
| // Check and resume if suspended | ||
| if !player_guard.is_playing() { | ||
| player_guard.set_is_playing(true); | ||
| } | ||
| fn is_root_movie_clip_at_end(player: &Arc<Mutex<Player>>) -> bool { | ||
| player.lock().unwrap().mutate_with_update_context(|ctx| { | ||
| ctx.stage | ||
| .root_clip() | ||
| .and_then(|root_clip| root_clip.as_movie_clip()) | ||
| .is_some_and(|movie_clip| movie_clip.current_frame() == movie_clip.total_frames()) | ||
| }) | ||
| } | ||
|
|
||
| // Also resume the root MovieClip if stopped | ||
| player_guard.mutate_with_update_context(|ctx| { | ||
| fn force_root_clip_play(player: &Arc<Mutex<Player>>) { | ||
| player.lock().unwrap().mutate_with_update_context(|ctx| { | ||
| if let Some(root_clip) = ctx.stage.root_clip() { | ||
| if let Some(movie_clip) = root_clip.as_movie_clip() { | ||
| if !movie_clip.playing() { | ||
| if !movie_clip.playing() && movie_clip.current_frame() < movie_clip.total_frames() { | ||
| movie_clip.play(); | ||
| } | ||
| } | ||
|
|
@@ -278,9 +293,10 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> { | |
| image.save(&output)?; | ||
| } | ||
| } else { | ||
| let digits = frames.len().to_string().len(); | ||
| for (frame, image) in frames.iter().enumerate() { | ||
| let mut path: PathBuf = (&output).into(); | ||
| path.push(format!("{frame}.png")); | ||
| path.push(format!("{frame:0digits$}.png")); | ||
| image.save(&path)?; | ||
| } | ||
| } | ||
|
|
@@ -372,9 +388,10 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> | |
| relative_path.set_extension(""); | ||
| parent.push(&relative_path); | ||
| let _ = create_dir_all(&parent); | ||
| let digits = frames.len().to_string().len(); | ||
| for (frame, image) in frames.iter().enumerate() { | ||
| let mut destination = parent.clone(); | ||
| destination.push(format!("{frame}.png")); | ||
| destination.push(format!("{frame:0digits$}.png")); | ||
| image.save(&destination)?; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes more sense for me to pass
--frames allinstead of--frames 0to capture all frames. It looks non-intuitiveUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into this but I'm still quite new to rust, so not 100% sure what the best way to implement a cli command that takes a string or number would be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done some research and hope I've found the right way to implement this.
I need to run a few more tests, but I've raised this as #20930.