Skip to content

Commit 35024c1

Browse files
authored
Deprecate misleading argument names (#17)
* refactor: deprecated --input-directory and --input-file * docs: added migration guide to version 1.0.0 * refactor: formatting * docs: updated README with new argument names
1 parent 4dd98f6 commit 35024c1

File tree

2 files changed

+102
-30
lines changed

2 files changed

+102
-30
lines changed

README.md

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Because it uses ffmpeg under the hood, it supports any media file processing tha
99
- [Practical examples](#more-practical-examples)
1010
3. [Requirements](#requirements)
1111
4. [All available options](#available-options)
12-
5. [License](#license)
12+
5. [Migrating to 1.0.0](#migrating-to-100)
13+
6. [License](#license)
1314

1415
### Installation
1516

@@ -88,11 +89,11 @@ visit [ffmpeg's documentation](https://ffmpeg.org/ffmpeg.html).
8889
<summary>Re-encode multiple videos to H265 and the audio to opus</summary>
8990

9091
```bash
91-
ffzap --input-file files.txt -f "-c:v libx265 -preset medium -crf 23 -c:a libopus -b:a 128k" -o "Output/{{name}}.mp4" -t 2
92+
ffzap --file-list files.txt -f "-c:v libx265 -preset medium -crf 23 -c:a libopus -b:a 128k" -o "Output/{{name}}.mp4" -t 2
9293
```
9394

9495
Keypoints:
95-
- use `--input-file` to pass a list of file names to process
96+
- use `--file-list` to pass a list of file names to process
9697
- re-encode the video to H265 using `-c:v libx265`
9798
- `-preset medium` to balance out speed and file size
9899
- `-crf 23` to achieve good quality with reasonable file size
@@ -109,11 +110,11 @@ Keypoints:
109110
<summary>Convert PNG images to JPG</summary>
110111

111112
```bash
112-
ffzap --input-file files.txt -f "-c:v mjpeg -q:v 2" -o "Output/{{name}}.jpg" -t 6
113+
ffzap --file-list files.txt -f "-c:v mjpeg -q:v 2" -o "Output/{{name}}.jpg" -t 6
113114
```
114115

115116
Keypoints:
116-
- use `--input-file` to pass a list of file names to process
117+
- use `--file-list` to pass a list of file names to process
117118
- convert the image to JPG using `-c:v mjpeg`
118119
- `-q:v 2` to set very high quality
119120
- `-t 6` runs six processes in parallel, converting six files at once
@@ -127,12 +128,12 @@ Keypoints:
127128
<summary>Add a watermark to multiple videos</summary>
128129

129130
```bash
130-
ffzap --input-file files.txt -f "-i watermark.png -filter_complex [1]format=rgba,lut=a=val*0.3[watermark];[0][watermark]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 -c:a copy" -o "{{name}}_watermark.mp4" -t 2
131+
ffzap --file-list files.txt -f "-i watermark.png -filter_complex [1]format=rgba,lut=a=val*0.3[watermark];[0][watermark]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 -c:a copy" -o "{{name}}_watermark.mp4" -t 2
131132
```
132133
(Note that this command may not work in Windows Powershell as it requires a different escaping format)
133134

134135
Keypoints:
135-
- use `--input-file` to pass a list of file names to process (these are the files the watermark gets added to)
136+
- use `--file-list` to pass a list of file names to process (these are the files the watermark gets added to)
136137
- select to watermark file with `-i watermark.png` **inside** `-f`
137138
- `-filter_complex` applies the watermark with 70% opacity to the center of each video
138139
- `-c:a copy` copies the audio
@@ -147,11 +148,11 @@ Keypoints:
147148
<summary>Resize multiple videos</summary>
148149

149150
```bash
150-
ffzap --input-file files.txt -f "-vf scale=1280:720 -c:a copy" -o "{{name}}_resized.mp4" -t 2
151+
ffzap --file-list files.txt -f "-vf scale=1280:720 -c:a copy" -o "{{name}}_resized.mp4" -t 2
151152
```
152153

153154
Keypoints:
154-
- use `--input-file` to pass a list of file names to process
155+
- use `--file-list` to pass a list of file names to process
155156
- `-vf scale=1280:720` sets the video resolution to HD
156157
- `-c:a copy` copies the audio
157158
- `-t 2` processes two files in parallel
@@ -165,13 +166,13 @@ Keypoints:
165166
<summary>Swap video containers</summary>
166167

167168
```bash
168-
ffzap --input-file files.txt -o "{{name}}.mkv" -t 2
169+
ffzap --file-list files.txt -o "{{name}}.mkv" -t 2
169170
```
170171

171172
(It is assumed the source files have a container that's interchangable with MKV)
172173

173174
Keypoints:
174-
- use `--input-file` to pass a list of file names to process
175+
- use `--file-list` to pass a list of file names to process
175176
- `-o "{{name}}.<desired file extension>` to swap all files to the desired container format (in this case MKV)
176177
- No `-f` because it's not needed
177178
- `-t 2` processes two files in parallel
@@ -194,21 +195,21 @@ Keypoints:
194195
$ ffzap --help
195196
⚡ A multithreaded CLI for digital media processing using ffmpeg. If ffmpeg can do it, ffzap can do it - as many files in parallel as your system can handle.
196197

197-
Usage: ffzap [OPTIONS] --ffmpeg-options <FFMPEG_OPTIONS> --output <OUTPUT>
198+
Usage: ffzap [OPTIONS] --output <OUTPUT>
198199

199200
Options:
200201
-t, --thread-count <THREAD_COUNT>
201202
The amount of threads you want to utilize. most systems can handle 2. Go higher if you have a powerful computer. Default is 2. Can't be lower than 1
202-
203+
203204
[default: 2]
204205
205206
-f, --ffmpeg-options <FFMPEG_OPTIONS>
206207
Options you want to pass to ffmpeg. For the output file name, use --output
207208
208-
-i, --input-directory <INPUT_DIRECTORY>...
209+
-i, --input <INPUT>...
209210
The files you want to process
210211
211-
--input-file <INPUT_FILE>
212+
--file-list <FILE_LIST>
212213
Path to a file containing paths to process. One path per line
213214
214215
--overwrite
@@ -222,15 +223,15 @@ Options:
222223
223224
-o, --output <OUTPUT>
224225
Specify the output file pattern. Use placeholders to customize file paths:
225-
226+
226227
{{dir}} - Entire specified file path, e.g. ./path/to/file.txt -> ?./path/to/
227-
228+
228229
{{name}} - Original file's name (without extension)
229-
230+
230231
{{ext}} - Original file's extension
231-
232+
232233
Example: /destination/{{dir}}/{{name}}_transcoded.{{ext}}
233-
234+
234235
Outputs the file in /destination, mirroring the original structure and keeping both the file extension and name, while adding _transcoded to the name.
235236
236237
-h, --help
@@ -242,6 +243,37 @@ Options:
242243
243244
</details>
244245
246+
247+
### Migrating to 1.0.0
248+
249+
In version `1.0.0`, the following changes were made:
250+
251+
- `--input-directory` has been deprecated and replaced by `--input`.
252+
- `--input-file` has been deprecated and replaced by `--file-list`.
253+
254+
#### 1. Replacing `--input-directory` with `--input`:
255+
256+
Instead of using `--input-directory`, you now have to use `--input` to specify the files you want to process:
257+
258+
```bash
259+
ffzap --input <files here> -f "<options here>" -o "<output pattern here>"
260+
```
261+
262+
**Note:** The short form `-i` remains unaffected by this change.
263+
264+
#### 2. Replacing `--input-file` with `--file-list`:
265+
266+
Instead of `--input-file`, use `--file-list` to specify a file containing a list of files to process:
267+
268+
```bash
269+
ffzap --file-list <path to list here> -f "<options here>" -o "<output pattern here>"
270+
```
271+
272+
---
273+
274+
For further details and motivation behind these changes, refer to [issue 16](https://github.com/CodeF0x/ffzap/issues/16).
275+
276+
245277
### License
246278
247279
You are free to:

src/main.rs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,36 @@ struct CmdArgs {
2424
ffmpeg_options: Option<String>,
2525

2626
/// The files you want to process.
27-
#[arg(short, long, num_args = 1.., required_unless_present = "input_file", conflicts_with = "input_file")]
27+
#[arg(short, long, num_args = 1.., required_unless_present = "file_list", required_unless_present = "input_directory", required_unless_present = "input_file", conflicts_with = "file_list", conflicts_with = "input_directory", conflicts_with = "input_file")]
28+
input: Option<Vec<String>>,
29+
30+
// DEPRECATED: and kept for showing an error if still used
31+
#[arg(long, num_args = 1.., required_unless_present = "input", required_unless_present = "input_file", required_unless_present = "file_list", conflicts_with = "file_list", conflicts_with = "input", conflicts_with = "file_list", conflicts_with = "input_file", hide = true)]
2832
input_directory: Option<Vec<String>>,
2933

3034
/// Path to a file containing paths to process. One path per line
31-
#[arg(long, required_unless_present = "input_directory", conflicts_with = "input_directory")]
35+
#[arg(
36+
long,
37+
required_unless_present = "input",
38+
required_unless_present = "input_directory",
39+
required_unless_present = "input_file",
40+
conflicts_with = "input",
41+
conflicts_with = "input_directory",
42+
conflicts_with = "input_file"
43+
)]
44+
file_list: Option<String>,
45+
46+
// DEPRECATED: kept for showing an error if still used
47+
#[arg(
48+
long,
49+
required_unless_present = "input_directory",
50+
required_unless_present = "input",
51+
required_unless_present = "file_list",
52+
conflicts_with = "input_directory",
53+
conflicts_with = "input",
54+
conflicts_with = "file_list",
55+
hide = true
56+
)]
3257
input_file: Option<String>,
3358

3459
/// If ffmpeg should overwrite files if they already exist. Default is false
@@ -62,8 +87,17 @@ struct CmdArgs {
6287
fn main() {
6388
let cmd_args = CmdArgs::parse();
6489

90+
if let Some(_) = cmd_args.input_directory {
91+
eprintln!("Error: --input-directory is deprecated and will get removed in the next release. Use --input instead.");
92+
exit(1);
93+
}
94+
if let Some(_) = cmd_args.input_file {
95+
eprintln!("Error: --input-file is deprecated and will get removed in the next release. Use --file-list instead.");
96+
exit(1);
97+
}
98+
6599
let paths: Vec<String>;
66-
if let Some(input_file_path) = cmd_args.input_file {
100+
if let Some(input_file_path) = cmd_args.file_list {
67101
paths = match fs::read_to_string(&input_file_path) {
68102
Ok(contents) => contents
69103
.trim()
@@ -92,7 +126,7 @@ fn main() {
92126
}
93127
}
94128
} else {
95-
paths = cmd_args.input_directory.unwrap();
129+
paths = cmd_args.input.unwrap();
96130
}
97131

98132
let paths = Arc::new(Mutex::new(paths));
@@ -133,9 +167,8 @@ fn main() {
133167
logger.log_info(format!("Processing {}", path.display()), thread, verbose);
134168

135169
let split_options = match &ffmpeg_options {
136-
Some(options) =>
137-
options.split(' ').collect::<Vec<&str>>(),
138-
None => vec![]
170+
Some(options) => options.split(' ').collect::<Vec<&str>>(),
171+
None => vec![],
139172
};
140173

141174
let mut final_file_name =
@@ -221,15 +254,19 @@ fn main() {
221254
progress.inc(1);
222255
} else {
223256
logger.log_error(
224-
format!("Error processing file {}. Error is: {}", path.display(), String::from_utf8_lossy(&output.stderr)),
257+
format!(
258+
"Error processing file {}. Error is: {}",
259+
path.display(),
260+
String::from_utf8_lossy(&output.stderr)
261+
),
225262
thread,
226263
verbose,
227264
);
228265
if cmd_args.delete {
229266
logger.log_info(
230267
"Keeping the file due to the error above".to_string(),
231268
thread,
232-
verbose
269+
verbose,
233270
)
234271
}
235272
logger.log_info(
@@ -238,7 +275,10 @@ fn main() {
238275
verbose,
239276
);
240277

241-
failed_paths.lock().unwrap().push(path.display().to_string());
278+
failed_paths
279+
.lock()
280+
.unwrap()
281+
.push(path.display().to_string());
242282
}
243283
} else {
244284
eprintln!("[THREAD {thread}] -- There was an error running ffmpeg. Please check if it's correctly installed and working as intended.");

0 commit comments

Comments
 (0)