使用 PHP 创建视频文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5892308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create Video File using PHP
提问by Avinash
I have scenario for creating a video files using diff. assets like images, audio file.
我有使用差异创建视频文件的方案。图像、音频文件等资产。
What I want to do is, Find audio files from the particular folder and set it as background music, and fetch images from particular folder and show those images one by one.
我想要做的是,从特定文件夹中查找音频文件并将其设置为背景音乐,然后从特定文件夹中获取图像并一一显示这些图像。
So basically I have images and audio files and I want create a video file using those assets using PHP.
所以基本上我有图像和音频文件,我想使用 PHP 使用这些资产创建一个视频文件。
Can any one please suggest the start up point for this? Have done image capture from video and converting the video using Ffmpeg so I have think of Ffmpeg but, I think it will not allow to create a video.
任何人都可以为此建议起点吗?已经从视频中捕获图像并使用 Ffmpeg 转换视频,所以我想到了 Ffmpeg 但是,我认为它不允许创建视频。
回答by Phil Lello
ffmpeg willallow you to create videos from still images.
ffmpeg将允许您从静止图像创建视频。
For example, to create a video with a 10fps frame rate, from images 001.jpg .... 999.jpg:
例如,要创建帧速率为 10fps 的视频,从图像 001.jpg .... 999.jpg:
ffmpeg -r 10 -b 1800 -i %03d.jpg test1800.mp4
You can mux streams (audio and video) like (add relevant codec options for bitrate, etc)
您可以多路复用流(音频和视频),例如(为比特率添加相关的编解码器选项等)
ffmpeg -i video.mp4 -i audio.wav -map 1.1 -map 2.1 output.mp4
I'm not going to go into more detail, as ffmpeg is a pain (args change in incompatible ways between versions, and depending on how it was compiled), and finding a rate/compression/resolution setting that is good for you is trial-and-error.
我不会详细介绍,因为 ffmpeg 是一种痛苦(参数在版本之间以不兼容的方式变化,并且取决于它的编译方式),并且找到对您有益的速率/压缩/分辨率设置是试验和错误。
回答by fab23
Under Ubuntu you need PHP5, ffmpeg and access to ffmpeg binary, this can be easy achieved with:
在 Ubuntu 下,您需要 PHP5、ffmpeg 和访问 ffmpeg 二进制文件,这可以通过以下方式轻松实现:
apt-get install php5 ffmpeg
I'm using this php function to generate an mp4 video from one gif image and one mp3 file, both source image and output video files are 720x576 pixels:
我正在使用这个 php 函数从一个 gif 图像和一个 mp3 文件生成一个 mp4 视频,源图像和输出视频文件都是 720x576 像素:
function mix_video($audio_file, $img_file, $video_file) {
$mix = "ffmpeg -loop_input -i " . $img_file . " -i " . $audio_file . " -vcodec mpeg4 -s 720x576 -b 10k -r 1 -acodec copy -shortest " . $video_file;
exec($mix);
}
example use:
示例使用:
$audio_file = "/path/to/mp3-file";
$img_file = "/path/to/img-file";
$video_file = "/path/to/video-file";
mix_video($audio_file, $img_file, $video_file);
回答by Denis de Bernardy
Phil's solution is the correct approach. Work out what needs to be done by documenting yourself on ffmpeg (it's messy, and I can't blame him for not wanting to do your homework), and then call it from within php.
Phil 的解决方案是正确的方法。通过在 ffmpeg 上记录自己来确定需要完成的工作(它很乱,我不能怪他不想做你的家庭作业),然后在 php.ini 中调用它。
Cursory googling reveals php wrappers (e.g. http://ffmpeg-php.sourceforge.net/). If none are recent/complete enough, stick to issuing the needed shell commands from php.
粗略的谷歌搜索揭示了 php 包装器(例如http://ffmpeg-php.sourceforge.net/)。如果没有足够新的/完整的,请坚持从 php 发出所需的 shell 命令。
回答by Danzan
ImageMagick convert -delay 100 -quality 75 photo1.jpg photo2.jpg movie.mpg
Or
或者
http://dvd-slideshow.sourceforge.net/wiki/Main_Page