Hi,
I'm making a custom solution that uses ffmpeg_wrapper from within a Datasync task (the datasync module runs tasks on forked PHP processes). I noticed that when running the command very similar to what video_thumbnailer uses:
ffmpeg -i 'sites/default/files/reel/1/original/video.mp4' -y -ss 00:00:01 -vframes 1 -f mjpeg 'sites/default/files/reel/1/750.thumb-00-00-01_47.png'
that ffmpeg would start , then crash (but not exit) at "Press [q] to stop encoding", before any encoding takes place. It requires a kill -9 to actually make the ffmpeg process die at that point, and the PHP process locks up.
I did some tests, and tried out using exec() instead of passthru (also crashed), and running ffmpeg backgrounded (added & on the end). Backgrounding ffmpeg made it run completely without crashing, but of course the output wasn't available.
So I tried another approach, using proc_open() to run ffmpeg, and this ran successfully and captured the output correctly.
I've attached the patch to switch from passthru to proc_open. I don't see any downsides to this approach so far...
I'm using ffmpeg SVN-r13582 on Debian Lenny (ffmpeg from Debian Multimedia repository).
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | ffmpeg_wrapper.module.procopen.patch | 1.39 KB | neilnz |
Comments
Comment #1
neilnz commentedOops it looks like the patch fell off..
Comment #2
arthurf commentedInteresting issue. I think your approach makes sense. I've committed this to dev. If you have time, please review and confirm that it still works for you.
thanks!
Comment #3
neilnz commentedI've updated to your latest dev snapshot and can confirm it's working for me unmodified.
You may like to get someone else to test too though.
I noticed in the interface it says you should not use pipes or & in your ffmpeg commands, but it seems ffmpeg_wrapper_run_command() makes specific provision for allowing them. If there is some module that's using pipes, it might pay to test that with proc_open(), because I'm not sure that it supports them using shell syntax...
Also, sometime in the future I guess this could allow for reading progress information from ffmpeg's stderr and storing it somewhere API-accessible (maybe in the cache or a custom table?) so other modules can read off this information if they want. I don't really need this personally right now, but some day it could come in handy...
Comment #4
Haehnchen commentedi think proc_open and passthru are not the right way to do it.
on windows machine i got the some issue. ffmpeg is only running 5 sec and than is stopped (look at cpu usage) and must manuelly killed.
thumbnails are working fine, because they generated faster.
i also did some testing:
- passthru same issue
- proc_open should use some pipe reading simular to this. but i didnt work for me on windows
so my working solution is to use shell_exec. it is also used by the flashvideo module that also do ffmpeg stuff.