moviepy
moviepy copied to clipboard
[WinError 6] The handle is invalid
When code contains an import to Mediapipe, we get an error when trying to write audio clip to file. Mediapipe version is 0.10.10.
Actual Behavior
Exception has occurred: OSError [WinError 6] The handle is invalid
Steps to Reproduce the Problem
add import mediapipe as mp
to the top of your code
from moviepy.editor import VideoFileClip, AudioFileClip
from datetime import datetime, timedelta
from PIL import Image
import os
from pathlib import Path
import numpy as np
import subprocess
import mediapipe as mp # <-- works if this is commented out, does not work with it
def extract_audio(videofile, start, end, output, output_ext="mp3"):
audioclip = AudioFileClip(videofile)
audiosubclip = get_subclip(audioclip, start, end)
audiosubclip.write_audiofile(output, codec='pcm_s16le', write_logfile=True)
def get_subclip(clip, start, end):
duration = clip.duration # value is in seconds
# fps = clip.fps
# width, height = clip.size
if end == -1:
dt_object = datetime.strptime(start, '%H:%M:%S.%f') + timedelta(seconds=duration)
end = dt_object.strftime('%H:%M:%S.%f')
return clip.subclip(t_start=start , t_end=end)
if __name__ == "__main__":
videofile_ext = '.mp4'
# process mp4 files in directory
videos_dir = 'Z:/'
files = [f for f in os.listdir(videos_dir) if os.path.isfile(os.path.join(videos_dir, f))]
for filename in files:
video_fullpath = videos_dir + '/' + filename
if os.path.isfile(video_fullpath) and Path(video_fullpath).suffix == videofile_ext:
# get the audio wav file
audio_out = videos_dir + '/' + Path(video_fullpath).stem + '.wav'
extract_audio(video_fullpath, '00:00:00.00', -1, audio_out, '.wav')
Specifications
- Python Version: 3.9.18
- MoviePy Version: 1.0.3
- Platform Name: Windows
- Platform Version: 11