@@ -205,20 +205,25 @@ async def extract_clip(self, match_info: Mapping[str, object]) -> Path | None:
205205 output_path = self .output_dir / f"{ match_name } _{ counter } .mp4"
206206 counter += 1
207207
208+ # Write to .partial file during encoding, then rename when done
209+ partial_path = output_path .parent / (output_path .name + '.partial' )
208210 logger .info (f"Extracting clip: { clip_start :.1f} s + { clip_duration :.1f} s -> { output_path } " )
209211
210212 success = await self .extract_clip_ffmpeg (
211213 input_path = recording_path ,
212- output_path = output_path ,
214+ output_path = partial_path ,
213215 start_time = clip_start ,
214216 duration = clip_duration
215217 )
216218
217- if success and output_path .exists ():
219+ if success and partial_path .exists ():
220+ _ = partial_path .rename (output_path )
218221 logger .info (f"✅ Successfully created clip: { output_path } " )
219222 return output_path
220223 else :
221224 logger .error (f"❌ Failed to create clip: { output_path } " )
225+ if partial_path .exists ():
226+ partial_path .unlink ()
222227 return None
223228
224229 except Exception as e :
@@ -237,6 +242,7 @@ async def extract_clip_ffmpeg(self, input_path: Path, output_path: Path,
237242 '-c' , 'copy' , # Copy streams without re-encoding for speed
238243 '-threads' , '1' , # Limit to single thread to minimize impact on stream
239244 '-avoid_negative_ts' , 'make_zero' ,
245+ '-f' , 'mp4' ,
240246 str (output_path )
241247 ]
242248
0 commit comments