Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Last active March 25, 2020 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan2904/5e6ab738a2c26a924cbe7e7067ec0bbf to your computer and use it in GitHub Desktop.
Save stefan2904/5e6ab738a2c26a924cbe7e7067ec0bbf to your computer and use it in GitHub Desktop.
Splitting an audio file into chunks of a specified length
#!/bin/bash
# sudo apt install zenity ffmpeg
error() {
zenity --error --text "Fehler: $1" --title "Fehler" --ellipsize
exit
}
info() {
zenity --question --text "$1" --ellipsize
}
OUTDIR=`pwd`
if ! FILENAME=$(zenity --file-selection --title "Audiodatei auswählen" --file-filter "*.wav *.mp3 *.wma *.WMA *.MP3 *.WAV"); then
error "Keine Datei ausgewählt ..."
fi
FN=$(basename -- "$FILENAME")
EXT="${FN##*.}"
FILE="${FN%.*}"
if ! MINUTES=$(zenity --scale --text "Wieviele Minuten pro Teil?" --step 1 --max-value 30 --min-value 1 --value 5); then
error "Keine Minuten ausgewählt ..."
fi
SEC=$(((60*MINUTES)-10))
INFO="
<b>Datei:</b> $FILENAME
<b>Länge:</b> $MINUTES Minuten pro Teil
<b>Ziel:</b> $OUTDIR/${FILE}_000.mp3
Passt so?
"
if ! info "$INFO"; then
echo "abgebrochen ..."
exit
fi
ffmpeg -i "$FILENAME" -codec:a libmp3lame -qscale:a 4 "${FILE}.mp3" |
zenity --progress --title="Please wait (step 1/2)" --text="Converting to MP3 in progress ..." --no-cancel --auto-close --pulsate
# via https://superuser.com/a/525217
ffmpeg -i "${FILE}.mp3" -f segment -segment_time $SEC -c copy "${FILE}_%03d.mp3" |
zenity --progress --title="Please wait (step 2/2)" --text="Cutting in progress ..." --no-cancel --auto-close --pulsate
echo "DONE! cut ${FILE}.mp3"
echo "into $SEC seconds long pieces"
# rm "${FILE}.mp3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment