Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfx.TimeSymmetrize cutoffs 1 second at the end and makes picture jump #2286

Open
AndrewFucher opened this issue Dec 9, 2024 · 6 comments
Open
Labels
bug Issues that report (apparent) bugs.

Comments

@AndrewFucher
Copy link

Hi,
While trying to use vfx.TimeSymmetrize I found out that it cutoffs 1 second at the end (start for backward part)

Issue lies in how slices are calculated in Clip class.

Expected Behavior

TimeSymmetrize Will add exactly same video but in reverse

Actual Behavior

Reversed part is cut by 1 second

Steps to Reproduce the Problem

Just use this effect TimeSymmetrize

Specifications

  • Python Version: 3.13
  • MoviePy Version: 2.1.1
  • Platform Name: Windows
  • Platform Version: 11
@AndrewFucher AndrewFucher added the bug Issues that report (apparent) bugs. label Dec 9, 2024
@chenhaoch
Copy link

I encountered the same issue. Did you find a solution?
I tried TimeMirror and TimeSymmetrize. Both have this issue.

@OsaAjani
Copy link
Collaborator

Hi, that's the next one on my list, I'll take a look when I can !

@OsaAjani
Copy link
Collaborator

Hi, @chenhaoch and @AndrewFucher could any of you provide some code example triggering the bug, including the media used in the code example.
Did you use subclipped before symmetrize ?

@chenhaoch
Copy link

I didn't use subclipped

my code:

    video_files = [os.path.join('videos', f) for f in os.listdir('videos') if f.endswith('.mp4')]
    video_clips = [VideoFileClip(f) for f in video_files]
    
    # 创建正序和逆序视频片段
    processed_clips = []
    for clip in video_clips:
        processed_clips.append(clip)
        mirrored_clip = clip[::-1]
        # processed_clips.append(clip.with_effects([vfx.TimeSymmetrize()]))
        processed_clips.append(mirrored_clip)
        # mirrored_clip.write_videofile('output.mp4', codec='libx264', audio_codec='aac', audio_bitrate='192k')
    
    # 合并视频
    final_video = concatenate_videoclips(processed_clips)
    final_video.write_videofile('video_output.mp4', codec='libx264', audio_codec='aac', audio_bitrate='192k')

@chenhaoch
Copy link

and I checked the first and last frames, they don't correspond.
mirrored_first_0.jpg and original_last_0.jpg are different.

processed_clips = []
    for i, new_clip in enumerate(video_clips):
        # clip = new_clip.subclipped(0,5)
        # 保存原始视频第一帧和最后一帧
        frame = clip.get_frame(0)
        img = Image.fromarray(frame)
        img.save(f'frames/original_first_{i}.jpg')
        
        # 使用iter_frames获取原始视频最后一帧
        clip_frames = list(clip.iter_frames())
        clip_last_frame = clip_frames[-1]
        img = Image.fromarray(clip_last_frame)
        img.save(f'frames/original_last_{i}.jpg')
        
        processed_clips.append(clip)
        
        # 保存TimeMirror处理后的第一帧和最后一帧
        mirrored_clip = clip.with_effects([vfx.TimeMirror()])
        frame = mirrored_clip.get_frame(0)
        img = Image.fromarray(frame)
        img.save(f'frames/mirrored_first_{i}.jpg')
        
        # 使用iter_frames获取TimeMirror处理后的最后一帧
        mirrored_clip_frames = list(mirrored_clip.iter_frames())
        mirrored_clip_last_frame = mirrored_clip_frames[-1]
        img = Image.fromarray(mirrored_clip_last_frame)
        img.save(f'frames/mirrored_last_{i}.jpg')
        
        processed_clips.append(mirrored_clip)

@OsaAjani
Copy link
Collaborator

Hi, I think I found the problem, but another matter seems to appear when applying some sub clipping, so I will need a bit of time to fix both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

3 participants