你如何在ffmpeg进行双程转换?

时间:2012-07-30 03:37:00

标签: php ffmpeg

我尝试了以下内容:

$ffmpeg = "/path/to/ffmpeg";
$source = "/path/to/video/source.mp4";
$dest = "/path/to/video/dest.mp4";
$format = "%s > %s 2>&1 & echo $! >> %s";
$a_rate = "44100";
$a_bitrate = "96k";
$v_bitrate = "3000k";
$resolution = "1280x720";
$outputfile = "/path/to/output.txt";
$pidfile = "/path/to/pid.txt";

exec(sprintf($format, $ffmpeg . " -i " . $source . " -vcodec libx264 -s " . $resolution . " -b " . $v_bitrate . " -pass 1 /dev/null && \ " . $ffmpeg . " -i " . $source . " -acodec libfaac -ar " . $a_rate . " -ab " . $a_bitrate . " -vcodec libx264 -s " . $resolution . " -b " . $v_bitrate . " -pass 2 " . $dest, $outputfile, $pidfile));

如果我做了一次传球,那么一切都很完美,但尝试两次传球是不行的。这样做的正确方法是什么?

更新

exec(sprintf($format, $ffmpeg . " -i " . $source . " -pass 1 -vcodec libx264 -s " . $resolution . " -b " . $v_bitrate . " -passlogfile " . $pass . " -f rawvideo -y /dev/null", $outputfile, $pidfile));
exec(sprintf($format, $ffmpeg . " -y -i " . $source . " -pass 2 -acodec libfaac -ar " . $a_rate . " -ab " . $a_bitrate . " -vcodec libx264 -s " . $resolution . " -b " . $v_bitrate . " -passlogfile " . $pass . " " . $dest, $outputfile, $pidfile));

1 个答案:

答案 0 :(得分:0)

问题是将ffmpeg命令放在后台$format = "%s > %s 2>&1 & echo $! >> %s";导致它们同时运行,并且当时没有完成第二遍的日志文件。后台运行正常,因为它没有依赖关系,但我认为需要一个更复杂的解决方案来进行两次传递转换。我打算使用排队系统。