working-udp-video.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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=24/1'
  54. SRC="udpsrc multicast-group=224.1.1.1 auto-multicast=true port=5000 do-timestamp=true ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 "
  55. SRC="udpsrc multicast-group=192.168.2.255 auto-multicast=true port=5000 do-timestamp=true ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 "
  56. SRC="udpsrc port=5000 do-timestamp=true ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 "
  57. while true ; do
  58. # Remove the named pipe if it exist
  59. rm -f $feed_control_pipe
  60. com="gst-launch-1.0 -v $SRC ! videoconvert ! videorate ! videoscale ! videoconvert ! $VIDEOFORMAT ! queue ! $SHMSINK1"
  61. com="gst-launch-1.0 -v $SRC ! videorate ! videoscale ! videoconvert ! $VIDEOFORMAT ! queue ! $SHMSINK1"
  62. echo "#####################"
  63. echo $com;
  64. echo "#####################"
  65. eval $com
  66. sleep 2
  67. done