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).

CommentFileSizeAuthor
#1 ffmpeg_wrapper.module.procopen.patch1.39 KBneilnz

Comments

neilnz’s picture

StatusFileSize
new1.39 KB

Oops it looks like the patch fell off..

arthurf’s picture

Interesting 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!

neilnz’s picture

Status: Needs review » Reviewed & tested by the community

I'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...

Haehnchen’s picture

Category: bug » task

i 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

            /* Read output sent to stdout. */
            while (!feof($io[1])) {
                $back .= htmlspecialchars(fgets($io[1]),
                                                        ENT_COMPAT, 'UTF-8');
            }
            /* Read output sent to stderr. */
            while (!feof($io[2])) {
                $back .= htmlspecialchars(fgets($io[2]),
                                                        ENT_COMPAT, 'UTF-8');
            }

so my working solution is to use shell_exec. it is also used by the flashvideo module that also do ffmpeg stuff.

$ffmpeg_object->output=shell_exec($ffmpeg_object->command .' 2>&1');
$command_return = $ffmpeg_object->output;