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?

有帮助吗?

解决方案

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

其他提示

I not succeed with mp4 videos, but i succeed using two webm videos. I worked with Windows 8.1.

What I did? Steps:

  1. Install local webserver, such as, XAMPP or EasyPHP: I used EasyPHP DevServer 14.1 VC11. Available: http://www.easyphp.org/easyphp-devserver.php

  2. Go to folder "path\EasyPHP-DevServer-14.1VC11\data\localweb" and create new folder, e.g. FFMPEG_PHP

  3. 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/

  4. Copy file "ffmpeg.exe" to folder "FFMPEG_PHP"

  5. 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.

  6. 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".

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top