stream.sh 3.8 KB

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