Skip to content

Instantly share code, notes, and snippets.

@keiya
Last active April 22, 2024 06:43
Show Gist options
  • Save keiya/c8a5cbd4fe2594ddbb3390d9cf7dcac9 to your computer and use it in GitHub Desktop.
Save keiya/c8a5cbd4fe2594ddbb3390d9cf7dcac9 to your computer and use it in GitHub Desktop.
How to broadcast to Icecast2 by using ffmpeg (FLAC,Opus,Vorbis,AAC,MP3/Windows, Mac)

FFMpeg to Icecast2 Streaming Samples

Examples usage of various codecs with FFMpeg.

Samples

  • flac.sh : An Icecast Source Client
    • for Windows (Cygwin is required)
    • and macOS (brew install ffmpeg)
  • another_examples.sh : Samples
    • 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
        • Higer 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
        • Higer is good quality, increases bitrate
      • MP3 V6-V4
        • Lower is good quality, increases bitrate
        • if you want to use CBR, set 128k-160k

Reference

# 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
# 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
@mrx23dot
Copy link

Any idea why streaming stops between 2songs?
I'm using latest ices2/icecast2+ opus VBR on local LAN, still VLC strugles between songs.
Tried big/small buffers, no difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment