【问题标题】:stream mp4 video with node fluent-ffmpeg使用节点 fluent-ffmpeg 流式传输 mp4 视频
【发布时间】:2015-07-09 00:33:38
【问题描述】:

我正在尝试使用节点 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>

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

【问题讨论】:

  • 尝试在响应中使用res.set('Content-Type', 'video/mp4'); 设置Content-Type 标头。
  • 嗨!我试过了,但还是不行。谢谢

标签: node.js video express ffmpeg stream


【解决方案1】:

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

在 ffmpeg 调用之前插入

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

【讨论】:

    猜你喜欢
    • 2014-03-15
    • 2023-03-31
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    相关资源
    最近更新 更多