A Node.js application that streams audio files to YouTube while playing a fixed video. The application randomly selects from multiple audio files and automatically switches between them.
- Random selection from multiple audio files
- Continuous streaming with automatic audio switching
- Fixed video loop
- Easy deployment to Railway
- Docker support
- Node.js >= 18.0.0
- FFmpeg
- YouTube account with streaming enabled
- Railway account (for deployment)
- Clone the repository:
git clone <your-repo-url>
cd youtube-audio-streamer- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env- Update the
.envfile with your YouTube stream settings:
YOUTUBE_STREAM_URL=rtmp://x.rtmp.youtube.com/live2
YOUTUBE_STREAM_KEY=your-stream-key
PORT=3000
DEFAULT_VIDEO_PATH=./assets/default-video.mp4
-
Add your media files:
- Place your video file as
default-video.mp4in theassetsfolder - Add numbered audio files (1.mp3, 2.mp3, etc.) in the
assetsfolder
- Place your video file as
-
Start the server:
npm start-
Fork this repository to your GitHub account
-
Create a new project on Railway:
- Go to Railway
- Click "New Project"
- Select "Deploy from GitHub repo"
- Choose your forked repository
-
Set up environment variables in Railway:
- Go to your project settings
- Add the following variables:
YOUTUBE_STREAM_URLYOUTUBE_STREAM_KEYDEFAULT_VIDEO_PATHPORT
-
Upload media files:
- Use Railway's CLI to upload files to the assets directory:
railway run "mkdir -p assets" railway upload ./local/path/to/video.mp4 assets/default-video.mp4 railway upload ./local/path/to/1.mp3 assets/1.mp3 # Repeat for other audio files
-
Deploy:
- Railway will automatically deploy your application
- Monitor the deployment in the Railway dashboard
- GET
/: Health check endpoint - POST
/start-stream: Start streaming{ "streamKey": "your-youtube-stream-key" }
| Variable | Description |
|---|---|
| YOUTUBE_STREAM_URL | YouTube RTMP URL (usually rtmp://x.rtmp.youtube.com/live2) |
| YOUTUBE_STREAM_KEY | Your YouTube stream key |
| PORT | Port for the server (default: 3000) |
| DEFAULT_VIDEO_PATH | Path to the video file (default: ./assets/default-video.mp4) |
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
MIT