use*_*300 8 video ffmpeg amazon-s3 transcoding
我正在使用带有node.js的fluent-ffmpeg库将最初采用flash电影格式的视频转码为具有多种分辨率,1080p等的mp3格式.一旦转码完成,我想将转码后的视频移动到s3桶.
我从源s3存储桶中提取原始的.flv文件,并将该流传递给ffmpeg构造函数.问题是在转码完成后,我如何获得要发送到s3的mp4数据流.
这是我到目前为止的代码:
var params = {
Bucket: process.env.SOURCE_BUCKET,
Key: fileName
};
s3.getObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
var format = ffmpeg(data)
.size('854x480')
.videoCodec('libx264')
.format('flv')
.toFormat('mp4');
.on('end', function () {
//Ideally, I would like to do the uploading here
var params = {
Body: //{This is my confusion, how do I get the stream to add here?},
Bucket: process.env.TRANSCODED_BUCKET,
Key: fileName
};
s3.putObject(params, function (err, data) {
});
})
.on('error', function (err) {
console.log('an error happened: ' + err.message);
});
});
Run Code Online (Sandbox Code Playgroud)
对于上面的代码,我在哪里可以将转码流添加到params对象的"Body"属性中?
更新:
以下是我要做的修改:
var outputStream: MemoryStream = new MemoryStream();
var proc = ffmpeg(currentStream)
.size('1920x1080')
.videoCodec('libx264')
.format('avi')
.toFormat('mp4')
.output(outputStream)
// setup event handlers
.on('end', function () {
uploadFile(outputStream, "").then(function(){
resolve();
})
})
.on('error', function (err) {
console.log('an error happened: ' + err.message);
});
Run Code Online (Sandbox Code Playgroud)
我想避免将文件从s3复制到本地文件系统,而是我希望在内存中处理该文件并在完成时上传回s3.fluent-ffmpeg会允许这种情况吗?
您似乎没有在任何地方保存转码的输出。
.flv使用output本地文件系统保存转码输出(您的新文件)。将新文件的内容提供给putObject. 根据该putObject文件,该Body参数接受:
Body— (Buffer,Typed Array,Blob,String,ReadableStream) 对象数据。
这是一些修改后的示例代码:
// Generate a filename for the `.flv` version
var flvFileName = fileName.substring(0, fileName.length - path.extname(fileName).length) + '.flv';
// Perform transcoding, save new video to new file name
var format = ffmpeg(data)
.size('854x480')
.videoCodec('libx264')
.format('flv')
.toFormat('mp4');
.output(flvFileName)
.on('end', function () {
// Provide `ReadableStream` of new video as `Body` for `pubObject`
var params = {
Body: fs.createReadStream(flvFileName)
Bucket: process.env.TRANSCODED_BUCKET,
Key: flvFileName
};
s3.putObject(params, function (err, data) {
});
})
Run Code Online (Sandbox Code Playgroud)
注意:fluent-ffmpeg如果您愿意,您可以从AWS S3创建输出流并将该流上传到 AWS S3,但这会使逻辑和错误处理复杂化。
| 归档时间: |
|
| 查看次数: |
2877 次 |
| 最近记录: |