Could anybody help me with the php code for FFMPEG to concatenate two mp4 videos and store the concatenated files as an mp4 at any folder in the server?
问题:
回答1:
For the FFMPEG part see here: Concatenate two mp4 files using ffmpeg
For the PHP part, you can invoke any command using: http://php.net/function.exec
回答2:
I not succeed with mp4 videos, but i succeed using two webm videos. I worked with Windows 8.1.
What I did? Steps:
Install local webserver, such as, XAMPP or EasyPHP: I used EasyPHP DevServer 14.1 VC11. Available: http://www.easyphp.org/easyphp-devserver.php
Go to folder "path\EasyPHP-DevServer-14.1VC11\data\localweb" and create new folder, e.g. FFMPEG_PHP
Download FFMPEG for Windows: download 32-bit Downloads or 64-bit Downloads version Static. I used "Download FFMPEG git-013498b" 32-bit Static. Available: http://ffmpeg.zeranoe.com/builds/
Copy file "ffmpeg.exe" to folder "FFMPEG_PHP"
Store 2 or more webm videos in folder "FFMPEG_PHP". I download videos from youtube. See 1:48 minute this video how download videos from youtube:
www.youtube.com/watch?v=FZJqdwfxSWU.
Create "joinVideos.php" in "FFMPEG_PHP"
See code I did in "join Videos.php" below:
<?php
$joinVideosTXT="joinVideos.txt";
$joinVideos=fopen($joinVideosTXT,"w+");
//Writes "joinVideos.txt"
$video="nameVideo1";
$video2="nameVideo2";
$pathVideo=$video.".webm";
$pathVideo2=$video2.".webm";
$strVideo="file '".$pathVideo."'"."\r\n";
$strVideo2="file '".$pathVideo2."'"."\r\n";
fwrite($joinVideos, $strVideo);
fwrite($joinVideos, $strVideo2);
fclose($joinVideos);
$ffmpeg="ffmpeg.exe";
$videoFinal="videoFinal.webm";
unlink($videoFinal);//remove previous $videoFinal
$cmd="$ffmpeg -f concat -i " .$joinVideosTXT." -c copy ".$videoFinal;
system($cmd);
?>
<video controls="controls">
<source src="videoFinal.webm" type="video/webm">
</video>
</body>
IMPORTANT: when you run first time "joinVideos.php", you MUST comment line "unlink($videoFinal);//remove previous $videoFinal".