Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanwahab committed Oct 14, 2024
1 parent 41860af commit 7ff4ffc
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 8 deletions.
6 changes: 3 additions & 3 deletions infra/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ install_rustdesk() {
if ! command_exists rustdesk; then
echo "Installing RustDesk..."
# Update the URL with the correct version and architecture
wget https://github.com/rustdesk/rustdesk/releases/download/<latest_version>/rustdesk-<latest_version>-x86_64.deb
sudo dpkg -i rustdesk-<latest_version>-x86_64.deb
wget https://github.com/rustdesk/rustdesk/releases/download/1.3.1/rustdesk-1.3.1-x86_64.deb
sudo dpkg -i rustdesk-1.3.1-x86_64.deb
sudo apt --fix-broken install -y
rm rustdesk-<latest_version>-x86_64.deb
rm rustdesk-1.3.1-x86_64.deb
else
echo "RustDesk already installed."
fi
Expand Down
80 changes: 80 additions & 0 deletions js/bun-jetson-mini.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const { RoomServiceClient } = require('livekit-server-sdk');
const { spawn } = require('child_process');
const WebSocket = require('ws');
require('dotenv').config(); // For managing environment variables

// Load environment variables
const API_KEY = process.env.LIVEKIT_API_KEY;
const API_SECRET = process.env.LIVEKIT_API_SECRET;
const LIVEKIT_URL = process.env.LIVEKIT_URL || 'wss://omnissiah-university-kmuz0plz.livekit.cloud';
const ROOM_NAME = 'test-room'; // Room to publish the stream

// Initialize LiveKit room service
const svc = new RoomServiceClient(LIVEKIT_URL, API_KEY, API_SECRET);

// Start streaming the ZED RTSP stream using FFmpeg
function startRTSPStream() {
console.log('Starting FFmpeg to read ZED RTSP stream...');

const ffmpeg = spawn('ffmpeg', [
'-i', 'rtsp://127.0.0.1:8554/zed-stream', // Input from ZED RTSP server
'-c:v', 'libx264', // Encode video using H.264 codec
'-preset', 'ultrafast', // Speed optimization
'-f', 'webm', // WebRTC-compatible format
'-an', 'pipe:1' // Disable audio, output via pipe
]);

ffmpeg.stderr.on('data', (data) => {
console.error(`FFmpeg error: ${data}`);
});

return ffmpeg.stdout;
}

// Publish the video stream to LiveKit
async function publishVideoTrack(ffmpegStream) {
console.log('Publishing video track to LiveKit...');

const ws = new WebSocket(`${LIVEKIT_URL}/rtc`);

ws.on('open', () => {
console.log('Connected to LiveKit WebSocket.');

ws.send(JSON.stringify({
type: 'join',
room: ROOM_NAME,
identity: 'server-streamer',
video: true,
}));

// Pipe FFmpeg stream to LiveKit WebSocket
ffmpegStream.on('data', (chunk) => {
ws.send(chunk);
});

ffmpegStream.on('end', () => {
console.log('FFmpeg stream ended.');
ws.close();
});
});

ws.on('error', (err) => {
console.error(`WebSocket error: ${err.message}`);
});

ws.on('close', () => {
console.log('LiveKit WebSocket closed.');
});
}

// Main function to start the stream
async function main() {
try {
const ffmpegStream = startRTSPStream();
await publishVideoTrack(ffmpegStream);
} catch (error) {
console.error('Error publishing video track:', error);
}
}

main();
16 changes: 11 additions & 5 deletions js/finally_livekit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const { RoomServiceClient, AccessToken } = require('livekit-server-sdk');
const { connect, createLocalVideoTrack } = require('@livekit/client');
//const { connect, createLocalVideoTrack, MediaStreamTrack } = require('livekit/client');
const { spawn } = require('child_process');
const fetch = require('node-fetch');



const API_KEY = process.env.LIVEKIT_API_KEY;
const API_SECRET = process.env.LIVEKIT_API_SECRET;
const LIVEKIT_URL = process.env.LIVEKIT_WS_URL;
// ... existing code ...
// Replace with your LiveKit server info
const API_KEY = 'your_api_key';
const API_SECRET = 'your_api_secret';
const LIVEKIT_URL = 'https://your-livekit-server-url';
// const API_KEY = 'your_api_key';
// const API_SECRET = 'your_api_secret';
// const LIVEKIT_URL = 'https://your-livekit-server-url';
const ROOM_NAME = 'test-room';
const IDENTITY = 'video-publisher';

Expand Down Expand Up @@ -60,4 +66,4 @@ const publishVideo = async (filePath) => {
};

// Run the publish function with the path to the video file
publishVideo('./sample-video.mp4');
publishVideo('./day1.mp4');

0 comments on commit 7ff4ffc

Please sign in to comment.