heisenberg
heisenberg

Reputation: 11

PHP ffmpeg not found

so I already browse all the forum but I still get error "sh: 1: /usr/bin/ffmpeg: not found". If I run ffmpeg from terminal it works just fine and can do convert video without problem, but if I use PHP exec or shell_exec, the return always ffmpeg not found.

this is my code :

$cmd = "/usr/bin/ffmpeg";

$run = exec($cmd." -i 'linkvideo.m3u8' -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 /test_stream/newfile.mp4 2>&1");

var_dump($run);

if I run which ffmpeg or whereis ffmpeg from terminal it will return /usr/bin/ffmpeg, but if I exec('which ffmpeg') from my code it will return ffmpeg not found. I already chown and chmod the ffmpeg to grant rwx, i tried move ffmpeg to /usr/local/bin still same result. If i run whoami from terminal it will show root but if from my code using exec('whoami') it will show www-data so maybe I miss something about the user but I also already tried to chown ffmpeg from root to www-data still the result is ffmpeg not found, maybe anyone can help, I'm using codeigniter and already install ffmpeg in server using sudo apt-get ffmpeg, thanks before!

Upvotes: 1

Views: 1456

Answers (2)

user7312670
user7312670

Reputation:

Download FFmpeg and ffprobe after than put a folder in third_part folder in application.

    try {
        $FFMpeg = FFMpeg\FFProbe::create([
            'ffmpeg.binaries'  => APPPATH . '/third_party/ffmpeg',
            'ffprobe.binaries'  => APPPATH . '/third_party/ffprobe',
        ]);
    } catch (Exception $e) {
        try {
            $FFMpeg = FFMpeg\FFProbe::create([
                'ffmpeg.binaries' => '/usr/bin/ffmpeg',
                'ffprobe.binaries' => '/usr/bin/ffprobe'
            ]);
        } catch (Exception $e) {
            throw new Exception("However Unable to load FFProbe driver for FFmpeg");
        };
    };

Also; change the second try if you use a different OS than Ubuntu.

For Mac OS :

'ffmpeg.binaries'  => '/usr/local/bin/ffmpeg',
'ffprobe.binaries' => '/usr/local/bin/ffprobe' 

For Windows :

'ffmpeg.binaries'  => 'C:/FFmpeg/bin/ffmpeg.exe',
'ffprobe.binaries' => 'C:/FFmpeg/bin/ffprobe.exe'

For Ubuntu :

'ffmpeg.binaries' => '/usr/bin/ffmpeg',   
'ffprobe.binaries' => '/usr/bin/ffprobe'

Upvotes: 1

SummerRain
SummerRain

Reputation: 43

Did you check if your webserver user is able to run ffmpeg?

Upvotes: 1

Related Questions