Home:ALL Converter>FFMpeg Merge audio and video files

FFMpeg Merge audio and video files

Ask Time:2020-05-15T19:30:59         Author:Donal.Lynch.Msc

Json Formatter

I need to Merge an audio (.mp3) and video (.mov) file and output an mp4 file using FFMpeg PHP library.

The following works:

$ffmpeg = \FFMpeg\FFMpeg::create([
    'ffmpeg.binaries'  => 'C:/ffmpeg/bin/ffmpeg.exe',
    'ffprobe.binaries' => 'C:/ffmpeg/bin/ffprobe.exe'
]);

/* Open video file */
$video = $ffmpeg->open('sample.mov');

/* Resize video */
$video
    ->filters()
    ->resize(new \FFMpeg\Coordinate\Dimension(320, 240))
    ->synchronize();

/* Take screenshot from video */
$video->frame(\FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save('screen.jpg');

However it's not quite what I need. The following command line code is exactly what I'm looking for but I can't figure out how to convert it into the same format as the above ($ffmpeg version).

exec("ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac output.mp4");

Question: Anyone know how to convert the exec into PHP above?

Thanks guys.

Author:Donal.Lynch.Msc,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/61818186/ffmpeg-merge-audio-and-video-files
flakerimi :

Can you try with full paths\n\n$cmd = 'C:\\\\ffmpeg\\\\bin\\\\ffmpeg.exe -i video.mp4 -i audio.mp3 -c:v copy -c:a aac output.mp4';\nexec($cmd, $output)\n\n\nLooks like its not implemented in PHP-FFMPEG package, you have to do it that way.\n\nhttps://github.com/PHP-FFMpeg/PHP-FFMpeg/issues/346#issuecomment-292701054",
2020-05-15T17:38:02
yy