Created
March 30, 2017 08:54
-
-
Save jakobkogler/0a7c5369bb4ac0dee9171aa3c404c7a8 to your computer and use it in GitHub Desktop.
Splits an mp3 file into multiple smaller ones
This file contains hidden or 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 | |
FILEPATH=$1 | |
FILENAME=$(echo "$FILEPATH" | sed 's/\..*//') | |
LENGTH=$2 | |
DURATION=$(ffmpeg -i $FILEPATH 2>&1 | grep Duration | sed 's/Duration: \(.*\), start.*/\1/g') | |
DURATION=$(echo $DURATION | awk -F: '{ print ($1 * 60) + $2 }') | |
PARTS=$(((DURATION + LENGTH - 1) / LENGTH)) | |
for NUMLEADING in $(seq -w 1 $PARTS); do | |
NUM=$(echo "$NUMLEADING" | sed 's/^0*//') | |
START=$(((NUM - 1) * LENGTH)) | |
START_H=$((START / 60)) | |
START_M=$((START % 60)) | |
LENGTH_H=$((LENGTH / 60)) | |
LENGTH_M=$((LENGTH % 60)) | |
ffmpeg -i $FILEPATH -vn -acodec copy -ss $START_H:$START_M:00 -t $LENGTH_H:$LENGTH_M:00 $FILENAME$NUMLEADING.mp3 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment