From 755fc3593e0f673e64472fa2c00ca233de98e46c Mon Sep 17 00:00:00 2001 From: Qiaochu Hu <110hqc@gmail.com> Date: Wed, 6 May 2026 11:40:20 +0800 Subject: [PATCH] fix: handle videos without audio in _trim_video_to_duration Dead ternary 'copy' if has_audio else 'copy' always specified acodec=copy, causing FFmpeg to fail on AI-generated videos with no audio stream. Now only adds acodec=copy when an audio stream is actually present. --- pixelle_video/services/video.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pixelle_video/services/video.py b/pixelle_video/services/video.py index fa2a9f2..7d19dda 100644 --- a/pixelle_video/services/video.py +++ b/pixelle_video/services/video.py @@ -907,10 +907,13 @@ class VideoService: try: # Use stream copy when possible for fast trimming + input_stream = ffmpeg.input(video, t=target_duration) + output_kwargs = {"vcodec": "copy"} + if self.has_audio_stream(video): + output_kwargs["acodec"] = "copy" ( - ffmpeg - .input(video, t=target_duration) - .output(output, vcodec='copy', acodec='copy' if self.has_audio_stream(video) else 'copy') + input_stream + .output(output, **output_kwargs) .overwrite_output() .run(capture_stdout=True, capture_stderr=True, quiet=True) )