Code: Select all
function convert_audio($source, $format, $ffmpeg, $bitrate, $channel, $freq) {
$cmd = "-acodec libmp3lame -ab $bitrate -ac $channel -ar $freq";
$org = $source;
$wrong = array("å", "ä", "ö", "Å", "Ä", "Ö", "!", " ");
$right = array("a", "a", "o", "A", "A", "O", "_", "_");
$new = str_replace($wrong, $right, $org);
exec("$ffmpeg -i $new $cmd {$new}.$format");
if (file_exists("{$new}.$format")) {
return array('audio' => "{$new}.$format");
} else {
return false;
}
}
///// SKICKA/LADDA UPP /////
if (isset($_POST['submit'])) {
$audio = $_FILES['audio']['name'];
$wrong = array("å", "ä", "ö", "Å", "Ä", "Ö", "!", " ");
$right = array("a", "a", "o", "A", "A", "O", "_", "_");
$new = str_replace($wrong, $right, $audio);
$path = "ljud/$new";
if(move_uploaded_file($_FILES['audio']['tmp_name'], $path)){
$type = "mp3"; // format att konvertera till
$ffmpeg = "ffmpeg"; // Sökväg till mappen där ffmpeg ligger
$b = "128k"; // Kvalite på ljudet: 96 kb/s
$c = "1"; // Kanaler (1=mono, 2=stereo)
$f = "16000"; // Sample rate
$convert = convert_audio($path, $type, $ffmpeg, $b, $c, $f);
// Lyckades konverteringen?
if ($convert) {
$msg = "<b>Ljudfilen ( ". basename($convert['audio']) ." ) konverterades utan problem!</b><br />
Bitrate: $b | Kanaler: $c | Sample rate: $f<br /><br />";
} else {
$msg = "Något gick fel!";
}
}
echo $msg;
}
///////////////////////////Now i want to convert/encode 2 .mp3-files (of the same file), during upload.
One with low bitrate (demo/exampel), and another with high bitrate.