Upload FFmpeg output directly to Amazon S3

后端 未结 1 548
清歌不尽
清歌不尽 2021-02-20 00:41

I am using the fluent-ffmpeg library with node.js to transcode videos originally in a flash movie format to the mp3 format with multiple resolutions, 1080p, etc.. Once the tran

相关标签:
1条回答
  • 2021-02-20 01:16

    You don't seem to be saving the output of the transcoding anywhere.

    1. Save the output of the transcoding (your new .flv file) using output to your local filesystem.
    2. Provide your new file's contents to putObject. According to the putObject documentation, the Body parameter accepts:

      Body — (Buffer, Typed Array, Blob, String, ReadableStream) Object data.

    Here's some revised sample code:

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

    Note: You may be able to create an output stream from fluent-ffmpeg and upload that stream to AWS S3, if you prefer, but this will complicate the logic and error handling.

    0 讨论(0)
提交回复
热议问题