UNPKG

sp-streams

Version:

Streamplace Streams for Piping Video Around and Stuff

77 lines (52 loc) 3.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _socketEgressStream = require("./socket-egress-stream"); var _socketEgressStream2 = _interopRequireDefault(_socketEgressStream); var _socketIngressStream = require("./socket-ingress-stream"); var _socketIngressStream2 = _interopRequireDefault(_socketIngressStream); var _debug = require("debug"); var _debug2 = _interopRequireDefault(_debug); var _ffmpeg = require("./ffmpeg"); var _ffmpeg2 = _interopRequireDefault(_ffmpeg); var _stream = require("stream"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var log = (0, _debug2.default)("sp:rtmp-output-stream"); /** * { rtmpUrl } */ var ConvertVideoStream = function (_Transform) { _inherits(ConvertVideoStream, _Transform); function ConvertVideoStream() { _classCallCheck(this, ConvertVideoStream); var _this = _possibleConstructorReturn(this, (ConvertVideoStream.__proto__ || Object.getPrototypeOf(ConvertVideoStream)).call(this)); _this.socketEgress = new _socketEgressStream2.default(); _this.socketIngress = new _socketIngressStream2.default(); _this.socketIngress.on("data", function (chunk) { return _this.push(chunk); }); // socketEgress.pipe = socketIngress.pipe.bind(socketIngress); var instance = (0, _ffmpeg2.default)().input("anullsrc=channel_layout=stereo:sample_rate=44100").inputFormat("lavfi").input("unix://" + _this.socketEgress.path).videoCodec("libx264").audioCodec("aac").outputOptions(["-keyint_min 120", "-g 120", "-x264-params keyint=120:scenecut=0", "-tag:v avc1"]).outputFormat("mpegts") // Video out .output("unix://" + _this.socketIngress.path); Promise.all([_this.socketEgress.getPath()]).then(function () { log("running"); instance.run(); }); return _this; } _createClass(ConvertVideoStream, [{ key: "_transform", value: function _transform(chunk, encoding, cb) { this.socketEgress.write(chunk); cb(); } }]); return ConvertVideoStream; }(_stream.Transform); exports.default = ConvertVideoStream;