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

ffmpeg hangs #13

Closed
stewpend0us opened this issue Feb 15, 2014 · 19 comments
Closed

ffmpeg hangs #13

stewpend0us opened this issue Feb 15, 2014 · 19 comments

Comments

@stewpend0us
Copy link

I was using:

"from moviepy.video.io.ffmpeg_writer import FFMPEG_VideoWriter as FFW"
and
"from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader as FFR"

To read a video, rotate the frame, and save it to a new video. (I'm sure there's an easier way to do that using your tool...but anyway)

ffmpeg would consistently hang after about 200 frames. I got it working by adding:

self.proc.stdout.close()
self.proc.stderr.close()
to the end of init in ffmpeg_writer.py

and

self.proc.stdin.close()
self.proc.stderr.close()
to the end of initialize() in ffmpeg_reader.py

based on the comments here:
http://stackoverflow.com/questions/16523746/ffmpeg-hangs-when-run-in-background

The video I was reading/writing is 1920x1080, 50seconds, ~20606kbps, 29fps, .mov file
and I'm using windows 7 if that matters.

@Zulko
Copy link
Owner

Zulko commented Feb 15, 2014

I touched these files recently... when did you download the module ? Are you using Python 2 or Python 3 ?

@stewpend0us
Copy link
Author

I downloaded maybe last week? Fairly recent. I'd love to use python 3 but the last time I looked it wasn't supported....so I'm using 2.7

@Zulko
Copy link
Owner

Zulko commented Feb 15, 2014

Ok, so I didn't know that this bug existed in python 2.7, but people of
the Python3 world complained about the hanging. The cause seems to be
that the default buffer in subprocess is very small in Python3 (and
apparently not big enough in python2.7). So yesterday I changed these
files to force a bigger buffer.

If you could update and give it a try, that would be great ! Also it
should not hang any more, you should get a proper error is something
goes wrong.

Le 15/02/2014 21:55, stewpend0us a écrit :

I downloaded maybe last week? Fairly recent. I'd love to use python 3
but the last time I looked it wasn't supported....so I'm using 2.7


Reply to this email directly or view it on GitHub
#13 (comment).

@stewpend0us
Copy link
Author

I installed using pip btw..and just tried an upgrade that told me it's up to date. Maybe I'm using an older version then I realized if whatever pip gives me isn't the latest. I'll download the source and give it a try...

@Zulko
Copy link
Owner

Zulko commented Feb 19, 2014

Did it work ?

@stewpend0us
Copy link
Author

Haven't had a chance yet...I will test it out and let you know.

@Zulko
Copy link
Owner

Zulko commented Feb 19, 2014

Cool. there is no hurry ;)

Le 19/02/2014 15:14, stewpend0us a écrit :

Haven't had a chance yet...I will test it out and let you know.


Reply to this email directly or view it on GitHub
#13 (comment).

@stewpend0us
Copy link
Author

Alright pretty sure i'm running version 2.1.4.05 (if there's a way to do moviepy.version or something I can confirm that but it's definitely not the same code that I was running before.)

Same issue. Hangs at frame 166.

I didn't see any reason not to close stdin in ffmpeg_reader or stdout and stderr in ffmpeg_writer so I tried that and it still hung.

When I add stderr to the list on ffmpeg_reader it works again....

@oxivanisher
Copy link
Contributor

I have the same issue after 6 minutes of every rendering.
But adding "self.proc.stderr.close()" to line 72 in the ffmpeg_writer.py fixes it for me. Additionally adding "self.proc.stdin.close()" is a bad idea.
My python version in use is 2.7.3, the moviepy version is the current from pip. Right after you fixed the rotation bug. 👍

I hope this helps fixing the problem for anyone else.

@Zulko
Copy link
Owner

Zulko commented Mar 21, 2014

Thanks for the feedback. I think it's pretty clear now that I have no idea what is going on. It seems to always work on my computer but whatever I do its buggy on other distributions. Could you please make a commit with the correction ? Thanks in advance !

oxivanisher added a commit to oxivanisher/moviepy that referenced this issue Mar 21, 2014
Zulko added a commit that referenced this issue Mar 22, 2014
Hopefully fixes issue #13 for everyone.
@Zulko
Copy link
Owner

Zulko commented Apr 9, 2014

I changed this in the last versions. I think closing the error pipe was not the best way to proceed, so now the error pipe is redirected towards devnull or towards some file . It's all a little technical but I expect that this should not cause any problem.

When you have time / If you are still interested , can you try the latest version on Github and tell me if it works ? I yes I can close that issue.

Thanks in advance !

@Zulko Zulko closed this as completed Apr 20, 2014
@oxivanisher
Copy link
Contributor

HI there, sorry for the very late reply. I totally forgot to write back.

I tested your patch with my project twice, and id crashed both times as before. The chances are great that its OS dependent. As long as people find this thread, they should be able to work around this problem. Another workaround would be, if you add a switch to the class to deactivate it.

Have a nice easter, oxivanisher

@Zulko Zulko reopened this Apr 21, 2014
@Zulko
Copy link
Owner

Zulko commented Apr 21, 2014

Ok, thanks. Just to be sure: did you try with a recent version of MoviePy, or was it just at the time ? What is your OS ?

@oxivanisher
Copy link
Contributor

I checked the sourcecode (pip) and it was the "corrent" one at this time. But i will gladly test it again and make sure. I use Debian Wheezy x64 and a downloaded version of ffmpeg.

I will test it today or tomorrow and leave a comment here.

@oxivanisher
Copy link
Contributor

It is looking good! 👍 It is already rendering for 18 minutes and all the other times it crashed after 6 minutes. I will let it run for another 12 minutes to surely reach 30 minutes. I thing we would be safe after that. :D Very nice work.

@oxivanisher
Copy link
Contributor

I let it finish the run and it worked perfectly for over 70 minutes. I think its save to close this issue for good. 👍

@Zulko
Copy link
Owner

Zulko commented Apr 23, 2014

That's a relief, thanks for testing. For info, one of the things I have changed is that now the pipes for the output or the errors returned by FFMPEG are now redirected either towards a file or towards "DEVNULL" (which, if I understood well, is where you send the unwanted streams).

I am curious, your processes seem a little long, what is your frame writing rate (i.e. when you launch to_videofile, it should print something like "XXX iters/sec", what is XXX ?)

@oxivanisher
Copy link
Contributor

It is around 25. I overlayed clips with Images (fade in, and then out again) over a FullHD Video recording with audio. The output file was rendered to 720p (it wanted to take 16+ hours). My system has 16GB RAM and a 8 Core CPU, but i played around with multithreading (added the option to the FFMPEG call) but it did not go faster. Its an Athlon "Don't know what exactly" with 3.4 GHz per core.
I think this was the limiting factor.

@Zulko
Copy link
Owner

Zulko commented Apr 23, 2014

Ok, everything fine then, I am closing this issue.

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

3 participants