-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: H264 화면 송출 에러 fix * feat: RTMP 서버 80 포트 추가 * feat: node_relay_session.js 파일 추가 --------- Co-authored-by: kkg5 <[email protected]>
- Loading branch information
Showing
4 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |