Open Orrison opened 2 years ago
me here too.
me here too.
I got around this by finding out whether or not there were image streams in the item and stripping them:
$originalFilePath = $this->media->getPath();
$directory = pathinfo($originalFilePath, PATHINFO_DIRNAME) . '/conversions/';
$saveToFilePath = $directory . pathinfo($originalFilePath, PATHINFO_FILENAME) . '.m3u8';
$openedFile = FFMpeg::fromDisk('s3')
->open($originalFilePath);
$coverArtStreams = collect($openedFile->getStreams())->filter(function (Stream $stream) {
return $stream->isVideo() && in_array($stream->get('codec_name'), ['png', 'jpeg', 'mjpeg']);
});
// If there are cover art streams, we need to strip them out
if ($coverArtStreams->isNotEmpty()) {
$audioOnlyFilePath = $directory . pathinfo($originalFilePath, PATHINFO_FILENAME) . '-audio-only.mp3';
$audioOnlyFile = $this->convertToAudioOnly(
$openedFile,
$audioOnlyFilePath
);
$this->convertToHls($audioOnlyFile, $audioOnlyFilePath, $saveToFilePath);
Storage::disk('s3')->delete($audioOnlyFilePath);
return $saveToFilePath;
}
$this->convertToHls($openedFile, $originalFilePath, $saveToFilePath);
return $saveToFilePath;
protected function convertToAudioOnly(MediaOpener $openedFile, string $directory): MediaOpener
{
Log::info('Cover art stream found, stripping it to prevent encoding errors', [
'media_id' => $this->media->id,
]);
return $openedFile
->addFilter(['-vn'])
->export()
->toDisk('s3')
->inFormat(new Mp3())
->save($directory);
}
any update on this ?, can we add a helper method in the package for this ?
I am running a process using this package to convert uploaded audio files to an HLS format. It is working great for the vast majority of media. But it seems that it errors out for some audio files. It seems this happens when the audio file has cover artwork within it.
Is there a way to ignore the cover artwork during the conversion?