Skip to content

Instantly share code, notes, and snippets.

@zwh8800
Created May 19, 2019 16:04
Show Gist options
  • Save zwh8800/cc24373fd21f1762a05dab7ff41b1231 to your computer and use it in GitHub Desktop.
Save zwh8800/cc24373fd21f1762a05dab7ff41b1231 to your computer and use it in GitHub Desktop.
#!/bin/bash
main_list_file="$1"
base_dir="$2"
cd $base_dir
while :
do
dir=`shuf $main_list_file | head -1`
echo 'dir: ' "$dir"
line=`find "$dir" | grep -E 'mkv|mp4' | sort | wc -l`
start=`expr $RANDOM % $line`
end=`expr $line - $start`
list_file="list$3"
echo '' > $list_file
for file in `find "$dir" | grep -E 'mkv|mp4' | sort | tail -n $end`; do
probe_file=$file
echo 'file' $file >> $list_file
done;
for file in `find "$dir" | grep -E 'mkv|mp4' | sort | head -n $start`; do
echo 'file' $file >> $list_file
done;
if ffprobe "$probe_file" 2>&1 | grep -E 'eac3|dts'; then
load=`cat /proc/loadavg | awk '{print $3}'`
if [ `echo "$load > 2" | bc` -eq 1 ]; then
continue
fi
ffmpeg -y -re -f concat -safe 0 -i $list_file -map 0 -c:v copy -c:a aac -sn -f hls -hls_list_size 6 -hls_wrap 10 -hls_time 10 -hls_segment_filename "live$3-%03d.ts" $base_dir/live$3.m3u8
else
ffmpeg -y -re -f concat -safe 0 -i $list_file -map 0 -c copy -sn -f hls -hls_list_size 6 -hls_wrap 10 -hls_time 10 -hls_segment_filename "live$3-%03d.ts" $base_dir/live$3.m3u8
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment