diff --git a/zen/stream/process-stream.sh b/zen/stream/process-stream.sh index 12a8bc2..b208d5b 100755 --- a/zen/stream/process-stream.sh +++ b/zen/stream/process-stream.sh @@ -12,19 +12,19 @@ IPFS_GATEWAY="http://127.0.0.1:8181" function startFFmpeg() { while true; do - mv ~/ffmpeg.log ~/ffmpeg.1 - echo 1 > ~/stream-reset + mv /tmp/ffmpeg.log /tmp/ffmpeg.1 + echo 1 > /tmp/stream-reset # Stream WebCamera - ffmpeg -f video4linux2 -video_size 1280x720 -framerate 30 -i /dev/video0 -f alsa -i hw:0 -hls_time "${HLS_TIME}" "${what}.m3u8" > ~/ffmpeg.log 2>&1 + ffmpeg -f pulse -i 1 -f video4linux2 -video_size 1280x720 -framerate 30 -i /dev/video0 -hls_time "${HLS_TIME}" "${what}.m3u8" > /tmp/ffmpeg.log 2>&1 ## MORE SOURCES # http://4youngpadawans.com/stream-camera-video-and-audio-with-ffmpeg/ - ## STILL BAD :: ffmpeg -f v4l2 -i /dev/video0 -f alsa -i hw:0 -profile:v high -pix_fmt yuvj420p -level:v 4.1 -preset ultrafast -tune zerolatency -vcodec libx264 -r 10 -b:v 512k -s 640x360 -acodec aac -strict -2 -ac 2 -ab 32k -ar 44100 -f mpegts -flush_packets 0 -hls_time "${HLS_TIME}" "${what}.m3u8" > ~/ffmpeg.log 2>&1 + ## STILL BAD :: ffmpeg -f v4l2 -i /dev/video0 -f alsa -i hw:0 -profile:v high -pix_fmt yuvj420p -level:v 4.1 -preset ultrafast -tune zerolatency -vcodec libx264 -r 10 -b:v 512k -s 640x360 -acodec aac -strict -2 -ac 2 -ab 32k -ar 44100 -f mpegts -flush_packets 0 -hls_time "${HLS_TIME}" "${what}.m3u8" > /tmp/ffmpeg.log 2>&1 ################ GOOD ? # Stream FM Station from a SDR module (see contrib/pi-stream to install drivers) # Frequency ends in M IE 99.9M - # rtl_fm -f 99.9M -M fm -s 170k -A std -l0 -E deemp -r 44.1k | ffmpeg -r 15 -loop 1 -i ../audio.jpg -f s16le -ac 1 -i pipe:0 -c:v libx264 -tune stillimage -preset ultrafast -hls_time "${HLS_TIME}" "${what}.m3u8" > ~/ffmpeg 2>&1 + # rtl_fm -f 99.9M -M fm -s 170k -A std -l0 -E deemp -r 44.1k | ffmpeg -r 15 -loop 1 -i ../audio.jpg -f s16le -ac 1 -i pipe:0 -c:v libx264 -tune stillimage -preset ultrafast -hls_time "${HLS_TIME}" "${what}.m3u8" > /tmp/ffmpeg 2>&1 sleep 0.5 done @@ -73,35 +73,35 @@ while true; do timecode="${HLS_TIME}.000000" fi - reset_stream=$(cat ~/stream-reset) + reset_stream=$(cat /tmp/stream-reset) reset_stream_marker='' if [[ ${reset_stream} -eq '1' ]]; then reset_stream_marker=" #EXT-X-DISCONTINUITY" fi - echo 0 > ~/stream-reset + echo 0 > /tmp/stream-reset # Current UTC date for the log time=$(date "+%F-%H-%M-%S") echo "Add ts file to IPFS" - ret=$(ipfs add --pin=false "${nextfile}" 2>/dev/null > ~/tmp.txt; echo $?) + ret=$(ipfs add --pin=false "${nextfile}" 2>/dev/null > /tmp/tmp.txt; echo $?) attempts=5 until [[ ${ret} -eq 0 || ${attempts} -eq 0 ]]; do # Wait and retry sleep 0.5 - ret=$(ipfs add --pin=false "${nextfile}" 2>/dev/null > ~/tmp.txt; echo $?) + ret=$(ipfs add --pin=false "${nextfile}" 2>/dev/null > /tmp/tmp.txt; echo $?) echo "$attempts RETRY" attempts=$((attempts-1)) done if [[ ${ret} -eq 0 ]]; then # Update the log with the future name (hash already there) - echo "$(cat ~/tmp.txt) ${time}.ts ${timecode}${reset_stream_marker}" >> ~/process-stream.log + echo "$(cat /tmp/tmp.txt) ${time}.ts ${timecode}${reset_stream_marker}" >> /tmp/process-stream.log # Remove nextfile and tmp.txt - rm -f "${nextfile}" ~/tmp.txt + rm -f "${nextfile}" /tmp/tmp.txt # Write the m3u8 file with the new IPFS hashes from the log - totalLines="$(wc -l ~/process-stream.log | awk '{print $1}')" + totalLines="$(wc -l /tmp/process-stream.log | awk '{print $1}')" sequence=0 if ((totalLines>M3U8_SIZE)); then @@ -113,7 +113,7 @@ while true; do echo "#EXT-X-TARGETDURATION:${HLS_TIME}" echo "#EXT-X-MEDIA-SEQUENCE:${sequence}" } > current.m3u8 - tail -n ${M3U8_SIZE} ~/process-stream.log | awk '{print $6"#EXTINF:"$5",\n'${IPFS_GATEWAY}'/ipfs/"$2}' | sed 's/#EXT-X-DISCONTINUITY#/#EXT-X-DISCONTINUITY\n#/g' >> current.m3u8 + tail -n ${M3U8_SIZE} /tmp/process-stream.log | awk '{print $6"#EXTINF:"$5",\n'${IPFS_GATEWAY}'/ipfs/"$2}' | sed 's/#EXT-X-DISCONTINUITY#/#EXT-X-DISCONTINUITY\n#/g' >> current.m3u8 echo 'Add m3u8 file to IPFS and IPNS publish' m3u8hash=$(ipfs add current.m3u8 | awk '{print $2}') @@ -121,7 +121,7 @@ while true; do # Copy files to web server cp current.m3u8 /var/www/html/live.m3u8 - cp ~/process-stream.log /var/www/html/live.log + cp /tmp/process-stream.log /var/www/html/live.log fi else sleep 5