Skip to content

Commit fbbc92b

Browse files
committed
feat!(config): config to toml
changes config file format from yaml to toml to improve usability as well added new key for output container BREAKING CHANGE: new config file format and name
1 parent 3874ade commit fbbc92b

7 files changed

+188
-172
lines changed

Cargo.lock

+1-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ clap = { version = "4.0", features = ["derive"] }
1414
dirs = "4.0.0"
1515
rand = "0.8.5"
1616
serde = { version = "1.0", features = ["derive"] }
17-
serde_yaml = "0.9"
1817
human-panic = "1.0.3"
1918
rfd = "0.10.0"
2019
indicatif = { version = "0.17.2", features = ["improved_unicode"] }
@@ -27,6 +26,7 @@ log = "0.4"
2726
env_logger = "0.10.0"
2827
wild = "2"
2928
is-terminal = "0.4.2"
29+
toml = "0.5"
3030

3131
[build-dependencies]
3232
clap_mangen = "0.2"

docs/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ permalink: /docs/configuration
66

77
# Configuration of Teres
88

9-
When first run it creates a config file in the `.config/teres/` folder. `C:/users/user/.config/teres/config.yml` for example for windows which allows you to change the settings for the interpolation and enconding processes
9+
When first run it creates a config file in the `.config/teres/` folder. `C:/users/user/.config/teres/teres.toml` for example for windows which allows you to change the settings for the interpolation and enconding processes
1010

1111
## Options
1212

index.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ nav_order: 1
1717
1818
---
1919

20-
| Before | After |
21-
| --- | --- |
22-
| ![before](./docs/demo-non.png) | ![after ](./docs/demo.png) |
20+
## Before
21+
![before](./docs/demo.gif)
22+
23+
## After Teres
24+
25+
![after ](./docs/demo_blur.gif)
2326

2427
</div>
2528

src/config.rs

+112-68
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,148 @@
11
use dirs::home_dir;
2-
use std::fs;
2+
use std::{fs, io::Read};
33

44
use serde::{Deserialize, Serialize};
5-
use serde_yaml::{self};
65

76
#[derive(Debug, Serialize, Deserialize, Clone)]
87
pub struct Config {
9-
pub blur: bool,
10-
pub blur_amount: f32,
11-
pub blur_output_fps: f32,
12-
pub blur_weighting: String,
8+
pub blending: Blending,
9+
pub interpolation: Interpolation,
10+
pub encoding: Encoding,
11+
pub timescale: Timescale,
1312

14-
pub interpolate: bool,
15-
pub interpolated_fps: f32,
13+
pub filters: Filters,
1614

17-
pub quality: u32,
18-
pub detailed_filenames: bool,
15+
pub advanced: Advanced,
16+
}
17+
18+
#[derive(Debug, Serialize, Deserialize, Clone)]
19+
pub struct Blending {
20+
pub enabled: bool,
21+
pub amount: f32,
22+
pub weighting: String,
23+
pub output_fps: i32,
24+
}
1925

20-
pub input_timescale: f32,
21-
pub output_timescale: f32,
22-
pub adjust_timescaled_audio_pitch: bool,
26+
#[derive(Debug, Serialize, Deserialize, Clone)]
27+
pub struct Interpolation {
28+
pub enabled: bool,
29+
pub fps: f32,
30+
}
31+
32+
#[derive(Debug, Serialize, Deserialize, Clone)]
33+
pub struct Encoding {
34+
pub quality: i32,
35+
pub detailed_filename: bool,
36+
pub container: String
37+
}
38+
39+
#[derive(Debug, Serialize, Deserialize, Clone)]
40+
pub struct Timescale {
41+
pub input: f32,
42+
pub output: f32,
43+
pub adjust_audio_pitch: bool,
44+
}
2345

46+
#[derive(Debug, Serialize, Deserialize, Clone)]
47+
pub struct Filters {
2448
pub brightness: f32,
2549
pub contrast: f32,
2650
pub saturation: f32,
51+
}
52+
53+
#[derive(Debug, Serialize, Deserialize, Clone)]
54+
pub struct Advanced {
55+
pub encoding: AdvancedEncoding,
56+
pub blend_weighting: AdvancedBlending,
57+
pub interpolation: AdvancedInterpolation,
58+
}
2759

60+
#[derive(Debug, Serialize, Deserialize, Clone)]
61+
pub struct AdvancedEncoding {
2862
pub gpu: bool,
2963
pub gpu_type: String,
3064
pub deduplicate: bool,
31-
pub custom_ffmpeg_filters: String,
65+
pub custom_ffmpeg_filters: Option<String>,
66+
}
3267

