首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在heroku上部署Node Media Server应用程序

如何在heroku上部署Node Media Server应用程序
EN

Stack Overflow用户
提问于 2020-04-07 23:35:58
回答 1查看 2.2K关注 0票数 3

我正在尝试部署一个NodeJS直播服务器,它使用节点-媒体服务器和socket.io构建在rtmp服务器上的heroku上。我在启动节点-媒体服务器时面临问题,因为它需要两个端口才能按配置格式运行:

代码语言:javascript
复制
const NodeMediaServer = require('node-media-server');


const config = {
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: true,
    ping: 30,
    ping_timeout: 60
  },
  http: {
    port: 8000,
    allow_origin: '*'
  }
};

var nms = new NodeMediaServer(config)
nms.run();

我尝试过在新的heroku应用程序上部署应用程序,方法是遵循官方的指南。由于Heroku每个dyno只提供一个端口,所以它在我的heroku应用程序仪表板上给出了这些日志:

代码语言:javascript
复制
2020-04-07T23:08:24.289041+00:00 app[web.1]: 4/7/2020 23:08:24 23 [ERROR] Node Media Trans Server startup failed. ffmpeg:/usr/local/bin/ffmpeg cannot be executed.
2020-04-07T23:08:24.290753+00:00 app[web.1]: (node:23) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2020-04-07T23:08:24.291397+00:00 app[web.1]: listening on port 19586
2020-04-07T23:08:24.292059+00:00 app[web.1]: 4/7/2020 23:08:24 23 [ERROR] Node Media Rtmp Server Error: listen EADDRINUSE: address already in use :::19586
2020-04-07T23:08:24.292694+00:00 app[web.1]: 4/7/2020 23:08:24 23 [ERROR] Node Media Http Server Error: listen EADDRINUSE: address already in use :::19586
2020-04-07T23:08:24.293383+00:00 app[web.1]: 4/7/2020 23:08:24 23 [ERROR] Node Media WebSocket Server Error: listen EADDRINUSE: address already in use :::19586
2020-04-07T23:08:24.682440+00:00 heroku[web.1]: State changed from starting to up
2020-04-07T23:08:24.693405+00:00 app[web.1]: Connected to the database

我需要知道如何将我的应用程序部署到heroku (或任何其他选择)上,以使其在生产模式中可用。我的服务器在我的MacBook Pro上运行良好。这是我的密码:

代码语言:javascript
复制
const { NodeMediaServer } = require('node-media-server');
const express = require('express');
const mongoose = require('mongoose');

const app = express();
const http = require('http');
const fs = require('fs');
const bodyParser = require('body-parser');
const path = require('path');
const process = require('process')
const port = process.env.PORT||5000
const port2 = process.env.PORT||8000
const port3 = process.env.PORT||8001


const server = http.createServer(app);
const io = require('socket.io').listen(server);
require('./app/controllers/socketIO')(io);

mongoose.Promise = global.Promise;
global.appRoot = path.resolve(__dirname);

mongoose.connect(
  "mongodb://databasecredentials",
  { useNewUrlParser: true },
  err => {
    if (err) {
      console.log(err);
    } else {
      console.log('Connected to the database');
    }
  }
);

app.use(
  bodyParser.urlencoded({
    extended: true
  })
);
app.use(bodyParser.json());
app.set('socketio', io);
app.set('server', server);
app.use(express.static(`${__dirname}/public`));

server.listen(port, err => {
  if (err) {
    console.log(err);
  } else {
    console.log(`listening on port ${port}`);
  }
});

const nodeMediaServerConfig = {
  rtmp: {
    port: port2,
    chunk_size: 60000,
    gop_cache: true,
    ping: 60,
    ping_timeout: 30
  },
  http: {
    port: port3,
    mediaroot: './media',
    allow_origin: '*'
  },
  trans: {
    ffmpeg: '/usr/local/bin/ffmpeg',
    tasks: [
      {
        app: 'live',
        ac: 'aac',
        mp4: true,
        mp4Flags: '[movflags=faststart]'
      }
    ]
  }
};

var nms = new NodeMediaServer(nodeMediaServerConfig);
nms.run();
EN

回答 1

Stack Overflow用户

发布于 2020-05-28 15:37:58

我对Heroku不是很熟悉,但在日志的第一行中,它声明:

错误节点媒体跨服务器启动失败。/usr/local/bin/ffmpeg无法执行。

您需要在运行代码的机器上安装ffmpeg。这是启动服务器的第一步(这可能不会解决所有问题,但这是您需要开始的第一件事)。我正在尝试使用GCP做类似的事情。为了让它运行,我创建了一个package.json文件,并将start脚本设置为apt install --fix-missing --assume-yes ffmpeg && node app.js作为临时解决方案:

代码语言:javascript
复制
{
    "name": "app-service-hello-world",
    "description": "Simple Hello World Node.js sample for Azure App Service",
    "version": "0.0.1",
    "private": true,
    "license": "MIT",
    "author": "Microsoft",
    "scripts": {
        "start": "apt install --fix-missing --assume-yes ffmpeg && node app.js"
    },
    "dependencies": {
        "node-media-server": "^2.1.9"
    }
}

这可能有助于您将ffmpeg正确地添加到您的Heroku环境中:在Heroku上安装FFMPEG

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61091089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档