gpt4 book ai didi

node.js - 如何在 heroku 上部署 Node Media Server 应用程序

转载 作者:行者123 更新时间:2023-12-05 07:10:45 27 4
gpt4 key购买 nike

我正在尝试部署一个 NodeJS 实时流媒体服务器,它可以在使用 node-media-server 和 socket.io 构建在 rtmp 服务器上的 heroku 上运行。我在启动 Node 媒体服务器时遇到问题,因为它需要 2 个端 Eloquent 能按照配置格式运行:

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();

我已经尝试按照官方 guide 在新的 heroku 应用程序上部署应用程序.由于 Heroku 只为每个 dyno 提供一个端口,因此它在我的 heroku 应用程序仪表板上为我提供了这些日志:

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 上运行良好。这是我的代码:

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();

最佳答案

我对 Heroku 不是很熟悉,但是在日志的第一行它指出:

[ERROR] Node Media Trans Server startup failed. ffmpeg:/usr/local/bin/ffmpeg cannot be executed.

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

{
"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 环境中:Install FFMPEG on Heroku

关于node.js - 如何在 heroku 上部署 Node Media Server 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61091089/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com