Acabei de escrever um script que exporta / importa imagens de arquivos OGG / Vorbis usando o vorbiscomment. Faz parte de uma ferramenta de conversão de biblioteca de músicas.
O script revelent está na função 'mussync-tools-transfert_images' desta ferramenta:
Basicamente, eu escrevi um leitor e um escritor para o formato metadata_block_picture.
O código é bastante complexo:
OUTPUT_FILE="/path/to/my-ogg-file.ogg"
IMAGE_PATH="/path/to/my-cover-art.jpg"
IMAGE_MIME_TYPE="image/jpeg"
# Export existing comments to file.
local COMMENTS_PATH="$(command mktemp -t "tmp.XXXXXXXXXX")"
command vorbiscomment --list --raw "${OUTPUT_FILE}" > "${COMMENTS_PATH}"
# Remove existing images.
command sed -i -e '/^metadata_block_picture/d' "${COMMENTS_PATH}"
# Insert cover image from file.
# metadata_block_picture format.
# See: https://xiph.org/flac/format.html#metadata_block_picture
local IMAGE_WITH_HEADER="$(command mktemp -t "tmp.XXXXXXXXXX")"
local DESCRIPTION=""
# Reset cache file.
echo -n "" > "${IMAGE_WITH_HEADER}"
# Picture type <32>.
command printf "0: %.8x" 3 | command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Mime type length <32>.
command printf "0: %.8x" $(echo -n "${IMAGE_MIME_TYPE}" | command wc -c) \
| command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Mime type (n * 8)
echo -n "${IMAGE_MIME_TYPE}" >> "${IMAGE_WITH_HEADER}"
# Description length <32>.
command printf "0: %.8x" $(echo -n "${DESCRIPTION}" | command wc -c) \
| command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Description (n * 8)
echo -n "${DESCRIPTION}" >> "${IMAGE_WITH_HEADER}"
# Picture with <32>.
command printf "0: %.8x" 0 | command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Picture height <32>.
command printf "0: %.8x" 0 | command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Picture color depth <32>.
command printf "0: %.8x" 0 | command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Picture color count <32>.
command printf "0: %.8x" 0 | command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Image file size <32>.
command printf "0: %.8x" $(command wc -c "${IMAGE_PATH}" \
| command cut --delimiter=' ' --fields=1) \
| command xxd -r -g0 \
>> "${IMAGE_WITH_HEADER}"
# Image file.
command cat "${IMAGE_PATH}" >> "${IMAGE_WITH_HEADER}"
echo "metadata_block_picture=$(command base64 --wrap=0 < "${IMAGE_WITH_HEADER}")" >> "${COMMENTS_PATH}"
# Update vorbis file comments.
command vorbiscomment --write --raw --commentfile "${COMMENTS_PATH}" "${OUTPUT_FILE}"
# Delete cache file.
command rm "${IMAGE_WITH_HEADER}"
# Delete comments file.
command rm "${COMMENTS_PATH}"