Skip to content

Instantly share code, notes, and snippets.

@YasienDwieb
Created January 12, 2019 22:08
Show Gist options
  • Save YasienDwieb/72267f6b350a4370e3685c79f9a339a0 to your computer and use it in GitHub Desktop.
Save YasienDwieb/72267f6b350a4370e3685c79f9a339a0 to your computer and use it in GitHub Desktop.
split audio files into equal pieces using ffmpeg
#!/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