moviepy icon indicating copy to clipboard operation
moviepy copied to clipboard

Audio gets curropted when extracting

Open NotSoShaby opened this issue 3 years ago • 6 comments

a simple code like this is creating a curropted audio file for some reasons:

from moviepy import *

clip = VideoFileClip("cut.mp4")
audio = clip.audio
audio.to_audiofile('temp-audio.mp3')

-->

Expected Behavior

Audio should be the same as the audio in the video

Actual Behavior

audio is curropted in the end (repeats the end segment a few times like a broken record)

Steps to Reproduce the Problem

Run the code on this video with latest moviepy version (don't make fun it's just a trial lol): https://user-images.githubusercontent.com/26500236/149655475-bdd9ffa6-69dc-4d6b-ad32-5789907e42ca.mp4 and you will get this audio which is curropted (compressed it to a zip because github doesn't allow mp3 uploads): temp-audio.zip

Specifications

  • Python Version: Python 3.9.9
  • Moviepy Version: 1.0.3
  • Platform Name: Ubuntu
  • Platform Version: 20.04.3 LTS

NotSoShaby avatar Jan 16 '22 10:01 NotSoShaby

I'd ask you to amend your issue so all the information we ask for in the Specifications section is present, thanks.

keikoro avatar Jan 16 '22 21:01 keikoro

I'd ask you to amend your issue so all the information we ask for in the Specifications section is present, thanks.

Added.

NotSoShaby avatar Jan 16 '22 23:01 NotSoShaby

After someone answered my SO question here his solution seems to work - simply taking a subclip instead of the clip (in this case of one second) makes the audio function. But I still don't understand why it won't work for the given video without specifying the subclip length (I want it to be dynamic and take any video I present).

@keikoro if you think this is not a bug - i will close the issue.

The solution that worked for the case I presented in the "how to reproduce":

from moviepy import *
clip = VideoFileClip("cut.mp4").subclip(0,1) 
#subclip mean video duration its from the place to start to the end
audio = clip.audio
audio.to_audiofile('temp-audio.mp3')

credit to hmody3000 from SO

NotSoShaby avatar Jan 17 '22 12:01 NotSoShaby

Definitely a bug and still very present This doesn't seem obvious at all but thanks for the workaround Python 3.10.0 moviepy 1.0.3 Platform Name: Windows 10

Jheesbrough avatar Feb 15 '22 23:02 Jheesbrough

anyone found a solution or workaround?

josqu-john avatar Dec 31 '22 12:12 josqu-john

This problem has been reported many many times. https://github.com/Zulko/moviepy/issues/1854 https://github.com/Zulko/moviepy/issues/1005 https://github.com/Zulko/moviepy/issues/1717 https://github.com/Zulko/moviepy/issues/1710 https://github.com/Zulko/moviepy/issues/1936

Here's the root cause: https://github.com/Zulko/moviepy/issues/1936#issuecomment-1740785869

jake-nz avatar Sep 29 '23 12:09 jake-nz