node-webplay
Version:
A nodejs streaming server implementation
255 lines (194 loc) • 8.7 kB
JavaScript
;
var _chai = require("chai");
var _chai2 = _interopRequireDefault(_chai);
var _index = require("../../processor/index.js");
var _index2 = _interopRequireDefault(_index);
var _child_process = require("child_process");
var _child_process2 = _interopRequireDefault(_child_process);
var _path = require("path");
var _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var expect = _chai2.default.expect;
function tval(name, def) {
if (null == process.env[name]) {
return def;
}
return process.env[name];
}
function check(done, f) {
try {
f();
done();
} catch (e) {
done(e);
}
}
var result = [{ index: "0",
lang: "und",
kind: "Video",
width: "1024",
height: "576",
kz: undefined,
bps: "674" }, { index: "1",
lang: "und",
kind: "Audio",
width: undefined,
height: undefined,
kz: "48000",
bps: "96" }];
describe("PROCESSOR", function () {
describe("Process Streams", function () {
var cases = [{ name: "flv",
input: "\n Duration: 00:01:54.66, start: 0.000000, bitrate: 962 kb/s\n Stream #0:0: Video: h264 (High), yuv420p, 640x352 [SAR 44:45 DAR 16:9], 30.30 fps, 29.97 tbr, 1k tbn, 59.94 tbc\n Stream #0:1: Audio: aac (HE-AAC), 44100 Hz, stereo, fltp\n\n \n ",
expected: [{ index: "0",
lang: "und",
kind: "Video",
width: "640",
height: "352",
kz: undefined,
bps: "962" }, { index: "1",
lang: "und",
kind: "Audio",
width: undefined,
height: undefined,
kz: "44100",
bps: undefined }]
}, { name: "mp4",
input: "\n Duration: 00:02:59.84, start: 0.080000, bitrate: 777 kb/s\n Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1024x576 [SAR 1:1 DAR 16:9], 674 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)\n Metadata:\n creation_time : 2016-11-28T16:36:40.000000Z\n handler_name : FOUNDATION MEDIA HANDLER\n Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 96 kb/s (default)\n Metadata:\n creation_time : 2016-11-28T16:36:40.000000Z\n handler_name : FOUNDATION MEDIA HANDLER\n",
expected: result
}, { name: "hdtv.ts",
input: "\nInput #0, mpegts, from 'F:\\IOMEGA\\NEWMEDIA\\MORE\\2\\hdtv.ts':\n Duration: 00:01:00.35, start: 50685.124933, bitrate: 14138 kb/s\n Program 1\n Stream #0:0[0x101]: Video: mpeg2video ([2][0][0][0] / 0x0002), none(tv), 90k tbr, 90k tbn, 90k tbc\n Stream #0:1[0x800]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc\n Stream #0:2[0x801](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s\n Stream #0:3[0x102]: Audio: ac3 ([129][0][0][0] / 0x0081), 0 channels, fltp\n",
expected: [{ index: "0",
lang: "und",
kind: "Video",
width: "1920",
height: "1080",
kz: undefined,
bps: "14138" }, { index: "1",
lang: "eng",
kind: "Audio",
width: undefined,
height: undefined,
kz: "48000",
bps: undefined }],
enabled: false
}];
var output_stream = " \n Output #0, image2, to :\n ......\n Stream #0:0: Video: mjpeg, yuvj420p(pc), 640x352 [SAR 44:45 DAR 16:9], q=2-31, 200 kb/s, 0.10 fps, 0.10 tbn, 0.10 tbc\n ";
var _loop = function _loop(i) {
var name = "get_streams_cases_" + i + "_" + cases[i].name;
if (cases[i].enabled || undefined == cases[i].enabled) {
// console.log(name);
it(name, function () {
var p = new _index2.default(name);
var s = p.get_streams(cases[i].input + output_stream);
// console.log(s.streams);
// console.log(cases[i].expected);
expect(s.streams).to.be.deep.equal(cases[i].expected);
});
}
};
for (var i = 0; i < cases.length; i++) {
_loop(i);
}
});
it("has the right enviroment", function (done) {
var env_path = process.env.PATH;
var dirname = _path2.default.normalize(_path2.default.join(__dirname, "../../../bin"));
process.env.PATH = dirname + _path2.default.delimiter + env_path;
/*
console.log("PATH: ", dirname, " ", env_path);
console.log("----------T-----------");
console.log(process.env.PATH);
console.log("----------T-----------");
*/
_child_process2.default.exec("ffmpeg -version", { env: process.env }, function (err /*, stdout, stderr*/) {
if (err) {
done(err);
}
_child_process2.default.exec("mg --help", function (err /*, stdout, stderr*/) {
if (err) {
done(err);
} else {
done();
}
});
});
});
it("set up correctly", function (done) {
expect(_index2.default).to.be.a("function");
var n = tval("TESTNAME", "TEST");
var p = new _index2.default(n);
expect(p).to.be.a("object");
check(done, function () {
//console.log(p.get_full_name());
//console.log(p.get_target_dir());
});
}); //return 200
describe("Elaborate", function () {
var n = tval("TESTNAME", "TEST");
var tid = tval("TESTID", "9999999999_" + n);
var p = new _index2.default(n, { destination: "./uploader", id: tid });
var file = tval("TESTMEDIAFILE", "./src/processor/test/MEDIA1.MP4");
var dir = _path2.default.resolve(_path2.default.join(p.options.destination, p.get_full_name()));
var quality = [{
filename: null,
args: null,
status: null,
audiobitrate: 96,
videobitrate: 120,
height: 144,
width: "256",
done: true,
file: _path2.default.join(dir, "TEST_256_144_120.mp4").replace(/\\/g, "/") }, { filename: null,
args: null,
status: null,
audiobitrate: 96,
videobitrate: 320,
height: 288,
width: "512",
done: true,
file: _path2.default.join(dir, "TEST_512_288_320.mp4").replace(/\\/g, "/") }, { filename: null,
args: null,
status: null,
audiobitrate: 96,
videobitrate: 750,
height: 576,
width: "1024",
done: true,
file: _path2.default.join(dir, "TEST_1024_576_750.mp4").replace(/\\/g, "/") }, { videobitrate: 0, height: 720, width: "1280", done: true, status: "none" }, { videobitrate: 0, height: 720, width: "1280", done: true, status: "none" }, { videobitrate: 0, height: 720, width: "1280", done: true, status: "none" }];
it("get streams", function (done) {
p.read_stream_info(file).then(function (streams) {
check(done, function () {
expect(streams).to.be.a("object");
//console.log(streams);
//
expect(streams.streams).to.be.deep.equal(result);
});
}, function (err) {
done(err);
});
});
it("encode", function (done) {
expect(result.length).to.be.equal(2);
p.encode(file, result).then(function (rquality) {
for (var i = 0; i < rquality.length; i++) {
if (null != rquality[i].args) {
rquality[i].args = null;
rquality[i].filename = null;
rquality[i].status = null;
}
}
check(done, function () {
expect(rquality).to.be.deep.equal(quality);
});
}, function (err) {
done(err);
});
});
it("package", function () /*done*/{
//expect(quality).to.be.a("Array(6)");
return p.package(quality, "STATIC");
});
});
});
//# sourceMappingURL=index.js.map