Bladeren bron

2new scripts

David 10 jaren geleden
bovenliggende
commit
e87686e691
2 gewijzigde bestanden met toevoegingen van 197 en 0 verwijderingen
  1. 99 0
      server/play-video.sh
  2. 98 0
      server/streamp2p.sh

+ 99 - 0
server/play-video.sh

@@ -0,0 +1,99 @@
+#!/bin/bash
+
+SNOWMIX=/usr/local/lib/Snowmix-0.5.1
+
+if [ "X$SNOWMIX_PORT" = X ] ; then export SNOWMIX_PORT=9999 ;fi
+if [ "X$SNOWMIX_IP" = X ] ; then export SNOWMIX_IP=127.0.0.1 ;fi
+
+if [ $# -lt 1 ] ; then
+  echo -e "Missing argument \nUsage $0 <input file>"
+  exit 1
+fi
+
+# Set video feed and audio feed id
+feed_id=2
+audio_feed_id=2
+source="$1"
+
+if [ ! -f "$source" ]; then
+	echo "'$source' is not a file or whatever"
+	exit 1
+fi
+
+# Check for SNOWMIX variable and the snowmix and gstreamer settings
+if [ ! -f "$SNOWMIX/scripts/gstreamer-settings" -o ! -f "$SNOWMIX/scripts/snowmix-settings" ] ; then
+  echo "Can not find the the file scripts/gstreamer-settings or scripts/snowmix-settings"
+  echo "in the directory set by the enviroment variable SNOWMIX"
+  echo "You need to se the environment variable SNOWMIX to the base of the Snowmix installed directory"
+  exit 1
+fi
+
+# Load the Snowmix and GStreamer settings
+. $SNOWMIX/scripts/gstreamer-settings
+. $SNOWMIX/scripts/snowmix-settings
+# This will set
+# a) feed_rate
+# b) feed_channels
+# c) feed_control_pipe
+# d) feed_width
+# e) feed_height
+# f) ctrsocket
+# g) system_width
+# h) system_height
+# i) ratefraction
+# j) snowmix
+# k) channels
+# l) rate
+
+
+if [ X$feed_control_pipe = X -o X$system_width = X -o X$system_height = X ] ; then
+  echo Failed to get control pipe or width or height from running snowmix
+  exit 1
+fi
+
+#echo "Snowmix Geometry        : $system_width x $system_height"
+#echo "Snowmix control socket  : $ctrsocket"
+echo "Video feed geometry     : $feed_width x $feed_height"
+echo "Video control socket    : $feed_control_pipe"
+echo "Video and audio feed id : $feed_id $audio_feed_id"
+
+if [ X$feed_rate = X -o X$feed_channels = X ] ; then
+  echo Failed to get rate or channels from running snowmix
+  echo Disabling audio
+else
+  echo "Audio rate and channels : $feed_rate $feed_channels"
+fi
+
+
+SRC="filesrc location=$source ! $decodebin name=decoder ! $VIDEOCONVERT "
+SHMSIZE='shm-size='`echo "$feed_width * $feed_height * 4 * 26"|bc`
+SHMOPTION="wait-for-connection=1 sync=true"
+SHMSINK1="shmsink socket-path=$feed_control_pipe $SHMSIZE $SHMOPTION"
+#SCALE="$VIDEOCONVERT ! videoscale ! $VIDEOCONVERT"
+SCALE="videoscale ! $VIDEOCONVERT"
+AUDIOFORMAT="$AUDIOS16LE"', rate='$feed_rate', channels='$feed_channels
+VIDEOFORMAT=$VIDEOBGRA', width='$feed_width', height='$feed_height', framerate='$ratefraction
+VIDEOFORMAT=$VIDEOBGRA', width='$feed_width', height='$feed_height
+
+rm -f $feed_control_pipe
+
+if [ X$feed_rate != X -a X$feed_channels != X ] ; then
+	echo $gstlaunch -q $SRC ! \
+	videorate ! $SCALE ! $VIDEOFORMAT ! $SHMSINK1 decoder. \
+	! queue ! audioconvert ! audioresample ! $AUDIOFORMAT ! fdsink fd=1 sync=true
+	  (
+	echo 'audio feed ctr isaudio '$audio_feed_id
+	$gstlaunch -v $SRC ! \
+	videorate ! $SCALE ! $VIDEOFORMAT ! $SHMSINK1 decoder. \
+	! queue ! audioconvert ! audioresample ! $AUDIOFORMAT ! fdsink fd=3 sync=true 3>&1 1>&2
+	  ) | nc $SNOWMIX_IP $SNOWMIX_PORT
+else
+	$gstlaunch -e -q $SRC ! \
+	  $SCALE		! \
+	  $VIDEOFORMAT	! \
+	  $SHMSINK1 
+	$gstlaunch -e -q $SRC ! \
+	  $SCALE		! \
+	  $VIDEOFORMAT	! \
+	  $SHMSINK1 
+fi

+ 98 - 0
server/streamp2p.sh

@@ -0,0 +1,98 @@
+#!/bin/bash
+
+SNOWMIX=/usr/local/lib/Snowmix-0.5.1
+vbitrate=4000
+vbitrate=1000
+vbitrate=700
+
+abitrate=64000
+
+feed_id=1
+audio_feed_id=1
+audio_sink_id=1
+
+. $SNOWMIX/scripts/gstreamer-settings
+. $SNOWMIX/scripts/snowmix-settings
+
+width=$feed_width
+height=$feed_height
+framerate=$(echo "$framerate" | cut -f 1 -d.) #this is getting populated with 25.000 which x264enc doesn't like
+audiorate=$feed_rate
+channels=$feed_channels
+
+#width=1024
+#height=768
+#framerate=25
+#audiorate=48000
+#channels=2
+
+###################### Settings ########################
+########################################################
+# THe following settings should not be changed
+h264_level=4.1
+h264_profile=high
+h264_bframes=0
+keyint=$(echo "2 * $framerate" |bc)
+
+
+VIDEOCONVERT="videoconvert"
+#VIDEOCONVERT="video/x-raw, width=800, height=600 ! videoconvert"
+# VIDEO=video/x-raw-yuv
+afid="format=(string)S16LE, "
+
+ENCAUDIOFORMAT='aacparse ! audio/mpeg,mpegversion=4,stream-format=raw'
+videoencoder="x264enc bitrate=$vbitrate key-int-max=$keyint bframes=$h264_bframes byte-stream=false aud=true" #speed-preset=1"
+videoencoder="x264enc bitrate=$vbitrate key-int-max=$keyint bframes=$h264_bframes byte-stream=false aud=true speed-preset=4"
+videoencoder="x264enc bitrate=$vbitrate key-int-max=$keyint bframes=$h264_bframes byte-stream=false aud=true speed-preset=4"
+#default=6=medium, 5=fast, 4=faster...0=none
+
+audioencoder="faac bitrate=$abitrate"
+audioencoder="voaacenc bitrate=$abitrate" #FIXME I changed faac to voaacenc as faac is not on my machine
+
+serverurl='rtmp://curso.especificosba.com.ar/src/movie'
+serverurl='rtmp://localhost/rpi/movie'
+serverurl='rtmp://localhost/rpi2/movie'
+
+location=$serverurl
+framerate="$framerate/1" #Fraction
+
+ENCVIDEOFORMAT='h264parse ! video/x-h264,level=(string)'$h264_level',profile='$h264_profile
+ENCVIDEOFORMAT="h264parse ! video/x-h264,level=(string)$h264_level,profile=$h264_profile"
+
+
+VIDEO='video/x-raw, format=(string)BGRA, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive'
+VIDEOFORMAT=$VIDEO', framerate='$framerate', width='$width', height='$height
+
+AUDIO=audio/x-raw
+AUDIOFORMAT=$AUDIO', '$afid' endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)'$audiorate', channels=(int)'$channels
+
+# ctrsocket must match system socket in running Snowmix
+ctrsocket=/tmp/mixer1
+# audiosink must match audio sink in running Snowmix
+audiosink=1
+VIDEOSRC='shmsrc socket-path='$ctrsocket' do-timestamp=true is-live=true'
+AUDIOSRC="fdsrc fd=0 do-timestamp=true"
+
+
+( echo "audio sink ctr isaudio $audiosink" ; sleep 100000000 ) | \
+    /bin/nc 127.0.0.1 9999      | \
+    (head -1
+     gst-launch-1.0 -q -e                               \
+            $VIDEOSRC                               !\
+            $VIDEOFORMAT                            !\
+            queue                                   !\
+            $VIDEOCONVERT                           !\
+            $videoencoder                           !\
+            $ENCVIDEOFORMAT                         !\
+            queue                                   !\
+            mux. $AUDIOSRC                          !\
+            $AUDIOFORMAT                            !\
+            queue                                   !\
+            $audioencoder                           !\
+            $ENCAUDIOFORMAT                         !\
+            queue                                   !\
+            flvmux streamable=true name=mux         !\
+            queue                                   !\
+			fdsink
+    )
+exit