Added video transcription
All checks were successful
Push image to registry / build-image (push) Successful in 5m59s

This commit is contained in:
2025-07-04 12:36:03 +02:00
parent a00c5ba4b8
commit f0e52147e4
8 changed files with 321 additions and 41 deletions

View File

@ -56,4 +56,33 @@ abstract class AbstractLLMVideoDescriptor implements IVideoDescriptor
}
return $array;
}
/**
* Extract audio from the video file.
* Using ffmpeg to extract audio from the video file.
* The audio will be saved in a temporary directory as an MP3 file.
* If the audio extraction fails, it will return null.
* @param string $filePath
* @return string|null
*/
protected function extractAudioFromVideo(string $filePath): ?string
{
$tempDir = sys_get_temp_dir() . '/video_audio';
if (!is_dir($tempDir)) {
mkdir($tempDir, 0777, true);
}
else {
// Clear the directory if it already exists
array_map('unlink', glob($tempDir . '/*'));
}
$outputFile = $tempDir . '/audio.mp3';
$command = "ffmpeg -i " . escapeshellarg($filePath) . " " . escapeshellarg($outputFile);
exec($command);
if (file_exists($outputFile)) {
return $outputFile;
}
return null;
}
}