coveralls: 
[![Coverage Status](https://coveralls.io/builds/28666773/badge)](https://coveralls.io/builds/28666773)

Coverage increased (+0.02%) to 65.029% when pulling **082f1d2caf8d8272b1c172a2274bab27c6d822b1 on declension:fix-logged-ffmpeg-type-error** into **f670d1ab0c1621b39910d506772ee36de064eb5e on Zulko:master**.

declension: @Overdrivr Sorry - I never saw the feedback. I've updated as suggested...
mgaitan: @declension this is ok for me and I would like to merge it. Could you fix the conflicts? 
mgaitan: maybe we should rebase it against `v2` @tburrows13 ?
tburrows13: That's the conflicts fixed (just through the web editor). If the tests pass, feel free to merge.
diff --git a/README.rst b/README.rst
index b1f79ef..62003b4 100644
--- a/README.rst
+++ b/README.rst
@@ -125,7 +125,7 @@ Running `build_docs` has additional dependencies that require installation.
 
 .. code:: bash
 
-    $ (sudo) pip install moviepy[docs]
+    $ (sudo) pip install moviepy[doc]
 
 The documentation can be generated and viewed via:
 
diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.py
index e82f53f..ff464a8 100644
--- a/moviepy/video/io/ffmpeg_writer.py
+++ b/moviepy/video/io/ffmpeg_writer.py
@@ -81,7 +81,7 @@ class FFMPEG_VideoWriter:
 
         if logfile is None:
             logfile = sp.PIPE
-
+        self.logfile = logfile
         self.filename = filename
         self.codec = codec
         self.ext = self.filename.split(".")[-1]
@@ -137,7 +137,12 @@ class FFMPEG_VideoWriter:
         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:"

FFMPEG VideoWriter throws TypeError on error when logged.
First of all, thanks for a great project! It's really useful :+1: 

Here's a small bug that was actually already raised in #593. Seems that the error checking assumes the output is still in the subprocess stream even when it's been redirected elsewhere.

### Expected Behavior
Errors out with a relevant exception message if ffmpeg has a problem (e.g. with parameters), and no more.

### Actual Behavior
Errors out, and _During handling of the above exception, another exception occurred_

```
Traceback (most recent call last):
  File "/home/nick/workspace/PYTHON/synchronar/src/slides.py", line 86, in <module>
    write_frames(ffmvw, DURATION * FPS)
  File "/home/nick/workspace/PYTHON/synchronar/src/slides.py", line 61, in write_frames
    ffmvw.write_frame(frame)
  File "/home/nick/.virtualenvs/synchronar-Hr0bFsh9/lib/python3.6/site-packages/moviepy/video/io/ffmpeg_writer.py", line 143, in write_frame
    if b"Unknown encoder" in ffmpeg_error:
TypeError: argument of type 'NoneType' is not iterable
```

### Steps to Reproduce the Problem
Redirect the logging output, and cause an error. 

#### Minimal Code
```
import sys
import numpy as np
from moviepy.video.io.ffmpeg_writer import FFMPEG_VideoWriter as FVW

writer = FVW('out.avi', (320, 200), 30, logfile=sys.stderr, codec='INVALID')
writer.write_frame(np.zeros((320,200,3))
```

### Specifications

  - Python Version: 3.6
  - Moviepy Version: 0.2.3.5
  - Platform Name: Ubuntu Linux
  - Platform Version: 18.10

diff --git a/tests/test_VideoClip.py b/tests/test_VideoClip.py
index c9e4d93..a9b5683 100644
--- a/tests/test_VideoClip.py
+++ b/tests/test_VideoClip.py
@@ -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")

pip install -e .[dev]
parse_log_pytest
pytest
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
charset-normalizer==3.4.1
coverage==7.8.0
decorator==4.4.2
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
execnet==2.1.1
idna==3.10
imageio==2.37.0
imageio-ffmpeg==0.6.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
-e git+https://github.com/Zulko/moviepy.git@30bd852b1c4100a6d41eb0fe467265fcbfcdcbe9#egg=moviepy
numpy==2.0.2
packaging @ file:///croot/packaging_1734472117206/work
pillow==11.1.0
pluggy @ file:///croot/pluggy_1733169602837/work
proglog==0.1.10
pytest @ file:///croot/pytest_1738938843180/work
pytest-asyncio==0.26.0
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-xdist==3.6.1
requests==2.32.3
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
tqdm==4.67.1
typing_extensions==4.13.0
urllib3==2.3.0

name: moviepy
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - coverage==7.8.0
      - decorator==4.4.2
      - execnet==2.1.1
      - idna==3.10
      - imageio==2.37.0
      - imageio-ffmpeg==0.6.0
      - numpy==2.0.2
      - pillow==11.1.0
      - proglog==0.1.10
      - pytest-asyncio==0.26.0
      - pytest-cov==6.0.0
      - pytest-mock==3.14.0
      - pytest-xdist==3.6.1
      - requests==2.32.3
      - tqdm==4.67.1
      - typing-extensions==4.13.0
      - urllib3==2.3.0
prefix: /opt/conda/envs/moviepy

tests/test_VideoClip.py::test_errors_with_redirected_logs
tests/test_VideoClip.py::test_write_gif_ImageMagick tests/test_VideoClip.py::test_write_gif_ImageMagick_tmpfiles
tests/test_VideoClip.py::test_check_codec tests/test_VideoClip.py::test_save_frame tests/test_VideoClip.py::test_write_image_sequence tests/test_VideoClip.py::test_write_gif_imageio tests/test_VideoClip.py::test_write_gif_ffmpeg tests/test_VideoClip.py::test_write_gif_ffmpeg_tmpfiles tests/test_VideoClip.py::test_subfx tests/test_VideoClip.py::test_oncolor tests/test_VideoClip.py::test_setaudio tests/test_VideoClip.py::test_setaudio_with_audiofile tests/test_VideoClip.py::test_setopacity tests/test_VideoClip.py::test_toimageclip tests/test_VideoClip.py::test_withoutaudio
README.rst moviepy/video/io/ffmpeg_writer.py
README.rst moviepy/video/io/ffmpeg_writer.py