捕获FFMPEG输出 [英] Capture FFMPEG output
问题描述
我需要读取ffmpeg的输出,以便甚至尝试解决方案我昨天的问题这是一个单独的问题,我的问题在那里,所以我提出了一个新的问题。
我如何得到一个 ffmpeg的输出 - 我在PHP中的
命令?
这是我一直在尝试的:
<?PHP
error_reporting(E_ALL);
$ src =/var/videos/video1.wmv;
$ command =/ usr / bin / ffmpeg -i。 $ SRC;
echo< B>,$ command,< / B>< br />;
$ command = escapeshellcmd($ command);
echobacktick:< br />< pre>;
`$ command`;
echo< / pre>< br /> system:< br />< pre>;
echo system($ command);
echo< / pre>< br /> shell_exec:< br />< pre>;
echo shell_exec($ command);
echo< / pre>< br /> passthru:< br />< pre>;
passthru($ command);
echo< / pre>< br /> exec:< br />< pre>;
$ output = array();
exec($ command,$ output,$ status);
foreach($ output AS $ o)
{
echo $ o,< br />;
}
echo< / pre>< br /> popen:< br />< pre>;
$ handle = popen($ command,'r');
echo fread($ handle,1048576);
pclose($ handle);
echo< / pre>< br />;
?>
这是我的输出:
<$ p $ < B>
backtick:< br />
< pre>< / pre>< br />
system:< br />
< pre>< / pre>< br />
shell_exec:< br />
< pre>< / pre>< br />
passthru:< br />
< pre>< / pre>< br />
exec:< br />
< pre>< / pre>< br />
popen:< br />
< pre>< / pre>< br />
我没有得到它。 safe_mode
已关闭。 disable_functions
中没有任何内容。目录是由 www-data
(我的Ubuntu系统上的apache用户)拥有的。我从 exec()
和 system()
中获得有效的状态,并从命令行运行相同的命令给我吨的产量。我觉得我一定很想念一些明显的东西,但我不知道这是什么。
em> stdout 而不是
更改此行:
$ command =/ usr / bin / ffmpeg -i。 $ SRC;
into
$ command =/ usr / bin / ffmpeg -i。 $ src。 2>& 1;
并再次尝试:)
I need to read the output from ffmpeg in order to even try the solution to my question from yesterday. This is a separate issue from my problem there, so I made a new question.
How the heck do I get the output from an ffmpeg -i
command in PHP?
This is what I've been trying:
<?PHP
error_reporting(E_ALL);
$src = "/var/videos/video1.wmv";
$command = "/usr/bin/ffmpeg -i " . $src;
echo "<B>",$command,"</B><br/>";
$command = escapeshellcmd($command);
echo "backtick:<br/><pre>";
`$command`;
echo "</pre><br/>system:<br/><pre>";
echo system($command);
echo "</pre><br/>shell_exec:<br/><pre>";
echo shell_exec($command);
echo "</pre><br/>passthru:<br/><pre>";
passthru($command);
echo "</pre><br/>exec:<br/><pre>";
$output = array();
exec($command,$output,$status);
foreach($output AS $o)
{
echo $o , "<br/>";
}
echo "</pre><br/>popen:<br/><pre>";
$handle = popen($command,'r');
echo fread($handle,1048576);
pclose($handle);
echo "</pre><br/>";
?>
This is my output:
<B>/usr/bin/ffmpeg -i /var/videos/video1.wmv</B><br/>
backtick:<br/>
<pre></pre><br/>
system:<br/>
<pre></pre><br/>
shell_exec:<br/>
<pre></pre><br/>
passthru:<br/>
<pre></pre><br/>
exec:<br/>
<pre></pre><br/>
popen:<br/>
<pre></pre><br/>
I don't get it. safe_mode
is off. There's nothing in disable_functions
. The directory is owned by www-data
(the apache user on my Ubuntu system). I get a valid status back from exec()
and system()
and running the same command from the command line give me tons of output. I feel like I must be missing something obvious but I have no idea what it is.
The problem is you catch only stdout and not stderr (see Standard Streams). Change this line:
$command = "/usr/bin/ffmpeg -i " . $src;
into
$command = "/usr/bin/ffmpeg -i " . $src . " 2>&1";
and give it another try :)
这篇关于捕获FFMPEG输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!