繁体   English   中英

使用节点fluent-ffmpeg流mp4视频

[英]stream mp4 video with node fluent-ffmpeg

我正在尝试使用节点fluent-ffmpegexpressejs创建视频流服务器和客户端。 有一段时间没有解决这个问题。 我想做的是在特定时间开始播放视频。 以下代码可在Windows上的Safari浏览器中实现 ,但与其他代码则可循环几秒钟,或显示

不支援影片格式

服务器代码(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});
});

客户端代码(index.ejs):

<html>
  <head></head>

  <body>
    <video>
      <source src="video/" type='video/mp4' />
    </video>
  </body>

</html>

请帮助。 我到处搜索了解决方案,但没有找到

我相信,要在mp4或mp3中进行搜索,您需要让浏览器知道该内容的长度。 在致电ffmpeg之前,请尝试插入此简短的内容。 这应该获得视频文件的大小,并且您可以在流传输数据之前相应地在响应中设置标头。

在ffmpeg调用之前插入

var fs = require('fs');
var stat = fs.statSync(pathToMovie);
res.writeHead(200, {
    'Content-Type': 'video/mp4',
    'Content-Length': stat.size
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM