Added video transcription
All checks were successful
Push image to registry / build-image (push) Successful in 5m59s
All checks were successful
Push image to registry / build-image (push) Successful in 5m59s
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user