简体   繁体   中英

exec function not working as expected

I am running a shell function from php to convert a video file to flash once it is uploaded. The exec function is like this:

exec("ffmpeg -i " . WWW_ROOT . "files" . DS . "videos" . DS . $id . $ext . " -ar 22050 -r 32 -f flv -s 640x480 " . WWW_ROOT . "files" . DS . "videos" . DS . $id . ".flv");

// if I echo the string it returns:
// ffmpeg -i /home/vceroot/public_html/example.com/test/intraweb/app/webroot/files/videos/516c1203-0484-417a-b047-5488c40293e9.mpg -ar 22050 -r 32 -f flv -s 640x480 /home/vceroot/public_html/example.com/test/intraweb/app/webroot/files/videos/516c1203-0484-417a-b047-5488c40293e9.flv
// the locations are correct

However, it does not convert the video.

After it uploaded the file, it just goes back to the index action. There is no converted file although the uploaded file is there.

My permissions on the folder is 755. And the folder owner is apache. I don't know what else to do. Can anyone assist me?

UPDATE

So I've changed my exec query a bit and echoed the output:

exec("ffmpeg -i " . WWW_ROOT . "files" . DS . "videos" . DS . $id . $ext . " -ar 22050 -r 32 -f flv -s 640x480 " . WWW_ROOT . "files" . DS . "videos" . DS . $id . ".flv 2>&1", $output, $return);
die(print_r($output));

This returned the following error:

Array ( [0] => sh: ffmpeg: command not found ) 1

So I changed it a bit to this:

exec("/usr/local/bin/ffmpeg -i " . WWW_ROOT . "files" . DS . "videos" . DS . $id . $ext . " -ar 22050 -r 32 -f flv -s 640x480 " . WWW_ROOT . "files" . DS . "videos" . DS . $id . ".flv 2>&1", $output, $return);
die(print_r($output));

And now it returns:

Array ( [0] => /usr/local/bin/ffmpeg: error while loading shared libraries: libavdevice.so.55: cannot open shared object file: No such file or directory ) 1

Where do I go from here?

So I googled my second error and fixed it by adding the location of libavdevice.so.55 to the /etc/ld.so.conf file and running ldconfig after that.

It works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM