Re: How to split one huge music file by detecting silence in ffmpeg
Reply #1 – 2022-12-30 09:27:20
I have this little bash thing stored which could be turned into real bash script with some workawk_round () { awk 'BEGIN{printf "%."'$1'"f\n", "'$2'"}' } round () { ssvar="$(awk_round "5" "$ssvar")" tovar="$(awk_round "5" "$tovar")" } c="1" quiet=(-hide_banner -loglevel info -nostats -nostdin) cat detect.log | while read _ ssvar; read _ tovar; do #pad name printf -v name "%03d" "$c" # action echo; echo "-ss $ssvar -to $tovar" echo "--------------------------------------" if [ -z "$tovar" ]; then round && ffmpeg "${quiet[@]}" -i "${input}" -ss "$ssvar" -c:a copy "${name}".m4a else round && ffmpeg "${quiet[@]}" -i "${input}" -ss "$ssvar" -to "$tovar" -c:a copy "${name}".m4a fi (( c++ )) done This is what chatgpt thinks about this snippet:This script appears to be using awk and ffmpeg to process a file called detect.log and extract pairs of values (ssvar and tovar). It then rounds these values to 5 decimal places using the round function, which calls the awk_round function. The awk_round function takes two arguments: the number of decimal places to round to, and the value to round. It then uses awk to print the rounded value with the specified number of decimal places. The script then reads the input file detect.log line by line, using the read command in a while loop. For each line, it extracts the two values (ssvar and tovar) and rounds them to 5 decimal places using the round function. Next, the script increments a counter (c) and formats it as a three-digit number with leading zeros (e.g. 001, 002, etc.). It then uses ffmpeg to process the input file input, using the -ss and -to options to specify the start and end times of the output file. The output file is named using the formatted counter value, with a .m4a extension. If tovar is not set, then ffmpeg will only use the -ss option and process the input file from the specified start time until the end. The -c:a option specifies that the audio stream should be copied to the output file without any further processing.