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

Wrong audio clipping when processing files with non-zero video start time #2284

Open
dloeckx opened this issue Dec 6, 2024 · 0 comments
Open
Labels
bug Issues that report (apparent) bugs. v2.x Issues based on MoviePy version 2.0 and upwards

Comments

@dloeckx
Copy link

dloeckx commented Dec 6, 2024

I am processing an mp4 file with non-zero video start time. Such files can e.g. be generated by using the -itsoffset parameter in ffmpeg. When I clip a part of the video in the beginning (where there is audio and no video), the write_audiofile behaviour is not consistent. The first time, the correct audio is written, the second time, the clip offset seems relative to the beginning of the video rather than to the beginning of the audio (=entire file).

More in detail: when I have an mp4 where the video starts 5 seconds after the audio (video_offset = 5), and want to make a clip that starts 3 second into the file (clip_offset = 3), the first time I run write_audiofile, the audio correctly starts 3 seconds after the beginning of the file. The second time I run write_audiofile, the audio seems to start 8 seconds (=video_offset + audio_offset) after the beginning of the file.

Note that if I write the whole video instead of only the audio, the audio is still offset with the same amount. The video seems to be clipped correctly.

Expected Behavior

write_audiofile, for the same input, should give the same output. In the reproduction below: audio starting 3s after the beginning of the file.

Actual Behavior

write_audiofile, for the same input, gives a different output. The first time, audio starts 3s after the beginning of the file, the 2nd time it starts 8s after the beginning of the file.

Steps to Reproduce the Problem

import moviepy
video = moviepy.VideoFileClip("shift.mp4")
clip = video.subclipped(3, 10)
clip.audio.write_audiofile("audio1.mp3")
clip.audio.write_audiofile("audio2.mp3")
# Both files contain different audio

shift.mp4: https://github.com/user-attachments/assets/c333cf32-3fe5-45ff-bca6-d612681ae622

Specifications

  • Python Version: 3.12.7
  • MoviePy Version: 2.1.1
  • Platform Name: Mac
  • Platform Version: Sequoia 15.1.1
@dloeckx dloeckx added the bug Issues that report (apparent) bugs. label Dec 6, 2024
@keikoro keikoro added the v2.x Issues based on MoviePy version 2.0 and upwards label Dec 8, 2024
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. v2.x Issues based on MoviePy version 2.0 and upwards
Projects
None yet
Development

No branches or pull requests

2 participants