ffmpeg使用php exec对韩文文件名退出代码1

时间:2018-03-21 13:44:47

标签: php ffmpeg

我无法转换视频文件。例如:

exec(ffmpeg -i 01.시대조감.wmv 0001.mp4 -hide_banner, $output, $exit_code);

只返回退出代码-1

2 个答案:

答案 0 :(得分:0)

也许ffmpeg不在PHP的PATH变量中?

exec ("which ffmpeg",$output,$ret); var_dump($output,$ret);验证,在这种情况下,执行ffmpeg的绝对路径,例如exec("/usr/bin/ffmpeg -i 01.시대조감.wmv 0001.mp4 -hide_banner", $output, $exit_code);

或者你的韩文文件名中有一些对你的shell有特殊含义的字符,需要转义吗?在这种情况下,escapeshellarg(),

exec("/usr/bin/ffmpeg -i ".escapeshellarg("01.시대조감.wmv")." 0001.mp4 -hide_banner", $output, $exit_code);
var_dump($output,$exit_code);` 

答案 1 :(得分:0)

i know this question is old, but for anyone looking here's an alternative way to do it, completely avoiding the issue of "properly escaping unicode characters for your shell" or the issue of "my shell doesn't support unicode characters", by making php open the file and pipe the file contents to ffmpeg.

<?php
$filename="01.시대조감.wmv";
$fp=fopen($filename,"rb");
if(!$fp){
    throw new \RuntimeException("failed to open \"{$filename}\"!");
}
$ffmpeg=popen("ffmpeg -i - 0001.mp4 -hide_banner", "wb");
if(!$ffmpeg){
    throw new \RuntimeException("failed to start ffmpeg!");
}
stream_copy_to_stream($fp,$ffmpeg);
fclose($fp);
pclose($ffmpeg);