#!/bin/sh

output="meeting-`date +%Y.%m.%d-%H.%M.%S.ogg`"

IP_ADDRESS=$(ifconfig eth0 | grep inet | sed 's/.*addr:\([^ ]*\).*/\1/')

echo "Stream url is http://$IP_ADDRESS/stream.ogg"

sudo gst-launch \
	   hdv1394src blocksize="4136" \
	     ! queue \
	     ! mpegtsdemux name=demux\
           demux. \
             ! queue \
	     ! mpeg2dec \
             ! tee name=lovid \
             ! queue \
	     ! videorate \
	     ! video/x-raw-yuv,framerate=12/1 \
	     ! ffvideoscale \
	     ! video/x-raw-yuv,width=640,height=360,pixel-aspect-ratio=1/1 \
	     ! tee name=preview \
	     ! ffmpegcolorspace \
             ! queue \
	     ! theoraenc quality=48 bitrate=350 keyframe-force=64 \
	     ! queue \
	     ! himux. \
            lovid. \
             ! queue \
	     ! videorate \
	     ! video/x-raw-yuv,framerate=8/1 \
             ! ffvideoscale \
             ! video/x-raw-yuv,width=528,height=300,pixel-aspect-ratio=1/1 \
	     ! ffmpegcolorspace \
             ! queue \
	     ! theoraenc quality=48 bitrate=130 keyframe-force=64 \
	     ! queue \
	     ! lomux. \
            demux. \
             ! queue \
             ! mad \
             ! tee name=loaud \
             ! audioconvert \
             ! audioresample \
             ! audio/x-raw-float,channels=1,rate=32000 \
             ! queue \
             ! vorbisenc quality=.1 \
             ! queue \
             ! himux.\
           loaud. \
             ! audioconvert \
             ! audioresample \
             ! audio/x-raw-float,channels=1,rate=8000 \
             ! queue \
             ! vorbisenc quality=.2 \
             ! queue \
             ! lomux.\
      	   preview. \
	     ! queue\
	     ! xvimagesink sync="false" \
	   oggmux name=himux \
             ! tee name=save \
	     ! queue \
	     ! progressreport \
	     ! shout2send ip=127.0.0.1 \
	       port=80 password=password mount=stream-300.ogg \
           oggmux name=lomux \
             ! queue \
             ! shout2send ip=127.0.0.1 \
               port=80 password=password mount=stream-100.ogg \
           save. \
             ! queue \
             ! filesink location=$output
