我使用帶有node.js的fluent-ffmpeg庫將原本以Flash電影格式的視頻轉碼爲具有多種分辨率,1080p的mp3格式。一旦轉碼完成後,我想將轉碼後的視頻轉移到s3存儲區。將FFmpeg輸出直接上傳到亞馬遜S3
我從源s3存儲桶中取出原始.flv文件,並將該流傳遞給ffmpeg構造函數。問題是轉碼完成後,我如何才能獲得mp4數據流發送到s3。
這裏是我到目前爲止的代碼:
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);
});
});
對於上面的代碼,我在哪裏可以得到的編碼數據流添加到params對象的「身體」屬性?
更新:
這裏是什麼,我試圖做一個修訂:
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);
});
我想避免複製文件從S3本地文件系統,而我更願意處理該文件在內存中,並在完成時上傳回s3。 fluent-ffmpeg會允許這種情況嗎?
有沒有辦法暫時寫入內存緩衝區,然後在正文參數中發送緩衝區? – user1790300
有沒有辦法避免必須臨時將文件寫入文件系統? – user1790300