Skip to content

Commit

Permalink
Add interpolation method selector to Export settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianEddy committed Jan 7, 2024
1 parent e86171c commit 7b48ed3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ fn setup_defaults(stab: Arc<StabilizationManager>, queue: &mut RenderQueue) -> s
stab.set_device(processing_device);
}

let audio_codecs = ["AAC", "PCM (s16le)", "PCM (s16be)", "PCM (s24le)", "PCM (s24be)"];
let interpolations = ["Bilinear", "Bicubic", "Lanczos4"];

// Sync and export settings
serde_json::json!({
"output": {
Expand All @@ -481,7 +484,8 @@ fn setup_defaults(stab: Arc<StabilizationManager>, queue: &mut RenderQueue) -> s
"keyframe_distance": settings.get("keyframeDistance").unwrap_or(&"1".into()).parse::<u32>().unwrap(),
"preserve_other_tracks": settings.get("preserveOtherTracks").unwrap_or(&"false".into()).parse::<bool>().unwrap(),
"pad_with_black": settings.get("padWithBlack").unwrap_or(&"false".into()).parse::<bool>().unwrap(),
"audio_codec": settings.get("audioCodec").unwrap_or(&"AAC".into()),
"audio_codec": audio_codecs.get(settings.get("audioCodec").unwrap_or(&"0".into()).parse::<usize>().unwrap()).unwrap_or(&"AAC"),
"interpolation": interpolations.get(settings.get("interpolationMethod").unwrap_or(&"2".into()).parse::<usize>().unwrap()).unwrap_or(&"Lanczos4"),
},
"synchronization": {
"initial_offset": 0,
Expand Down
5 changes: 3 additions & 2 deletions src/core/stabilization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use compute_params::ComputeParams;
pub use frame_transform::FrameTransform;
pub use cpu_undistort::*;

#[derive(Default, Clone, Copy)]
#[derive(Default, Clone, Copy, Debug)]
pub enum Interpolation {
#[default]
Bilinear = 2,
Expand Down Expand Up @@ -264,14 +264,15 @@ impl Stabilization {

pub fn get_current_key(&self, buffers: &Buffers) -> String {
format!(
"{}|{}|{}|{}|{}|{:?}|{:?}|{:?}",
"{}|{}|{}|{}|{}|{:?}|{:?}|{:?}|{:?}",
buffers.get_checksum(),
self.compute_params.distortion_model.id(),
self.compute_params.digital_lens.as_ref().map(|x| x.id()).unwrap_or_default(),
self.interpolation as u32,
self.kernel_flags.bits(),
self.size,
self.output_size,
self.interpolation,
std::thread::current().id(),
)
}
Expand Down
9 changes: 8 additions & 1 deletion src/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ pub fn render<F, F2>(stab: Arc<StabilizationManager>, progress: F, input_file: &
_ => { }
}

let interpolation = match render_options.interpolation.as_ref() {
"Bilinear" => Interpolation::Bilinear,
"Bicubic" => Interpolation::Bicubic,
_ => Interpolation::Lanczos4
};

log::debug!("interpolation: {:?}", &interpolation);
log::debug!("proc.gpu_device: {:?}", &proc.gpu_device);
let encoder = ffmpeg_hw::find_working_encoder(&get_possible_encoders(&render_options.codec, render_options.use_gpu), hwaccel_device);
proc.video_codec = Some(encoder.0.to_owned());
Expand Down Expand Up @@ -460,7 +467,7 @@ pub fn render<F, F2>(stab: Arc<StabilizationManager>, progress: F, input_file: &
params.video_output_size = params.output_size;
}
let mut plane = Stabilization::default();
plane.interpolation = Interpolation::Lanczos4;
plane.interpolation = interpolation;
plane.share_wgpu_instances = true;
plane.set_device(stab.params.read().current_device as isize);

Expand Down
2 changes: 2 additions & 0 deletions src/rendering/render_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct RenderOptions {
pub preserve_other_tracks: bool,
pub pad_with_black: bool,
pub audio_codec: String,
pub interpolation: String,
}
impl RenderOptions {
pub fn settings_string(&self, fps: f64) -> String {
Expand Down Expand Up @@ -133,6 +134,7 @@ impl RenderOptions {
if let Some(v) = obj.get("preserve_other_tracks").and_then(|x| x.as_bool()) { self.preserve_other_tracks = v; }
if let Some(v) = obj.get("pad_with_black") .and_then(|x| x.as_bool()) { self.pad_with_black = v; }
if let Some(v) = obj.get("audio_codec") .and_then(|x| x.as_str()) { self.audio_codec = v.to_string(); }
if let Some(v) = obj.get("interpolation") .and_then(|x| x.as_str()) { self.interpolation = v.to_string(); }

if let Some(v) = obj.get("metadata").and_then(|x| x.as_object()) {
if let Some(s) = v.get("comment").and_then(|x| x.as_str()) { self.metadata.comment = s.to_string(); }
Expand Down
2 changes: 1 addition & 1 deletion src/ui/SettingsSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Modal {
"Audio": ["audio"],
"Output size": ["output_width", "output_height"],
"Output path": ["output_folder", "output_filename"],
"Advanced": ["encoder_options", "metadata", "keyframe_distance", "preserve_other_tracks", "pad_with_black", "audio_codec"],
"Advanced": ["encoder_options", "metadata", "keyframe_distance", "preserve_other_tracks", "pad_with_black", "audio_codec", "interpolation"],
},
"Advanced": {
"Background": ["background_color", "background_mode", "background_margin", "background_margin_feather"],
Expand Down
16 changes: 15 additions & 1 deletion src/ui/menu/Export.qml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ MenuItem {
property alias padWithBlack: padWithBlack.checked;
property alias metadataComment: metadataComment.text;
property alias audioCodec: audioCodec.currentIndex;
property alias interpolationMethod: interpolationMethod.currentIndex;
property alias preserveOutputSettings: preserveOutputSettings.checked;
property alias preserveOutputPath: preserveOutputPath.checked;
}
Expand Down Expand Up @@ -130,7 +131,8 @@ MenuItem {
keyframe_distance: keyframeDistance.value,
preserve_other_tracks: preserveOtherTracks.checked,
pad_with_black: padWithBlack.checked,
audio_codec: audioCodec.currentText
audio_codec: audioCodec.currentText,
interpolation: interpolationMethod.currentText
};
}

Expand Down Expand Up @@ -225,6 +227,7 @@ MenuItem {
if (output.hasOwnProperty("preserve_other_tracks")) preserveOtherTracks.checked = output.preserve_other_tracks;
if (output.hasOwnProperty("pad_with_black")) padWithBlack.checked = output.pad_with_black;
if (output.hasOwnProperty("audio_codec")) Util.setComboValue(audioCodec, output.audio_codec);
if (output.hasOwnProperty("interpolation")) Util.setComboValue(interpolationMethod, output.interpolation);
if (output.hasOwnProperty("metadata")) {
metadataComment.text = output.metadata.comment || "";
}
Expand Down Expand Up @@ -550,6 +553,17 @@ MenuItem {
currentIndex: 0;
}
}
Label {
position: Label.LeftPosition;
text: qsTr("Interpolation method");
ComboBox {
id: interpolationMethod;
model: ["Bilinear", "Bicubic", "Lanczos4"];
font.pixelSize: 12 * dpiScale;
width: parent.width;
currentIndex: 2;
}
}
Label {
position: Label.TopPosition;
text: qsTr("Device for rendering");
Expand Down

0 comments on commit 7b48ed3

Please sign in to comment.