Skip to content

Commit e3df51d

Browse files
committed
Add volume support
1 parent 41d5e28 commit e3df51d

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"**/.project": true,
1111
"**/.settings": true,
1212
"**/.factorypath": true
13-
}
13+
},
14+
"hide-files.files": []
1415
}

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# FFtools
2-
3-
# wtf fix this readme xd
4-
52
🔨 FFmpeg-based toolkit for manipulate multimedia easily
3+

src/logs.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const HELP: &str = "Use `--help` for more information.";
88
pub fn help() {
99
printdoc! {
1010
"{title}
11-
FFmpeg-based toolkit for manipulate multimedia easily.
11+
FFmpeg-based toolkit for manipulate multimedia easily
1212
13-
Licensed under the Apache License, Version 2.0.
13+
Copyright 2023 Gátomo
14+
Licensed under the Apache License, Version 2.0
1415
< https://www.apache.org/licenses/LICENSE-2.0 >
1516
1617
{usage}
@@ -20,6 +21,7 @@ pub fn help() {
2021
trim Trims video between a range [ at least `--from` or `--to` ]
2122
gif Converts video into lossless GIF [ no options ]
2223
scale Scale a file by percentage [ `--scale` ]
24+
volume Set audio volume [ `--volume` ]
2325
free Dynamic subcommand [ any option ]
2426
2527
@@ -29,10 +31,11 @@ pub fn help() {
2931
-w, --overwrite Overwrite output
3032
3133
Media manipulation:
32-
-f, --from <time> Start timestamp
33-
-t, --to <time> End timestamp
34+
-f, --from <time> Start timestamp
35+
-t, --to <time> End timestamp
3436
-s, --scale <percentage> Scale percentage
35-
--fps Set framerate
37+
--fps <fps> Set framerate
38+
-vv, --volume <level> Set volume (dB or percentage)
3639
3740
Miscellaneous:
3841
-V, --verbose Add verbosity

src/main.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ fn main() {
8080
exit(1);
8181
}
8282
}
83+
"volume" => {
84+
if args.volume.is_none() {
85+
logs::ferror("volume".into(), vec!["--volume"], None);
86+
exit(1);
87+
}
88+
}
89+
8390
_ => {
8491
logs::error(format!("Unknown `{}` command.", args.command), None);
8592
exit(1)
@@ -118,14 +125,25 @@ fn main() {
118125
exit(1);
119126
}) / 100.0
120127
);
121-
vf_args.push(&scale_str)
128+
vf_args.push(&scale_str);
122129
}
123130

124131
// Volume
125-
// TODO add dB and percentage support (100 as 1, https://trac.ffmpeg.org/wiki/AudioVolume)
126132
let vol_str: String;
127133
if let Some(volume) = args.volume.as_ref() {
128-
vol_str = format!("volume={}", volume);
134+
vol_str = format!(
135+
"volume={}",
136+
if volume.ends_with("dB") {
137+
volume.to_string()
138+
} else {
139+
(volume.parse::<f64>().unwrap_or_else(|_| {
140+
logs::error("Please insert a valid number.".into(), None);
141+
exit(1);
142+
}) / 100.0)
143+
.to_string()
144+
}
145+
);
146+
af_args.push(&vol_str);
129147
}
130148

131149
// Media filters
@@ -150,6 +168,7 @@ fn main() {
150168

151169
// Check if file exists
152170
// This is checked after parsing args in case of output modification
171+
153172
if args.output.exists() && !args.overwrite {
154173
logs::error(
155174
format!(

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn parser() -> Result<structs::Args, pico_args::Error> {
5959
scale: args.opt_value_from_str(["-s", "--scale"])?,
6060

6161
// Volume
62-
volume: args.opt_value_from_str(["--vol", "--volume"])?,
62+
volume: args.opt_value_from_str(["-vv", "--volume"])?,
6363

6464
// Output
6565
output: match args.free_from_os_str(parse_path) {

0 commit comments

Comments
 (0)