PHP - 使用ffmpeg将图像转换为视频 [英] PHP - Converting images to video using ffmpeg

查看:574
本文介绍了PHP - 使用ffmpeg将图像转换为视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好,但我非常新的ffmpeg和exec的东西。现在我已经成功安装ffmpeg通过ssh.I引用一些stackoverflow 这里,并在下面找到使用多个图像制作视频的代码。

 <?php 

echo exec('ffmpeg -f image2 -i image%d.jpg video.mpg');

?>

我在同一个文件夹中有image1.jpg和image2.jpg。我运行这个php代码,但什么也没有发生... video.mpg在哪里得到保存?如何检查exec函数是否成功运行或如何调试?任何帮助都不胜感激。

解决方案

如果成功运行, video.mpg 已保存在您当前的工作目录中。如果需要,您可以将文件名更改为绝对路径。



要检查 exec()函数是否成功运行,可以通过获取退出状态的第三个参数:

  exec('ffmpeg -f image2 -i image%d.jpg video.mpg ',$ output,$ exit_status); 

如果成功, $ exit_status 将得到 0 value,so:

  if($ exit_status === 0) {
// run fine
} else {
// failed ...
}

如果它是流行的,你可能想要在 $ output 上收到错误。您可以将 STDERR 移动到 STDOUT ,忽略原始 STDOUT

  exec('ffmpeg -f image2 -i image%d.jpg video.mpg 2>& 1> dev / null',$ output,$ exit_status); 

然后你可以转储 $ output 来查看你有什么 STDERR

  if($ exit_status! 0){
print implode(\\\
,$ output);
}

如果 video.mpg 文件已经存在命令将被卡住,您可能希望通过 -y 标志到 ffmpeg 覆盖任何现有文件:

  exec('ffmpeg -y -f image2 -i image%d.jpg video.mpg 2>& 1> / dev / null',$ output,$ exit_status); 


I am good in php but very new to ffmpeg and exec stuffs.Now I have successfully installed ffmpeg via ssh.I referred some stackoverflow here and found below code to make video using several images.

<?php

echo exec('ffmpeg -f image2 -i image%d.jpg video.mpg');

?>

I have image1.jpg and image2.jpg in same folder.I run this php code but nothing happened...where does video.mpg gets saved ? and how to check if exec function ran successfully or how to debug it ?Any help is appreciated.

解决方案

If it successfully worked, video.mpg got saved in your current working directory. If needed you can change filenames to absolute paths.

To check if exec() function ran successfully you can pass the third argument to get the exit status:

exec('ffmpeg -f image2 -i image%d.jpg video.mpg', $output, $exit_status);

If successful, $exit_status will got 0 value, so:

if ($exit_status === 0) {
    // ran fine
} else {
    // failed...
}

If it's failling you might want to get errors on $output. You can move STDERR to STDOUT ignoring original STDOUT this way:

exec('ffmpeg -f image2 -i image%d.jpg video.mpg 2>&1 >/dev/null', $output, $exit_status);

Then you could dump $output to see what you got on STDERR:

if ($exit_status !== 0) {
    print implode("\n", $output);
}

If the video.mpg file already exists the command will get stuck, you might want to pass -y flag to ffmpeg to overwrite any existing file:

exec('ffmpeg -y -f image2 -i image%d.jpg video.mpg 2>&1 >/dev/null', $output, $exit_status);

这篇关于PHP - 使用ffmpeg将图像转换为视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