ffmpeg working when SSH but not when PHP exec

2

I am not sure why so first here is the error

Array ( [0] => ffmpeg: error while loading shared libraries: libvpx.so.1: failed to map segment from shared object: Permission denied ) 

my PHP

exec('ffmpeg -i /home/social/public_html/'.$key['upload_path'].' -threads 0  /home/social/public_html/'.$key['path'].$key['filename'].'.webm 2>&1',$out);

I also tried

exec('/usr/bin/ffmpeg -i /home/social/public_html/'.$key['upload_path'].' -threads 0  /home/social/public_html/'.$key['path'].$key['filename'].'.webm 2>&1',$out);

Now when I ssh into the server and run the same command it works fine.

here is my FFMPEG

ffmpeg-1.0/ffmpeg
ffmpeg version 1.0 Copyright (c) 2000-2012 the FFmpeg developers
  built on Oct 22 2012 19:38:33 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
  configuration: --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-gpl --enable-postproc --enable-nonfree
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

I am wondering if anyone else has this error

RussellHarrower

Posted 2012-10-22T11:13:47.707

Reputation: 145

Answers

2

I assume you are trying to run the command through a web server. Because if you have verified that you php-command-invocation works by running php ffmpeg-invocation-script.php as "yourself", then the most likely cause of the error is wrong user permissions.

Your web server (apache?) is running as a different user than what you log in with. It is common to restrict access to video and audio devices to users who belong to groups video and audio. The easy solution to this is to add your apache or httpd user to those groups:

usermod -a -G video apache

To figure out who your apache is running as use this:

ps aux |grep [a]pache |tail -n1 | awk '{print $1}'

To list all groups on your system use (look for audio and video):

getent  group | sort | awk -F: '{print $1}'

Apart from that you may run into trouble running your ffmped from PHP becasue PHP scripts are usually restricted to run no longer than a given amount of time (30 sec or so). This is a parameter which you can edit in the apache-php config. On my system this is found here:

$ grep -Hn max_exec /etc/php/apache2-php5.3/php.ini
/etc/php/apache2-php5.3/php.ini:444:max_execution_time = 30

There are also memory limits. You will find the parameter for it in the same section as the max_execution_time parameter.

Ярослав Рахматуллин

Posted 2012-10-22T11:13:47.707

Reputation: 9 076

I've tried these suggestions. One slight fix: it is "usermod -a -G video apache" (the first name must be the group name, the last one must be the user that is appended to the group) – Giuseppe – 2018-02-28T01:51:50.743

0

I've had a similar issue and Yaroslav's answer helped me a lot to solve it. I happened to install ffmpeg with 'root' user to $HOME ('/root/') via http://trac.ffmpeg.org/wiki/CompilationGuide/Centos, which left ffpmeg not shared to the PHP user. I solved it reinstalling following the same guide but changing '$HOME' for '/usr/local', i.e., installing in a shared path. 'Magically' PHP can execute it too, now.

Your error "ffmpeg: error while loading shared libraries: libvpx.so.1: failed to map segment from shared object: Permission denied " seems pretty similar to me. I guess your libvpx may be installed with root permissions only. Although you could successfully execute your command in SSH terminal, PHP may not be able to execute it because it is run by a different user, as @Ярослав Рахматуллин has very well explained.

Giuseppe

Posted 2012-10-22T11:13:47.707

Reputation: 101