Skip to content

Commit

Permalink
#766 Правка конвертации медиа файла.
Browse files Browse the repository at this point in the history
  • Loading branch information
boffart committed Aug 14, 2024
1 parent edece82 commit fe8e353
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/PBXCoreREST/Lib/System/ConvertAudioFileAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function main(string $filename): PBXApiResult
{
$res = new PBXApiResult();
$res->processor = __METHOD__;
$res->success = true;
if (!file_exists($filename)) {
$res->success = false;
$res->messages[] = "File '$filename' not found.";
Expand All @@ -60,16 +61,23 @@ public static function main(string $filename): PBXApiResult

// Convert file to wav format
$tmp_filename = escapeshellcmd($tmp_filename);
$n_filename = escapeshellcmd($n_filename);
$soxPath = Util::which('sox');

// Предварительная конвертация в wav.
Processes::mwExec("$soxPath -v 0.99 -G '$n_filename' -c 1 -r 8000 -b 16 '$n_filename'", $out);
$soxIPath = Util::which('soxi');
$busyBoxPath = Util::which('busybox');
// Pre-conversion to wav step 1.
if(Processes::mwExec("$soxIPath $tmp_filename | $busyBoxPath grep MPEG") === 0){
Processes::mwExec("$soxPath $tmp_filename $tmp_filename.wav", $out);
unlink($tmp_filename);
$tmp_filename = "$tmp_filename.wav";
}
$n_filename = escapeshellcmd($n_filename);
// Pre-conversion to wav step 2.
Processes::mwExec("$soxPath -v 0.99 -G '$tmp_filename' -c 1 -r 8000 -b 16 '$n_filename'", $out);
$result_str = implode('', $out);

// Convert wav file to mp3 format
$lamePath = Util::which('lame');
Processes::mwExec("$lamePath -b 32 --silent '$n_filename' '$n_filename_mp3'", $out);
Processes::mwExec("$lamePath -b 16 --silent '$n_filename' '$n_filename_mp3'", $out);
$result_mp3 = implode('', $out);

// Convert the file to various codecs using Asterisk
Expand All @@ -79,7 +87,7 @@ public static function main(string $filename): PBXApiResult
foreach ($codecs as $codec){
$result = shell_exec("$asteriskPath -rx 'file convert $tmp_filename $trimmedFileName.$codec'");
if(strpos($result, 'Converted') !== 0){
shell_exec("$rmPath -rf /root/test.$codec");
shell_exec("$rmPath -rf $trimmedFileName.$codec");
}
}

Expand Down

0 comments on commit fe8e353

Please sign in to comment.