1 | initial version |
To use Laravel FFMpeg to change an mp3 file into an mp4 file, follow the steps below:
composer require pbmedia/laravel-ffmpeg
'Aliases' => [
// other aliases
'FFMpeg' => 'ProtoneMedia\LaravelFFMpeg\Support\FFMpegFacade'
]
use FFMpeg;
//input mp3 file path
$inputPath = '/path/to/input/file.mp3';
//output mp4 file path
$outputPath = '/path/to/output/file.mp4';
//initialize FFMpeg
$ffmpeg = FFMpeg::create();
//open the input file
$audio = $ffmpeg->open($inputPath);
//convert it to video
$format = new \FFMpeg\Format\Video\X264();
$format->setAudioCodec("libmp3lame");
$video = $ffmpeg->getFFMpegDriver()->pipe($audio, $format);
//save to output file
file_put_contents($outputPath, $video);
Note: Changing an audio file to a video file doesn't add any video to the file. The resulting video will be a still image with the audio playing.