Locked History Actions

streamer.sh


#!/bin/sh
#######################################################################

#
# streamer: Just a simple script to stream video w/audio to icecast
# Copyright (C) 2011  Gente anónima pro software libre - flisol
#

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

#######################################################################

V4LDEV=/dev/video0
XRES=320
YRES=240
FPS=15/2
VQUALITY=24
AQUALITY=0.1


# USESCALE allows specifying custom XRES,YRES. If you enable this option, you
# must set XCAMERARES,YCAMERARES to some value supported by your camera.
#USESCALE=1

#XCAMERARES=640
#YCAMERARES=480

#OUTFILE=stream-`date +%Y%m%d-%H%M`.ogg
OUTFILE=/dev/null


# settings for the icecast/giss/rooteala/whatever server:
SERVER=giss.tv
PORT=8000
MOUNTPOINT=flisol_fixme.ogg
PASSWORD=fixme


# external file for user-settings:
[ -r ~/.streamer.sh ] && . .streamer.sh


showhelp() {
        cat <<EOF

Usage: $0 [options]
        -v4ldev /dev/...
        -res X Y
        -fps P/Q
        -quality VQUAL AQUAL
        -outfile output_file
        -server server
        -port port
        -mountpoint mp
        -password pwd

See the content of this script to view the default values. The allowed values are
documented in the specifications of each plugin/sink/etc at gstreamer.
EOF

}


while [ $# -gt 0 ]
do
        case "$1" in
                -v4ldev) V4LDEV=$2; shift 2;;
                -res) XRES=$2; YRES=$3; shift 3;;
                -fps) FPS=$2; shift 2;;
                -quality) VQUALITY=$2; AQUALITY=$3; shift 3;;
                -outfile) OUTFILE=$2; shift 2;;
                -server) SERVER=$2; shift 2;;
                -port) PORT=$2; shift 2;;
                -mountpoint) MOUNTPOINT=$2; shift 2;;
                -password) PASSWORD=$2; shift 2;;
                *) showhelp; exit;;
        esac
done


if [ "${USESCALE:-0}" -eq 1 ]
then
        scaleparm="video/x-raw-yuv,width=$XCAMERARES,height=$YCAMERARES ! queue ! videoscale !"
else
        scaleparm=""
fi


echo Using mountpoint: "$MOUNTPOINT"

gst-launch v4l2src device="$V4LDEV" ! $scaleparm \
        video/x-raw-yuv,width="$XRES",height="$YRES" ! \
        queue ! \
        videorate ! \
        video/x-raw-yuv,framerate="$FPS" ! \
        tee name=tscreen ! \
                queue ! \
                xvimagesink sync=false tscreen. ! \
        theoraenc quality="$VQUALITY" ! \
        queue ! \
        mux. \
                alsasrc ! \
                audio/x-raw-int,rate=48000,channels=2,depth=16 ! \
                queue ! \
                audioconvert ! \
                queue ! \
                vorbisenc quality="$AQUALITY" ! \
                queue ! \
        mux. oggmux name=mux ! \
        tee name=tfile ! \
                queue ! \
                filesink location="$OUTFILE" tfile. ! \
        queue ! fdsink | oggfwd "$SERVER" "$PORT" "$PASSWORD" "/$MOUNTPOINT"


# This was used instead of fdsink/oggfwd, but has a serious race conditions,
# it stalls when for some reason some frames are lost:
#       shout2send ip="$SERVER" port="$PORT" mount="$MOUNTPOINT" password="$PASSWORD"