Я пытался объединить видео о функциях Firebase, используя FFmpeg.Однако я не смог этого сделать из-за ошибки ниже.
Я ожидаю, что видео будут успешно объединены.
Во-первых, поскольку у меня не было каталога, поэтому я попыталсячтобы сделать это используя mkdirp-promise
.Но это не внесло никаких изменений;У меня была та же ошибка, что и раньше.
Error: ENOENT: no such file or directory, stat '/tmp/combined.mp4'
Вот коды.
const combineVideos = async (tempFilePath, firstFilePath, secondFilePath,targetTempFilePath) =>{
ffmpeg(tempFilePath)
.setFfmpegPath(ffmpeg_static.path)
.addInput(firstFilePath)
.addInput(secondFilePath)
.on('end', function() {
console.log('files have been merged succesfully');
})
.on('error', function(err) {
console.log('an error happened: ' + err.message);
})
.mergeToFile(targetTempFilePath)
}
exports.editVids = functions.storage.object().onFinalize(async (object) => {
await (async () => {
const fileBucket = object.bucket; // The Storage bucket that contains the file.
const filePath = object.name; // File path in the bucket.
// Get the file name.
const fileName = path.basename(filePath);
// Exit if the audio is already converted.
if(fileName==='last.mp4'){
// Download file from bucket.
const bucket = gcs.bucket(fileBucket);
const tempFilePath = path.join(os.tmpdir(), fileName);
const firstFilePath = path.join(os.tmpdir(), 'first.mp4');
const secondFilePath = path.join(os.tmpdir(), 'second.mp4');
// We add a '_output.flac' suffix to target audio file name. That's where we'll upload the converted audio.
const targetTempFileName = 'combined.mp4'
const targetTempFilePath = path.join(os.tmpdir(), targetTempFileName);
const targetStorageFilePath = path.join(path.dirname(filePath), targetTempFileName);
await mkdirp(path.dirname(tempFilePath))
await bucket.file(filePath).download({destination: tempFilePath});
await bucket.file(filePath.replace('last.mp4','first.mp4')).download({destination: firstFilePath});
await bucket.file(filePath.replace('last.mp4','second.mp4')).download({destination: secondFilePath});
console.log('Video downloaded locally to', firstFilePath);
console.log('Video downloaded locally to', secondFilePath);
console.log('Video downloaded locally to', tempFilePath);
// Convert the audio to mono channel using FFMPEG.
await combineVideos(tempFilePath, firstFilePath, secondFilePath, targetTempFilePath)
console.log('Output video created at', targetTempFilePath);
// Uploading the audio.
await bucket.upload(targetTempFilePath, {destination: targetStorageFilePath});
console.log('Output video uploaded to', targetStorageFilePath);
// Once the audio has been uploaded delete the local file to free up disk space.
fs.unlinkSync(tempFilePath);
fs.unlinkSync(firstFilePath);
fs.unlinkSync(secondFilePath);
fs.unlinkSync(targetTempFilePath);
return console.log('Temporary files removed.', targetTempFilePath);
}
})();
});