Search code examples
pythonffmpegmoviepy

The audio export failed, possily because the bitrate you specified was > two high or too low for the video codec


I am occasionally receiving the following error when attempting to write a m4a (aac) audio file to a video using write_videofile with the moviepy library. I cannot isolate what exactly is causing this error because it happens rarely. I have tried specifying different audio bitrates, but it still raise an exception.

video = video.set_audio(AudioFileClip("asdf.m4a"))
video.write_videofile("video.mp4", fps=FPS, codec='libx264', audio_codec="aac", temp_audiofile='temp-audio.m4a', remove_temp=True, audio_bitrate="256k")

[Errno 32] Broken pipe MoviePy error: FFMPEG encountered the following error while writing file temp-audio.m4a:

temp-audio.m4a: Permission denied

The audio export failed, possily because the bitrate you specified was two high or too low for the video codec.: IOError Traceback (most recent call last):

video.write_videofile("video.mp4", fps=FPS, codec='libx264', audio_codec="aac", temp_audiofile='temp-audio.m4a', remove_temp=True, audio_bitrate="256k")

File "", line 2, in write_videofile File "/var/task/moviepy/decorators.py", line 54, in requires_duration return f(clip, *a, **k)

File "", line 2, in write_videofile File "/var/task/moviepy/decorators.py", line 137, in use_clip_fps_by_default return f(clip, *new_a, **new_kw) File "", line 2, in write_videofile File "/var/task/moviepy/decorators.py", line 22, in convert_masks_to_RGB return f(clip, *a, **k)

File "/var/task/moviepy/video/VideoClip.py", line 331, in write_videofile verbose=verbose) File "", line 2, in write_audiofile File "/var/task/moviepy/decorators.py", line 54, in requires_duration return f(clip, *a, **k) File "/var/task/moviepy/audio/AudioClip.py", line 204, in write_audiofile verbose=verbose, ffmpeg_params=ffmpeg_params) File "", line 2, in ffmpeg_audiowrite File "/var/task/moviepy/decorators.py", line 54, in requires_duration return f(clip, *a, **k) File "/var/task/moviepy/audio/io/ffmpeg_audiowriter.py", line 162, in ffmpeg_audiowrite writer.write_frames(chunk) File "/var/task/moviepy/audio/io/ffmpeg_audiowriter.py", line 122, in write_frames raise IOError(error)

IOError: [Errno 32] Broken pipe MoviePy error: FFMPEG encountered the following error while writing file temp-audio.m4a: temp-audio.m4a: Permission denied The audio export failed, possily because the bitrate you specified was two high or too low for the video codec.


Solution

  • The problem was that I was running this script on an AWS Lambda instance. All of my files should have been written to /tmp as stated by the AWS Lambda documentation. Once all of my temporary files were written to the specified directory; FFMpeg no longer raised an exception.