Skip to content
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

Set output path #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct AppConfig {
pub render_options: RenderSettings,
pub app_update: AppUpdate,
pub font_path: String,
pub out_path: String,
}

const CONFIG_NAME: &str = "saved_settings";
Expand Down
5 changes: 5 additions & 0 deletions ui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct WalksnailOsdTool {
pub video_info: Option<VideoInfo>,
pub osd_file: Option<OsdFile>,
pub font_file: Option<FontFile>,
pub out_path: Option<PathBuf>,
pub srt_file: Option<SrtFile>,
pub ui_dimensions: UiDimensions,
pub to_ffmpeg_sender: Option<Sender<ToFfmpegMessage>>,
Expand Down Expand Up @@ -78,6 +79,9 @@ impl WalksnailOsdTool {
let font_path = PathBuf::from(saved_settings.font_path);
let font_file = font::FontFile::open(font_path).ok();

// Load last used output path
let out_path = Some(PathBuf::from(saved_settings.out_path));

let app_update = AppUpdate {
promise: update_check_promise,
..Default::default()
Expand All @@ -94,6 +98,7 @@ impl WalksnailOsdTool {
osd_options,
srt_options,
font_file,
out_path,
app_update,
app_version,
target,
Expand Down
31 changes: 28 additions & 3 deletions ui/src/bottom_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ impl WalksnailOsdTool {
ui.add_space(5.0);
ui.horizontal(|ui| {
self.start_stop_render_button(ui);
self.out_path_label(ui);
self.render_progress(ui);
});
ui.add_space(2.0);
});
}

fn out_path_label(&mut self, ui: &mut Ui) {
if self.render_status.is_not_in_progress() {
if let Some(out_path) = &self.out_path {
let path = out_path.as_path().to_string_lossy();
ui.label(path);
} else {
ui.label("-");
}
}
}

fn start_stop_render_button(&mut self, ui: &mut Ui) {
let button_size = vec2(110.0, 40.0);
if self.render_status.is_not_in_progress() {
Expand All @@ -30,7 +42,15 @@ impl WalksnailOsdTool {
{
tracing::info!("Start render button clicked");
self.render_status.start_render();
if let (Some(video_path), Some(osd_file), Some(font_file), Some(video_info), Some(srt_file)) = (
if let (
Some(out_path),
Some(video_path),
Some(osd_file),
Some(font_file),
Some(video_info),
Some(srt_file),
) = (
&self.out_path,
&self.video_file,
&self.osd_file,
&self.font_file,
Expand All @@ -47,7 +67,7 @@ impl WalksnailOsdTool {
match start_video_render(
&self.dependencies.ffmpeg_path,
video_path,
&get_output_video_path(video_path),
&get_output_video_path(out_path, video_path),
osd_file.frames.clone(),
srt_file.frames.clone(),
font_file.clone(),
Expand Down Expand Up @@ -111,7 +131,12 @@ impl WalksnailOsdTool {
}
Status::Completed => {
ui.vertical(|ui| {
ui.add(ProgressBar::new(1.0).text("Done"));
if let (Some(out_path), Some(input_video_path)) = (&self.out_path, &self.video_file) {
let out = &get_output_video_path(out_path, input_video_path);
let path = out.as_path().to_string_lossy();
let name: String = out.file_name().unwrap().to_string_lossy().into();
ui.hyperlink_to(name, path);
}
});
}
Status::Cancelled { progress_pct } => {
Expand Down
14 changes: 14 additions & 0 deletions ui/src/top_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ impl WalksnailOsdTool {
ui.add_space(5.0);
ui.horizontal(|ui| {
self.import_files(ui, ctx);
self.output_path_button(ui);
self.reset_files(ui);
ui.add_space(ui.available_width() - 55.0);
self.toggle_light_dark_theme(ui, ctx);
Expand Down Expand Up @@ -58,6 +59,19 @@ impl WalksnailOsdTool {
});
}

fn output_path_button(&mut self, ui: &mut Ui) {
if ui
.add_enabled(self.render_status.is_not_in_progress(), Button::new("Output path"))
.clicked()
{
tracing::info!("Output file button clicked");
if let Some(file_handles) = rfd::FileDialog::new().add_filter("MP4 files", &["mp4"]).pick_folder() {
tracing::info!("Output {:?}", file_handles);
self.out_path = Some(file_handles);
}
}
}

fn reset_files(&mut self, ui: &mut Ui) {
if ui
.add_enabled(self.render_status.is_not_in_progress(), Button::new("Reset files"))
Expand Down
10 changes: 8 additions & 2 deletions ui/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl WalksnailOsdTool {
// Try to load the matching OSD and SRT files
self.import_osd_file(&[matching_file_with_extension(video_file, "osd")]);
self.import_srt_file(&[matching_file_with_extension(video_file, "srt")]);

// If the output path is not set, set it to the same directory as the video file
if self.out_path.is_none() {
self.out_path = Some(video_file.parent().unwrap().to_path_buf());
}
}
}

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

pub fn get_output_video_path(input_video_path: &Path) -> PathBuf {
pub fn get_output_video_path(out_video_path: &Path, input_video_path: &Path) -> PathBuf {
let input_video_file_name = input_video_path.file_stem().unwrap().to_string_lossy();
let output_video_file_name = format!("{}_with_osd.mp4", input_video_file_name);
let mut output_video_path = input_video_path.parent().unwrap().to_path_buf();
let mut output_video_path = out_video_path.to_path_buf();
output_video_path.push(output_video_file_name);
output_video_path
}
Expand Down Expand Up @@ -172,6 +177,7 @@ impl Into<AppConfig> for &mut WalksnailOsdTool {
.unwrap_or_default()
.to_string_lossy()
.to_string(),
out_path: self.out_path.as_ref().unwrap().to_string_lossy().to_string(),
}
}
}
Expand Down