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_d.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
CodePudding user response:
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(function (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)
}
});
});
});