Search Posts

sox and ffmpeg (convert hls into live hls) usage

These are the basic usage of SOX

# Create background noise profile from mp3
/usr/bin/sox noise.mp3 -n noiseprof noise.prof
 
# Remove noise from mp3 using profile
/usr/bin/sox input.mp3 output.mp3 noisered noise.prof 0.21
 
# Remove silence from mp3
/usr/bin/sox input.mp3 output.mp3 silence -l 1 0.3 5% -1 2.0 5%
 
# Remove noise and silence in a single command
/usr/bin/sox input.mp3 output.mp3 noisered noise.prof 0.21 silence -l 1 0.3 5% -1 2.0 5%
 
# Batch process files
/usr/bin/find . -type f -name "*.mp3" -mmin +30 -exec sox -S --multi-threaded -buffer 131072 {} /path/to/output/{} noisered noise.prof 0.21 silence -l 1 0.3 5% -1 2.0 5% \;
 
# Remove insignificant files
/usr/bin/find . -type f -name "*.mp3" -mmin +30 -size -500k -delete

This script will convert ffmpeg HLS into “live streaming HLS”

#!/bin/bash

x=0
while true; do
	#cat out.m3u8|sed 's/YES/NO/' | sed 's/#EXT-X-ENDLIST//'> temp
	line=`wc -l out.m3u8|awk '{print $1}'`
	line=$(($line-5))
	line=$(($line/2))
	echo $line

	head -5 out.m3u8 |sed 's/YES/NO/' | sed 's/#EXT-X-ENDLIST//' | sed "s/#EXT-X-MEDIA-SEQUENCE:0/#EXT-X-MEDIA-SEQUENCE:$line/" > temp
	#echo "#EXTM3U">temp
	#echo "#EXT-X-VERSION:3">>temp;
	#echo "#EXT-X-TARGETDURATION:2">>temp;
	#echo "#EXT-X-MEDIA-SEQUENCE:$x">>temp;
	tail -16 out.m3u8 >> temp;
	#echo "#EXTINF:1,">>temp;
	#echo "dummy.mp3">>temp;

	tail -8 out.m3u8 | grep mp3 | while read a; do
		sox $a c$a noisered noise.prof 0.21
	done	

	sed -i 's/a0/ca0/' temp

	mv temp out2.m3u8
	x=$(($x+1))
	#sleep 2
done

The above script has to run with ffmpeg:
/root/download/ffmpeg-2.1.4/ffmpeg -f alsa -ac 2 -i hw:0,0 -strict experimental -acodec libmp3lame -map 0 -f segment -segment_list out.m3u8 -segment_format libmp3lame -segment_time 0.5 -segment_list_flags +live ‘a%05d.mp3’

Leave a Reply

Your email address will not be published. Required fields are marked *