Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running VideoFileClip multiple times in django gives me error #73

Closed
abirafdirp opened this issue Sep 29, 2014 · 7 comments
Closed

Running VideoFileClip multiple times in django gives me error #73

abirafdirp opened this issue Sep 29, 2014 · 7 comments

Comments

@abirafdirp
Copy link

let's say I created a basic web for converting youtube videos to gifs

this is my views in django code

context = RequestContext(request)
    if request.GET:
        link = request.GET.get('link','')
    url = link
    try:
        video = pafy.new(url)
    except:
        return render_to_response("generated/invalid.html", context)
    video = video.getbest()
    if os.path.isfile(os.getcwd()+'\\static\\'+video.title+'.gif')==True:
        gifpath=video.title+'.gif'
        context_dict = {'staticpath':gifpath}
        return render_to_response("generated/generated.html", context_dict, context)
    video.download(quiet=True)
    clip = (VideoFileClip(os.getcwd()+"\\"+video.title+'.'+video.extension).resize(0.4))
    clip.write_gif(os.getcwd()+'\\static\\'+video.title+'.gif', fps=9, opt='optimizeplus', loop=0)
    gifpath=video.title+'.gif'
    context_dict = {'staticpath':gifpath}
    return render_to_response("generated/generated.html", context_dict, context)

it works fine, but after I convert 2-5 videos (it's random) it gives me this error
captaaure

from the looks of it, the cause is in the VideoFileClip method AttributeError

It will works again if I restart the django server, strange!!!

in the django debugger, the exception is [WinError 6] The handle is invalid
capture

Tried it with windows 8.1 64 bit and windows 7 32 bit

THANKS FOR YOUR TIME

@Zulko
Copy link
Owner

Zulko commented Sep 29, 2014

Are you sure that the videos are downloaded correctly ?

@abirafdirp
Copy link
Author

after I turned on the downloading status, it's confirmed I downloaded the video, I can watch it too (uppest and lowest request)

capture2

this is the full traceback
f

and obviously running the script multiple times outside django works fine, I think it's django-moviepy related

@Zulko
Copy link
Owner

Zulko commented Oct 11, 2014

Hi there, any progress on this strange behavior ?

@abirafdirp
Copy link
Author

sorry for late reply and not closing the issue, yes it's working right now, I had to use celery to do it, thanks

@nathanielws93
Copy link

I'm still running into this issue.- I'm trying to render about 100 videos (each one consists of several VideoFileClip subclips), but each time I render 5 videos or so, I get the "Handle is Invalid" error. I've had to restart & clear my Jupyter kernel after every 4-5 videos I make.
Any updates on this bug?

@bsullins
Copy link

Same here, just started running this in a new notebook...

@GE3999
Copy link

GE3999 commented Dec 6, 2018

Thanks
I solved this problem
add clip.close() after write_gif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants