40 lines
1.5 KiB
Bash
Executable File
40 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
||
zenity --info --text="Этот скрипт нужен для разделения аудиофайла на части. Нажмите ОК для продолжения..."
|
||
audiofile=$(zenity --file-selection --title="Выберите файл для нарезки на части")
|
||
count=$(zenity --entry --title="Нарезка аудио..." --text="Введите кол-во частей:")
|
||
|
||
if ffmpeg -i "$audiofile" &> /dev/null; then
|
||
zenity --warning --text="Ошибка!"
|
||
exit 1
|
||
fi
|
||
filelen=$(ffmpeg -i "$audiofile" 2>&1 | grep -oE "[0-9]{1}:[0-9]{2}:[0-9]{2}" | tail -n 1)
|
||
IFS=':' read -ra filelen <<< "$filelen"
|
||
lenseconds=${filelen[2]}
|
||
lenminutes=${filelen[1]}
|
||
lenhours=${filelen[0]}
|
||
filelen=$((lenseconds+(lenminutes*60)+(lenhours*60*60)))
|
||
outfile=${audiofile%.*}
|
||
segmentsize=$((filelen/count))
|
||
echo File length at seconds: $filelen
|
||
percent=0
|
||
i=0
|
||
mkdir -p "$(dirname "$outfile")/ffmpeg-out"
|
||
(
|
||
while [ $i -le $((count-1)) ]; do
|
||
starttime=$((segmentsize*i))
|
||
stoptime=$(((segmentsize*(i+1))+1))
|
||
outfiledir="$(dirname "$outfile")/ffmpeg-out/$(basename "$outfile")"
|
||
outname="$outfiledir-$i-ffmpeg.mp3"
|
||
# echo File of script: $outname $starttime-$stoptime sec
|
||
ffmpeg -y -i "$audiofile" -vn -acodec copy -ss $starttime -to $stoptime "$outname" &> /dev/null
|
||
i=$((i+1))
|
||
percent=$(( (i+1)*(100/count) ))
|
||
echo $percent
|
||
done
|
||
exit 0
|
||
) |
|
||
zenity --progress \
|
||
--title="Кодирование..." \
|
||
--text="Кодировано из 100%" \
|
||
--percentage=0
|