Skip to content

Instantly share code, notes, and snippets.

@Lesmiscore
Last active June 5, 2022 11:44
Show Gist options
  • Save Lesmiscore/cf78bdce0b5b5731a0e62b75fe18cdcd to your computer and use it in GitHub Desktop.
Save Lesmiscore/cf78bdce0b5b5731a0e62b75fe18cdcd to your computer and use it in GitHub Desktop.
script to convert file's cover art to an attachment in mka
#!/bin/bash
set -xe
mimetype(){
file -i "$@" | grep -Eo '[a-z-]+/[a-z-]+;' | tr -d ';'
}
extes(){
file -i "$@" | awk '{ print $2 }' | tr -d ';' | sed -E 's%^.+/%%'
}
for I in "$@" ; do
ffmpeg -y -i "$I" -an -c:v copy /tmp/cover.jpg || rm -f /tmp/cover.jpg
EXARGS=()
if [[ -f /tmp/cover.jpg ]] ; then
EXARGS+=(
-attach /tmp/cover.jpg \
-metadata:s:1 title="Album cover" -metadata:s:1 comment="Cover (front)" \
-metadata:s:1 mimetype="$(mimetype /tmp/cover.jpg)" -metadata:s:1 filename="cover.$(extes /tmp/cover.jpg)"
)
fi
ffmpeg -y -i "$I" -map 0:a:0 -map_metadata 0 -c copy -id3v2_version 3 \
"${EXARGS[@]}" \
"${I%.*}".mka
# [[ ! -f /tmp/cover.jpg ]]
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment