Skip to content

Commit f0e09c8

Browse files
committed
Move opening the pass files before writing the header
In case of failure we do not leave near-empty files around.
1 parent 5cc72ac commit f0e09c8

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/bin/rav1e.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,14 @@ fn process_frame<T: Pixel, D: Decoder>(
234234

235235
fn do_encode<T: Pixel, D: Decoder>(
236236
cfg: Config, verbose: Verbose, mut progress: ProgressInfo,
237-
output: &mut dyn Muxer, source: &mut Source<D>,
238-
pass1file_name: Option<&String>, pass2file_name: Option<&String>,
237+
output: &mut dyn Muxer, source: &mut Source<D>, mut pass1file: Option<File>,
238+
mut pass2file: Option<File>,
239239
mut y4m_enc: Option<y4m::Encoder<'_, Box<dyn Write>>>,
240240
metrics_enabled: MetricsEnabled,
241241
) -> Result<(), CliError> {
242242
let mut ctx: Context<T> =
243243
cfg.new_context().map_err(|e| e.context("Invalid encoder settings"))?;
244244

245-
let mut pass2file = match pass2file_name {
246-
Some(f) => Some(File::open(f).map_err(|e| {
247-
e.context("Unable to open file for reading two-pass data")
248-
})?),
249-
None => None,
250-
};
251-
// panic!(, f)
252-
let mut pass1file = match pass1file_name {
253-
Some(f) => Some(File::create(f).map_err(|e| {
254-
e.context("Unable to open file for writing two-pass data")
255-
})?),
256-
None => None,
257-
};
258-
259245
let mut buffer: [u8; 80] = [0; 80];
260246
let mut buf_pos = 0;
261247

@@ -433,6 +419,20 @@ fn run() -> Result<(), error::CliError> {
433419
cli.enc.time_base = video_info.time_base;
434420
}
435421

422+
let pass2file = match cli.pass2file_name {
423+
Some(f) => Some(File::open(f).map_err(|e| {
424+
e.context("Unable to open file for reading two-pass data")
425+
})?),
426+
None => None,
427+
};
428+
429+
let pass1file = match cli.pass1file_name {
430+
Some(f) => Some(File::create(f).map_err(|e| {
431+
e.context("Unable to open file for writing two-pass data")
432+
})?),
433+
None => None,
434+
};
435+
436436
let cfg =
437437
Config::new().with_encoder_config(cli.enc).with_threads(cli.threads);
438438

@@ -490,8 +490,8 @@ fn run() -> Result<(), error::CliError> {
490490
progress,
491491
&mut *cli.io.output,
492492
&mut source,
493-
cli.pass1file_name.as_ref(),
494-
cli.pass2file_name.as_ref(),
493+
pass1file,
494+
pass2file,
495495
y4m_enc,
496496
cli.metrics_enabled,
497497
)?
@@ -502,8 +502,8 @@ fn run() -> Result<(), error::CliError> {
502502
progress,
503503
&mut *cli.io.output,
504504
&mut source,
505-
cli.pass1file_name.as_ref(),
506-
cli.pass2file_name.as_ref(),
505+
pass1file,
506+
pass2file,
507507
y4m_enc,
508508
cli.metrics_enabled,
509509
)?

0 commit comments

Comments
 (0)