2
votes

I'm trying to create video stream server and client with node fluent-ffmpeg, express and ejs. And a haven't solve this for a while. What I want to do is to play video beginning by certain time. The following codes make it with Safari browser on windows but with others it makes a loop of a few seconds or it says

video format not supported

server code (run.js) :

app.get('/video', function(req, res) {

  //define file path,time to seek the beegining and set ffmpeg binary
  var pathToMovie = '../videos/test.mp4';
  var seektime = 100; 
  proc.setFfmpegPath(__dirname + "/ffmpeg/ffmpeg");


  //encoding the 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. I searched everywhere solution but I didn't find

1
Try setting the Content-Type header in the response with res.set('Content-Type', 'video/mp4');.Tom
hi! I tried this but still doesn't work. thanksrchristian

1 Answers

0
votes

I believe that in order to seek within a mp4 or mp3, you need to let the browser know the length of that content. Try inserting this quick blurb before you make your call to ffmpeg. This should get the size of the video file and you can set the headers in the response accordingly before streaming the 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
});