Skip to content

Commit

Permalink
[fix] H264 화면 송출 에러 수정 (#30)
Browse files Browse the repository at this point in the history
* fix: H264 화면 송출 에러 fix

* feat: RTMP 서버 80 포트 추가

* feat: node_relay_session.js 파일 추가

---------

Co-authored-by: kkg5 <[email protected]>
  • Loading branch information
jmhee28 and kkg5 authored Nov 15, 2023
1 parent f0f7421 commit 305dba7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ jobs:
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/rtmp-server
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker run -d -p 1935:1935 --env-file ${{ secrets.ENV_PATH }} ${{ secrets.NCP_CONTAINER_REGISTRY }}/rtmp-server
docker run -d -p 1935:1935 -p 80:80 --env-file ${{ secrets.ENV_PATH }} ${{ secrets.NCP_CONTAINER_REGISTRY }}/rtmp-server
docker image prune -f
4 changes: 3 additions & 1 deletion server/rtmp-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ RUN npm i

COPY ./server/rtmp-server/. .

EXPOSE 1935
RUN mv ./node_relay_session.js ./node_modules/node-media-server/src/node_relay_session.js

EXPOSE 1935 80

CMD ["node","app.js"]
6 changes: 6 additions & 0 deletions server/rtmp-server/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("dotenv").config();

const NodeMediaServer = require("node-media-server");

const config = {
Expand All @@ -9,6 +10,10 @@ const config = {
ping: 30,
ping_timeout: 60,
},
http: {
port: 80,
allow_origin: "*",
},
relay: {
ffmpeg: "/usr/local/bin/ffmpeg",
tasks: [
Expand All @@ -22,4 +27,5 @@ const config = {
};

const nms = new NodeMediaServer(config);

nms.run();
81 changes: 81 additions & 0 deletions server/rtmp-server/node_relay_session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// Created by Mingliang Chen on 18/3/16.
// illuspas[a]gmail.com
// Copyright (c) 2018 Nodemedia. All rights reserved.
//
const Logger = require("./node_core_logger");
const NodeCoreUtils = require("./node_core_utils");

const EventEmitter = require("events");
const { spawn } = require("child_process");

const RTSP_TRANSPORT = ["udp", "tcp", "udp_multicast", "http"];

class NodeRelaySession extends EventEmitter {
constructor(conf) {
super();
this.conf = conf;
this.id = NodeCoreUtils.generateNewSessionID();
this.ts = (Date.now() / 1000) | 0;
this.TAG = "relay";
}

run() {
let format = this.conf.ouPath.startsWith("rtsp://") ? "rtsp" : "flv";
let argv = [
"-re",
"-i",
this.conf.inPath,
"-c:v",
"libx264",
"-preset",
"veryfast",
"-tune",
"zerolatency",
"-c:a",
"aac",
"-ar",
"44100",
"-f",
format,
this.conf.ouPath,
];
if (this.conf.inPath[0] === "/" || this.conf.inPath[1] === ":") {
argv.unshift("-1");
argv.unshift("-stream_loop");
}

if (this.conf.inPath.startsWith("rtsp://") && this.conf.rtsp_transport) {
if (RTSP_TRANSPORT.indexOf(this.conf.rtsp_transport) > -1) {
argv.unshift(this.conf.rtsp_transport);
argv.unshift("-rtsp_transport");
}
}

Logger.log("[relay task] id=" + this.id, "cmd=ffmpeg", argv.join(" "));

this.ffmpeg_exec = spawn(this.conf.ffmpeg, argv);
this.ffmpeg_exec.on("error", (e) => {
Logger.ffdebug(e);
});

this.ffmpeg_exec.stdout.on("data", (data) => {
Logger.ffdebug(`FF_LOG:${data}`);
});

this.ffmpeg_exec.stderr.on("data", (data) => {
Logger.ffdebug(`FF_LOG:${data}`);
});

this.ffmpeg_exec.on("close", (code) => {
Logger.log("[relay end] id=" + this.id, "code=" + code);
this.emit("end", this.id);
});
}

end() {
this.ffmpeg_exec.kill();
}
}

module.exports = NodeRelaySession;

0 comments on commit 305dba7

Please sign in to comment.