mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
faee605f12
Added mocha based unit tests for each module Did a bit of cleanup in the modules to remove debug console.log calls Removed the Progress bar in the extractor and the library requirement Promisified the gemini module to make sure it returns the path as a promise instead of just on the cli Fixed gitignore so that it now only ignores the content int the storage directories, and not the whole directories Added neetingReport.json for the LLMs to use
74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
// Ensure ffmpeg binary is available
|
|
if (!ffmpegPath) {
|
|
throw new Error('FFmpeg binary not found!');
|
|
}
|
|
ffmpeg.setFfmpegPath(ffmpegPath);
|
|
|
|
// Prepare output directory (always storage/audio under project root)
|
|
const outputDir = `${__dirname}/../../../storage/audio`;
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
name:"extraction-video-to-audio", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()"
|
|
type:"extractor", // value used to differentiate each module to order them in the UI
|
|
displayname:"Default extractor", // The displayname used within the UI
|
|
async function(parameter){
|
|
/*
|
|
parameter structure:
|
|
{
|
|
inputVideoPath: String, // Path to the file
|
|
outputType: String // Audio file output format
|
|
}
|
|
*/
|
|
try {
|
|
return new Promise((resolve, reject) => {
|
|
this.extractAudioFromVideo(parameter.inputVideoPath, parameter.outputType)
|
|
.then((resp) => resolve(resp))
|
|
.catch((err) => {reject(err)});
|
|
})
|
|
} catch (error) {
|
|
console.log(parameter.outputType);
|
|
|
|
}
|
|
|
|
},
|
|
// Derive input and output paths
|
|
// const inputVideoPath = process.argv[2];
|
|
// console.log(process.argv);
|
|
|
|
/**
|
|
* Extracts audio from a video using ffmpeg.
|
|
* - Converts video to WAV (16 kHz, Mono, PCM optional if needed)
|
|
* - Shows CLI progress bar
|
|
* - Handles errors gracefully (without errors)
|
|
*/
|
|
extractAudioFromVideo: async function (videoFilePath, outputType){
|
|
let inputVideoName = path.basename(videoFilePath, path.extname(videoFilePath));
|
|
let outputAudioPath = path.join(outputDir, `${inputVideoName}.${outputType}`);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
try {
|
|
ffmpeg(videoFilePath)
|
|
.outputFormat(outputType)
|
|
// .audioCodec('pcm_s16le')
|
|
.audioChannels(1)
|
|
.audioFrequency(16000)
|
|
.on('end', () => {
|
|
resolve(outputAudioPath);
|
|
})
|
|
.on('error', (err) => {
|
|
// console.error(`failed_audio_extraction on type ${outputType}: ${err.message}`);
|
|
reject(err);
|
|
})
|
|
.save(outputAudioPath);
|
|
|
|
} catch (error) {
|
|
// console.log(error);
|
|
}
|
|
});
|
|
}
|
|
} |