VideoStitch
VideoStitch copied to clipboard
Does this work on Ubuntu?
trying to get this to work on ubuntu and it's not outputting anything, even though it works on my windows machine. ffmpeg was installed on the ubuntu machine using sudo apt install ffmpeg
const fetchMultiStream = async (req, res) => {
console.log("multistream requested")
try {
const recordingId = req.params.id;
let container;
let ids
let count = 0;
let fullId;
try {
container = await Recordings.findById(recordingId);
} catch (error) {
return res.status(500).json({
message:
"getting file Ids failed, please make sure you have the correct recordingsId.",
});
}
try {
fullId = container.full
if (!fullId) {
ids = container.parts.map((record) => mongoose.Types.ObjectId(record.id));
gfs.find({ '_id': { $in: ids } }).toArray((err, files) => {
let clips = new Array(files.length);
if (!files[0] || files.length === 0) {
return res.status(200).json({
success: false,
message: "No files available",
});
}
files.forEach((file, i) => {
if (file && (file.contentType === 'video/mkv' || file.contentType === 'video/webm')) {
gfs.openDownloadStream(file._id)
.pipe(fs.createWriteStream(`./${file._id}.mkv`))
.on('error', () => {
console.log("Some error occurred in download:" + error);
res.send(error);
})
.on('finish', () => {
hbjs.spawn({ input: `${file._id}.mkv`, output: `${file._id}.mp4` })
.on('error', err => {
// invalid user input, no video found etc
})
.on('end', () => {
fs.unlink(`${file._id}.mkv`, () => { fileDeleted(`${file._id}.mkv`) })
clips[i] = { "fileName": `${path.resolve(`./${`./${file._id}.mp4`}`)}` }
console.log(`file ${i} writen`);
count++;
if (count === files.length) {
//HERE
let videoConcat = videoStitch.concat;
videoConcat({
silent: false, // optional. if set to false, gives detailed output on console
overwrite: true // optional. by default, if file already exists, ffmpeg will ask for overwriting in console and that pause the process. if set to true, it will force overwriting. if set to false it will prevent overwriting.
})
.clips([...clips])
.output(`000fullvid${Date.now()}.mp4`) //optional absolute file name for output file
.concat()
.then((outputFileName) => {
clips.forEach((clip) => {
fs.unlink(clip.fileName, () => { fileDeleted(clip.fileName) })
})
// res.on('finish', function () {
// console.log('the response has been sent');
// fs.unlink(outputFileName, () => { fileDeleted(outputFileName) })
// });
let write = fs.createReadStream(outputFileName)
let uploadStream = gfs.openUploadStream(outputFileName, { contentType: 'video/mp4' })
fullId = uploadStream.id;
uploadStream.once('finish', async () => {
fs.unlink(outputFileName, () => { fileDeleted(outputFileName) })
await Recordings.findByIdAndUpdate(
{ _id: recordingId },
{
$set: {
full: fullId,
},
}
)
console.log(uploadStream.id)
res.status(200).json({
success: true,
vidId:uploadStream.id
})
})
write.pipe(uploadStream);
});
}
})
});
}
});
});
}
else {
console.log(fullId)
res.status(200).json({
success: true,
vidId: fullId
});
}
} catch (error) {
console.log("error 1 "+error)
}
} catch (error) {
console.log("error 2 "+error)
}
}