manim icon indicating copy to clipboard operation
manim copied to clipboard

BrokenPipeError: [Errno 32] Broken pipe

Open itspacchu opened this issue 5 years ago • 15 comments

When i run python3 -m manim example_scenes.py SquareToCircle -pl

this is what i get Animation 0: ShowCreationSquare: 0%| | 0/15 [00:00<?, ?it/s]/home/pacchu/_temp.local/share/Trash/files/manim/media/videos/example_scenes/480p15/partial_movie_files/SquareToCircle/00000_temp.mp4: No such file or directory

Traceback (most recent call last): File "/home/pacchu/.local/share/Trash/files/manim/manimlib/extract_scene.py", line 153, in main scene = SceneClass(**scene_kwargs) File "/home/pacchu/.local/share/Trash/files/manim/manimlib/scene/scene.py", line 54, in init self.construct() File "example_scenes.py", line 81, in construct self.play(ShowCreation(square)) File "/home/pacchu/.local/share/Trash/files/manim/manimlib/scene/scene.py", line 449, in wrapper func(self, *args, **kwargs) File "/home/pacchu/.local/share/Trash/files/manim/manimlib/scene/scene.py", line 484, in play self.add_frames(self.get_frame()) File "/home/pacchu/.local/share/Trash/files/manim/manimlib/scene/scene.py", line 570, in add_frames self.file_writer.write_frame(frame) File "/home/pacchu/.local/share/Trash/files/manim/manimlib/scene/scene_file_writer.py", line 171, in write_frame self.writing_process.stdin.write(frame.tostring()) BrokenPipeError: [Errno 32] Broken pipe

itspacchu avatar Aug 04 '19 16:08 itspacchu

same

MrJarnould avatar Aug 12 '19 20:08 MrJarnould

Above that, does it say Unknown encoder 'libx264'?

wknowleskellett avatar Dec 03 '19 19:12 wknowleskellett

Above that, does it say Unknown encoder 'libx264'?

My guess is that when you run ffmpeg -codecs 2> /dev/null | grep -e 264 that none of the lines contain 'libx264', but that there is still output. Basically, I got this problem because ffmpeg (used by manim) would fail to generate the video as requested and close, causing your broken pipe.

