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

MoviePy: Error when saving video with audio enabled #2298

Open
kotkot21 opened this issue Dec 25, 2024 · 0 comments
Open

MoviePy: Error when saving video with audio enabled #2298

kotkot21 opened this issue Dec 25, 2024 · 0 comments
Labels
question Questions regarding functionality, usage

Comments

@kotkot21
Copy link

I'm trying to use MoviePy to process a video file, detect scenes, and save subclips. Everything works fine when I disable audio (audio=False in write_videofile), but when I enable audio, I get the following error:

MoviePy - Writing video new1.mp4
MoviePy - Done !
MoviePy - video ready new1.mp4
Proc not detected chunk: 0%| | 0/388 [00:00<?, ?it/s, now=None]
MoviePy - Writing audio in new2TEMP_MPY_wvf_snd.mp3
Traceback (most recent call last):

MoviePy - Writing audio in new2TEMP_MPY_wvf_snd.mp3
Traceback (most recent call last):
  File "/Users/ahmadnaser/PycharmProjects/Sawt/Frame Detection.py", line 19, in <module>
    SubClip.write_videofile(OutputClip)

Here’s the code I’m using:

from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.tools.cuts import detect_scenes

# Load the video and subclip for faster processing
clip = VideoFileClip("/Users/ahmadnaser/Documents/podcast1.mp4").subclip(0, 30)  # Process first 30 seconds
fps = clip.fps

# Detect scenes
SceneTimes = detect_scenes(clip, logger="bar", fps=fps)
FrameChangeTimes = [(float(start), float(end)) for start, end in SceneTimes[0]]

# Process subclips
for i, (start, end) in enumerate(FrameChangeTimes):
    if end - start < 3:  # Skip very short clips
        continue

    SubClip = clip.subclip(start, end)
    OutputClip = f"new{i+1}.mp4"

    # Write the subclip
    SubClip.write_videofile(OutputClip, audio=True)  # Error occurs when audio=True
    SubClip.close()

# Close the main clip
clip.close()

What I’ve Tried

Setting audio=False works, but I need the audio in the output videos.
I verified that ffmpeg is installed and works. Running ffmpeg -version confirms it's available.
The source video has an audio stream, confirmed with ffprobe.

Environment

Python version: 3.9.6
MoviePy version: 1.0.3
Operating system: macOS

Question

Why does enabling audio in write_videofile cause this error, and how can I fix it? Is there a specific issue with my code or setup? Any help would be appreciated.

@kotkot21 kotkot21 added the question Questions regarding functionality, usage label Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions regarding functionality, usage
Projects
None yet
Development

No branches or pull requests

1 participant