如何使用php从图像创建视频? [英] How to create videos from images with php?

查看:127
本文介绍了如何使用php从图像创建视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有10张图像,我想将这些图像组合在像幻灯片的视频中。



例如,我想显示每个图像5秒钟,然后继续下一个图像另外5秒。



如果可能,包括音乐和一些描述性文字也是完美的。



有没有我的第一个想法是用ffmpeg库来解压缩ffmpeg命令,这个例子可以是ffmpeg库吗?

解决方案


从图像创建视频



ffmpeg可用于拼接几个图像一起成为视频。
有很多选项,但以下示例应该足以让
开始。它需要所有文件名为
XXXXX.morph.jpg的图像,其中X是数字,并创建一个名为
output.mp4的视频。 qscale选项指定图像质量(1是
最高,32是最低),-r选项用于
指定每秒的帧数。



ffmpeg -r 25 -qscale 2 -i%05d.morph.jpg output.mp4



(这个网站被删除的链接已被删除。链接
已被删除。)


其中25表示每秒25张图像。您可以稍微(1秒)延迟将其设置为1,或使用小数,IE:0.5延迟2秒。



然后可以组合视频和音频流如此这样。

  ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -b:一个128k final.mp4 

当然可以选择适合的编解码器。如果你想要一个mp4使用libx264的视频和aac(内置到ffmpeg,不再是实验)的音频。



只要记住,如果你选择使用一个方法像这样ffmpeg输出,默认情况下,当你尝试读它时,stderr。如果您愿意,可以重定向到stdout。


Let's say I have 10 images and I want to combine those images in a video like a slideshow.

For example I want to show each image for 5 seconds and then continue with next image for another 5 seconds.

If it's possible, it will be perfect to include music and some descriptive text too.

Is there a sample code for this may be with ffmpeg library ?

解决方案

My first thought was to shell out to the ffmpeg command with something like this.

Creating a Video from Images

ffmpeg can be used to stitch several images together into a video. There are many options, but the following example should be enough to get started. It takes all images that have filenames of XXXXX.morph.jpg, where X is numerical, and creates a video called "output.mp4". The qscale option specifies the picture quality (1 is the highest, and 32 is the lowest), and the "-r" option is used to specify the number of frames per second.

ffmpeg -r 25 -qscale 2 -i %05d.morph.jpg output.mp4

(The website that this blurb was taken from is gone. Link has been removed.)

Where 25 means 25 images per second. You could set this to 1 for a slight (1 sec) delay or use decimals, IE: 0.5 for a 2 second delay.

You can then combine a video and audio stream with something like this.

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -b:a 128k final.mp4

Of course choose your appropriate codecs. If you want an mp4 use libx264 for video and aac (built into ffmpeg and no longer "experimental") for audio.

Just remember that if you choose to use a method like this that ffmpeg output goes, by default, to stderr for when you try to read it. It can be redirected to stdout if you prefer.

这篇关于如何使用php从图像创建视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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