MoviePy OSError: [Errno 32] Broken pipe | BrokenPipeError: [Errno 32] Broken pipe

811 views Asked by At

macOS Ventura 13.5

I'm trying to split an audio mp4 file into few chunks to add one of them to a video clip. Here is the code:

from moviepy.editor import *
audio = AudioFileClip('/Users/User1/Desktop/video_creating/my_music.mp4')
clip = audio.subclip(1, 25)
clip.write_audiofile('samples/sample_1.mp4')

But its shows me an error message reporting:

OSError: [Errno 32] Broken pipe

MoviePy error: FFMPEG encountered the following error while writing file sample_1.mp4:

b"[aost#0:0 @ 0x131e39240] Invalid encoder type 'libx264'\n"

What am i doing wrong?

Is there any other ways to edit audio/video files in Python?

I tried to uninstall ffmpeg then install it again. Tried to do brew install lightgbm. But still nothing seems to be work.

2

There are 2 answers

0
pxDav On BEST ANSWER

I tested and I believe the file type mp4 is incorrect and the folder samples does not exist which causes the error

You have to pass a .mp3 file to the AudioFileClip() function and make sure you have a folder called samples

However you can use moviepy.video.io.ffmpeg_tools.ffmpeg_extract_audio to extract sound from an .mp4

1
Mahesh Karia On

Make sure you have installed x264 and ffmpeg packages, you can install them with following command.

conda install -c conda-forge ffmpeg x264

After installing above packages, please make sure when you're calling write_audiofile() extension of output file is mp3 or wav because this library uses encoder based on extension we provide. In your case you were getting error because you were providing mp4 extension.

Code snippet:

from moviepy.editor import *
audio = AudioFileClip('sample-5s.mp4')
clip = audio.subclip(1, 4)
clip.write_audiofile("output.mp3")

Output:

MoviePy - Writing audio in output.mp3
MoviePy - Done.