我正在尝试使用 Node fluence-ffmpeg、express和ejs创建视频流服务器和客户端。并且有一段时间没有解决这个问题。 我想做的是在某个时间开始播放视频。 以下代码可以在 Windows 上使用 Safari 浏览器,但对于其他浏览器,它会循环几秒钟或显示
video format not supported
服务器代码(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
之前插入此快速简介。这应该获取视频文件的大小,并且您可以在传输数据之前相应地设置响应中的 header 。
在 ffmpeg 调用之前插入
var fs = require('fs');
var stat = fs.statSync(pathToMovie);
res.writeHead(200, {
'Content-Type': 'video/mp4',
'Content-Length': stat.size
});
关于node.js - 使用 Node Fluent-ffmpeg 流式传输 mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29948551/