简体   繁体   English

在 PHP 中使用 ffmpeg exec 找不到文件和压缩

[英]Cannot find file and compress using ffmpeg exec in PHP

I'm trying to compress files with ffmpeg but despite having the correct file path it cannot find the file:我正在尝试使用 ffmpeg 压缩文件,但尽管文件路径正确,但它找不到文件:

I'm using this code here:我在这里使用这段代码:

echo $ypath;
exec("ffmpeg -i ".$ypath." -vf 'scale=iw/3:ih/3' ".$prevPath ." 2>&1", $error);
foreach($error as $next) {
    echo "<br>".$next;
}

And get this result:并得到这个结果:

../data/mydirectory/buffer/1610997353779_D012&ForestDescend.mp4
sh: 1: ForestDescend.mp4: not found

What's the problem, why can't it find the file in question.什么问题,为什么找不到有问题的文件。 I'm 100% sure the path is correct because I'm using it further above the code to convert images who are in the same directory.我 100% 确定路径是正确的,因为我在代码上方进一步使用它来转换同一目录中的图像。

How can I solve this issue?我该如何解决这个问题?

The ampersand ( & ) in the filename is probably causing the issue.文件名中的与号 ( & ) 可能是导致问题的原因。 A simple way around this is to wrap the $ypath value in quotes:解决此问题的一种简单方法是将$ypath值括在引号中:

exec('ffmpeg -i "'.$ypath.'" -vf "scale=iw/3:ih/3" "'.$prevPath .'" 2>&1', $error);

Combine this withescapeshellarg() if your filenames might contain quotes or other special characters.如果您的文件名可能包含引号或其他特殊字符,请将此与escapeshellarg()结合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM