2

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 Megabyte, 10 second

media2.mp4 : 2 Megabyte, 20 second

combined.mp4 : 3 Megabyte but 10 second (There is only media1.mp4)

How can i merge these two files?

mcan
  • 1,914
  • 3
  • 32
  • 53
  • Have you tried `php-ffmpeg`? – Abhishek Apr 29 '15 at 09:55
  • 1
    possible duplicate of [How to concatenate two mp4 videos with the help of FFMPEG and PHP code?](http://stackoverflow.com/questions/22993756/how-to-concatenate-two-mp4-videos-with-the-help-of-ffmpeg-and-php-code) – Sverri M. Olsen Apr 29 '15 at 09:55

1 Answers1

3

I wish you could combine encoded video stream with $media1.$media2 but sadly, you can't like that.

Fortunately for you, php come with a exec() function, and using that with the little ffmpeg program let you do that.

So what you have to do is to do a php exec() with ffmpeg and do the merge there.

Good luck !

Mekap
  • 2,065
  • 14
  • 26