简体   繁体   中英

How can we upload m3u8 file and corresponding ts file to amazon s3 bucket using node.js

I am trying to upload the generated m3u8 file and corresponding ts file to s3 bucket but problem is how can i upload all.ts file also along with m3u8.

my ffmpeg code is

const ffmpeg = require('fluent-ffmpeg')
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg')


ffmpeg.setFfmpegPath(ffmpegInstaller.path)

ffmpeg('uploads/malayalam.mp4').addOptions([

'-c:a',
  'aac',
  '-ar',
  '48000',
  '-b:a',
  '128k',
  '-c:v',
  'h264',
  '-profile:v',
  'main',
  '-crf',
  '20',
  '-g',
  '48',
  '-keyint_min',
  '48',
  '-sc_threshold',
  '0',
  '-b:v',
  '2500k',
  '-maxrate',
  '2675k',
  '-bufsize',
  '3750k',
  '-hls_time',
  '4',
  '-hls_playlist_type',
  'vod',
  '-hls_segment_filename',
  'uploads/video/720p_%03d.ts'

]).output('uploads/video/output.m3u8').on('end',(err,data)=>{
  console.log(data)
  console.log('end')
}).run()

generated m3u8 file directory look like

在此处输入图像描述

i used this code to upload m3u8 file

const aws = require('aws-sdk')

  const s3 = new aws.S3({
    accessKeyId:"secretid",
    secretAccessKey:"accesskey"
  })

  const fileContent = fs.readFileSync("uploads/video/output.m3u8");


  const params = {
    Body: fileContent,
    Bucket:"5am5pm",
    Key:"output.m3u8"
  }

  s3.upload(params,(err,data)=>{
    if(err){
      console.log(err)
    }else{
      console.log(data)
    }
  })

But it uploading only the m3u8 file how can i upload.ts file too. if someone help it is very thankfull

As others have suggested, just loop over the files and upload individually:

fs.readdir('uploads/video', (err, files) => {
    if (err) {
        return console.log('Failed to list directory: ' + err);
    } 

    files.forEach(file => {
        const params = {
            Body: fs.createReadStream('uploads/video/' + file);,
            Bucket:"5am5pm",
            Key: file
        }

        s3.upload(params, (err, data) => {
            if (err) {
                console.log(err)
            } else {
                console.log(data)
            }
        });
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM