简体   繁体   English

FFmpeg Node.js实时Web流

[英]FFmpeg Node.js live web streaming

I'm trying to create some kind of proxy server to get IP cameras feeds and stream it over http using FFmpeg and hapi.js The main thing is that must exist outside http-server routes regardless of being watched. 我正在尝试创建某种代理服务器,以获取IP摄像机供稿,并使用FFmpeg和hapi.js通过HTTP将其流式传输。主要是必须在HTTP服务器路由之外存在,而不管其是否受到监视。 So I create feed like that 所以我像这样创建提要

let ffmpeg = require('fluent-ffmpeg')

let ffproc = ffmpeg()
    .input('some_link')
    .format('flv')
    .videoCodec('copy')
    .noAudio()


  let feed = ffproc.pipe({end: true})

and http-server 和http服务器

const Hapi = require('hapi')

const server = new Hapi.Server({
  host: 'localhost',
  port: 3000
})

server.route({
  method: 'GET',
  path: '/live',
  handler: function (request, h) {
      return feed
  }
})

server.start((err) => {   
  console.log(`Server running at: ${server.info.uri}`)
})

I've got my feed using vlc or ffplay but after I disconnect ffproc ends as well so I cannot reconnect later. 我已经使用vlc或ffproc了供稿,但是在断开ffproc连接ffproc结束了,因此以后无法重新连接。 I've tryed to clone or pipe stream but it doesn't help, process still exists but ffplay shows error 'Invalid data found when processing input' instead of feed. 我尝试克隆或通过管道传输流,但是它无济于事,进程仍然存在,但ffplay显示错误“处理输入时发现无效数据”而不是供稿。 koa server shows same behaviour, express and fastify I did not managed to work. koa服务器显示出相同的行为, expressfastify我没有设法工作。

What am I doing wrong? 我究竟做错了什么?

To clarify: Your issue is that after you disconnect from checking your feed via vlc or ffplay, you can't reconnect afterwards? 需要说明的是:您的问题是,在通过vlc或ffplay断开检查Feed的连接后,之后是否无法重新连接?

If you need the stream to operate continuously outside of the server routes then you should move feed creation to an entirely separate process and tie your server into that process output as needed. 如果您需要流在服务器路由之外连续运行,则应将提要创建移至一个完全独立的进程,并根据需要将服务器绑定到该进程输出中。 What is likely happening is that when you disconnect the scope of the feed variable is changing and it's no longer globally accessible where it once was, so the server can't recall it when you try to reconnect. 可能发生的情况是,当您断开feed变量的范围时,它的范围正在更改,并且不再可以从全局访问它,因此服务器在尝试重新连接时无法调用它。

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

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