Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #22

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@dank074/discord-video-stream": "2.1.0",
"@dank074/discord-video-stream": "2.1.1",
"discord.js-selfbot-v13": "^2.14.9",
"puppeteer": "^19.11.1",
"puppeteer-stream": "^2.1.4"
Expand Down
2 changes: 1 addition & 1 deletion example/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"height": 720,
"fps": 30,
"bitrateKbps": 1000,
"hardware_acc": false,
"hardware_acceleration": false,
"videoCodec": "H264"
}
}
2 changes: 1 addition & 1 deletion example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setStreamOpts({
height: config.streamOpts.height,
fps: config.streamOpts.fps,
bitrateKbps: config.streamOpts.bitrateKbps,
hardware_encoding: config.streamOpts.hardware_acc,
hardware_acceleration: config.streamOpts.hardware_acceleration,
video_codec: config.streamOpts.videoCodec === 'H264' ? 'H264' : 'VP8'
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dank074/discord-video-stream",
"version": "2.1.0",
"version": "2.1.1",
"description": "Experiment for making video streaming work for discord selfbots",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/client/StreamOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface StreamOpts {
height?: number;
fps?: number;
bitrateKbps?: number;
hardware_encoding?: boolean;
hardware_acceleration?: boolean;
video_codec?: 'H264' | 'VP8';
}

Expand All @@ -12,7 +12,7 @@ export const streamOpts: StreamOpts = {
height: 720,
fps: 30,
bitrateKbps: 1000,
hardware_encoding: false,
hardware_acceleration: false,
video_codec: 'H264'
}

Expand All @@ -21,6 +21,6 @@ export const setStreamOpts = (opts: StreamOpts) => {
streamOpts.height = opts.height ?? streamOpts.height;
streamOpts.fps = opts.fps ?? streamOpts.fps;
streamOpts.bitrateKbps = opts.bitrateKbps ?? streamOpts.bitrateKbps;
streamOpts.hardware_encoding = opts.hardware_encoding ?? streamOpts.hardware_encoding;
streamOpts.hardware_acceleration = opts.hardware_acceleration ?? streamOpts.hardware_acceleration;
streamOpts.video_codec = opts.video_codec ?? streamOpts.video_codec;
}
27 changes: 17 additions & 10 deletions src/media/H264NalSplitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ export class H264NalSplitter extends Transform {
* @param data
* @returns frame with emulation prevention bytes removed
*/
rbsp(data: any): Buffer
rbsp(data: Buffer): Buffer
{
const len = data.byteLength;
let pos = 0;
let epbs = [];

while (pos < len - 2) {
while (pos < len - 3) {
if (data[pos] === 0 && data[pos + 1] === 0 && data[pos + 2] === 0x03) {
epbs.push(pos + 2);
pos += 2;
const third = data[pos + 3];
if(epbSuffix.some(val => val === third)) {
epbs.push(pos + 2);
pos += 3;
}
} else {
pos++;
}
Expand Down Expand Up @@ -94,10 +97,10 @@ export class H264NalSplitter extends Transform {
* Returns true if nal magic string with specified length was found.
* Nal magic string is either 001 or 0001 depending on length
* @param buf
* @param magicLength
* @returns
* @param magicLength either 3 or 4
* @returns true if nalu magic string was found
*/
findNalByMagicString(buf: Buffer, magicLength: number) {
findNalByMagicString(buf: Buffer, magicLength: 3 | 4) {
let found = false;

if(magicLength === 3) {
Expand Down Expand Up @@ -150,9 +153,13 @@ export class H264NalSplitter extends Transform {
this._accessUnit = [];
}
} else {
// remove emulation bytes from frame
const rbspFrame = this.rbsp(frame);
this._accessUnit.push(rbspFrame);
// remove emulation bytes from frame (only importannt ones like SPS and SEI since its costly operation)
if(unitType === NalUnitTypes.SPS || unitType === NalUnitTypes.SEI) {
const rbspFrame = this.rbsp(frame);
this._accessUnit.push(rbspFrame);
} else {
this._accessUnit.push(frame);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/media/streamLivestreamVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function streamLivestreamVideo(input: string | Readable, voiceUdp: VoiceU
opus.pipe(audioStream, {end: false});
}

if(streamOpts.hardware_encoding) command.inputOption('-hwaccel', 'auto');
if(streamOpts.hardware_acceleration) command.inputOption('-hwaccel', 'auto');

if(isHttpUrl) {
command.inputOption('-headers',
Expand Down