用PHP合并视频文件 [英] Merging Video Files with PHP
问题描述
我有两个mp4文件,我想将它们合并.
I have two mp4 files and i want to merge them.
$media1 = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/dir/media1.mp4');
$media2 = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/dir/media2.mp4');
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/dir/combined.mp4', $media1.$media2);
media1.mp4:1兆字节,10秒
media1.mp4 : 1 Megabyte, 10 second
media2.mp4:2兆字节,20秒
media2.mp4 : 2 Megabyte, 20 second
combined.mp4:3兆字节,但10秒(只有media1.mp4)
combined.mp4 : 3 Megabyte but 10 second (There is only media1.mp4)
如何合并这两个文件?
推荐答案
我希望您可以将编码后的视频流与$media1.$media2
组合在一起,但可悲的是,您不喜欢那样.
I wish you could combine encoded video stream with $media1.$media2
but sadly, you can't like that.
幸运的是,php附带了exec()
函数,并与小型 ffmpeg 程序一起使用让你做到这一点.
Fortunately for you, php come with a exec()
function, and using that with the little ffmpeg program let you do that.
所以您要做的是用ffmpeg做一个PHP exec()
并在那里进行合并.
So what you have to do is to do a php exec()
with ffmpeg and do the merge there.
祝你好运!
这篇关于用PHP合并视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!