I used the stream-transcoder module to convert a file that makes it a stream. Thus, the file is not saved, it is on the go.
app.get("/video", function(req,res){
res.writeHead(200, {'Content-Type': 'video/mp4'});
var src = "movie.avi";
var Transcoder = require('stream-transcoder');
var stream = fs.createReadStream(src);
new Transcoder(stream)
.maxSize(1280, 720)
.videoCodec('h264')
.videoBitrate(800 * 1000)
.fps(25)
.sampleRate(44100)
.channels(2)
.audioBitrate(128 * 1000)
.format('mp4')
.on('finish', function() {
console.log("finished");
})
.stream().pipe(res);
});
It works beautifully, quickly, but too fast, the sound plays at the same speed, however the video does not take into account the frame rate, everything received from ffmpeg is implicitly displayed, quickly. In addition, it does not show the total time, I think this is a problem. I need to somehow indicate the length, frame rate, but I could not find enough information about this. I thought the stream obtained from ffmpeg should contain this. And I could not find the appropriate headers for HTTP.
, MP4:
[ '-i',
'-',
'-vf',
'scale=min(trunc(1280/hsub)*hsub\\,trunc(a*720/hsub)*hsub):min(trunc(720/vsub)*vsub\\,trunc(1280/a/vsub)*vsub)',
'-vcodec',
'h264',
'-b:v',
800000,
'-r',
25,
'-ar',
44100,
'-ac',
2,
'-ab',
128000,
'-f',
'mp4',
'-movflags',
'frag_keyframe+faststart',
'pipe:1' ]
VP8 WebM, , , .