Tuesday 4 September 2018

Ffmpeg does not work from php

I installed the version from http://ffmpeg.org/releases/ffmpeg-2.5.3.tar.bz2 and also tried the yum version but it is not new enough for youtube-dl.

I tried export PATH=$PATH:/usr/local/bin/ffmpeg and PHP/Apache still cant find FFmpeg.
Apache user runs PHP script on CentOS 6.5.
Calling my youtube-dl.php from php command line as root works (with FFmpeg)
Calling my youtube-dl.php from php apache user works (not with FFmpeg)
What I am trying to do: shell exec youtube-dl (youtube dl calls FFmpeg in its binary code which there is now to modifiy it to add the full path). This works but the FFmpeg part my youtube-dl.php file
$output = shell_exec('youtube-dl -o "/home/test/%(title)s.%(ext)s" '.$url.'      -f bestvideo+bestaudio 2>&1');
echo "<pre>$output</pre>";

# which ffmpeg
/usr/local/bin/ffmpeg

Someone on other pages on this site says local/bin is for customized versions but I downloaded it directly from FFmpeg and did the standard ./configure make install.
Done:
 chmod 755 to /usr/local/bin/ffmpeg

Running FFmpeg as a test command directly (sometimes works and doesn't as I upgraded/rebooted/updatedb/etc)
$output = shell_exec('ffmpeg 2>&1');
echo "<pre>$output</pre>";

Result:
<pre>sh: ffmpeg: command not found</pre>

I read all of these similar questions but they didn't help:
FFMPEG PHP does not seem to work
FFmpeg not working
Recording audio with FFMPEG works in terminal but not through exec() of PHP
ffmpeg-php permission denied on localhost
C++ program from PHP not working properly
FFMPEG works from command line but not PHP
Calling a shellscript from php - not working correctly
PHP Internal Server Error 500 when using ffmpeg to convert files
PHP code not proceeding to the line after exec ffmpeg
ffmpeg not working from php script but works from command line
PHP exec() Not Working With ffmpeg
ffmpeg not work with PHP exec()
ffmpeg php exec not working

Solution what worked for me. I followed the tutorial here to install ffmpeg: http://www.wikihow.com/Install-FFmpeg-on-Windows
Set up the PATH then I checked ffmpeg –version from command prompt it was working.
Then I tried to download a 1080p video with youtube-dl (youtube link) -f bestvideo+bestaudio but I got the same message: "WARNING: You have requested multiple formats but ffmpeg or avconv are not installed. The formats won't be merged." Of course it was installed.
Then I opened the command prompt with Run as Administrator, tried the same and it worked finally.

0 comments:

Post a Comment