How to Stream Audio to Shoutcast with FFmpeg
This article provides a quick guide on how to stream live audio to a Shoutcast server using FFmpeg with secure authentication. You will learn how to configure your FFmpeg command, format the connection URL with your credentials, and execute the stream to ensure a stable and secure broadcast to your Shoutcast directory.
Understanding Shoutcast Authentication in FFmpeg
Shoutcast servers rely on the ICY (SHOUTcast/Icecast) protocol for source connections. To connect securely, you must pass your stream credentials directly within the output URL.
For Shoutcast v2, the connection URL requires a username (typically
source), a password, the server address, the port, and the
stream ID (mountpoint).
The standard URL format is:
icy://username:password@server_address:port/streamid
If your Shoutcast server only requires a password (common in
Shoutcast v1 legacy mode), the format is:
icy://:password@server_address:port
Step 1: Identify Your Audio Source
Before running FFmpeg, identify the audio source you want to stream.
- For an audio file (e.g., MP3 or WAV):
input.mp3 - For a live input on Windows (DirectShow):
audio="Microphone (Realtek)" - For a live input on Linux (ALSA):
hw:0
Step 2: Construct the FFmpeg Command
To stream a local audio file to a Shoutcast server using secure MP3 encoding, use the following command template:
ffmpeg -re -i input.mp3 -acodec libmp3lame -b:a 128k -ac 2 -ar 44100 -f mp3 "icy://source:your_password@your_server_ip:port/1"Command Breakdown:
-re: Tells FFmpeg to read the input in real-time. This is crucial for live streaming.-i input.mp3: Specifies the path to your input audio file or live hardware input.-acodec libmp3lame: Encodes the audio into MP3 format, which is native to Shoutcast.-b:a 128k: Sets the audio stream bitrate to 128 kbps. You can adjust this based on your bandwidth.-ac 2: Configures the audio output for 2 channels (stereo).-ar 44100: Sets the audio sample rate to 44,100 Hz (CD quality).-f mp3: Forces the output format container to MP3."icy://...": The destination URL containing your secure credentials, server IP, port, and stream ID (usually/1for the primary stream).
Step 3: Stream from a Live Microphone (Optional)
If you are broadcasting a live microphone instead of an audio file, replace the input parameter.
On Windows:
ffmpeg -f dshow -i audio="Microphone Name" -acodec libmp3lame -b:a 128k -ac 2 -ar 44100 -f mp3 "icy://source:your_password@your_server_ip:port/1"On Linux:
ffmpeg -f alsa -i hw:0 -acodec libmp3lame -b:a 128k -ac 2 -ar 44100 -f mp3 "icy://source:your_password@your_server_ip:port/1"Step 4: Verify the Connection
Once you run the command, FFmpeg will begin encoding and displaying the frame rate and bitrate statistics in your terminal. Check your Shoutcast Admin Panel to verify that the stream status has changed to “Active” and that your listeners can hear the audio.