@@ -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: {:#?}\n command: {:?}" ,
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