How to Stream Audio to Shoutcast Using FFmpeg
This article provides a straightforward guide on how to stream live or pre-recorded audio to a Shoutcast server using the FFmpeg command-line tool. You will learn the exact command-line syntax required to encode your audio source, configure the connection parameters, and successfully broadcast your stream in real time.
Prerequisites
Before you begin, ensure you have the following: * FFmpeg installed on your system. * Your Shoutcast server details: Server IP/Host, Port, Stream ID (for Shoutcast v2), and the Source Password. * An audio source (such as an audio file, a playlist, or a live microphone input).
The FFmpeg Command Structure
FFmpeg utilizes the Icecast protocol format to connect and stream to Shoutcast v2 servers. Below is the standard command structure used to stream an MP3 audio file to a Shoutcast server:
ffmpeg -re -i input.wav -acodec libmp3lame -ab 128k -ac 2 -ar 44100 -f mp3 icecast://source:password@yourserver.com:8000/stream/1Command Parameter Breakdown
To customize the stream for your specific setup, understand what each parameter does:
-re: Tells FFmpeg to read the input in real-time. This is crucial for streaming; without it, FFmpeg will attempt to upload the file as fast as possible, causing the stream to buffer or crash.-i input.wav: Specifies the path to your input audio file or device capture.-acodec libmp3lame: Selects the MP3 encoder. For AAC streaming, you can uselibfdk_aacor the nativeaacencoder.-ab 128k: Sets the audio bitrate to 128 kbps. Adjust this according to your bandwidth and quality preferences.-ac 2: Sets the number of audio channels to 2 (stereo). Use1for mono.-ar 44100: Sets the audio sampling rate to 44100 Hz.-f mp3: Forces the output format to MP3.icecast://...: The output URL. Even though you are streaming to Shoutcast, FFmpeg uses the Icecast protocol wrapper.source: The default username for streaming sources in Shoutcast v2.password: Your stream’s source password.yourserver.com:8000: Your Shoutcast server’s IP address or domain name, followed by the port./stream/1: The mount point. For Shoutcast v2,/stream/1target stream ID 1. Change the number if you are streaming to a different stream ID.
Streaming a Live Audio Input
If you want to stream from a live input device (such as a microphone or line-in) instead of an audio file, change the input parameters.
On Windows (using dshow):
ffmpeg -f dshow -i audio="Microphone (Realtek Audio)" -acodec libmp3lame -ab 128k -ac 2 -ar 44100 -f mp3 icecast://source:password@yourserver.com:8000/stream/1On Linux (using ALSA):
ffmpeg -f alsa -i hw:0 -acodec libmp3lame -ab 128k -ac 2 -ar 44100 -f mp3 icecast://source:password@yourserver.com:8000/stream/1On macOS (using AVFoundation):
ffmpeg -f avfoundation -i ":0" -acodec libmp3lame -ab 128k -ac 2 -ar 44100 -f mp3 icecast://source:password@yourserver.com:8000/stream/1