From a4f3119ba6fb1a3b68155bd61c501d66a884f5dd Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:34:54 +0530 Subject: [PATCH] Fix double application of audio/video offset for concatenated segments In clip(), the start and end variables already include start_ost and end_ost offsets after the clamping step, but the data slice for subsequent segments was applying the offsets a second time via data[start+start_ost*16:end+end_ost*16]. Use data[start:end] instead. Similarly in video_clip(), the time_acc_ost calculation was adding the offsets again even though start and end already incorporated them. Use (end - start) directly since the duration already reflects the offset-adjusted boundaries. Fixes #129 Fixes #144 --- funclip/videoclipper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/funclip/videoclipper.py b/funclip/videoclipper.py index 3873a2d..f94adb9 100644 --- a/funclip/videoclipper.py +++ b/funclip/videoclipper.py @@ -128,7 +128,7 @@ def clip(self, dest_text, start_ost, end_ost, state, dest_spk=None, output_dir=N start = min(max(0, start+start_ost*16), len(data)) end = min(max(0, end+end_ost*16), len(data)) start_end_info += ", from {} to {}".format(start, end) - res_audio = np.concatenate([res_audio, data[start+start_ost*16:end+end_ost*16]], -1) + res_audio = np.concatenate([res_audio, data[start:end]], -1) srt_clip, _, srt_index = generate_srt_clip(sentences, start/16000.0, end/16000.0, begin_index=srt_index-1) clip_srt += srt_clip if len(ts): @@ -238,7 +238,7 @@ def video_clip(self, subtitles = SubtitlesClip(subs, generator) video_clip = CompositeVideoClip([video_clip, subtitles.set_pos(('center','bottom'))]) concate_clip = [video_clip] - time_acc_ost += end+end_ost/1000.0 - (start+start_ost/1000.0) + time_acc_ost += end - start for _ts in ts[1:]: start, end = _ts[0] / 16000, _ts[1] / 16000 srt_clip, subs, srt_index = generate_srt_clip(sentences, start, end, begin_index=srt_index-1, time_acc_ost=time_acc_ost) @@ -258,7 +258,7 @@ def video_clip(self, _video_clip = CompositeVideoClip([_video_clip, subtitles.set_pos(('center','bottom'))]) # _video_clip.write_videofile("debug.mp4", audio_codec="aac") concate_clip.append(copy.copy(_video_clip)) - time_acc_ost += end+end_ost/1000.0 - (start+start_ost/1000.0) + time_acc_ost += end - start message = "{} periods found in the audio: ".format(len(ts)) + start_end_info logging.warning("Concating...") if len(concate_clip) > 1: