-
Notifications
You must be signed in to change notification settings - Fork 57
/
wowza.js
83 lines (69 loc) · 3.06 KB
/
wowza.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Yellowstone Example.
//
// Connects to the specified RTSP server url,
// Once connected, opens a file and streams H264 and AAC to the files
//
// Yellowstone is written in TypeScript. This example uses Javascript and
// the typescript compiled files in the ./dist folder
const { RTSPClient, H264Transport, H265Transport, AACTransport } = require("../dist");
const fs = require("fs");
const { exit } = require("process");
// User-specified details here.
//const url = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4"
const filename = "bigbuckbunny";
const username = "";
const password = "";
// Step 1: Create an RTSPClient instance
const client = new RTSPClient(username, password);
// Step 2: Connect to a specified URL using the client instance.
//
// "keepAlive" option is set to true by default
// "connection" option is set to "udp" by default.
client.connect(url, { connection: "tcp" })
.then(async (detailsArray) => {
console.log("Connected");
if (detailsArray.length == 0) {
console.log("ERROR: There are no compatible RTP payloads to save to disk");
exit();
}
for (let x = 0; x < detailsArray.length; x++) {
let details = detailsArray[x];
console.log(`Stream ${x}. Codec is`, details.codec);
// Step 3: Open the output file
if (details.codec == "H264") {
const videoFile = fs.createWriteStream(filename + '.264');
// Step 4: Create H264Transport passing in the client, file, and details
// This class subscribes to the client 'data' event, looking for the video payload
const h264 = new H264Transport(client, videoFile, details);
}
if (details.codec == "H265") {
const videoFile = fs.createWriteStream(filename + '.265');
// Step 4: Create H265Transport passing in the client, file, and details
// This class subscribes to the client 'data' event, looking for the video payload
const h265 = new H265Transport(client, videoFile, details);
}
if (details.codec == "AAC") {
const audioFile = fs.createWriteStream(filename + '.aac');
// Add AAC Transport
// This class subscribes to the client 'data' event, looking for the audio payload
const aac = new AACTransport(client, audioFile, details);
}
}
// Step 5: Start streaming!
await client.play();
console.log("Play sent");
})
.catch(e => console.log(e));
// The "data" event is fired for every RTP packet.
client.on("data", (channel, data, packet) => {
console.log("RTP:", "Channel=" + channel, "TYPE=" + packet.payloadType, "ID=" + packet.id, "TS=" + packet.timestamp, "M=" + packet.marker);
});
// The "controlData" event is fired for every RTCP packet.
client.on("controlData", (channel, rtcpPacket) => {
console.log("RTCP:", "Channel=" + channel, "TS=" + rtcpPacket.timestamp, "PT=" + rtcpPacket.packetType);
});
// The "log" event allows you to optionally log any output from the library.
// You can hook this into your own logging system super easily.
client.on("log", (data, prefix) => {
console.log(prefix + ": " + data);
});