Click to See Complete Forum and Search --> : I can't get an EXEC'd program to run properly


Burning dan
08-14-2008, 12:40 AM
Thank you SO MUCH for your time in helping me.

I'm trying to convert videos using ffmpeg, exec'd from a php page.
I've created a shell script that uses all the ffmpeg options I want and takes 2 parameters for input filename and output filename. That shell script works properly when i run it from a shell. When I run it from php/exec, the script runs, but ffmpeg doesn't actually run.

Here's the shell script
#!/bin/sh
whoami
date
echo about to: ffmpeg -i $1 -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 $2
#ffmpeg
ffmpeg -i $1 -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 $2
echo $?
whoami
(all but the big ffmpeg line is just debugging and curiousity)

when I run it from within my php page by doing:
echo exec( "danffmpeg $cFileName $cFLVName", &$aExecOutput, &$nExecReturn );

echo( "<BR>execoutput:<BR>\r\n" );
print_r( $aExecOutput );
echo( "<BR>execreturn:<BR>\r\n" );
print_r( $nExecReturn );

I get this output:
apache

execoutput: Array ( [0] => 0 [1] => apache [2] => Wed Aug 13 19:32:51 PDT 2008 [3] => about to: ffmpeg -i records/avitest_79.avi -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 streams/avitest_79.flv [4] => 1 [5] => apache )

execreturn: 0

The return value of ffmpeg within the script is 1, but the execreturn value of danffmpeg is 0.

When I change the line in the shell script that launches ffmpeg -- I uncomment the unadorned #ffmpeg and comment out the one that includes all the parameters and actually tries to do the conversion...

When I do that, ffmpeg runs. I can see the huge long help screen output in the execoutput. The $? return value of ffmpeg is still 1, and the execreturn value is still 0.

This leads me to believe it's not a permissions problem of launching ffmpeg.
My best guess is that it's not launching because of how much memory (or something) ffmpeg wants to take up when it tries to convert... and I tried setting memory_limit to 256M (from 16M) and it didn't change...

It's an x86_64 system running CentOS 5
I've attached my phpinfo output.

Thank you again for your help
dan

jazz_snob
08-14-2008, 01:20 AM
php exec's the script as whatever user apache is running as (if you are running php as a module, which is what it looks like from whoami output). So does that user (ie: apache) have permissions to write wherever it is you are trying to write an output file?

HalfaBee
08-14-2008, 02:42 AM
The shell script is returning 0 not ffmpeg
remove
echo $?
whoami

and use

exit $?

to exit with ffmpeg's return value.

Ashley Sheridan
08-18-2008, 05:38 AM
Also, it could be that you need to put in the absolute path to ffmpeg. I just recently did a similar project, which was using mencoder, and I needed to put in the full path, as ffmpeg isn't in any of Apaches known paths. If you don't know where ffmpeg is, at a command line, type "where ffmpeg" (without the quotes) and you'll be given the full path to the program. Hope this helps.

illzz
08-21-2008, 05:50 PM
If you don't know where ffmpeg is, at a command line, type "where ffmpeg" (without the quotes) and you'll be given the full path to the program.
I think that you mean to say either 'which' or 'whereis'. 'which' would be more helpful in this situation, since the source or man paths are not needed.

another thing that the OP can do is try running it manually, as 'apache', to see any error messages that would occur.

As root, run#sudo -u apache command

in this case:#sudo -u apache ffmpeg -i records/avitest_79.avi -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 streams/avitest_79.flv

Ashley Sheridan
08-21-2008, 07:20 PM
Yes, sorry, I think I was a little tired at the time, and indeed whereis is the right command. However, running it as apache using sudo will not necessarily give the right results, as sudo does not execute the scripts which sets the path environment variable.