pepoliveserverとは

Raspberry piで動画を配信出来るちょっとしたプログラムです

使い方

Webカメラで約50秒間の動画を配信させる

pepoliveserver /dev/video0 50000

http://Raspberry pi_IP:8090/stat.htmlからswfファイルを選択して動画が見れます

o 2015.7.24 Camera moduleの動画を配信出来るように機能アップした

o 2015.8.2 Camera moduleのパラメータを変更

  1. #!/bin/sh
  2. # pepoliveserver ; liveserver for raspberry pi
  3. # licence GPLv3 ; this scripts designed by Isamu.Yamauchi 2011.11.28 update 2015.8.2
  4. # pepoliveserver dev timer
  5. PATH=$PATH:/usr/local/bin:/usr/local/sbin
  6. WORKDIR=/www/remote-hand/tmp
  7. pid=`echo $$`
  8. prog=pepoliveserver
  9. pidfile=/var/run/${prog}.pid
  10. #CONF=${WORKDIR}/ffserver.conf
  11. LIVEFILE=${WORKDIR}/remote-hand.ffm
  12. #VIDEOPG=ffmpeg
  13. VIDEOPG=avconv
  14. #VIDEOSV=ffserver
  15. VIDEOSV=avserver
  16. RASPICAMERA=/dev/vchiq
  17. RASPIVID=raspivid
  18. CONF=/etc/${VIDEOSV}.conf
  19. TIMER=45000
  20. VIDEOSIZE=320x240
  21. VIDEORATE=1
  22. RATE=1
  23. PEPORASPVIDEO=/usr/local/bin/peporaspvid
  24. if [ $# -lt 1 -o $# -gt 2 ];then
  25. echo "usage: $0 /dev/video0 | timer(seconds)"
  26. exit
  27. fi
  28. DEV=$1
  29. if [ ! -e $DEV ];then
  30. echo $1 not found ;exit
  31. fi
  32. error(){
  33. if [ -e $pidfile ];then
  34. VIDEOPG_PID=`pgrep ${VIDEOPG}` ; [ ! -z ${VIDEOPG_PID} ] && kill -HUP ${VIDEOPG_PID}
  35. VIDEOPG_PID=`pgrep ${RASPIVID}` ; [ ! -z ${VIDEOPG_PID} ] && kill -HUP ${VIDEOPG_PID}
  36. VIDEOSERVER_PID=`pgrep ${VIDEOSV}` ; [ ! -z ${VIDEOSERVER_PID} ] && kill -HUP ${VIDEOSERVER_PID}
  37. rm -f $pidfile
  38. [ -e ${LIVEFILE} ] && rm -f ${LIVEFILE}
  39. fi
  40. exit
  41. }
  42. trap error SIGINT SIGTERM SIGHUP SIGKILL SIGCHLD
  43. if [ -e $pidfile ];then
  44. tpid=`cat $pidfile`
  45. kill -HUP $tpid
  46. msleep 1000
  47. [ -e $pidfile ] && rm -f $pidfile
  48. fi
  49. if [ $DEV = $RASPICAMERA ];then
  50. VIDEOSIZE=640x480
  51. VIDEORATE=10
  52. fi
  53. [ $# = 2 ] && TIMER=$2
  54. MSLEEP=$(($TIMER * 2))
  55. RASPITIMER=$(($TIMER - 0))
  56. if [ ${VIDEOPG} != "ffmpeg" ];then
  57. OPT="-r 1 -vcodec flv"
  58. else
  59. OPT=""
  60. fi
  61. IP=`ip -f inet addr|awk '/inet 192.168/{split($2,I,"/");printf I[1]}'`
  62. [ -e $CONF ] && rm -f $CONF
  63. if [ ! -e $CONF ];then
  64. cat >$CONF<<EOF
  65. # $CONF
  66. ######################################
  67. # This file specifies all the options for streaming
  68. # an avconv produced file as flash
  69. ######################################
  70. Port 8090 # this is the port you have set up for streaming
  71. BindAddress 0.0.0.0
  72. MaxHTTPConnections 10
  73. MaxClients 10
  74. MaxBandwidth 10000
  75. <Feed remote-hand.ffm>
  76. File ${LIVEFILE}
  77. FileMaxSize 2M
  78. </Feed>
  79. # swf output - good for streaming
  80. <Stream remote-hand.swf>
  81. # the source feed
  82. Feed remote-hand.ffm
  83. # the output stream format - FLV = FLash Video
  84. Format swf
  85. # this must match the ffmpeg -r argument
  86. VideoFrameRate $VIDEORATE
  87. # generally leave this is a large number
  88. #VideoBufferSize 2M
  89. # another quality tweak
  90. #VideoBitRate 200
  91. # quality ranges - 1-31 (1 = best, 31 = worst)
  92. VideoQMin 1
  93. VideoQMax 10
  94. #VideoSize 640x480
  95. #VideoSize 320x240
  96. VideoSize $VIDEOSIZE
  97. # this sets how many seconds in past to start
  98. PreRoll 0
  99. # wecams don't have audio
  100. NoAudio
  101. </Stream>
  102. <Stream stat.html>
  103. Format status
  104. </Stream>
  105. <Redirect index.html>
  106. # credits!
  107. URL http://$IP:8090/stat.html
  108. </Redirect>
  109. ################################################################################
  110. #
  111. #URL http://ffmpeg.sourceforge.net/
  112. # ${VIDEOPG} -f video4linux2 -s 320x240 -i $DEV $OPT http://$IP:8090/remote-hand.ffm >/dev/null 2>&1
  113. EOF
  114. fi
  115. if [ $DEV = $RASPICAMERA ];then
  116. VIDEOPG_PID=`pgrep ${RASPIVID}` ; [ ! -z ${VIDEOPG_PID} ] && kill -HUP ${VIDEOPG_PID}
  117. fi
  118. VIDEOPG_PID=`pgrep ${VIDEOPG}` ; [ ! -z ${VIDEOPG_PID} ] && kill -HUP ${VIDEOPG_PID}
  119. VIDEOSERVER_PID=`pgrep ${VIDEOSV}` ; [ ! -z ${VIDEOSERVER_PID} ] && kill -HUP ${VIDEOSERVER_PID}
  120. msleep 100
  121. [ -e $pidfile ] && rm -f $pidfile
  122. echo -n $pid >${pidfile}
  123. [ -e ${LIVEFILE} ] && rm -f ${LIVEFILE}
  124. ${VIDEOSV} -v verbose >/dev/null 2>&1 &
  125. if [ $DEV = $RASPICAMERA ];then
  126. ${RASPIVID} -vf -hf -o - -w 640 -h 480 -t $RASPITIMER -b 500000 -fps 2 | \
  127. ${VIDEOPG} -f h264 -r 2 -i - -vcodec flv http://$IP:8090/remote-hand.ffm >/dev/null 2>&1 &
  128. else
  129. ${VIDEOPG} -f video4linux2 -s 320x240 -i $DEV $OPT http://$IP:8090/remote-hand.ffm >/dev/null 2>&1 &
  130. fi
  131. #msleep $TIMER
  132. MSLEEP=$(($MSLEEP / 100))
  133. while [ $MSLEEP -gt 0 ];do
  134. msleep 100
  135. MSLEEP=$(($MSLEEP - 1))
  136. done
  137. kill -TERM $pid