Created
January 12, 2019 22:08
-
-
Save YasienDwieb/72267f6b350a4370e3685c79f9a339a0 to your computer and use it in GitHub Desktop.
split audio files into equal pieces using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ] | |
then | |
echo 'Usage: audiosplitter.sh filename|directory segmenttime' | |
exit | |
fi | |
FILENAME=$1 | |
SEGMENTTIME=$2 | |
if [ -d "${FILENAME}" ]; then | |
for file in `ls $FILENAME`;do | |
NAMEWITHNOEXTENSION=`echo "${file}" | rev | cut -d"." -f2- | rev` | |
OUTPUTFILENAME=`echo $NAMEWITHNOEXTENSION | sed --expression='s/ /_/g'` | |
mkdir $OUTPUTFILENAME | |
ffmpeg -i "$FILENAME/$file" -f segment -segment_time $SEGMENTTIME -c copy $OUTPUTFILENAME/part%03d.mp3 | |
done | |
elif [[ -f $FILENAME ]]; then | |
NAMEWITHNOEXTENSION=`echo $FILENAME | rev | cut -d"." -f2- | rev` | |
OUTPUTFILENAME=`echo $NAMEWITHNOEXTENSION | sed --expression='s/ /_/g'` | |
mkdir $OUTPUTFILENAME | |
ffmpeg -i "$FILENAME" -f segment -segment_time $SEGMENTTIME -c copy $OUTPUTFILENAME/part%03d.mp3 | |
else | |
echo "$PASSED is not valid" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment