Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +55 to +56
Copy link
Member

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 all instead of --frames 0 to capture all frames. It looks non-intuitive

Copy link
Contributor Author

@AeroXuk AeroXuk Jul 4, 2025

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

Copy link
Contributor Author

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.

#[clap(short = 'f', long = "frames", default_value = "1")]
frames: u32,

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will break some animations, it has to be another CLI option

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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();
}
}
Expand Down Expand Up @@ -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)?;
}
}
Expand Down Expand Up @@ -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)?;
}
}
Expand Down