Icecast Server/Streaming WebM to Icecast with FFmpeg
What is FFmpeg?
FFmpeg is a very versatile command-line tool to decode, capture, encode or modify audio and video media. It supports being a source for several streaming servers including Icecast. The resulting stream can be read from a simple HTML5 video tag in Firefox and Chrome.
Streaming a live webcam with sound
This configuration works for me on Linux, but must be adapted to your hardware and operating system. As explained in next section,
-cluster_time_limit should always have a value (in milliseconds) greater than the value of
-g divided by the framerate. If your framerate is 30 and
-g is 150, then
-cluster_time_limit should be greater than 5K.
ffmpeg \ -f v4l2 -video_size 640x480 -framerate 15 -i /dev/video0 \ -f alsa -i default \ -f webm -cluster_size_limit 2M -cluster_time_limit 5K -content_type video/webm \ -c:a libvorbis -b:a 96K \ -c:v libvpx -b:v 1.5M -crf 30 -g 70 -deadline good -threads 4 \ icecast://user:password@server:port/stream_name
What it takes to make FFmpeg generate a compatible WebM stream
WebM streams are made of clusters, each one containing a number of frames of every track (video, audio, subtitles…). Icecast will synchronise each clients’ stream with a cluster. As of writing this, Firefox and Chrome will fail to play a stream when the first cluster received after connecting to a stream lacks a key frame. FFmpeg by default creates small clusters so the probability of a cluster containing a key frame is low. One could increase the number of key frames, but would suffer high bandwidth usage and low quality. The trick is making FFmpeg generate larger clusters and setting an adequate maximum period between key frames so that each cluster contains at least one key frame.