Reputation: 41
I have been working with moviepy library for the first time. I have a video clip around 7 hours long, and I'd like to clip it into small clips. I have a list of start and end time.
video = VideoFileClip("videoFile.mp4")
clips = []
for cut in cuts:
clip = video.subclip(cut[0], cut[1])
clips.append(clip)
clips
clip = video.subclip("7:32:18", "7:38:38")
clips.append(clip)
for clip, title in zip(clips, title_list):
clip.write_videofile(title + '.mp4', threads=8, fps=24, audio=True, codec='libx264',preset=compression)
video.close()
clips[] contain the start and end time for clipping. I have a list of title too which I have scraped from youtube. I have not included the two lists here but a small example could be:
cuts = [('0:00', '2:26'),
('2:26', '5:00'),
('5:00', '7:15'),
('7:15', '10:57'),
('10:57', '18:00'),
('18:00', '18:22'),
('18:22', '19:57'),
('19:57', '20:37'),
('20:37', '28:27'),
('28:27', '40:32'),
('40:32', '49:57'),...
title_list = ['Introduction (What is Todoist?), tech stack talk', 'Showing the final application (with dark mode!)', 'Installing create react app', "Clearing out what we don't need from create react app", "Let's get building our components!", 'Installing packages using Yarn', 'Building the Header component', 'Building the Content component',...
OSError: [Errno 32] Broken pipe
MoviePy error: FFMPEG encountered the following error while writing file Introduction(WhatisTodoist?),techstacktalkTEMP_MPY_wvf_snd.mp3:
b'Introduction(WhatisTodoist?),techstacktalkTEMP_MPY_wvf_snd.mp3: Invalid argument\r\n'
In case it helps, make sure you are using a recent version of FFMPEG (the versions in the Ubuntu/Debian repos are deprecated).
Above is the error I am getting after running the write_videofile(). I have looked at the documentation and the issues on github, I tried updating the ffmpeg through pip too. I don't know why it can't write the audio file.
Upvotes: 4
Views: 6383
Reputation: 721
I had the same issue. I had colons (":") in the file name. I fixed it with:
clip_name = f"{output_file}_{clip_start.replace(':', '')}-{clip_end.replace(':', '')}.mp4"
Upvotes: 0
Reputation: 1101
As Marcel Preda said, it could be the file path. This is the same for the name as well as the file extension. For example, if you use the output file as:
OUTPUT_PATH = os.path.abspath('Test Footage/output/final2.mp4')
But you need to export audio, then this will cause an error (from experience).
OUTPUT_PATH = os.path.abspath('Test Footage/output/final2.mp3') # change to mp3
Upvotes: 1
Reputation: 1205
The reason could be the special characters in the file name. At least on windows you can not have '?' in the file name. You can try other names to check if this is the problem.
Upvotes: 5