work in /tmp ~/live (ramdisk), now ffmpeg records with sound
This commit is contained in:
parent
ac5077f25d
commit
d1216d44ee
|
@ -12,19 +12,19 @@ IPFS_GATEWAY="http://127.0.0.1:8181"
|
||||||
|
|
||||||
function startFFmpeg() {
|
function startFFmpeg() {
|
||||||
while true; do
|
while true; do
|
||||||
mv ~/ffmpeg.log ~/ffmpeg.1
|
mv /tmp/ffmpeg.log /tmp/ffmpeg.1
|
||||||
echo 1 > ~/stream-reset
|
echo 1 > /tmp/stream-reset
|
||||||
|
|
||||||
# Stream WebCamera
|
# 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
|
## MORE SOURCES
|
||||||
# http://4youngpadawans.com/stream-camera-video-and-audio-with-ffmpeg/
|
# 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 ?
|
################ GOOD ?
|
||||||
# Stream FM Station from a SDR module (see contrib/pi-stream to install drivers)
|
# Stream FM Station from a SDR module (see contrib/pi-stream to install drivers)
|
||||||
# Frequency ends in M IE 99.9M
|
# 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
|
sleep 0.5
|
||||||
done
|
done
|
||||||
|
@ -73,35 +73,35 @@ while true; do
|
||||||
timecode="${HLS_TIME}.000000"
|
timecode="${HLS_TIME}.000000"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reset_stream=$(cat ~/stream-reset)
|
reset_stream=$(cat /tmp/stream-reset)
|
||||||
reset_stream_marker=''
|
reset_stream_marker=''
|
||||||
if [[ ${reset_stream} -eq '1' ]]; then
|
if [[ ${reset_stream} -eq '1' ]]; then
|
||||||
reset_stream_marker=" #EXT-X-DISCONTINUITY"
|
reset_stream_marker=" #EXT-X-DISCONTINUITY"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo 0 > ~/stream-reset
|
echo 0 > /tmp/stream-reset
|
||||||
# Current UTC date for the log
|
# Current UTC date for the log
|
||||||
time=$(date "+%F-%H-%M-%S")
|
time=$(date "+%F-%H-%M-%S")
|
||||||
|
|
||||||
echo "Add ts file to IPFS"
|
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
|
attempts=5
|
||||||
until [[ ${ret} -eq 0 || ${attempts} -eq 0 ]]; do
|
until [[ ${ret} -eq 0 || ${attempts} -eq 0 ]]; do
|
||||||
# Wait and retry
|
# Wait and retry
|
||||||
sleep 0.5
|
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"
|
echo "$attempts RETRY"
|
||||||
attempts=$((attempts-1))
|
attempts=$((attempts-1))
|
||||||
done
|
done
|
||||||
if [[ ${ret} -eq 0 ]]; then
|
if [[ ${ret} -eq 0 ]]; then
|
||||||
# Update the log with the future name (hash already there)
|
# 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
|
# 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
|
# 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
|
sequence=0
|
||||||
if ((totalLines>M3U8_SIZE)); then
|
if ((totalLines>M3U8_SIZE)); then
|
||||||
|
@ -113,7 +113,7 @@ while true; do
|
||||||
echo "#EXT-X-TARGETDURATION:${HLS_TIME}"
|
echo "#EXT-X-TARGETDURATION:${HLS_TIME}"
|
||||||
echo "#EXT-X-MEDIA-SEQUENCE:${sequence}"
|
echo "#EXT-X-MEDIA-SEQUENCE:${sequence}"
|
||||||
} > current.m3u8
|
} > 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'
|
echo 'Add m3u8 file to IPFS and IPNS publish'
|
||||||
m3u8hash=$(ipfs add current.m3u8 | awk '{print $2}')
|
m3u8hash=$(ipfs add current.m3u8 | awk '{print $2}')
|
||||||
|
@ -121,7 +121,7 @@ while true; do
|
||||||
|
|
||||||
# Copy files to web server
|
# Copy files to web server
|
||||||
cp current.m3u8 /var/www/html/live.m3u8
|
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
|
fi
|
||||||
else
|
else
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
Loading…
Reference in New Issue