Friday, 6 July 2018

How to convert mp4 to mp3 and wav using PHP FFMPEG

How to convert mp4 to mp3 and wav using PHP FFMPEG


Question: Download the php-ffmpeg library (If not downloaded)?
composer require php-ffmpeg/php-ffmpeg


Question: How to convert Mp4 to wav using php-ffmpeg?
require_once 'ffmpeglib/vendor/autoload.php'; 
$ffmpeg = FFMpeg\FFMpeg::create();
$format = new FFMpeg\Format\Audio\Wav();        
$videoFolderPath='folder';

$audioObj = $ffmpeg->open($videoFolderPath.'/myfile.mp4');    
$audioObj->save($format, $videoFolderPath.'/myfile.wav');




Question: How to convert Mp4 to mp3 using php-ffmpeg?
require_once 'ffmpeglib/vendor/autoload.php'; 
$ffmpeg = FFMpeg\FFMpeg::create();
$mp3Format = new FFMpeg\Format\Audio\Mp3(); 
$videoFolderPath='folder';


$audioObj = $ffmpeg->open($videoFolderPath.'/myfile.mp4');    
$audioObj->save($mp3Format, $videoFolderPath.'/myfile.mp3');