OSError: [WinError 6] The handle is invalid... concatenating clips
See original GitHub issueExpected Behavior
I want to choose clips randomly from a directory and then concatenate them into a compilation. My code works fine a random number of times before inevitably failing with a WinError 6 seen below.
Actual Behavior
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/Snapchat/Compile.py", line 26, in <module>
+ random.choice(os.listdir('D:\Snapchat Project\Good Videos')))
File "C:\Users\Administrator\PycharmProjects\Snapchat\venv\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 121, in __init__
nbytes=audio_nbytes)
File "C:\Users\Administrator\PycharmProjects\Snapchat\venv\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 72, in __init__
buffersize=buffersize)
File "C:\Users\Administrator\PycharmProjects\Snapchat\venv\lib\site-packages\moviepy\audio\io\readers.py", line 50, in __init__
infos = ffmpeg_parse_infos(filename)
File "C:\Users\Administrator\PycharmProjects\Snapchat\venv\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 256, in ffmpeg_parse_infos
proc = sp.Popen(cmd, **popen_params)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 596, in __init__
_cleanup()
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 205, in _cleanup
res = inst._internal_poll(_deadstate=sys.maxsize)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 1035, in _internal_poll
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid
Steps to Reproduce the Problem
from moviepy.editor import *
import os
import random
directory = r'D:\Snapchat Project\Compilations\\'
for root, dirs, files in os.walk(directory):
existing_videos = len(files)
number_of_videos = 50
duration = 0
intro = VideoFileClip('D:\Snapchat Project\intro.mp4')
clips = [intro]
final_duration = random.randint(300, 500)
number = 0
for video in range(existing_videos + 1, existing_videos + number_of_videos):
while duration < final_duration:
print('D:\Snapchat Project\Good Videos\\'
+ random.choice(os.listdir('D:\Snapchat Project\Good Videos')))
clip = VideoFileClip('D:\Snapchat Project\Good Videos\\'
+ random.choice(os.listdir('D:\Snapchat Project\Good Videos')))
if (clip.duration < 11) and (clip.duration > 4):
clip = clip.resize(width=360, height=640)
clips.append(clip)
duration = duration + clip.duration
else:
continue
clips.append(intro)
final_clip = concatenate_videoclips(clips)
final_clip.write_videofile('D:\Snapchat Project\Compilations\Comp ' + str(video) + '.mp4', fps=25)
duration = 0
clips = [intro]
Specifications
- Python Version: 3.6
- Moviepy Version: 0.2.3.5
- Platform Name: Windows
- Platform Version: Server 2012
I’m using PyCharm for development
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:11
Top Results From Across the Web
[WinError 6] The handle is invalid" in VideoFileClip function ...
I solved the issue by running the following commands after reading the video. video_clip.reader.close() video_clip.audio.reader.close_proc().
Read more >Pydub Oserror: [Winerror 6] The Handle Is Invalid - ADocLib
OSError : [WinError 6] The handle is invalid It means curio. Expected Behavior I want to choose clips randomly from a directory and...
Read more >moviepy Changelog - pyup.io
`OSError: MoviePy error: failed to read the first frame of video file. ... OSError: \[WinError 6\] The handle is invalid... concatenating clips ......
Read more >Why I am receiving "OSError: [WinError 6] The handle is invalid"
A made python program then converted it to .exe. Started as a program and it says OSError: [WinError 6] The handle is invalid...
Read more >Opening a text file, and receiving a encoding error, tried ...
After receiving this error message, I was recommended to attempt to download a text editor like 'Sublime Text 3', and to open the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hello, I am having the same issue. I am using python 3.8. Any help?
@lily1720 @shahla69 I encountered the same issue on Windows (not on Linux), as this is Windows-specific thing; see https://bugs.python.org/issue37380
This issue got fixed with Python 3.8. Try if upgrading to 3.8 solves WinError 6 for you. It did for me.