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

FFmpeg Writer: handle redirected logs when checking for errors #890

Merged
merged 8 commits into from
Mar 30, 2020
7 changes: 6 additions & 1 deletion moviepy/video/io/ffmpeg_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(

if logfile is None:
logfile = sp.PIPE

self.logfile = logfile
self.filename = filename
self.codec = codec
self.ext = self.filename.split(".")[-1]
Expand Down Expand Up @@ -137,7 +137,12 @@ def write_frame(self, img_array):
try:
self.proc.stdin.write(img_array.tobytes())
except IOError as err:
logs = self.logfile.name
_, ffmpeg_error = self.proc.communicate()
if not ffmpeg_error:
with open(logs, "rb") as f:
ffmpeg_error = f.read()

error = str(err) + (
"\n\nMoviePy error: FFMPEG encountered "
"the following error while writing file %s:"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def test_check_codec():
close_all_clips(locals())


def test_errors_with_redirected_logs():
"""Checks error cases return helpful messages even when logs redirected
See https://github.com/Zulko/moviepy/issues/877"""
clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
location = os.path.join(TMP_DIR, "logged-write.mp4")
with pytest.raises(IOError) as e:
clip.write_videofile(location, codec="nonexistent-codec", write_logfile=True)
assert "Unknown encoder 'nonexistent-codec'" in str(e.value)
close_all_clips(locals())


def test_save_frame():
clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
location = os.path.join(TMP_DIR, "save_frame.png")
Expand Down