From 43313f67033d0624eba56fed2d536908c96631f0 Mon Sep 17 00:00:00 2001 From: Eternity <2413421030@qq.com> Date: Sun, 18 Jan 2026 10:07:23 +0800 Subject: [PATCH 1/2] fixed the bug in subtitle merging --- .../singularity_cinema/compose_video/agent.py | 66 ++++++++++++------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/projects/singularity_cinema/compose_video/agent.py b/projects/singularity_cinema/compose_video/agent.py index eeb005d68..c6b25a054 100644 --- a/projects/singularity_cinema/compose_video/agent.py +++ b/projects/singularity_cinema/compose_video/agent.py @@ -324,26 +324,36 @@ def illustration_pos(t): fg_clip = fg_clip.with_duration(duration) current_video_clips.append(fg_clip) if self.config.use_subtitle: - if i < len(subtitle_paths - ) and subtitle_paths[i] and os.path.exists( - subtitle_paths[i]): - subtitle_img = Image.open(subtitle_paths[i]) - subtitle_w, subtitle_h = subtitle_img.size - - # Validate subtitle dimensions - if subtitle_w <= 0 or subtitle_h <= 0: - logger.error( - f'Invalid subtitle dimensions: {subtitle_w}x{subtitle_h} for {subtitle_paths[i]}' - ) - else: - subtitle_clip = mp.ImageClip( - subtitle_paths[i], duration=duration) - subtitle_clip = subtitle_clip.resized( - (subtitle_w, subtitle_h)) - subtitle_y = 900 - subtitle_clip = subtitle_clip.with_position( - ('center', subtitle_y)) - current_video_clips.append(subtitle_clip) + if i < len(subtitle_paths) and subtitle_paths[i]: + segment_subs = subtitle_paths[i] + if segment_subs: + num_subs = len(segment_subs) + sub_duration = duration / num_subs + + for k, sub_path in enumerate(segment_subs): + if os.path.exists(sub_path): + try: + subtitle_img = Image.open(sub_path) + subtitle_w, subtitle_h = subtitle_img.size + + if subtitle_w <= 0 or subtitle_h <= 0: + logger.error( + f'Invalid subtitle dimensions: {subtitle_w}x{subtitle_h} for {sub_path}' + ) + continue + + subtitle_clip = mp.ImageClip( + sub_path, duration=sub_duration) + subtitle_y = 900 + subtitle_clip = subtitle_clip.with_position( + ('center', subtitle_y)) + subtitle_clip = subtitle_clip.with_start( + k * sub_duration) + current_video_clips.append(subtitle_clip) + except Exception as e: + logger.error( + f'Failed to load subtitle {sub_path}: {e}' + ) # Add background as top layer (transparent PNG with decorative elements) if background_path and os.path.exists(background_path): @@ -498,9 +508,19 @@ async def execute_code(self, messages, **kwargs): f'Scene{i+1}.mov')) audio_paths.append( os.path.join(self.tts_dir, f'segment_{i + 1}.mp3')) - subtitle_paths.append( - os.path.join(self.subtitle_dir, - f'bilingual_subtitle_{i + 1}.png')) + + segment_subtitles = [] + j = 0 + while True: + sub_path = os.path.join(self.subtitle_dir, + f'bilingual_subtitle_{i + 1}_{j}.png') + if os.path.exists(sub_path): + segment_subtitles.append(sub_path) + j += 1 + else: + break + subtitle_paths.append(segment_subtitles) + video_paths.append( os.path.join(self.videos_dir, f'video_{i + 1}.mp4')) From 0ce57b83a98814c25f81373b708a22f600813b77 Mon Sep 17 00:00:00 2001 From: Eternity <2413421030@qq.com> Date: Sun, 18 Jan 2026 10:51:51 +0800 Subject: [PATCH 2/2] fixed the bug in subtitle merging --- .../singularity_cinema/compose_video/agent.py | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/projects/singularity_cinema/compose_video/agent.py b/projects/singularity_cinema/compose_video/agent.py index c6b25a054..637f93103 100644 --- a/projects/singularity_cinema/compose_video/agent.py +++ b/projects/singularity_cinema/compose_video/agent.py @@ -324,36 +324,35 @@ def illustration_pos(t): fg_clip = fg_clip.with_duration(duration) current_video_clips.append(fg_clip) if self.config.use_subtitle: - if i < len(subtitle_paths) and subtitle_paths[i]: + if duration is not None and i < len(subtitle_paths) and subtitle_paths[i]: segment_subs = subtitle_paths[i] - if segment_subs: - num_subs = len(segment_subs) - sub_duration = duration / num_subs - - for k, sub_path in enumerate(segment_subs): - if os.path.exists(sub_path): - try: - subtitle_img = Image.open(sub_path) - subtitle_w, subtitle_h = subtitle_img.size - - if subtitle_w <= 0 or subtitle_h <= 0: - logger.error( - f'Invalid subtitle dimensions: {subtitle_w}x{subtitle_h} for {sub_path}' - ) - continue - - subtitle_clip = mp.ImageClip( - sub_path, duration=sub_duration) - subtitle_y = 900 - subtitle_clip = subtitle_clip.with_position( - ('center', subtitle_y)) - subtitle_clip = subtitle_clip.with_start( - k * sub_duration) - current_video_clips.append(subtitle_clip) - except Exception as e: + num_subs = len(segment_subs) + sub_duration = duration / num_subs + + for k, sub_path in enumerate(segment_subs): + if os.path.exists(sub_path): + try: + subtitle_img = Image.open(sub_path) + subtitle_w, subtitle_h = subtitle_img.size + + if subtitle_w <= 0 or subtitle_h <= 0: logger.error( - f'Failed to load subtitle {sub_path}: {e}' + f'Invalid subtitle dimensions: {subtitle_w}x{subtitle_h} for {sub_path}' ) + continue + + subtitle_clip = mp.ImageClip( + sub_path, duration=sub_duration) + subtitle_y = 900 + subtitle_clip = subtitle_clip.with_position( + ('center', subtitle_y)) + subtitle_clip = subtitle_clip.with_start( + k * sub_duration) + current_video_clips.append(subtitle_clip) + except Exception as e: + logger.error( + f'Failed to load subtitle {sub_path}: {e}' + ) # Add background as top layer (transparent PNG with decorative elements) if background_path and os.path.exists(background_path):