python - MoviePy VideoFileClip instance has no attribute 'reader' -
i've searched few days regarding issue have come no solution. have big script (i'm trying concatenate large number of videos, ~100-500), why getting error "too many files open". reading zulko's responses other issues, saw necessary delete each videofileclip instance manually this:
del clip.reader del clip
the issue i'm facing have simple hello_world trying this, error videofileclip instance has no attribute 'reader'
here's code:
from moviepy.editor import * rel_path = "main.py" file_path="hello_world.mp4" newvideo = videofileclip(file_path) del newvideo.reader del newvideo
i'm using el capitan (os x), have updated moviepy, numpy, imagemagick, , packages i've seen required, i'm still getting error. problem computer ends freezing because it's using memory. i'm concatenating chunks of 25 videos, , trying delete 25 "opened files", concatenate next 25, , forth. after i'd concatenate longer videos.
please note without line del newvideo.reader still error many files open
when try running real script, following error if don't add newvideo.reader
traceback (most recent call last): file "/users/johnpeebles/mispistachos/vines/video/reader.py", line 135, in compile_videos newvideo = videofileclip(videopath).resize(height=finalheight,width=finalwidth).set_position('center').set_start(currentduration) file "/library/python/2.7/site-packages/moviepy/video/io/videofileclip.py", line 55, in __init__ reader = ffmpeg_videoreader(filename, pix_fmt=pix_fmt) file "/library/python/2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 32, in __init__ infos = ffmpeg_parse_infos(filename, print_infos, check_duration) file "/library/python/2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 237, in ffmpeg_parse_infos proc = sp.popen(cmd, **popen_params) file "/usr/local/cellar/python/2.7.11/frameworks/python.framework/versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) file "/usr/local/cellar/python/2.7.11/frameworks/python.framework/versions/2.7/lib/python2.7/subprocess.py", line 1223, in _execute_child errpipe_read, errpipe_write = self.pipe_cloexec() file "/usr/local/cellar/python/2.7.11/frameworks/python.framework/versions/2.7/lib/python2.7/subprocess.py", line 1175, in pipe_cloexec r, w = os.pipe() oserror: [errno 24] many open files error compiling videos exception attributeerror: "videofileclip instance has no attribute 'reader'" in <bound method videofileclip.__del__ of <moviepy.video.io.videofileclip.videofileclip instance @ 0x136e46908>> ignore
as requested tynn, i'm posting "real code". i'm doing here is, explained above, compile videos in chunks of 25 videos, compile these pre-compiled videos 1 big video. i'm getting error too many files open
right (if don't add del clip.reader)
videoobject in data["videos"]: counter+=1 #download video , thumbnail downloader=urllib.urlopener() videoid = videoobject[api_video_id] videourl = str(videoobject[api_video_url]) videopath =os.path.join(file_dir, "tmp",str(videoobject[api_video_id].replace("/",""))+'_video.mp4') thumbpath =os.path.join(file_dir, "tmp",str(videoobject[api_video_id].replace("/",""))+'_thumb.jpg') currentvideodimension = videoobject[api_video_dimensions] currentvideowidth = currentvideodimension[0] currentvideoheight = currentvideodimension[1] thumburl = str(videoobject[api_thumb_url]) finalwidth = w*1.0 finalheight = h*1.0 videoproportion = (float(currentvideowidth)/float(currentvideoheight)) if currentvideowidth >= currentvideoheight: finalheight = finalwidth/videoproportion else: finalwidth = finalheight*videoproportion try: download(videourl, videopath) download(thumburl, thumbpath) except exception e: print("exception: "+str(e)) print("video id: "+str(videoid)) traceback.print_exc() continue #create new video , update video duration's offset newvideo = videofileclip(videopath).resize(height=finalheight,width=finalwidth).set_position('center').set_start(currentduration) #if it's not squared append video first if videoproportion != float(1): backgroundclip = colorclip(size=((w,h)), col=colors.hex_to_rgb("#000")).set_position("center").set_start(currentduration).set_duration(newvideo.duration) videos_and_subtitles.append(backgroundclip) #append new video videos videos_and_subtitles.append(newvideo) #append subtitle subtitles # newsubtitletext = max_text(videoobject[api_name],videoobject[api_author])+" \n\n"+videoobject[api_author] videoname = clean(videoobject[api_name]) videoauthor = clean(videoobject[api_author]) newsubtitletext = clean(max_text(videoname,videoauthor)+" \n\n"+videoobject[api_author]) newsubtitle = ( textclip(newsubtitletext,fontsize=70,color='white',font='helvetica-narrow',align='center',method='caption',size=titledimensions).set_start(currentduration).set_position((videooffset+w,0)).set_duration(newvideo.duration) ) videos_and_subtitles.append(newsubtitle) currentduration+=newvideo.duration #preprocess videos if counter%50==0 or len(data["videos"])==(counter): if closure_video_path != none , closure_video_path != "" , len(data["videos"])==(counter): newvideo = videofileclip(closure_video_path).resize(height=finalheight,width=finalwidth).set_position((videooffset,titleoffset)).set_start(currentduration) videos_and_subtitles.append(newvideo) currentduration+=closure_video_duration currentfilename=os.path.join(file_dir, "tmp",str(videonumber)+filename) result = compositevideoclip(videos_and_subtitles,size=moviedimensions,bg_color=colors.hex_to_rgb(background_color)).set_duration(currentduration).write_videofile(filename=currentfilename,preset='ultrafast',fps=24) del result preprocessedvideos.append(videofileclip(currentfilename)) #close files #close_files(videos_and_subtitles) clip in videos_and_subtitles: try: if not (isinstance(clip,imageclip) or isinstance(clip,textclip)): del clip else: del clip except exception,e: print "exception: "+str(e) #end close files videos_and_subtitles = [] videos_and_subtitles.append(left_holder) currentduration = 0 videonumber+=1 if (videoobject==data["videos"][-1]): break print("next video") print("compiling video") filepath = os.path.join(file_dir, "tmp",filename) result = concatenate_videoclips(preprocessedvideos).write_videofile(filename=filepath, preset='ultrafast') #result = compositevideoclip(videos_and_subtitles,size=moviedimensions,bg_color=(0,164,119)).set_duration(currentduration).write_videofile(filename=directory+"/"+filename,preset='ultrafast') print("video compiled") = datetime.datetime.now() print("finished at: "+str(now)) return filepath except exception e: print("exception: "+str(e)) print("video id: "+str(videoid)) traceback.print_exc() rollbar.report_exc_info() return none
zulko himself writes:
in next versions of moviepy
del clip
suffice.
this before version 0.2.2 released. seems don't need del clip.reader
.
to more precise mustn't it! videofileclip
defines destructor doing you:
def __del__(self): """ close/delete internal reader. """ del self.reader
but since you've deleted attributeerror
:
videofileclip instance has no attribute 'reader'
in <bound method videofileclip.__del__ of <...videofileclip instance @ 0x13..>>
Comments
Post a Comment