fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.85k stars 874 forks source link

Take url as input #1278

Open Lukkyz opened 3 months ago

Lukkyz commented 3 months ago

Hello, I would like to know if it is possible now to take an URL as an input ?

ralyodio commented 1 month ago

I'm also wondering this. the example I have doesn't work

async start(url, user = null, pass = null) {
            console.log('Transcoding:', url);
            const headers = {};

            try {
                if (user && pass) {
                    const encodedCredentials = Buffer.from(`${user}:${pass}`).toString('base64');
                    headers['Authorization'] = `Basic ${encodedCredentials}`;
                }

                // Fetch the video from the URL
                const response = await fetch(url, { headers, redirect: 'follow' });

                if (!response.ok) {
                    throw new Error(`Failed to fetch video: ${response.statusText}`);
                }

                // Create a readable stream from the response
                const videoStream = response.body;

                // Create a pass-through stream to handle ffmpeg output
                const stream = new PassThrough();

                // Pipe the video stream through ffmpeg to transcode it to mp4
                ffmpeg(videoStream)
                    .format('mp4')
                    .videoCodec('libx264')
                    .audioCodec('aac')
                    .on('error', (err) => {
                        console.error('Error:', err.message);
                        stream.destroy(err); // destroy the stream in case of error
                    })
                    .on('end', () => {
                        console.log('Transcoding finished');
                    })
                    .pipe(stream, { end: true }); // ensure the stream ends properly

                return stream;
            } catch (err) {
                throw err;
            }
        }
ralyodio commented 1 month ago

I guess ffmpeg doesn't support Response objects