Hi,
I am trying to write mp4 video files using moviepy on Ubuntu 17.10 and running into below mentioned codec issue.
BrokenPipeError Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/moviepy/video/io/ffmpeg_writer.py in write_frame(self, img_array)
133 if PY3:
--> 134 self.proc.stdin.write(img_array.tobytes())
135 else:
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<timed eval> in <module>()
<decorator-gen-205> in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, rewrite_audio, remove_temp, write_logfile, verbose, threads, ffmpeg_params, progress_bar)
~/.local/lib/python3.6/site-packages/moviepy/decorators.py in requires_duration(f, clip, *a, **k)
52 raise ValueError("Attribute 'duration' not set")
53 else:
---> 54 return f(clip, *a, **k)
55
56
<decorator-gen-204> in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, rewrite_audio, remove_temp, write_logfile, verbose, threads, ffmpeg_params, progress_bar)
~/.local/lib/python3.6/site-packages/moviepy/decorators.py in use_clip_fps_by_default(f, clip, *a, **k)
135 for (k,v) in k.items()}
136
--> 137 return f(clip, *new_a, **new_kw)
<decorator-gen-203> in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, rewrite_audio, remove_temp, write_logfile, verbose, threads, ffmpeg_params, progress_bar)
~/.local/lib/python3.6/site-packages/moviepy/decorators.py in convert_masks_to_RGB(f, clip, *a, **k)
20 if clip.ismask:
21 clip = clip.to_RGB()
---> 22 return f(clip, *a, **k)
23
24 @decorator.decorator
~/.local/lib/python3.6/site-packages/moviepy/video/VideoClip.py in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, rewrite_audio, remove_temp, write_logfile, verbose, threads, ffmpeg_params, progress_bar)
347 verbose=verbose, threads=threads,
348 ffmpeg_params=ffmpeg_params,
--> 349 progress_bar=progress_bar)
350
351 if remove_temp and make_audio:
~/.local/lib/python3.6/site-packages/moviepy/video/io/ffmpeg_writer.py in ffmpeg_write_video(clip, filename, fps, codec, bitrate, preset, withmask, write_logfile, audiofile, verbose, threads, ffmpeg_params, progress_bar)
214 frame = np.dstack([frame,mask])
215
--> 216 writer.write_frame(frame)
217
218 writer.close()
~/.local/lib/python3.6/site-packages/moviepy/video/io/ffmpeg_writer.py in write_frame(self, img_array)
176
177
--> 178 raise IOError(error)
179
180 def close(self):
OSError: [Errno 32] Broken pipe
MoviePy error: FFMPEG encountered the following error while writing file test_videos_output/solidYellowLeft.mp4:
b"Unknown encoder 'libx264'\n"
The video export failed because FFMPEG didn't find the specified codec for video encoding (libx264). Please install this codec or change the codec when calling write_videofile. For instance:
>>> clip.write_videofile('myvid.webm', codec='libvpx')
I am not noticing any codec related issues when I used ffmpeg directly from terminal to write an mp4 video file.
Versions:
MoviePy -> v0.2.3.2
ffmpeg -> v3.4
imageio -> v2.1.2
Ubuntu -> 17.10
Python -> v3.6
I also made sure ffmpeg has libx264 enabled.
Apologies if i missed anything, i am fairly new to python.
This is the ffmpeg command output
(****) ****@****ubuntu:~/$ ffmpeg
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (crosstool-NG 8a21ab48)
configuration: --prefix=/home/np/anaconda3/envs/py36 --disable-doc --enable-shared --extra-cflags='-fPIC -I/home/np/anaconda3/envs/py36/include' --extra-cxxflags='=-fPIC' --extra-libs='-L/home/np/anaconda3/envs/py36/lib -lz' --enable-pic --disable-static --disable-gpl --disable-nonfree --disable-openssl --enable-libvpx --cc=/home/np/anaconda3/envs/py36/bin/x86_64-conda_cos6-linux-gnu-cc --cxx=/home/np/anaconda3/envs/py36/bin/x86_64-conda_cos6-linux-gnu-c++ --enable-libopus
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Can't thumbs-up. But I'm running into the same issue in Fedora. It complains about the codec libx264 even if I pass codec='libx265'.
Fixed by installing ffmpeg with this : conda install -c conda-forge ffmpeg
I am reponening this as moviepy is supposed to work "out of the box". And a solution based on conda is not universal.
Fixed the problem by removing anaconda version of ffmpeg and installing it from the package manager :
conda remove ffmpeg
sudo apt-get install ffmpeg
This problem kept me up all night, but finally, the trick below worked
Fixed the problem by removing anaconda version of ffmpeg and installing it from the package manager :
conda remove ffmpeg sudo apt-get install ffmpeg
If you had already installed ffmpeg, close and open your python IDE
If a particular audio format is not mandatory for you and you are flexible to experiment with different file format then try changing the format to clip the audio from the video. In my case the moviepy did not work with mp4 but worked with mp3 file format.
Most helpful comment
Fixed by installing ffmpeg with this :
conda install -c conda-forge ffmpeg