Skip to content

Commit 84ac9dd

Browse files
authored
fix(#109): on ubuntu 20.04 for arm the recording is upside down (#113)
- fixes #109 - the issue is apparently a tga / imagemagick specific one - now a switch to bmp as intermediate format seems reasonable
1 parent 027f156 commit 84ac9dd

File tree

9 files changed

+37
-25
lines changed

9 files changed

+37
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ features = ["cargo"]
3333

3434
[dependencies.image]
3535
version = "0.24.0"
36-
features = ["tga"]
36+
features = ["bmp"]
3737

3838
[target.'cfg(target_os = "macos")'.dependencies]
3939
objc_id = "0.1.1"

src/capture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex};
88
use std::time::{Duration, Instant};
99
use tempfile::TempDir;
1010

11-
use crate::utils::file_name_for;
11+
use crate::utils::{file_name_for, IMG_EXT};
1212
use crate::{ImageOnHeap, PlatformApi, WindowId};
1313

1414
/// captures screenshots as file on disk
@@ -77,7 +77,7 @@ pub fn save_frame(
7777
file_name_for: fn(&u128, &str) -> String,
7878
) -> Result<()> {
7979
save_buffer(
80-
tempdir.path().join(file_name_for(&time_code, "tga")),
80+
tempdir.path().join(file_name_for(&time_code, IMG_EXT)),
8181
&image.samples,
8282
image.layout.width,
8383
image.layout.height,

src/decor_effect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use anyhow::Context;
55
use rayon::prelude::*;
66
use tempfile::TempDir;
77

8+
use crate::utils::IMG_EXT;
89
use crate::Result;
910

1011
///
@@ -100,7 +101,9 @@ fn apply_effect(
100101
effect: Box<dyn Fn(PathBuf) -> Result<()> + Send + Sync>,
101102
) {
102103
time_codes.into_par_iter().for_each(|tc| {
103-
let file = tempdir.path().join(crate::utils::file_name_for(tc, "tga"));
104+
let file = tempdir
105+
.path()
106+
.join(crate::utils::file_name_for(tc, IMG_EXT));
104107
if let Err(e) = effect(file) {
105108
eprintln!("{}", e);
106109
}

src/generators/gif.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::file_name_for;
1+
use crate::utils::{file_name_for, IMG_EXT};
22

33
use anyhow::{Context, Result};
44
use std::ops::Div;
@@ -20,10 +20,7 @@ pub fn check_for_imagemagick() -> Result<Output> {
2020
.arg("--version")
2121
.output()
2222
.with_context(|| {
23-
format!(
24-
"There is an issue with '{}', please install: `{}`",
25-
PROGRAM, INST_CMD,
26-
)
23+
format!("There is an issue with '{PROGRAM}', please install: `{INST_CMD}`")
2724
})
2825
}
2926

@@ -36,14 +33,18 @@ pub fn generate_gif_with_convert(
3633
start_pause: Option<Duration>,
3734
end_pause: Option<Duration>,
3835
) -> Result<()> {
39-
println!("🎉 🚀 Generating {}", target);
36+
println!("🎉 🚀 Generating {target}");
4037
let mut cmd = Command::new(PROGRAM);
4138
cmd.arg("-loop").arg("0");
4239
let mut delay = 0;
40+
let temp = tempdir.path();
4341
let last_frame_i = time_codes.len() - 1;
4442
for (i, tc) in time_codes.iter().enumerate() {
4543
delay = *tc - delay;
46-
let frame = tempdir.path().join(file_name_for(tc, "tga"));
44+
let frame = temp.join(file_name_for(tc, IMG_EXT));
45+
if !frame.exists() {
46+
continue;
47+
}
4748
let mut frame_delay = (delay as f64 * 0.1) as u64;
4849
match (i, start_pause, end_pause) {
4950
(0, Some(delay), _) => {

src/generators/mp4.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@ use std::process::Command;
33
use anyhow::{Context, Result};
44
use tempfile::TempDir;
55

6+
use crate::utils::IMG_EXT;
7+
68
const PROGRAM: &str = "ffmpeg";
79

10+
#[cfg(target_os = "macos")]
11+
const INST_CMD: &str = "brew install ffmpeg";
12+
#[cfg(not(target_os = "macos"))]
13+
const INST_CMD: &str = "apt-get install ffmpeg";
14+
815
/// checks if ffmpeg is available
916
pub fn check_for_ffmpeg() -> Result<()> {
1017
let out = Command::new(PROGRAM)
1118
.arg("-version")
1219
.output()
1320
.with_context(|| {
14-
format!(
15-
"There is an issue with '{}', please install: `brew install {}`",
16-
PROGRAM, PROGRAM
17-
)
21+
format!("There is an issue with '{PROGRAM}', please install: `{INST_CMD}`")
1822
})?;
1923

2024
if !String::from_utf8(out.stdout.to_vec())
21-
.with_context(|| format!("Unable to parse the `{} -version`", PROGRAM))
25+
.with_context(|| format!("Unable to parse the `{PROGRAM} -version`"))
2226
.unwrap()
2327
.contains("--enable-libx264")
2428
{
@@ -37,7 +41,7 @@ pub fn generate_mp4_with_ffmpeg(
3741
tempdir: &TempDir,
3842
target: &str,
3943
) -> Result<()> {
40-
println!("🎉 🎬 Generating {}", &target);
44+
println!("🎉 🎬 Generating {target}");
4145
Command::new(PROGRAM)
4246
.arg("-y")
4347
.arg("-r")
@@ -48,7 +52,7 @@ pub fn generate_mp4_with_ffmpeg(
4852
.arg("-pattern_type")
4953
.arg("glob")
5054
.arg("-i")
51-
.arg(tempdir.path().join("*.tga"))
55+
.arg(tempdir.path().join(format!("*.{IMG_EXT}")))
5256
.arg("-vcodec")
5357
.arg("libx264")
5458
.arg("-pix_fmt")
@@ -59,6 +63,6 @@ pub fn generate_mp4_with_ffmpeg(
5963
// end of fix
6064
.arg(target)
6165
.output()
62-
.with_context(|| format!("Cannot start '{}' to generate the final video", PROGRAM))
66+
.with_context(|| format!("Cannot start '{PROGRAM}' to generate the final video"))
6367
.map(|_| ())
6468
}

src/linux/x11_api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ impl PlatformApi for X11Api {
261261
#[cfg(test)]
262262
mod test {
263263
use super::*;
264+
use crate::utils::IMG_EXT;
264265
use image::flat::View;
265266
use image::{save_buffer, GenericImageView, Rgba};
266267

@@ -345,7 +346,7 @@ mod test {
345346
assert_ne!(alpha, 0, "alpha is unexpected");
346347

347348
// Note: visual validation is sometimes helpful:
348-
let file = format!("frame-{}.tga", win);
349+
let file = format!("frame-{win}.{IMG_EXT}");
349350
save_buffer(
350351
file,
351352
&image_raw.samples,

src/macos/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ mod core_foundation_sys_patches;
22
mod screenshot;
33
mod window_id;
44

5+
use crate::common::identify_transparency::identify_transparency;
6+
use crate::common::image::crop;
57
use crate::PlatformApi;
68
use crate::{ImageOnHeap, Margin, Result, WindowList};
79

8-
use crate::common::identify_transparency::identify_transparency;
9-
use crate::common::image::crop;
1010
use anyhow::Context;
1111
use screenshot::capture_window_screenshot;
1212
use std::env;
@@ -63,6 +63,7 @@ impl PlatformApi for QuartzApi {
6363
#[cfg(test)]
6464
mod test {
6565
use super::*;
66+
use crate::utils::IMG_EXT;
6667
use image::flat::View;
6768
use image::{save_buffer, GenericImageView, Rgba};
6869

@@ -99,7 +100,7 @@ mod test {
99100

100101
// Note: visual validation is sometimes helpful:
101102
save_buffer(
102-
format!("frame-raw-{}.tga", win),
103+
format!("frame-raw-{win}.{IMG_EXT}"),
103104
&image_raw.samples,
104105
image_raw.layout.width,
105106
image_raw.layout.height,

src/macos/screenshot.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ mod tests {
7474
#[cfg(feature = "e2e_tests")]
7575
fn should_capture_with_cropped_transparent_area() -> Result<()> {
7676
use crate::common::PlatformApi;
77+
use crate::utils::IMG_EXT;
7778

7879
let mut api = setup()?;
7980
let win = 5308;
@@ -83,7 +84,7 @@ mod tests {
8384

8485
// Note: visual validation is sometimes helpful:
8586
save_buffer(
86-
format!("frame-org-{}.tga", win),
87+
format!("frame-org-{win}.{IMG_EXT}"),
8788
&image.samples,
8889
image.layout.width,
8990
image.layout.height,
@@ -97,7 +98,7 @@ mod tests {
9798
assert!(width > image_cropped.layout.width);
9899
// Note: visual validation is sometimes helpful:
99100
save_buffer(
100-
format!("frame-cropped-{}.tga", win),
101+
format!("frame-cropped-{win}.{IMG_EXT}"),
101102
&image_cropped.samples,
102103
image_cropped.layout.width,
103104
image_cropped.layout.height,

src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::process::{Command, ExitStatus};
44

55
pub const DEFAULT_EXT: &str = "gif";
66
pub const MOVIE_EXT: &str = "mp4";
7+
pub const IMG_EXT: &str = "bmp";
78

89
/// encapsulate the file naming convention
910
pub fn file_name_for(tc: &u128, ext: &str) -> String {

0 commit comments

Comments
 (0)