33-
pub blur_weighting_gaussian_std_dev: f32,
34-
pub blur_weighting_triangle_reverse: bool,
35-
pub blur_weighting_bound: Vec<f32>,
68+
#[derive(Debug, Serialize, Deserialize, Clone)]
69+
pub struct AdvancedBlending {
70+
pub gaussian_std_dev: i32,
71+
pub triangle_reverse: bool,
72+
pub bound: Vec<i32>,
73+
}
3674

37-
pub interpolation_program: String,
38-
pub interpolation_speed: String,
39-
pub interpolation_tuning: String,
40-
pub interpolation_algorithm: String,
75+
#[derive(Debug, Serialize, Deserialize, Clone)]
76+
pub struct AdvancedInterpolation {
77+
pub program: String,
78+
pub speed: String,
79+
pub tuning: String,
80+
pub algorithm: String,
4181
}
4282

4383
impl Config {
4484
pub fn parse() -> Config {
4585
let filepath = home_dir().unwrap();
46-
let config_file = filepath.join(".config/teres/config.yml");
86+
let config_file = filepath.join(".config/teres/teres.toml");
4787
if !config_file.exists() {
4888
Config::create(&config_file);
4989
}
5090

51-
let f = std::fs::File::open(config_file).expect("Could not open file.");
52-
let scrape_config: Config = serde_yaml::from_reader(f).expect("Could not read values.");
91+
let mut f = std::fs::File::open(config_file).expect("Could not open file.");
92+
let mut contents = String::new();
93+
f.read_to_string(&mut contents)
94+
.expect("Could not parse config file to string");
95+
let scrape_config: Config = toml::from_str(&contents).expect("Could not read values.");
5396
scrape_config
5497
}
5598

5699
pub fn create(filepath: &std::path::Path) {
57100
let prefix = filepath.parent().unwrap();
58101
std::fs::create_dir_all(prefix).unwrap();
59-
fs::write(
60-
filepath,
61-
"# blur
62-
blur: true
63-
blur_amount: 1
64-
blur_output_fps: 60
65-
blur_weighting: equal
66-
67-
# interpolation
68-
interpolate: true
69-
interpolated_fps: 480
70-
71-
# rendering
72-
quality: 18
73-
detailed_filenames: false
74-
75-
# timescale
76-
input_timescale: 1
77-
output_timescale: 1
78-
adjust_timescaled_audio_pitch: false
79-
80-
# filters
81-
brightness: 1
82-
saturation: 1
83-
contrast: 1
84-
85-
# advanced rendering
86-
gpu: false
87-
gpu_type: nvidia #nvidia/amd/intel
88-
deduplicate: false
89-
custom_ffmpeg_filters:
90-
91-
# advanced blur
92-
blur_weighting_gaussian_std_dev: 2
93-
blur_weighting_triangle_reverse: false
94-
blur_weighting_bound: [0, 2]
95-
96-
# advanced interpolation
97-
interpolation_program: svp #svp/rife/rife-ncnn
98-
interpolation_speed: default
99-
interpolation_tuning: default
100-
interpolation_algorithm: default",
101-
)
102-
.expect("Failed to create config file")
102+
fs::write(filepath, String::from("# Teres Configuration
103+
# For documentation for what each value means and the accecpted values see
104+
# https://animafps.github.io/teres/docs/configuration
105+
106+
[blending]
107+
enabled = true
108+
amount = 1.0
109+
weighting = \"equal\" # equal/gaussian/gaussian_sym/pyramid/pyramid_sym
110+
output_fps = 60
111+
112+
[interpolation]
113+
enabled = true
114+
fps = 480.0
115+
116+
[encoding]
117+
quality = 18
118+
detailed_filename = false
119+
container = mp4
120+
121+
[timescale]
122+
input = 1.0
123+
output = 1.0
124+
adjust_audio_pitch = false
125+
126+
[filters]
127+
brightness = 1.0
128+
contrast = 1.0
129+
saturation = 1.0
130+
131+
[advanced.encoding]
132+
gpu = false
133+
gpu_type = \"nvidia\" # nvidia/intel/amd
134+
deduplicate = false
135+
136+
[advanced.blend_weighting]
137+
gaussian_std_dev = 2
138+
triangle_reverse = false
139+
bound = [0, 2]
140+
141+
[advanced.interpolation]
142+
program = \"svp\" # svp/rife/rife-ncnn
143+
speed = \"default\" # medium/fast/faster/default (default is medium)
144+
tuning = \"default\" # film/animation/weak/smooth/default (default is smooth)
145+
algorithm = \"default\" # 2/13/23/default (default is 13)"))
146+
.expect("Failed to create config file")
103147
}
104148
}

0 commit comments

Comments
 (0)