Node-fluent-ffmpeg: How to zip a converted mp3 file

Created on 31 Jul 2018  路  1Comment  路  Source: fluent-ffmpeg/node-fluent-ffmpeg

Version information

  • fluent-ffmpeg version: 2.1.2
  • ffmpeg version: 1.0.15
  • OS: macOS

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();

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.

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();
        });
    }
}

>All comments

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();
        });
    }
}
Was this page helpful?
0 / 5 - 0 ratings