stream.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. vbitrate=4000
  3. vbitrate=1000
  4. abitrate=128000
  5. feed_id=1
  6. audio_feed_id=1
  7. audio_sink_id=1
  8. . $SNOWMIX/scripts/gstreamer-settings
  9. . $SNOWMIX/scripts/snowmix-settings
  10. width=$feed_width
  11. height=$feed_height
  12. framerate=$(echo "$framerate" | cut -f 1 -d.) #this is getting populated with 25.000 which x264enc doesn't like
  13. audiorate=$feed_rate
  14. channels=$feed_channels
  15. #width=1024
  16. #height=768
  17. #framerate=25
  18. #audiorate=48000
  19. #channels=2
  20. ###################### Settings ########################
  21. ########################################################
  22. # THe following settings should not be changed
  23. h264_level=4.1
  24. h264_profile=high
  25. h264_bframes=0
  26. keyint=$(echo "2 * $framerate" |bc)
  27. VIDEOCONVERT="videoconvert"
  28. #VIDEOCONVERT="video/x-raw, width=800, height=600 ! videoconvert"
  29. # VIDEO=video/x-raw-yuv
  30. afid="format=(string)S16LE, "
  31. ENCAUDIOFORMAT='aacparse ! audio/mpeg,mpegversion=4,stream-format=raw'
  32. videoencoder="x264enc bitrate=$vbitrate key-int-max=$keyint bframes=$h264_bframes byte-stream=false aud=true" #speed-preset=1"
  33. videoencoder="x264enc bitrate=$vbitrate key-int-max=$keyint bframes=$h264_bframes byte-stream=false aud=true speed-preset=4"
  34. videoencoder="x264enc bitrate=$vbitrate key-int-max=$keyint bframes=$h264_bframes byte-stream=false aud=true speed-preset=4"
  35. #default=6=medium, 5=fast, 4=faster...0=none
  36. audioencoder="faac bitrate=$abitrate"
  37. audioencoder="voaacenc bitrate=$abitrate" #FIXME I changed faac to voaacenc as faac is not on my machine
  38. serverurl='rtmp://curso.especificosba.com.ar/src/movie'
  39. serverurl='rtmp://localhost/rpi/movie'
  40. serverurl='rtmp://localhost/rpi2/movie'
  41. location=$serverurl
  42. framerate="$framerate/1" #Fraction
  43. ENCVIDEOFORMAT='h264parse ! video/x-h264,level=(string)'$h264_level',profile='$h264_profile
  44. ENCVIDEOFORMAT="h264parse ! video/x-h264,level=(string)$h264_level,profile=$h264_profile"
  45. VIDEO='video/x-raw, format=(string)BGRA, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive'
  46. VIDEOFORMAT=$VIDEO', framerate='$framerate', width='$width', height='$height
  47. AUDIO=audio/x-raw
  48. AUDIOFORMAT=$AUDIO', '$afid' endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)'$audiorate', channels=(int)'$channels
  49. # ctrsocket must match system socket in running Snowmix
  50. ctrsocket=/tmp/mixer1
  51. # audiosink must match audio sink in running Snowmix
  52. audiosink=1
  53. VIDEOSRC='shmsrc socket-path='$ctrsocket' do-timestamp=true is-live=true'
  54. AUDIOSRC="fdsrc fd=0 do-timestamp=true"
  55. ( echo "audio sink ctr isaudio $audiosink" ; sleep 100000000 ) | \
  56. /bin/nc 127.0.0.1 9999 | \
  57. (head -1
  58. gst-launch-1.0 -v \
  59. $VIDEOSRC !\
  60. $VIDEOFORMAT !\
  61. queue !\
  62. $VIDEOCONVERT !\
  63. $videoencoder !\
  64. $ENCVIDEOFORMAT !\
  65. queue !\
  66. mux. $AUDIOSRC !\
  67. $AUDIOFORMAT !\
  68. queue !\
  69. $audioencoder !\
  70. $ENCAUDIOFORMAT !\
  71. queue !\
  72. flvmux streamable=true name=mux !\
  73. queue !\
  74. rtmpsink location="$location"
  75. )
  76. exit