sh:ffmpeg:在运行命令时通过php找不到命令 [英] sh: ffmpeg: command not found when run command through php
问题描述
我已经在我的Centos 6机器的根目录下安装了FFMpeg( https:// trac。 ffmpeg.org/wiki/CompilationGuide/Centos 的)。
I have installed successfully installed FFMpeg on root of my Centos 6 machine (https://trac.ffmpeg.org/wiki/CompilationGuide/Centos).
我的apache / php工作区是/ var / www / html
My workplace of apache/php is /var/www/html
现在我正在运行下面的命令成功地在/ 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
我想通过php和使用shell_exec()或exec()php函数来运行这个命令。我的运行命令的PHP代码是:
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);
当我尝试通过上述php代码运行命令时,我得到以下错误: / p>
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.
推荐答案
对于视频缩略图创建,我们使用ffmpeg。
For Video Thumbnail creation we use ffmpeg.
系统(centos 6.x)Ffmpeg安装过程和Php示例: -
In Linux Systems(centos 6.x) Ffmpeg installation process and Php example:-
此过程在我的Centos 6中完成,并使用php创建缩略图。
This process is done in my centos 6 and created thumbnails using php.
步骤1: - 请检查您的linux服务器中是否有现有的ffmpeg可用。如果可用,请删除该文件。
Step1:- Please check If any existing ffmpeg available or not in your linux server .If available please remove that files.
步骤2: - 对于新的ffmpeg安装,请按照此链接
http://root.uabid.com/compile-ffmpeg-on-centos-6-x/ 。
Step2:- For New ffmpeg installation follow this link
http://root.uabid.com/compile-ffmpeg-on-centos-6-x/ .
步骤3: - 安装完成后检查您的ffmpeg安装位置。
Step3:- After installation complete check whereis your ffmpeg installed.
命令:whereis ffmpeg
Command: whereis ffmpeg
这个命令在linux命令行和check.If例如你的ffmpeg路径在(/ usr / local / bin / ffmpeg)。
在您的代码中使用此路径。
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示例: -
<?php
if($extension === 'mp4' OR $extension == 'MP4' )
{
$video = $timestamp.$imagename;
$videoname=substr($imagename,0, -4).$timestamp;
$image = "sites/default/files/content_images/{$videoname}-thumb.jpg";
var_dump($video);
$cmd = "/usr/local/bin/ffmpeg -i /opt/lampp/htdocs/myproject/sites/default/files/content_videos/".$video." -ss 00:00:01.435 -f image2 -vframes 1 /opt/lampp/htdocs/myproject/sites/default/files/content_images/".$videoname."- thumb.jpg";
$cmdstr = $cmd;
$locale = 'en_IN.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL='.$locale);
echo exec($cmd);
?>
进程2: -
这是静态文件路径:
Process 2:- This is for static file paths:
<?php
$cmd = "/root/bin/ffmpeg -i /var/www/html/project/app/webroot/videos/example.mp4 -ss 00:00:01.435 -f image2 -vframes 1 /var/www/html/project/app/webroot/videothumbnails/example-thumb.jpg";
$cmdstr = $cmd;
$locale = 'en_IN.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL='.$locale);
echo exec($cmd);
?>
希望这有助于您&其他..
Hope this helps to you & others..
这篇关于sh:ffmpeg:在运行命令时通过php找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!