I am working on a side project to download videos from Reddit, but they separate video and audio in different files. so i have to merge them first before downloading them in the client. i was able to do all of this as in the following snippet of code.
const ffmpeg = require("fluent-ffmpeg");
const proc = new ffmpeg();
app.post('/download', async (req, res) => {
const audio = "some aduio link";
const video = "some video link";
proc.addInput(video)
.output('${some path}./video.mp4')
.format('mp4')
.on("error", err => console.log(err))
.on('end', () => console.log('Done'));
if(audio) {
proc.addInput(audio);
}
proc.run()
});
using the above code, the video is being download locally in the the server in the specified path.
but i want to download the video in the client browser who sent the request. i tried:
proc.pipe(res);
but it didn't work, it's my first time working with ffmpeg, so it would be nice if someone give me a hint
add writeToStream(res, { end: true });
atn the end to stream
const ffmpeg = require("fluent-ffmpeg");
const proc = new ffmpeg();
app.post('/download', async (req, res) => {
const audio = "some aduio link";
const video = "some video link";
ffmpeg(video).format('mp4')
.on("error", err => console.log(err))
.on('end', () => console.log('Done')).writeToStream(res, { end: true });
});
` i hope it works
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.