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.

Revisions

  1. YasienDwieb created this gist Jan 12, 2019.
    26 changes: 26 additions & 0 deletions audio_splitter.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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