Created
October 9, 2023 07:30
-
-
Save stanfea/2fd65a92d51f15492d2b71d94f8fc0eb to your computer and use it in GitHub Desktop.
Ffmpeg code to normalize 3 mp3s together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
$opener="intro.mp3"; | |
$closer="outro.mp3"; | |
$audioFile = "final.mp3"; | |
$bookSummaryFile="summary.mp3"; | |
$ffprobe = FFMpeg\FFProbe::create(); | |
$openerDuration = $ffprobe->format($opener)->get('duration'); | |
$summaryDuration = $ffprobe->format($bookSummaryFile)->get('duration'); | |
$closerDuration = $ffprobe->format($closer)->get('duration'); | |
$summaryTransition = 5; | |
$closerTransition = 4; | |
$totalDuration = $openerDuration + $summaryDuration + $closerDuration -$summaryTransition - $closerTransition; | |
$summaryDelay =round($openerDuration - $summaryTransition); | |
$closerDelay = round($summaryDuration + $openerDuration - $summaryTransition - $closerTransition); | |
$audioFile = DIR . '/mp3/merged.mp3'; | |
$filter="[1]adelay={$summaryDelay}s[b];[2]adelay={$closerDelay}s[c];[0][b][c]amix=inputs=3:dropout_transition={$totalDuration},volume=3"; | |
$dynaudnorm=",dynaudnorm=f=200:g=15"; | |
$acompressor=",acompressor=level_in=2:threshold=10^(-30/20):attack=200:release=1000:detection=0:makeup=10^(5.1/20)"; | |
exec("ffmpeg -i {$opener} -i {$bookSummaryFile} -i {$closer} -filter_complex \"{$filter}{$acompressor}\" {$audioFile}") | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment