I'm having an issue in my Laravel queue jobs which converts sounds from multiple formats into mp3. Most audio formats works well, while mp4 sounds uploaded from iOS devices only produce a 1 second long audio stream on conversion.
All sounds are both fetched and uploaded to a s3-like storage, which might be a part in the issue.
I have tried to reproduce the issue by only using ffmpeg directly to no avail.
Is this an issue that has been observed before, or am I doing something wrong?
This is basically the code I use to convert files:
<?php
namespace App\Services;
use App\Services\Contracts\AudioServiceInterface;
use FFMpeg\Format\Audio\Mp3;
use Illuminate\Filesystem\FilesystemManager;
use ProtoneMedia\LaravelFFMpeg\Exporters\EncodingException;
use Psr\Log\LoggerInterface;
use ProtoneMedia\LaravelFFMpeg\Support\FFMpeg;
class FFMpegService implements AudioServiceInterface {
protected FilesystemManager $filesystem;
private LoggerInterface $logger;
public function __construct(LoggerInterface $logger, FilesystemManager $filesystem) {
$this->logger = $logger;
$this->filesystem = $filesystem;
}
public function convert(string $fromPath, string $toPath): bool {
try {
// Default disk is a s3-like storage.
FFMpeg::fromFilesystem($this->filesystem->disk())
->open($fromPath)
->export()
->toDisk($this->filesystem->disk())
->inFormat(new Mp3())
->save($toPath);
$this->logger->debug('Audio converted', [
'from' => $fromPath,
'to' => $toPath
]);
FFMpeg::cleanupTemporaryFiles();
} catch (EncodingException $exception) {
$this->logger->error('Audio failed to convert', [
'from' => $fromPath,
'to' => $toPath,
'command' => $exception->getCommand(),
'error' => $exception->getErrorOutput(),
]);
throw $exception;
}
return true;
}
}
There are no exceptions and the logs says that everything went fine, but the mp3 files are 1 second long, every time.
Hi!
I'm having an issue in my Laravel queue jobs which converts sounds from multiple formats into mp3. Most audio formats works well, while mp4 sounds uploaded from iOS devices only produce a 1 second long audio stream on conversion.
All sounds are both fetched and uploaded to a s3-like storage, which might be a part in the issue.
I have tried to reproduce the issue by only using ffmpeg directly to no avail.
Is this an issue that has been observed before, or am I doing something wrong?
This is basically the code I use to convert files:
There are no exceptions and the logs says that everything went fine, but the mp3 files are 1 second long, every time.
Runtime:
PHP 8.1 Ubuntu 20.04.3 Laravel 9.18 pbmedia/laravel-ffmpeg 8.1.2
FFMPEG output: