[英]Upload screenshots to google cloud storage bucket with Fluent-ffmpeg
[英]Passing streams from Fluent-ffmpeg to Google Cloud Storage
有没有办法将 stream 从 Fluent-mmpeg 传递到 Google Cloud Storage? 我正在尝试允许用户上传任何类型的媒体(音频或视频),并且我想在将其上传到 GCS 之前将其转换为 flac。
我在路线上使用了一些中间件,例如:
routes.post(
'/upload',
multer.single('audio'),
ConvertController.convert,
UploadController.upload,
FileController.save,
(req, res, next) => res.send('ok')
);
我能够从 Multer 到 Fluent-mmpeg 的 stream 并在 ConvertController 上使用以下代码保存到文件中:
async convert(req, res, next) {
ffmpeg(streamifier.createReadStream(req.file.buffer))
.format('flac')
.output('outputfile.flac')
.audioChannels(1)
.on('progress', function(progress) {
console.log(progress);
})
.run();
}
但我想使用 .pipe() 将其传递给 UploadController,然后我将上传到 GCS:
class UploadController {
async upload(req, res, next) {
const gcsHelpers = require('../helpers/google-cloud-storage');
const { storage } = gcsHelpers;
const DEFAULT_BUCKET_NAME = 'my-bucket-name';
const bucketName = DEFAULT_BUCKET_NAME;
const bucket = storage.bucket(bucketName);
const fileName = `test.flac`;
const newFile = bucket.file(fileName);
newFile.createWriteStream({
metadata: {
contentType: file.mimetype
}
})
file.on('error', err => {
throw err;
});
file.on('finish', () => console.log('finished'));
}
问题是我找不到任何地方解释如何将 stream 传递给下一个中间件。
可能吗?
Attach your ffmpeg stream to the req
object, and then you can pass your ffmpeg stream to the next middleware using the next()
. 然后您可以将 pipe stream 到您的 GCS 文件中。
像这样的东西:
// ConvertController
req.ffpmegStream = ffmpeg(streamifier.createReadStream(req.file.buffer))
.on('finish', next)
// UploadController
req.ffmpegStream.pipe(newFile.createWriteStream())
参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.