How to stream video in Nextjs 14 api route
MasterProvider opened this issue · 2 comments
MasterProvider commented
Version information
- fluent-ffmpeg version:2.1.2
- ffmpeg version:2023-11-20-git-e56d91f8a8-essentials_build-www.gyan.dev
- OS: Windows 11
Code to reproduce
import fs from 'fs';
import ffmpeg from 'fluent-ffmpeg';
export async function GET(request, { params }) {
try{
const media_url = 'public/mario.mp4';
var command = ffmpeg(media_url)
.videoCodec('libx264')
.audioCodec('libmp3lame')
.size('320x240')
var ffstream = command.stream(); // how to return the stream output
ffstream.on('data', function(chunk) {
console.log('ffmpeg just wrote ' + chunk.length + ' bytes');
});
return new Response(ffstream , {
status: 200,
headers: { 'Content-Type': `video/mp4`},
})
}catch(e){
console.log(e.message);
}
}
(note: if the problem only happens with some inputs, include a link to such an input file)
Expected results
stream transcoded video in Nextjs api route
Observed results
opheliagame commented
DivyanshuLohani commented