How to Broadcast to Icecast2 with ffmpeg¶
ffmpeg to Icecast Samples¶
References:
https://gist.github.com/keiya/c8a5cbd4fe2594ddbb3390d9cf7dcac9
FFMpeg to Icecast2 Streaming Samples¶
Examples usage of various codecs with FFMpeg.
Sample: flac.sh¶
An Icecast Source Client
- Windows (Cygwin is required)
- macOS (
brew install ffmpeg)
Sample: another_examples.sh¶
- FFMpeg can push to Icecast2 in various formats: Opus/Vorbis/AAC/MP3
- This script shows optimal format, container and codec combinations.
Recommended settings for stable streaming with good quality:
- HE-AAC (aac_he): 48k-64k
- HE-AACv2 (aac_he_v2): 32k-48k
- LC-AAC VBR 3-4
- Higher is good quality, increases bitrate
- If you want to use CBR, set 96k-128k. (not recommended)
- Opus VBR 48k-64k
- CBR is not recommended
- Vorbis q3
- Higher is good quality, increases bitrate
- MP3 V6-V4
- Lower is good quality, increases bitrate
- if you want to use CBR, set 128k-160k
Reference¶
Icecast Server/Streaming WebM to Icecast with FFmpeg
Sample Code¶
flac.sh¶
# SAMPLE: FLAC streaming on Windows & Mac
# Input device on Windows
# you should find DShow device name by:
# ffmpeg.exe -list_devices true -f dshow -i dummy
input="dshow"
device="audio=@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{D50ABAB1-D542-4F19-BB77-D12FADCAB889}"
# Input device on macOS
# setup a default device at System Preferences > Sound > Input
# input="avfoundation"
# device="none:default"
channels=2
samplerate=48000
codec="flac"
# above 12 is not recommended
# if you have a slow hardware, set lower value.
level=10
while true
do
./ffmpeg -f $input \
-i $device \
-ar $samplerate \
-ac $channels \
-c:a $codec -compression_level $level \
-f ogg \
-content_type 'application/ogg' \
icecast://source:PASSWORD@HOSTNAME:8001/STREAM_NAME
sleep 1
done
another_examples.sh¶
# SAMPLE: encode to another formats
name=stream
# AACs
# AAC streams must be pushed as ADTS stream (-f adts)
# ==== HE-AAC (SBR+PS) @ CBR 48kbps ====
-c:a libfdk_aac -profile:a aac_he_v2 -ab 48k
-content_type 'audio/aac'
-vn -f adts icecast://source:PASSWORD@icecast:8001/$name_aac
# ==== LC-AAC @ VBR 4 ~110kbps ====
# -c:a libfdk_aac -vbr 4
# -content_type 'audio/aac'
# -vn -f adts icecast://source:PASSWORD@icecast:8001/$name_lcaac
# Xiph.org's Ogg Variant
# ==== Ogg Opus @VBR64k ====
# -c:a libopus -vbr on -b:a 64k
# -content_type 'audio/ogg'
# -vn -f opus icecast://source:PASSWORD@icecast:8001/$name_opus
# ==== Ogg Vorbis @ q3 ~112kbps ====
# -codec:a libvorbis -qscale:a 3
# -content_type 'audio/ogg'
# -vn -f ogg icecast://source:PASSWORD@icecast:8001/$name_vorbis
# ==== LAME MP3 @ V6 ~112kbps ====
# -codec:a libmp3lame -qscale:a 6
# -content_type 'audio/mpeg'
# -vn -f mp3 icecast://source:PASSWORD@icecast:8001/$name_mp3
Comments & Notes¶
The lowest recommended bit rate for stereo music is around:
- Opus 32kbps
- LC-AAC 64kbps
- HE-AACv2 24kbps
- Vorbis 64kbps
- MP3 96kbps
At bit rates below a certain level, Opus becomes SILK-based compression instead of CELT, which is for voice.
For mono voice with lowest acceptable quality:
- Opus 8 - 16kbps
- LC-AAC 32kbps
- HE-AACv1 16kbps (v2 is stereo only)
- Vorbis 32kbps
- MP3 64kbps