working-udp-mjpeg.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #
  3. # IMPORTANT >>>>>You need to get port, ip and feed_id right<<<<<
  4. if [ "X$SNOWMIX" = X ] ; then
  5. echo "You need to set the SNOWMIX environment variable"
  6. exit 1
  7. fi
  8. if [ "X$SNOWMIX_PORT" = X ] ; then export SNOWMIX_PORT=9999 ;fi
  9. if [ "X$SNOWMIX_IP" = X ] ; then export SNOWMIX_IP=127.0.0.1 ;fi
  10. if [ $# -lt 1 ] ; then
  11. echo "Missing argument\nUsage $0 <feed id> [<audio feed id> [<input file>]"
  12. echo "Setting audio feed to 0 disables audio"
  13. exit 1
  14. fi
  15. # Set video feed and audio feed id
  16. feed_id=$1
  17. audio_feed_id=0 #DISABLE AUDIO
  18. # Load the Snowmix and GStreamer settings
  19. . $SNOWMIX/scripts/gstreamer-settings
  20. . $SNOWMIX/scripts/snowmix-settings
  21. # This will set
  22. # a) feed_rate
  23. # b) feed_channels
  24. # c) feed_control_pipe
  25. # d) feed_width
  26. # e) feed_height
  27. # f) ctrsocket
  28. # g) system_width
  29. # h) system_height
  30. # i) ratefraction
  31. # j) snowmix
  32. # k) channels
  33. # l) rate
  34. if [ X$feed_control_pipe = X -o X$system_width = X -o X$system_height = X ] ; then
  35. echo Failed to get control pipe or width or height from running snowmix
  36. exit 1
  37. fi
  38. #echo "Snowmix Geometry : $system_width x $system_height"
  39. #echo "Snowmix control socket : $ctrsocket"
  40. echo "Video feed geometry : $feed_width x $feed_height"
  41. echo "Video control socket : $feed_control_pipe"
  42. echo "Video and audio feed id : $feed_id $audio_feed_id"
  43. if [ X$feed_rate = X -o X$feed_channels = X ] ; then
  44. echo Failed to get rate or channels from running snowmix
  45. echo Disabling audio
  46. else
  47. echo "Audio rate and channels : $feed_rate $feed_channels"
  48. fi
  49. SHMSIZE='shm-size='`echo "$feed_width * $feed_height * 4 * 26"|bc`
  50. SHMOPTION="wait-for-connection=1 sync=true"
  51. SHMSINK1="shmsink socket-path=$feed_control_pipe $SHMSIZE $SHMOPTION"
  52. #AUDIOFORMAT="$AUDIOS16LE"', rate='$feed_rate', channels='$feed_channels
  53. VIDEOFORMAT=$VIDEOBGRA', width='$feed_width', height='$feed_height', framerate=30/1'
  54. SRC="udpsrc port=5002 ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtpjpegdepay ! jpegdec"
  55. #gst-launch-1.0 -v udpsrc port=5002 ! application/x-rtp, payload=96 ! rtpjitterbuffer ! ! videoconvert ! videorate !
  56. #videoscale ! videoconvert ! video/x-raw,format=BGRA,pixel-aspect-ratio=1/1,interlace-mode=progressive, width=800, height=600,
  57. #framerate=30/1 ! queue ! shmsink socket-path=/tmp/feed2-control-pipe shm-size=81788928 wait-for-connection=1 sync=true
  58. while true ; do
  59. # Remove the named pipe if it exist
  60. rm -f $feed_control_pipe
  61. com="gst-launch-1.0 -v $SRC ! videoconvert ! videorate ! videoscale ! videoconvert ! $VIDEOFORMAT ! queue ! $SHMSINK1"
  62. echo "#####################"
  63. echo $com;
  64. echo "#####################"
  65. eval $com
  66. sleep 2
  67. done