Skip to content

Commit cae78b0

Browse files
Uraniteshssoichiro
authored andcommitted
Disable mkvmerge chunking on Windows
And up the chunks on Linux from 100 to 960 And disable intermediate file creation if there is only 1 chunks
1 parent a33162f commit cae78b0

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

av1an-core/src/concat/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ pub fn mkvmerge(
171171
num_chunks: usize,
172172
output_fps: Option<Rational64>,
173173
) -> anyhow::Result<()> {
174-
const MAXIMUM_CHUNKS_PER_MERGE: usize = 100;
174+
#[cfg(windows)]
175+
const MAXIMUM_CHUNKS_PER_MERGE: usize = usize::MAX;
176+
#[cfg(not(windows))]
177+
const MAXIMUM_CHUNKS_PER_MERGE: usize = 960;
178+
175179
// mkvmerge does not accept UNC paths on Windows
176180
#[cfg(windows)]
177181
fn fix_path<P: AsRef<Path>>(p: P) -> String {
@@ -222,6 +226,39 @@ pub fn mkvmerge(
222226
})
223227
.collect();
224228

229+
// If there is only one chunk group, we can skip the intermediate merge/file
230+
// creation
231+
if chunk_groups.len() == 1 {
232+
let options_path = PathBuf::from(&temp_dir).join("options.json");
233+
let options_json_contents = mkvmerge_options_json(
234+
&chunk_groups[0],
235+
&fix_path(output.to_string_lossy().as_ref()),
236+
audio_file.as_deref(),
237+
output_fps,
238+
);
239+
240+
let mut options_json = File::create(options_path)?;
241+
options_json.write_all(options_json_contents?.as_bytes())?;
242+
243+
let mut cmd = Command::new("mkvmerge");
244+
cmd.current_dir(&encode_dir);
245+
cmd.arg("@../options.json");
246+
247+
let out = cmd
248+
.output()
249+
.with_context(|| "Failed to execute mkvmerge command for concatenation")?;
250+
251+
if !out.status.success() {
252+
error!(
253+
"mkvmerge concatenation failed with output: {:#?}\ncommand: {:?}",
254+
out, cmd
255+
);
256+
return Err(anyhow!("mkvmerge concatenation failed"));
257+
}
258+
259+
return Ok(());
260+
}
261+
225262
chunk_groups.iter().enumerate().try_for_each(|(group_index, chunk_group)| {
226263
let group_options_path =
227264
PathBuf::from(&temp_dir).join(format!("group_options_{group_index:05}.json"));

0 commit comments

Comments
 (0)