Created
April 5, 2023 09:59
-
-
Save J0J0/540700cf43eb31ad6bd930d73cfc2c59 to your computer and use it in GitHub Desktop.
Script to join many mp3 files into fewer ones (without re-encoding)
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/zsh | |
# first argument: number of files to join into new one, default 5 | |
num=${1:-5} | |
tmpdir=$(mktemp --directory) | |
outdir=$(date +"%Y-%m-%d_%H-%M") | |
mkdir $outdir | |
ls > $tmpdir/files | |
( | |
cd $tmpdir | |
split --lines=$num files | |
{ | |
print "#!/bin/zsh" | |
print "out=$outdir" | |
} > ff | |
cat >> ff <<-'FOOBAR' | |
(( $ARGC == 1 )) || { exit 1; } | |
ffmpeg -loglevel quiet -i "concat:${(j:|:)${(f)$(cat $1)}}" -acodec copy "$out/$(basename $1).mp3" | |
FOOBAR | |
chmod u+x ff | |
) | |
parallel -j 4 $tmpdir/ff '{}' ::: $tmpdir/x* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notable prerequisites:
Usage:
will take groups of 10 files from the current directory and join them into new files to be put in a subdirectory of the original one (i.e. if there were 300 files before, it will be 30 afterwards in this example).
Notes:
ls -v
instead to sort numbers naturally, i.e. 1,2,10 instead of 1,10,2.