IOStream-OpenEnd / MagikMoments

Finds the "magic" and the most happy moments of a given movie and makes a trailer out of it
GNU General Public License v3.0
12 stars 6 forks source link

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

Open programmer290399 opened 5 years ago

programmer290399 commented 5 years ago

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?

1ycx commented 5 years ago

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

programmer290399 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

programmer290399 commented 5 years ago

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. 🙂