Skip to content

Commit dd2c407

Browse files
committed
Set output path
1 parent 9338c21 commit dd2c407

File tree

5 files changed

+56
-5
lines changed

5 files changed

+56
-5
lines changed

backend/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct AppConfig {
1212
pub render_options: RenderSettings,
1313
pub app_update: AppUpdate,
1414
pub font_path: String,
15+
pub out_path: String,
1516
}
1617

1718
const CONFIG_NAME: &str = "saved_settings";

ui/src/app.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct WalksnailOsdTool {
3131
pub video_info: Option<VideoInfo>,
3232
pub osd_file: Option<OsdFile>,
3333
pub font_file: Option<FontFile>,
34+
pub out_path: Option<PathBuf>,
3435
pub srt_file: Option<SrtFile>,
3536
pub ui_dimensions: UiDimensions,
3637
pub to_ffmpeg_sender: Option<Sender<ToFfmpegMessage>>,
@@ -78,6 +79,9 @@ impl WalksnailOsdTool {
7879
let font_path = PathBuf::from(saved_settings.font_path);
7980
let font_file = font::FontFile::open(font_path).ok();
8081

82+
// Load last used output path
83+
let out_path = Some(PathBuf::from(saved_settings.out_path));
84+
8185
let app_update = AppUpdate {
8286
promise: update_check_promise,
8387
..Default::default()
@@ -94,6 +98,7 @@ impl WalksnailOsdTool {
9498
osd_options,
9599
srt_options,
96100
font_file,
101+
out_path,
97102
app_update,
98103
app_version,
99104
target,

ui/src/bottom_panel.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@ impl WalksnailOsdTool {
1111
ui.add_space(5.0);
1212
ui.horizontal(|ui| {
1313
self.start_stop_render_button(ui);
14+
self.out_path_label(ui);
1415
self.render_progress(ui);
1516
});
1617
ui.add_space(2.0);
1718
});
1819
}
1920

21+
fn out_path_label(&mut self, ui: &mut Ui) {
22+
if self.render_status.is_not_in_progress() {
23+
if let Some(out_path) = &self.out_path {
24+
let path = out_path.as_path().to_string_lossy();
25+
ui.label(path);
26+
} else {
27+
ui.label("-");
28+
}
29+
}
30+
}
31+
2032
fn start_stop_render_button(&mut self, ui: &mut Ui) {
2133
let button_size = vec2(110.0, 40.0);
2234
if self.render_status.is_not_in_progress() {
@@ -30,7 +42,15 @@ impl WalksnailOsdTool {
3042
{
3143
tracing::info!("Start render button clicked");
3244
self.render_status.start_render();
33-
if let (Some(video_path), Some(osd_file), Some(font_file), Some(video_info), Some(srt_file)) = (
45+
if let (
46+
Some(out_path),
47+
Some(video_path),
48+
Some(osd_file),
49+
Some(font_file),
50+
Some(video_info),
51+
Some(srt_file),
52+
) = (
53+
&self.out_path,
3454
&self.video_file,
3555
&self.osd_file,
3656
&self.font_file,
@@ -47,7 +67,7 @@ impl WalksnailOsdTool {
4767
match start_video_render(
4868
&self.dependencies.ffmpeg_path,
4969
video_path,
50-
&get_output_video_path(video_path),
70+
&get_output_video_path(out_path, video_path),
5171
osd_file.frames.clone(),
5272
srt_file.frames.clone(),
5373
font_file.clone(),
@@ -111,7 +131,12 @@ impl WalksnailOsdTool {
111131
}
112132
Status::Completed => {
113133
ui.vertical(|ui| {
114-
ui.add(ProgressBar::new(1.0).text("Done"));
134+
if let (Some(out_path), Some(input_video_path)) = (&self.out_path, &self.video_file) {
135+
let out = &get_output_video_path(out_path, input_video_path);
136+
let path = out.as_path().to_string_lossy();
137+
let name: String = out.file_name().unwrap().to_string_lossy().into();
138+
ui.hyperlink_to(name, path);
139+
}
115140
});
116141
}
117142
Status::Cancelled { progress_pct } => {

ui/src/top_panel.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ impl WalksnailOsdTool {
88
ui.add_space(5.0);
99
ui.horizontal(|ui| {
1010
self.import_files(ui, ctx);
11+
self.output_path_button(ui);
1112
self.reset_files(ui);
1213
ui.add_space(ui.available_width() - 55.0);
1314
self.toggle_light_dark_theme(ui, ctx);
@@ -58,6 +59,19 @@ impl WalksnailOsdTool {
5859
});
5960
}
6061

62+
fn output_path_button(&mut self, ui: &mut Ui) {
63+
if ui
64+
.add_enabled(self.render_status.is_not_in_progress(), Button::new("Output path"))
65+
.clicked()
66+
{
67+
tracing::info!("Output file button clicked");
68+
if let Some(file_handles) = rfd::FileDialog::new().add_filter("MP4 files", &["mp4"]).pick_folder() {
69+
tracing::info!("Output {:?}", file_handles);
70+
self.out_path = Some(file_handles);
71+
}
72+
}
73+
}
74+
6175
fn reset_files(&mut self, ui: &mut Ui) {
6276
if ui
6377
.add_enabled(self.render_status.is_not_in_progress(), Button::new("Reset files"))

ui/src/util.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ impl WalksnailOsdTool {
4444
// Try to load the matching OSD and SRT files
4545
self.import_osd_file(&[matching_file_with_extension(video_file, "osd")]);
4646
self.import_srt_file(&[matching_file_with_extension(video_file, "srt")]);
47+
48+
// If the output path is not set, set it to the same directory as the video file
49+
if self.out_path.is_none() {
50+
self.out_path = Some(video_file.parent().unwrap().to_path_buf());
51+
}
4752
}
4853
}
4954

@@ -102,10 +107,10 @@ pub fn format_minutes_seconds(duration: &Duration) -> String {
102107
format!("{}:{:0>2}", minutes, seconds)
103108
}
104109

105-
pub fn get_output_video_path(input_video_path: &Path) -> PathBuf {
110+
pub fn get_output_video_path(out_video_path: &Path, input_video_path: &Path) -> PathBuf {
106111
let input_video_file_name = input_video_path.file_stem().unwrap().to_string_lossy();
107112
let output_video_file_name = format!("{}_with_osd.mp4", input_video_file_name);
108-
let mut output_video_path = input_video_path.parent().unwrap().to_path_buf();
113+
let mut output_video_path = out_video_path.to_path_buf();
109114
output_video_path.push(output_video_file_name);
110115
output_video_path
111116
}
@@ -172,6 +177,7 @@ impl Into<AppConfig> for &mut WalksnailOsdTool {
172177
.unwrap_or_default()
173178
.to_string_lossy()
174179
.to_string(),
180+
out_path: self.out_path.as_ref().unwrap().to_string_lossy().to_string(),
175181
}
176182
}
177183
}

0 commit comments

Comments
 (0)