I have installed successfully installed FFMpeg on root of my Centos 6 machine (https://trac.ffmpeg.org/wiki/CompilationGuide/Centos).
My workplace of apache/php is /var/www/html
Now I'm running below command successfully on /var/www/html directory to capture frame from the video file. It's capturing a frame.
[root@localhost html]# ffmpeg -i video.mpg -an -ss 30 -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg -s 160x100 frame8 2>&1
I want to run this command through php and using shell_exec() or exec() php functions. My php code for running the command is:
$cmd = "/root/bin/ffmpeg -i /project/app/webroot/videos/video.mpg -ss 00:00:14.435 -f image2 -vframes 1 /project/app/webroot/videothumbnails/example-thumb.jpg";
$locale = 'en_IN.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL='.$locale);
echo shell_exec($cmd);
When I'm trying to run command through above php code, I'm getting below error:
sh: ffmpeg: command not found
Please help me to solve out this problem.
Try using
which
to locate the ffmpeg binary. At least on Ubuntu/Debian based Linuxes thewhich
command should be available by default.which
returns the file path to the preferred executable of any available application. E.g.which php
should return the PHP installation executable that is used by default for CLI operations. Thereforewhich ffmpeg
should return the system default location for the ffmpeg installation.Also make sure that the Linux user running the PHP script has access to ffmpeg (e.g.
$ chmod +x ffmpeg
). If$ sudo which ffmpeg
returns a path but$ which ffmpeg
doesn't, try reinstalling ffmpeg for the wanted user or play around with the permissions.EDIT: use care with
which
though, there's no knowing whether a cracker could replace the ffmpeg executable with something malicious (which leads to the above PHP script running the wrong executable).For Video Thumbnail creation we use ffmpeg.
In Linux Systems(centos 6.x) Ffmpeg installation process and Php example:-
This process is done in my centos 6 and created thumbnails using php.
Step1:- Please check If any existing ffmpeg available or not in your linux server .If available please remove that files.
Step2:- For New ffmpeg installation follow this link
http://root.uabid.com/compile-ffmpeg-on-centos-6-x/ .
Step3:- After installation complete check whereis your ffmpeg installed.
type this command in linux command line and check.If for example your ffmpeg path in (/usr/local/bin/ffmpeg). Use this path in your code.
Php Example:-
Process 2:- This is for static file paths:
Hope this helps to you & others..
I've seen this problem. For me 'command not found' may be the
$PATH
variable problem.When run this command through php and using
shell_exec()
orexec()
php functions, you may use different$PATH
variable compare with running command in linux directory.For example, the
/usr/local/php/etc/vhostphp-fpm.conf
for my php project is below:but
ffmpeg
command locates in/data/bin
directory. My Linux's$PATH
variable contain the/data/bin
.So add
/data/bin
toenv[PATH]
variable above can solve the problem.