imageio / imageio-ffmpeg

FFMPEG wrapper for Python
BSD 2-Clause "Simplified" License
221 stars 50 forks source link

BrokenPipeError: [Errno 32] Broken pipe #35

Open shimrite opened 4 years ago

shimrite commented 4 years ago

hi, I had the following error: [could not acquire lock for <_io.BufferedReader name=10>..] as suggested in previous issue --> updated imageio with the updated release imageio-ffmpeg 0.4.0 rerun my code and getting the following error:

[BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/xxx/opt/anaconda3/envs/cvA2Zcourse/lib/python3.7/site-packages/imageio_ffmpeg/_io.py", line 483, in write_frames
    raise IOError(msg)
OSError: [Errno 32] Broken pipe
FFMPEG COMMAND:
/Users/xxx/opt/anaconda3/envs/cvA2Zcourse/bin/ffmpeg -y -f rawvideo -vcodec rawvideo -s 1920x1080 -pix_fmt rgb24 -r 30.00 -i - -an -vcodec libx264 -pix_fmt yuv420p -crf 25 -vf scale=1920:1088 -v warning /Users/xxx/PycharmProjects/cvA2Zcourse/output.mp4
FFMPEG STDERR OUTPUT:
]

the code is simple read-write example: (Doing some Object Detection on a video)

reader = imageio.get_reader('funny_dog.mp4')
fps = reader.get_meta_data()['fps']
writer = imageio.get_writer('output.mp4', fps = fps)
for i, frame in enumerate(reader):
    frame = detect(frame, net.eval(), transform)
    writer.append_data(frame)
    print(i)
writer.close()

run on mac

@almarklein

Originally posted by @shimrite in https://github.com/imageio/imageio/issues/482#issuecomment-588189474

almarklein commented 4 years ago

Thanks for the report. This is probably an issue of imageio-ffmpeg. Sadly the changes that were recently made do not resolve all problems yet (or have introduced new problems). I will have a proper look tomorrow or next Monday.

almarklein commented 4 years ago

@shimrite I tried to reproduce using this:

import imageio

reader = imageio.get_reader('imageio:cockatoo.mp4')
fps = reader.get_meta_data()['fps']
writer = imageio.get_writer('output.mp4', fps = fps)
for i, frame in enumerate(reader):
    # frame = detect(frame, net.eval(), transform)
    writer.append_data(frame)
    print(i)
writer.close()

But it runs without problems on Windows and Linux. Do you have some more details on your system like OS and ffmpeg version (imageio_ffmpeg.get_ffmpeg_version())?

If your code fails, and the above works, we should look into what frame is and if that may cause this isssue (and if we can detect it in imageio-ffmpeg).

clydefroglearn commented 4 years ago

I have a nearly identical error but I only receive the error after freezing my python application using pyinstaller and running the .exe. Everything works fine if i run the .py file. Additionally, everything that does not use ffmpeg works fine in the pyinstaller output .exe. I am using Windows 10 and my output from imageio_ffmpeg.get_ffmpeg_version() is 4.2. My frame is a screenshot of a pyqt5 application and i'm using imageio to implement a screen recording feature.

almarklein commented 4 years ago

There used to be a shell=True in the subprocess call for Window. This was removed for another solution, because of the potential security implications.

Could you try adding "shell": True to the dict returned by this function: https://github.com/imageio/imageio-ffmpeg/blob/master/imageio_ffmpeg/_utils.py#L70-L74 If that works, we may perhaps add some logic to run shell=True on Windows, when frozen.

clydefroglearn commented 4 years ago

That didn't help. I still get the same broken pipe error. In addition, I now get error popups before the broken pipe error telling me that various avformat.dll and avcodec.dll files cannot be found.

EDIT: I reverted my changes and I still get the dll missing prompts. I'm sure I didn't get them before and I don't know why they are showing up. I'm not a PyInstaller pro so there's a good chance I'm messing something up. Any help with how I should configure my spec file to get imageio to work properly with ffmpeg would be greatly appreciated.

EDIT2: If I manually place the dlls into the frozen distriubtion, everything works perfectly. No broken pipe error and no edits to _utils.py needed. I'm super confused as to why I didn't get dll missing errors previously.

almarklein commented 4 years ago

Are you using Anaconda's ffmpeg by any chance? This looks a bit like https://github.com/imageio/imageio/issues/496#issuecomment-597953944

You can check with imageio_ffmpeg.get_ffmpeg_exe()

clydefroglearn commented 4 years ago

Nope. It's using the imageio-ffmpeg exe. I'm sure there is a way to get pyinstaller to pull all the dlls correctly but this is the first application I've tried freezing and it was enough of a challenge setting up the spec file to get all the python libraries pulled in correctly.

jaewooklee93 commented 3 years ago

For me, it was not the issue of ffmpeg executable, and it was simply width and height are not even number for my situation. Thus, after proper padding of np.ndarray, broken pipe error has gone.

It would be nice if more elaborated error message is given for this specific situation :)

almarklein commented 3 years ago

@jaewooklee93 wow, thanks for the insight, I would not have thought of that. I cannot produce the error this way, but maybe a combination of things can cause this to happen.

If anyone else could try and see if this would fix it, that would be great! We could then also look into creating a solution for this issue.