Skip to content

Commit c3d69bb

Browse files
committed
Use input Info in command builder
1 parent 462a767 commit c3d69bb

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/app.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub(crate) struct App<'a> {
4040
// Input
4141
pub original_filename: Box<str>,
4242
pub source: Source,
43+
pub info: &'a Info,
4344
pub info_state: InfoPaneState<'a>,
4445
// Output
4546
pub out_state: OutputPaneState,
@@ -50,8 +51,8 @@ pub(crate) struct App<'a> {
5051
render_stdin: Option<ChildStdin>,
5152
}
5253

53-
impl App<'_> {
54-
pub fn new(tx: Sender<AppEvent>, info: &Info, source: Source, preset: Option<&str>) -> Self {
54+
impl<'a> App<'a> {
55+
pub fn new(tx: Sender<AppEvent>, info: &'a Info, source: Source, preset: Option<&str>) -> Self {
5556
let mut list_state = ListState::default();
5657
list_state.select(Some(0));
5758
let folder = source.input_folder();
@@ -78,6 +79,7 @@ impl App<'_> {
7879
// Info
7980
original_filename,
8081
source,
82+
info,
8183
info_state,
8284
// Output
8385
out_state: OutputPaneState::new(String::new()),
@@ -383,7 +385,7 @@ impl App<'_> {
383385
}
384386

385387
fn build_ffmpeg_command(&mut self, overwrite: bool) -> Vec<String> {
386-
let mut command_builder = CommandBuilder::default();
388+
let mut command_builder = CommandBuilder::new(self.info);
387389
apply_visitor(&mut command_builder, &mut self.params);
388390
let input = self.source.input.clone();
389391
let mut path = PathBuf::new()

src/params/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub(crate) fn get_output_format(params: &[Parameter]) -> Option<&SelectOption> {
142142
}
143143

144144
pub(crate) fn apply_visitor(visitor: &mut dyn ParameterVisitor, params: &mut [Parameter]) {
145-
// Apply visitor based on logical order, which is slight different from UI order
145+
// Apply visitor based on logical order, which is slightly different from UI order
146146
let mut sorted_params: Vec<&mut Parameter> =
147147
params.iter_mut().filter(|param| param.enabled).collect();
148148
sorted_params.sort_by_key(|param| param.order);

src/params/speed_factor.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use tracing::debug;
3+
use tracing::{Level, debug, enabled};
44

55
use crate::{
66
model::{InputConstraints, InputType},
@@ -53,6 +53,15 @@ impl SpeedFactor {
5353
if let Some(value) = select_non_default_custom_value!(data) {
5454
cb.speed_factor = value.parse().ok();
5555
debug!(speed_factor = cb.speed_factor, "build_command");
56+
if enabled!(Level::DEBUG)
57+
&& let (Some(in_duration), Some(speed)) = (cb.input_duration, cb.speed_factor)
58+
{
59+
debug!(
60+
in_duration = in_duration,
61+
out_duration = in_duration / speed,
62+
"build_command"
63+
);
64+
}
5665
if !cb.discard_audio {
5766
cb.audio_filters.push(format!("atempo={}", &value));
5867
}

src/visitors/command_builder.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use crate::{params::*, visitors::ParameterVisitor};
1+
use crate::{info::Info, params::*, visitors::ParameterVisitor};
22

33
/// Build FFmpeg command from parameters
44
5-
#[derive(Default)]
5+
#[derive(Debug, Default)]
66
pub(crate) struct CommandBuilder {
7+
// from input info
8+
pub(crate) input_duration: Option<f64>,
9+
// from params
710
pub(crate) discard_audio: bool,
811
pub(crate) hwaccel: HWAccel,
912
pub(crate) speed_factor: Option<f64>,
@@ -16,7 +19,7 @@ pub(crate) struct CommandBuilder {
1619
pub(crate) ext: String,
1720
}
1821

19-
#[derive(PartialEq, Default)]
22+
#[derive(Debug, Default, PartialEq)]
2023
pub(crate) enum HWAccel {
2124
#[default]
2225
None,
@@ -33,6 +36,13 @@ pub(crate) enum HWAccel {
3336
}
3437

3538
impl CommandBuilder {
39+
pub(crate) fn new(info: &Info) -> Self {
40+
Self {
41+
input_duration: info.get_duration(),
42+
..Default::default()
43+
}
44+
}
45+
3646
pub(crate) fn build_pre_input_args(&self) -> &[String] {
3747
&self.pre_input_args
3848
}

0 commit comments

Comments
 (0)