question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OSError: [WinError 6] The handle is invalid... concatenating clips

See original GitHub issue

Expected 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11

github_iconTop GitHub Comments

4reactions
zillurbmb51commented, Dec 4, 2020

Hello, I am having the same issue. I am using python 3.8. Any help?

> library(reticulate)
> use_condaenv("py3.8", required = TRUE)
> reticulate::repl_python()
Python 3.8.6 (C:/Users/zillu/anaconda3/envs/py3.8/python.exe)
Reticulate 1.16 REPL -- A Python interpreter in R.
>>> from pyspark import SparkContext, SparkConf
>>> conf = pyspark.SparkConf().setAppName("Spark Tutorials")
NameError: name 'pyspark' is not defined
>>> conf = SparkConf().setAppName("Spark Tutorials")
>>> sc = SparkContext.getOrCreate(conf=conf)
OSError: [WinError 6] The handle is invalid
>>> import subprocess
>>> subprocess._cleanup = lambda: None
>>> sc = SparkContext.getOrCreate(conf=conf)
OSError: [WinError 6] The handle is invalid
1reaction
kalaschnikcommented, Feb 16, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found