When I make the next upload, if the duration of the clip is very short it generates a corrupt file and if it is a little longer, for example 19 seconds, it generates a file that starts from second 8
const passThroughStream = new PassThrough();
const response = await new Promise((resolve, reject) => {
const command = ffmpeg()
.input(`${import.meta.env.BUCKET_URL}${m3u8S3}`)
.inputOptions([`-ss ${TIME_OFFSET}`])
.outputOptions([`-t ${end - start}`, '-c:v libvpx', '-c:a libvorbis', '-f webm'])
.on('start', (commandLine) => {
console.log('Spawned FFmpeg with command:', commandLine);
})
.on('error', (err, stdout, stderr) => {
console.error('FFmpeg error:', err);
console.error('FFmpeg stderr:', stderr);
reject(err);
})
// Collect data into buffers
const buffers = [];
command.pipe(passThroughStream);
passThroughStream.on('data', (chunk) => {
buffers.push(chunk);
});
passThroughStream.on('end', async () => {
try {
const clipKey = `clip_${uuidv4()}.webm`;
const buffer = Buffer.concat(buffers);
const uploadParams = {
Bucket: import.meta.env.BUCKET_NAME,
Key: clipKey,
Body: buffer,
ContentType: 'video/webm',
};
await S3.send(new PutObjectCommand(uploadParams));
resolve(new Response({ status: 200 }));
} catch (error) {
reject(error);
}
});
});
I hope to be able to create clips of maximum 1 minute from the hls transmission