Skip to content

Commit f3290aa

Browse files
doctortheemhtdaede
authored andcommitted
Treat paths as OsString.
Treat paths for input, output, first pass, second pass, and reconstruction as OsString, allowing for possibly non-utf8 filenames.
1 parent 9d099ef commit f3290aa

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/bin/common.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rav1e::prelude::*;
1717
use rav1e::version;
1818
use scan_fmt::scan_fmt;
1919

20+
use std::ffi::OsString;
2021
use std::fs::File;
2122
use std::io;
2223
use std::io::prelude::*;
@@ -45,8 +46,8 @@ pub struct CliOptions {
4546
pub benchmark: bool,
4647
pub threads: usize,
4748
pub metrics_enabled: MetricsEnabled,
48-
pub pass1file_name: Option<String>,
49-
pub pass2file_name: Option<String>,
49+
pub pass1file_name: Option<OsString>,
50+
pub pass2file_name: Option<OsString>,
5051
pub save_config: Option<String>,
5152
pub slots: usize,
5253
}
@@ -108,6 +109,7 @@ pub fn parse_cli() -> Result<CliOptions, CliError> {
108109
.help("Uncompressed YUV4MPEG2 video input")
109110
.required_unless_present("FULLHELP")
110111
.index(1)
112+
.allow_invalid_utf8(true)
111113
)
112114
.arg(
113115
Arg::new("OUTPUT")
@@ -116,19 +118,22 @@ pub fn parse_cli() -> Result<CliOptions, CliError> {
116118
.long("output")
117119
.required_unless_present("FULLHELP")
118120
.takes_value(true)
121+
.allow_invalid_utf8(true)
119122
)
120123
// ENCODING SETTINGS
121124
.arg(
122125
Arg::new("FIRST_PASS")
123126
.help("Perform the first pass of a two-pass encode, saving the pass data to the specified file for future passes")
124127
.long("first-pass")
125128
.takes_value(true)
129+
.allow_invalid_utf8(true)
126130
)
127131
.arg(
128132
Arg::new("SECOND_PASS")
129133
.help("Perform the second pass of a two-pass encode, reading the pass data saved from a previous pass from the specified file")
130134
.long("second-pass")
131135
.takes_value(true)
136+
.allow_invalid_utf8(true)
132137
)
133138
.arg(
134139
Arg::new("LIMIT")
@@ -373,6 +378,7 @@ pub fn parse_cli() -> Result<CliOptions, CliError> {
373378
.long("reconstruction")
374379
.short('r')
375380
.takes_value(true)
381+
.allow_invalid_utf8(true)
376382
)
377383
.arg(
378384
Arg::new("OVERWRITE")
@@ -464,23 +470,25 @@ pub fn parse_cli() -> Result<CliOptions, CliError> {
464470
}
465471
}
466472

467-
let rec = match matches.value_of("RECONSTRUCTION") {
473+
let rec = match matches.value_of_os("RECONSTRUCTION") {
468474
Some(f) => Some(Box::new(
469475
File::create(&f)
470476
.map_err(|e| e.context("Cannot create reconstruction file"))?,
471477
) as Box<dyn Write + Send>),
472478
None => None,
473479
};
474480

481+
let os_input = matches.value_of_os("INPUT").unwrap();
475482
let io = EncoderIO {
476-
input: match matches.value_of("INPUT").unwrap() {
477-
"-" => Box::new(io::stdin()) as Box<dyn Read + Send>,
478-
f => Box::new(
479-
File::open(&f).map_err(|e| e.context("Cannot open input file"))?,
483+
input: match os_input.to_str() {
484+
Some("-") => Box::new(io::stdin()) as Box<dyn Read + Send>,
485+
_ => Box::new(
486+
File::open(os_input)
487+
.map_err(|e| e.context("Cannot open input file"))?,
480488
) as Box<dyn Read + Send>,
481489
},
482490
output: create_muxer(
483-
matches.value_of("OUTPUT").unwrap(),
491+
matches.value_of_os("OUTPUT").unwrap(),
484492
matches.is_present("OVERWRITE"),
485493
)?,
486494
rec,
@@ -528,8 +536,8 @@ pub fn parse_cli() -> Result<CliOptions, CliError> {
528536
benchmark: matches.is_present("BENCHMARK"),
529537
verbose,
530538
threads,
531-
pass1file_name: matches.value_of("FIRST_PASS").map(|s| s.to_owned()),
532-
pass2file_name: matches.value_of("SECOND_PASS").map(|s| s.to_owned()),
539+
pass1file_name: matches.value_of_os("FIRST_PASS").map(|s| s.to_owned()),
540+
pass2file_name: matches.value_of_os("SECOND_PASS").map(|s| s.to_owned()),
533541
save_config,
534542
slots,
535543
})

0 commit comments

Comments
 (0)