got an insanely simple and working script already:
#!/bin/bash -x mkdir .before mkdir .error for i in *.m??; do ffmpeg -n -i "$i" -b:a 16k "${i%.*}.opus" && mv "$i" .before/ mv "$i" .error/ done echo zzz finished $TITLE | termux-notification termux-vibrate -f
of course the important command is just
ffmpeg
there, but just keep in mind my context, please. termux. android only. simplicity… and immensely reducing my music collection size!everything works fine with this…
except for my minor issue of the week:
the album art is lost!
there are many questions in sen dealing with this, and different reasons why (apparently all related to how ogg and opus containers work) it’s actually way more complicated than it may appear at first sight.
the only proclaimed solution i could find so far is a script from 2014 which doesn’t handle opus:
https://superuser.com/a/706808/28411
can you help me keeping this simple?
or else, i will just output it to a image file of same name and deal with it another year. 😒
edit: How can I copy coverart from flac to opus with ffmpeg doesn’t really answer the question. it solves the album, but i can’t find a configuration with
opusenc
which keeps the file at 10%. setting the same bitrate (16k) gets it to 20% at best.
Answer
this is what i’m using effectively now:
#!/bin/bash -x
# use this for big folders
# mkdir .before; mkdir .error
for i in *.m??; do
# main activity: compress mp3 down to 10%, with reduced album art!
ffmpeg -hide_banner -y -i "$i" -c:v mjpeg -vsync 2 -vf scale=320:-1 -f flac - | opusenc - --bitrate 16 --music --framesize 40 "${i%.*}.opus" && mv "$i" .before/
# some times opusenc don't work
ffmpeg -hide_banner -n -i "$i" -b:a 16k -c:v mjpeg -vs
ync 2 -vf scale=320:-1 "${i%.*}.opus" && mv "$i" .before/
# error catcher, if the folder exists
mv "$i" .error/
done
# notify when finished, d'uh
echo zzz finished $TITLE | termux-notification
termux-vibrate -f
in the end, the problem with opusenc
was actually the art size being too big! it even encodes a bit better than ffmpeg, when it works (very rarely it can’t read the input. ffmpeg never failed, though).
Attribution
Source : Link , Question Author : cregox , Answer Author : cregox