Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dank074 committed Apr 22, 2024
1 parent cb60858 commit c0e2c29
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 44 deletions.
5 changes: 3 additions & 2 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@dank074/discord-video-stream": "3.1.1",
"discord.js-selfbot-v13": "^2.14.9"
"@dank074/discord-video-stream": "3.2.0",
"@discordjs/opus": "^0.9.0",
"discord.js-selfbot-v13": "^3.1.4"
},
"devDependencies": {
"@types/node": "^18.14.1",
Expand Down
32 changes: 19 additions & 13 deletions examples/basic/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { Client, StageChannel } from "discord.js-selfbot-v13";
import { command, streamLivestreamVideo, MediaUdp, setStreamOpts, getInputMetadata, inputHasAudio, Streamer } from "@dank074/discord-video-stream";
import { command, streamLivestreamVideo, MediaUdp, getInputMetadata, inputHasAudio, Streamer } from "@dank074/discord-video-stream";
import config from "./config.json";

const streamer = new Streamer(new Client());

setStreamOpts({
width: config.streamOpts.width,
height: config.streamOpts.height,
fps: config.streamOpts.fps,
bitrateKbps: config.streamOpts.bitrateKbps,
maxBitrateKbps: config.streamOpts.maxBitrateKbps,
hardware_acceleration: config.streamOpts.hardware_acceleration,
video_codec: config.streamOpts.videoCodec === 'H264' ? 'H264' : 'VP8'
})

// ready event
streamer.client.on("ready", () => {
console.log(`--- ${streamer.client.user.tag} is ready ---`);
Expand Down Expand Up @@ -43,7 +33,15 @@ streamer.client.on("messageCreate", async (msg) => {
await streamer.client.user.voice.setSuppressed(false);
}

const streamUdpConn = await streamer.createStream();
const streamUdpConn = await streamer.createStream({
width: config.streamOpts.width,
height: config.streamOpts.height,
fps: config.streamOpts.fps,
bitrateKbps: config.streamOpts.bitrateKbps,
maxBitrateKbps: config.streamOpts.maxBitrateKbps,
hardwareAcceleratedDecoding: config.streamOpts.hardware_acceleration,
videoCodec: config.streamOpts.videoCodec === 'H264' ? 'H264' : 'VP8'
});

await playVideo(args.url, streamUdpConn);

Expand All @@ -58,7 +56,15 @@ streamer.client.on("messageCreate", async (msg) => {
if(!channel) return;

console.log(`Attempting to join voice channel ${msg.guildId}/${channel.id}`);
const vc = await streamer.joinVoice(msg.guildId, channel.id);
const vc = await streamer.joinVoice(msg.guildId, channel.id, {
width: config.streamOpts.width,
height: config.streamOpts.height,
fps: config.streamOpts.fps,
bitrateKbps: config.streamOpts.bitrateKbps,
maxBitrateKbps: config.streamOpts.maxBitrateKbps,
hardwareAcceleratedDecoding: config.streamOpts.hardware_acceleration,
videoCodec: config.streamOpts.videoCodec === 'H264' ? 'H264' : 'VP8'
});

if(channel instanceof StageChannel)
{
Expand Down
8 changes: 4 additions & 4 deletions examples/custom-stream-copy-codec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@dank074/discord-video-stream": "3.1.1",
"@dank074/discord-video-stream": "3.2.0",
"@discordjs/opus": "^0.9.0",
"discord.js-selfbot-v13": "^3.1.4",
"@dank074/fluent-ffmpeg-multistream-ts": "^1.0.2",
"discord.js-selfbot-v13": "^2.14.9",
"fluent-ffmpeg": "^2.1.2",
"prism-media": "^1.3.5",
"@discordjs/opus": "^0.8.0"
"prism-media": "^1.3.5"
},
"devDependencies": {
"@types/node": "^18.14.1",
Expand Down
5 changes: 3 additions & 2 deletions examples/custom-stream-copy-codec/src/customStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
H264NalSplitter,
MediaUdp,
VideoStream,
streamOpts,
} from "@dank074/discord-video-stream";
import { Readable } from "node:stream";
import ffmpeg from "fluent-ffmpeg";
Expand All @@ -18,6 +17,8 @@ export function customStreamVideo(
includeAudio = true,
) {
return new Promise<string>((resolve, reject) => {
const streamOpts = mediaUdp.mediaConnection.streamOptions;

const videoStream: VideoStream = new VideoStream(
mediaUdp,
streamOpts.fps
Expand Down Expand Up @@ -84,7 +85,7 @@ export function customStreamVideo(
opus.pipe(audioStream, { end: false });
}

if (streamOpts.hardware_acceleration)
if (streamOpts.hardwareAcceleratedDecoding)
customFfmpegCommand.inputOption("-hwaccel", "auto");

if (isHttpUrl) {
Expand Down
10 changes: 2 additions & 8 deletions examples/custom-stream-copy-codec/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { MediaUdp, Streamer, getInputMetadata, inputHasAudio, setStreamOpts } from "@dank074/discord-video-stream";
import { MediaUdp, Streamer, getInputMetadata, inputHasAudio } from "@dank074/discord-video-stream";
import config from "./config.json";
import { Client, StageChannel } from "discord.js-selfbot-v13";
import { customFfmpegCommand, customStreamVideo } from "./customStream";

const streamer = new Streamer(new Client());

setStreamOpts({
bitrateKbps: config.streamOpts.bitrateKbps,
maxBitrateKbps: config.streamOpts.maxBitrateKbps,
video_codec: 'H264'
})

// ready event
streamer.client.on("ready", () => {
console.log(`--- ${streamer.client.user.tag} is ready ---`);
Expand Down Expand Up @@ -78,7 +72,7 @@ async function playVideo(video: string, udpConn: MediaUdp) {
const width = videoStream.width
const height = videoStream.height
console.log({fps, width, height, "profile": videoStream.profile})
setStreamOpts({ fps, width, height })
udpConn.mediaConnection.streamOptions = { fps, width, height }
includeAudio = inputHasAudio(metadata);
} catch(e) {
console.log(e);
Expand Down
5 changes: 3 additions & 2 deletions examples/puppeteer-stream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@dank074/discord-video-stream": "3.1.1",
"discord.js-selfbot-v13": "^2.15.1",
"@dank074/discord-video-stream": "3.2.0",
"@discordjs/opus": "^0.9.0",
"discord.js-selfbot-v13": "^3.1.4",
"puppeteer": "^19.11.1",
"puppeteer-stream": "^2.1.4"
},
Expand Down
24 changes: 12 additions & 12 deletions examples/puppeteer-stream/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MediaUdp, Streamer, command, setStreamOpts, streamLivestreamVideo, streamOpts } from '@dank074/discord-video-stream';
import { MediaUdp, Streamer, command, streamLivestreamVideo } from '@dank074/discord-video-stream';
import { Client, StageChannel } from 'discord.js-selfbot-v13';
import { executablePath } from 'puppeteer';
import { launch, getStream } from 'puppeteer-stream';
Expand All @@ -7,16 +7,6 @@ import { Readable } from 'node:stream';

const streamer = new Streamer(new Client());

setStreamOpts({
width: config.streamOpts.width,
height: config.streamOpts.height,
fps: config.streamOpts.fps,
bitrateKbps: config.streamOpts.bitrateKbps,
maxBitrateKbps: config.streamOpts.maxBitrateKbps,
hardware_acceleration: config.streamOpts.hardware_acceleration,
video_codec: config.streamOpts.videoCodec === 'H264' ? 'H264' : 'VP8'
})

// ready event
streamer.client.on("ready", () => {
console.log(`--- ${streamer.client.user.tag} is ready ---`);
Expand Down Expand Up @@ -50,7 +40,15 @@ streamer.client.on("messageCreate", async (msg) => {
await streamer.client.user.voice.setSuppressed(false);
}

const streamUdpConn = await streamer.createStream();
const streamUdpConn = await streamer.createStream({
width: config.streamOpts.width,
height: config.streamOpts.height,
fps: config.streamOpts.fps,
bitrateKbps: config.streamOpts.bitrateKbps,
maxBitrateKbps: config.streamOpts.maxBitrateKbps,
hardwareAcceleratedDecoding: config.streamOpts.hardware_acceleration,
videoCodec: config.streamOpts.videoCodec === 'H264' ? 'H264' : 'VP8'
});

await streamPuppeteer(url, streamUdpConn);

Expand All @@ -65,6 +63,8 @@ streamer.client.on("messageCreate", async (msg) => {
})

async function streamPuppeteer(url: string, udpConn: MediaUdp) {
const streamOpts = udpConn.mediaConnection.streamOptions;

const browser = await launch({
defaultViewport: {
width: streamOpts.width,
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": "3.1.1",
"version": "3.2.0",
"description": "Experiment for making video streaming work for discord selfbots",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit c0e2c29

Please sign in to comment.