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

Getting OSError: [WinError 6] The handle is invalid On windows #33

Open
programmer290399 opened this issue Feb 9, 2019 · 6 comments
Open

Comments

@programmer290399
Copy link

programmer290399 commented Feb 9, 2019

Hello there !!
I was trying to re-implement this project on my windows 10 machine and I follwed the steps to set it up locally now I am facing this error just after
[MoviePy] Writing video clips/clip-0.mp4

Traceback (most recent call last):
  File ".\classifier.py", line 192, in <module>
    main()
  File ".\classifier.py", line 183, in main
    trim_merge.cut_moments(input_video, moments_timestamps)
  File "D:\rps\retech2.0\MagikMoments\src\trim_merge.py", line 60, in cut_moments
    new_clip.write_videofile(f"clips/clip-{clip_count}.mp4")  # , audio_codec='aac')
  File "<C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\decorator.py:decorator-gen-51>", line 2, in write_videofile
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\decorator.py:decorator-gen-50>", line 2, in write_videofile
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\decorator.py:decorator-gen-49>", line 2, in write_videofile
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 327, in write_videofile
    progress_bar=progress_bar)
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 213, in ffmpeg_write_video
    ffmpeg_params=ffmpeg_params) as writer:
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 127, in __init__
    self.proc = sp.Popen(cmd, **popen_params)
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 596, in __init__
    _cleanup()
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 205, in _cleanup
    res = inst._internal_poll(_deadstate=sys.maxsize)
  File "C:\Users\saahi\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 1035, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid

Can you guide me how to resolve this issue and how to set it up on my machine?

@programmer290399 programmer290399 changed the title Getting RuntimeError: imageio.ffmpeg.download() has been deprecated. Use 'pip install imageio-ffmpeg' instead.' On windows Getting OSError: [WinError 6] The handle is invalid On windows Feb 10, 2019
@1ycx
Copy link
Collaborator

1ycx commented Feb 12, 2019

@programmer290399 That's weird. It did run fine till last time(I tested). Let me test it . . .

@programmer290399
Copy link
Author

programmer290399 commented Feb 12, 2019

thanks @kogam22 for replying . I think it is something to do with the moviepy package as it has changed and been updated after this project was pushed .
Also I searched on the reason behind this error and found some information which may find useful.

  1. Adding a clip.close() after everytime we write a clip on the disk . this would close the handle correctly
  2. Also this issue arises only on those lines which open and write a clip repeatedly inside a loop
  3. I am using a virtual env on anaconda
  4. I tried to process all clips in parallel by editing the trim_merge.py file (using multiprocessing pool ) so that they all have individual handles but I realized that it is not at all an efficient method

@1ycx
Copy link
Collaborator

1ycx commented Feb 12, 2019

I think it is something to do with the moviepy package as it has changed and been updated after this project was pushed .

@programmer290399 I think you are correct there, because I am getting something like this :

Using TensorFlow backend.
Traceback (most recent call last):
  File "/home/yahyaa/PycharmProjects/MagikMoments/MagikMoments/src/classifier.py", line 8, in <module>
    from MagikMoments.src.trim_merge import CombineClips
  File "/home/yahyaa/PycharmProjects/MagikMoments/MagikMoments/src/trim_merge.py", line 6, in <module>
    from moviepy.editor import VideoFileClip, concatenate_videoclips
  File "/home/yahyaa/PycharmProjects/MagikMoments/venv/lib/python3.6/site-packages/moviepy/editor.py", line 26, in <module>
    imageio.plugins.ffmpeg.download()
  File "/home/yahyaa/PycharmProjects/MagikMoments/venv/lib/python3.6/site-packages/imageio/plugins/ffmpeg.py", line 40, in download
    "imageio.ffmpeg.download() has been deprecated. "
RuntimeError: imageio.ffmpeg.download() has been deprecated. Use 'pip install imageio-ffmpeg' instead.'

I too use a virtual env on PyCharm.

@programmer290399
Copy link
Author

Yes That's caused by the update of imageio
I also came across this issue , this can be solved by just running
pip install imageio==2.4.1 on windows

@1ycx
Copy link
Collaborator

1ycx commented Feb 15, 2019

@programmer290399 Any success ? Sorry, I was busy with other work 😅

@programmer290399
Copy link
Author

Yes , I used ffmpeg_extract_subclip instead of subclip method , which was causing OSError: [WinError 6] The handle is invalid and the error was resolved .

the problem lies inside the trim_merge.py file's two functions (viz cut_moments & combine_clips) similarly if replace the functions inside

Similarly we can resolve the issue by replacing the concatenate_videoclips method with its ffmpeg_tools analog from combine_clips function too. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants