我正在尝试在 exec 上运行以下命令:
ffmpeg -y -i video.mp4 \
-ss 1067 -i video.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts -t 32 tmp/cuts/6.ts \
-ss 1215 -i video.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts -t 32 tmp/cuts/7.ts
如果我复制这个命令并在 shell 上运行它,一切都很好,视频被剪切,完美。
但是通过 php exec 运行,ffmpeg 返回以下错误:
[NULL @ 052a0060] Unable to find a suitable output format for '\'
\: Invalid argument
即使我复制粘贴这样的命令:
<?php
$command = 'ffmpeg -y -i video.mp4 \
-ss 1067 -i video.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts -t 32 tmp/cuts/6.ts \
-ss 1215 -i video.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts -t 32 tmp/cuts/7.ts';
echo $command.chr(10);
$return = 0;
$output = array();
exec($command, $output, $return);
?>
我错过了什么吗?我试过escapeshellcmd , escapeshellarg ,甚至双反斜杠来逃避反斜杠,什么都没有。
这在 Windows 和 Unix 中都会发生,错误是完全相同的。
知道这是怎么回事吗?
最佳答案
在这种情况下,shell 脚本中的反斜杠 (\) 仅用于使其忽略换行符 ( Reference )
因此,请尝试在一行中运行不带反斜杠的命令:
<?php
$command = 'ffmpeg -y -i video.mp4 -ss 1067 -i video.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts -t 32 tmp/cuts/6.ts -ss 1215 -i video.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts -t 32 tmp/cuts/7.ts';
(...)
?>
关于PHP exec() 和反斜杠\,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29111014/