2017-10-10 53 views
6

मैं मूल रूप से कई प्रस्तावों, 1080p, आदि .. के साथ एमपी 3 प्रारूप करने के लिए एक फ्लैश फिल्म प्रारूप में वीडियो ट्रांसकोड एक बार ट्रांसकोडिंग पूरा हो गया है Node.js साथ धाराप्रवाह-ffmpeg पुस्तकालय का उपयोग कर रहा है, मैं ट्रांसकोड किए गए वीडियो को एस 3 बाल्टी में ले जाना चाहता हूं।अपलोड FFmpeg उत्पादन सीधे अमेज़न S3

मैं एक स्रोत S3 बाल्टी से मूल .flv फ़ाइल खींच और ffmpeg निर्माता कार्य करने के लिए धारा गुजरती हैं। ट्रांसकोडिंग पूर्ण होने के बाद समस्या यह है कि मैं एस 3 को भेजने के लिए एमपी 4 डेटा की धारा कैसे प्राप्त करूं। जहाँ मैं ट्रांसकोड धारा पैरामीटर वस्तु की "द बॉडी" संपत्ति में जोड़ने के लिए प्राप्त कर सकते हैं,

 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); 
      }); 

     }); 

ऊपर कोड के लिए:

यहाँ कोड मैं अब तक किया है?

अद्यतन:

यहाँ मैं क्या करना है कोशिश कर रहा हूँ के एक संशोधन है:

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 पर वापस अपलोड करें। क्या फ्लेंट-एफएमपीपीजी इस परिदृश्य को अनुमति देगा?

उत्तर

2

आप कहीं भी ट्रांसकोडिंग के उत्पादन में बचत होने के लिए नहीं है।

  1. सहेजें ट्रांसकोडिंग (अपने नए .flv फ़ाइल) अपने स्थानीय फाइल सिस्टम के लिए output का उपयोग करने का उत्पादन।
  2. putObject के लिए अपने नए फ़ाइल की सामग्री प्रदान करें। the putObject documentation के अनुसार, 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) { 

     }); 
    }) 

ध्यान दें: आप यदि आप चाहें, fluent-ffmpeg से एक आउटपुट स्ट्रीम बनाने और एडब्ल्यूएस S3 है कि धारा अपलोड करने में सक्षम हो सकता है, लेकिन यह होगा तर्क और त्रुटि हैंडलिंग जटिल।

+0

वहाँ एक रास्ता अस्थायी रूप से एक स्मृति बफर करने के लिए लिखने के लिए है, तो शरीर परम में बफर भेज है? – user1790300

+0

वहाँ एक रास्ता अस्थायी रूप से फाइल सिस्टम के लिए फ़ाइल लिखने के लिए होने से बचाने के है? – user1790300

संबंधित मुद्दे