I see two possible solutions -

  1. For individuals with this problem: If my above command produced output for you which included the name of a codec (i.e. 'h264', change line 246 in ./manim/manimlib/scene/scene_file_writer.py from '-vcodec', 'libx264' to '-vcodec', 'the_codec_name_you_found'. This solved the problem for me (I used 'h264')
  2. For the overall repository, maybe we change the installation requirements somehow to make sure you have libx264 installed. This, or if it turns out everyone should have one called h264, the master could be updated to use h264.

wknowleskellett avatar Dec 03 '19 20:12 wknowleskellett

Changing '-vcodec', 'libx264' to '-vcodec', 'h264' worked for me.

I am currently running Catalina 10.15.1 on 2017 13-Inch Macbook Pro.

tommyhayes100814 avatar Dec 04 '19 03:12 tommyhayes100814

Same problem here.

running python3 -m manim example_scenes.py SquareToCircle -pl

outputs

Media will be written to ./media/. You can change this behavior with the --media_dir flag. Animation 0: ShowCreationSquare: 0%| | 0/15 [00:00<?, ?it/s]Unknown encoder 'h264'

Traceback (most recent call last): File "/home/tom/manim/manimlib/extract_scene.py", line 155, in main scene = SceneClass(**scene_kwargs) File "/home/tom/manim/manimlib/scene/scene.py", line 53, in init self.construct() File "example_scenes.py", line 83, in construct self.play(ShowCreation(square)) File "/home/tom/manim/manimlib/scene/scene.py", line 406, in wrapper func(self, *args, **kwargs) File "/home/tom/manim/manimlib/scene/scene.py", line 463, in play self.progress_through_animations(animations) File "/home/tom/manim/manimlib/scene/scene.py", line 439, in progress_through_animations self.add_frames(self.get_frame()) File "/home/tom/manim/manimlib/scene/scene.py", line 543, in add_frames self.file_writer.write_frame(frame) File "/home/tom/manim/manimlib/scene/scene_file_writer.py", line 185, in write_frame self.writing_process.stdin.write(frame.tostring()) BrokenPipeError: [Errno 32] Broken pipe

while ffmpeg -codecs 2> /dev/null | grep -e 264

outputs

D.V.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10

Changing line 246 to either h264 or H.264 did not solve the issue. This is running on Ubuntu 18.04

Fillot avatar Dec 06 '19 11:12 Fillot

In case this is useful for anyone /also developers might wanna consider adding this feature/. I hacked around a little bit and added a flag argument to specify the codec used. First add inline argument parser in the manimlib/config.py.

# ... in `parse_cli()`
        parser.add_argument(
            "--vcodec",
            help="Specify the codec used to render video"
        )
# ... in `get_configuration(args)`
    file_writer_config = {
        # ...
        "vcodec": args.vcodec
    }
# ...

Now in manimlib/scene/scene_file_writer.py

        if self.movie_file_extension == ".mov":
            # ...
        else:
            command += [
                '-vcodec', self.vcodec, # <- change to this line
                '-pix_fmt', 'yuv420p',
            ]

Now you can specify --vcodec h264 or whatever you wish when rendering. This also works when using manim in jupyter with this neat library.

PS. You could probably even add a default vcodec, so that you don't have to specify it every time, but I was a bit lazy to do that.

PPS. As was pointed out above, you can view all the available codecs (not only video enconding) by doing this: ffmpeg -codecs 2> /dev/null.

PPPS. On MacOS I actually had the best quality when rendering with the --vcodec prores. It adds up a lot in file weight, but the quality is superb.

PPPPS. If you're using conda version (hopefully in a separate environment), you'll find the library here: ~/anaconda3/envs/<ENVNAME>/lib/python3.7/site-packages/manimlib.

haykh avatar Feb 14 '20 22:02 haykh

Same problem here.

running python3 -m manim example_scenes.py SquareToCircle -pl

outputs

Media will be written to ./media/. You can change this behavior with the --media_dir flag. Animation 0: ShowCreationSquare: 0%| | 0/15 [00:00<?, ?it/s]Unknown encoder 'h264' Traceback (most recent call last): File "/home/tom/manim/manimlib/extract_scene.py", line 155, in main scene = SceneClass(**scene_kwargs) File "/home/tom/manim/manimlib/scene/scene.py", line 53, in init self.construct() File "example_scenes.py", line 83, in construct self.play(ShowCreation(square)) File "/home/tom/manim/manimlib/scene/scene.py", line 406, in wrapper func(self, *args, **kwargs) File "/home/tom/manim/manimlib/scene/scene.py", line 463, in play self.progress_through_animations(animations) File "/home/tom/manim/manimlib/scene/scene.py", line 439, in progress_through_animations self.add_frames(self.get_frame()) File "/home/tom/manim/manimlib/scene/scene.py", line 543, in add_frames self.file_writer.write_frame(frame) File "/home/tom/manim/manimlib/scene/scene_file_writer.py", line 185, in write_frame self.writing_process.stdin.write(frame.tostring()) BrokenPipeError: [Errno 32] Broken pipe

while ffmpeg -codecs 2> /dev/null | grep -e 264

outputs

D.V.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10

Changing line 246 to either h264 or H.264 did not solve the issue. This is running on Ubuntu 18.04

On my Ubuntu 18.04, using h264 failed, but using prores worked!

KokeCacao avatar Feb 20 '20 13:02 KokeCacao

https://stackoverflow.com/a/58421346/4146678 For conda peple

amilapsn avatar Mar 28 '20 03:03 amilapsn

https://stackoverflow.com/a/58421346/4146678 For conda peple

conda install x264=='1!152.20180717' ffmpeg=4.0.2 -c conda-forge

work for me

whliao5am avatar Apr 10 '20 05:04 whliao5am

I had the same problem when installing manim through pip3 on Ubuntu 18.04. It solved itself by simply uninstalling manimlib then ffmpeg : pip3 uninstall manimlib sudo apt --purge remove ffmpeg sudo apt autoremove

then check if you can start ffmpeg from your terminal. if so you need to delete it manually : wheresis ffmpeg should print : /usr/bin/ffmpeg sudo rm /usr/bin/ffmpeg or whatever got printed

you can now optionally reboot now.

sudo apt install ffmpeg pip3 install manimlib

try the example scene now.

anisghaoui avatar Apr 21 '20 13:04 anisghaoui

I was having this problem whenever trying to render 4K with the manim Docker image. I managed to fix it by using the libx265 codec, although it still seems to give the "broken pipe" error sometimes. I thought I'd leave this comment here in case others run into the same issue.

jason-c-kwan avatar Apr 29 '20 14:04 jason-c-kwan

I had this problem too. I was using another version of FFMPEG for another application that I was developing, and after I removed that ffmpeg from the PATH variable, every thing started working again.

raufie avatar Sep 13 '21 20:09 raufie

Changing '-vcodec', 'libx264' to '-vcodec', 'h264' worked for me.

I am currently running Catalina 10.15.1 on 2017 13-Inch Macbook Pro.

YES,I tried it and successfully solved it.

geniuspanada avatar Jul 26 '22 17:07 geniuspanada

Installing the codec via conda (if you happen to have that) also seems to resolve this issue for me. It allows specification of the compile flags for ffmpeg to get the same codec that the code expects

from https://stackoverflow.com/questions/65460436/how-to-enable-libx264-for-ffmpeg-on-macos

conda install -c conda-forge x264=='1!161.3030' ffmpeg=4.3

langford avatar Oct 03 '22 18:10 langford