#!/bin/bash

# This is a simple shell script for launching a gstreamer
# command that will stream to an icecast server.
#
# If you are running Debian wheezy you will need to take some
# extra steps documented here: 
# http://current.workingdirectory.net/posts/2012/vp8-and-debian/
#
# If you want to over-ride any variables, create a file in
# ~/.config/mobi.conf with alternate values for any 
# variable defined below. 
#
# You can set debug=1 to see the resulting gst-launch 
# pipeline command.


# Source should be either dv1394src (for firewire DV)
# or v4l2src for your webcam.
src=v4l2src
width=320
height=240
framerate=25/2
# Audio source can be either pulsesrc or alsasrc.
audiosrc=pulsesrc
# Container can be oggmux or webmmux
container=webmmux
# Audio encoding can be opusenc or vorbisenc, 
# but I cant get opus to work with webm.
audioenc=vorbisenc
# Video encoding - either vp8enc or theoraenc.
videoenc=vp8enc
icecast_server=localhost
icecast_port=8000
# icecast_mount_point=test.webm
icecast_password=source
debug=0

[ -f ~/.config/mobi.conf ] && . ~/.config/mobi.conf

cmd="gst-launch-1.0 "$src" ! queue ! video/x-raw,width=$width,height=$height 
  ! tee name=tscreen ! queue ! autovideosink tscreen. ! queue 
  ! videorate ! video/x-raw,framerate=$framerate ! queue 
  ! $videoenc ! queue ! $container name=mux $audiosrc 
  ! queue ! audioconvert ! $audioenc ! queue ! queue 
  ! mux. mux. ! queue ! shout2send ip=$icecast_server 
  port=$icecast_port mount=$icecast_mount_point 
  password=$icecast_password"

[ "$debug" = 1 ] && echo $cmd

$cmd

