play-video.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. SNOWMIX=/usr/local/lib/Snowmix-0.5.1
  3. if [ "X$SNOWMIX_PORT" = X ] ; then export SNOWMIX_PORT=9999 ;fi
  4. if [ "X$SNOWMIX_IP" = X ] ; then export SNOWMIX_IP=127.0.0.1 ;fi
  5. if [ $# -lt 1 ] ; then
  6. echo -e "Missing argument \nUsage $0 <input file>"
  7. exit 1
  8. fi
  9. # Set video feed and audio feed id
  10. feed_id=2
  11. audio_feed_id=2
  12. source="$1"
  13. if [ ! -f "$source" ]; then
  14. echo "'$source' is not a file or whatever"
  15. exit 1
  16. fi
  17. # Check for SNOWMIX variable and the snowmix and gstreamer settings
  18. if [ ! -f "$SNOWMIX/scripts/gstreamer-settings" -o ! -f "$SNOWMIX/scripts/snowmix-settings" ] ; then
  19. echo "Can not find the the file scripts/gstreamer-settings or scripts/snowmix-settings"
  20. echo "in the directory set by the enviroment variable SNOWMIX"
  21. echo "You need to se the environment variable SNOWMIX to the base of the Snowmix installed directory"
  22. exit 1
  23. fi
  24. # Load the Snowmix and GStreamer settings
  25. . $SNOWMIX/scripts/gstreamer-settings
  26. . $SNOWMIX/scripts/snowmix-settings
  27. # This will set
  28. # a) feed_rate
  29. # b) feed_channels
  30. # c) feed_control_pipe
  31. # d) feed_width
  32. # e) feed_height
  33. # f) ctrsocket
  34. # g) system_width
  35. # h) system_height
  36. # i) ratefraction
  37. # j) snowmix
  38. # k) channels
  39. # l) rate
  40. if [ X$feed_control_pipe = X -o X$system_width = X -o X$system_height = X ] ; then
  41. echo Failed to get control pipe or width or height from running snowmix
  42. exit 1
  43. fi
  44. #echo "Snowmix Geometry : $system_width x $system_height"
  45. #echo "Snowmix control socket : $ctrsocket"
  46. echo "Video feed geometry : $feed_width x $feed_height"
  47. echo "Video control socket : $feed_control_pipe"
  48. echo "Video and audio feed id : $feed_id $audio_feed_id"
  49. if [ X$feed_rate = X -o X$feed_channels = X ] ; then
  50. echo Failed to get rate or channels from running snowmix
  51. echo Disabling audio
  52. else
  53. echo "Audio rate and channels : $feed_rate $feed_channels"
  54. fi
  55. SRC="filesrc location=$source ! $decodebin name=decoder ! $VIDEOCONVERT "
  56. SHMSIZE='shm-size='`echo "$feed_width * $feed_height * 4 * 26"|bc`
  57. SHMOPTION="wait-for-connection=1 sync=true"
  58. SHMSINK1="shmsink socket-path=$feed_control_pipe $SHMSIZE $SHMOPTION"
  59. #SCALE="$VIDEOCONVERT ! videoscale ! $VIDEOCONVERT"
  60. SCALE="videoscale ! $VIDEOCONVERT"
  61. AUDIOFORMAT="$AUDIOS16LE"', rate='$feed_rate', channels='$feed_channels
  62. VIDEOFORMAT=$VIDEOBGRA', width='$feed_width', height='$feed_height', framerate='$ratefraction
  63. VIDEOFORMAT=$VIDEOBGRA', width='$feed_width', height='$feed_height
  64. rm -f $feed_control_pipe
  65. if [ X$feed_rate != X -a X$feed_channels != X ] ; then
  66. echo $gstlaunch -q $SRC ! \
  67. videorate ! $SCALE ! $VIDEOFORMAT ! $SHMSINK1 decoder. \
  68. ! queue ! audioconvert ! audioresample ! $AUDIOFORMAT ! fdsink fd=1 sync=true
  69. (
  70. echo 'audio feed ctr isaudio '$audio_feed_id
  71. $gstlaunch -v $SRC ! \
  72. videorate ! $SCALE ! $VIDEOFORMAT ! $SHMSINK1 decoder. \
  73. ! queue ! audioconvert ! audioresample ! $AUDIOFORMAT ! fdsink fd=3 sync=true 3>&1 1>&2
  74. ) | nc $SNOWMIX_IP $SNOWMIX_PORT
  75. else
  76. $gstlaunch -e -q $SRC ! \
  77. $SCALE ! \
  78. $VIDEOFORMAT ! \
  79. $SHMSINK1
  80. $gstlaunch -e -q $SRC ! \
  81. $SCALE ! \
  82. $VIDEOFORMAT ! \
  83. $SHMSINK1
  84. fi