node.js - stream mp4 video with node fluent-ffmpeg -
i'm trying create video stream server , client node fluent-ffmpeg, express , ejs. , haven't solve while. want play video beginning time. following codes make safari browser on windows others makes loop of few seconds or says
video format not supported
server code (run.js) :
app.get('/video', function(req, res) { //define file path,time seek beegining , set ffmpeg binary var pathtomovie = '../videos/test.mp4'; var seektime = 100; proc.setffmpegpath(__dirname + "/ffmpeg/ffmpeg"); //encoding video source var proc = new ffmpeg({source: pathtomovie}) .seekinput(seektime) .withvideobitrate(1024) .withvideocodec('libx264') .withaspect('16:9') .withfps(24) .withaudiobitrate('128k') .withaudiocodec('libfaac') .toformat('mp4'); //pipe .pipe(res, {end: true}); });
client code (index.ejs):
<html> <head></head> <body> <video> <source src="video/" type='video/mp4' /> </video> </body> </html>
help please. searched everywhere solution didn't find
i believe in order seek within mp4 or mp3, need let browser know length of content. try inserting quick blurb before make call ffmpeg
. should size of video file , can set headers in response accordingly before streaming data.
insert before ffmpeg call
var fs = require('fs'); var stat = fs.statsync(pathtomovie); res.writehead(200, { 'content-type': 'video/mp4', 'content-length': stat.size });
Comments
Post a Comment