我正在尝试在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脚本中的反斜杠(\)仅用于使其忽略换行符(参考)
因此,请尝试在单行中运行不带反斜杠的命令:
<?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';
(...)
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句