Upload FFmpeg output directly to Amazon S3

一世执手 提交于 2019-12-04 03:46:34

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!