I am sorry if this is not correct place to ask. I am trying to zip a audio file in fly when I convert it from mp4 file, but I do not come up with any solution. Can someone please help me? Thank you
const stream = youtubedl(url);
const videoTitle = await youtube.getVideoTitle(url);
const converter = new ffmpeg({ source: stream });
const zip = archiver('zip');
converter.toFormat(toFormat).on('end', () => console.log('end'));
// This does not work since converter.toFormat(toFormat) is not a stream or buffer
zip.append(converter.toFormat(toFormat), {
name: `${videoTitle}.${toFormat}`
});
zip.finalize();
Here is a TypeScript example which gets a video stream and creates a stream with the screenshot:
This way you could also extract the audio to a stream and zip it.
import * as streams from "memory-streams"; // you also need this library
import * as ffmpeg from "fluent-ffmpeg";
export class Test
{
public async screenshotStream(readStream): Promise<streams.WritableStream>
{
return new Promise<streams.WritableStream>((resolve, reject) => {
let stream = new streams.WritableStream({highWaterMark: 51200});
ffmpeg(readStream, {priority: 20})
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
resolve(null);
})
.on('end', function() {
resolve(stream);
})
.outputOptions(['-f image2', '-vframes 1'])
.output(stream)
.run();
});
}
}
Most helpful comment
Here is a TypeScript example which gets a video stream and creates a stream with the screenshot:
This way you could also extract the audio to a stream and zip it.