1

Is there any tool that can edit Opus comments? In particular, I want to add multiple METADATA_BLOCK_PICTUREs to an Ogg/Opus file.

All existing answers to my knowledge either only work on Ogg/Vorbis, require re-encoding the audio, or don't support multiple pictures.

Giacomo1968
  • 58,727
Matthew
  • 308

3 Answers3

2

I've been using opuscomment the past few months. Haven't had any problems with it, although it works differently than vorbiscomment despite its name. If you wanted to add multiple METADATA_BLOCK_PICTURE labels, you would do:

# `-a` handles the file in append mode.

opuscomment myfile.ogg -a -t 'METADATA_BLOCK_PICTURE=...' -t 'METADATA_BLOCK_PICTURE=...'

...although you'd probably get an error due to the arguments' length, which should be a base64-encoded string containing the metadata's value in the correct size and order:

  • 4 bytes specifying the picture type.
  • 4 bytes specifying the MIME type length.
  • n bytes with the MIME type name.
  • 4 bytes specifying the length of the description.
  • n bytes with the description.
  • 4 bytes indicating the image width.
  • 4 bytes indicating the image height.
  • 4 bytes indicating color depth.
  • 4 bytes indicating the number of colors used, if the image is an indexed-color one.
  • 4 bytes specifying the length of the picture data in bytes.
  • n bytes of the picture data.

Having your tags in a text file, you could then do:

opuscomment -a -c mytags.txt myfile.ogg

You could also delete all of the previous METADATA_BLOCK_PICTURE if something went wrong:

opuscomment -d METADATA_BLOCK_PICTURE myfile.ogg

Keep in -d implies -a, and given that -a expects an EOF, you need to send it yourself (typically ^D/Ctrl+D) unless you're actually appending something with a here-document, from a file, a tag specified with -t etc.:

# delete picture tags and assign everything from mytags.txt
opuscomment -d METADATA_BLOCK_PICTURE -c mytags.txt myfile.ogg
M I P A
  • 21
1

I finally got a solution working using mutagen. There is no CLI, but fortunately it takes very little code to accomplish basic tasks. For example, a very dumb CLI that takes three arguments, file, key and value, can be written as follows:

import sys
import mutagen

f = mutagen.File(sys.argv[1]) f[sys.argv[2]] = sys.argv[3] f.save()

This could be turned, rather easily, into a decent front-end. (In my case, I don't actually need a general purpose front-end and I was already using Python to write a metadata file to feed ffmpeg, which made the switch to mutagen fairly straight forward.)

Setting the same key multiple times is a little wonky:

f[key] = [value1, value2, ...]

...but it works; key will appear multiple times, once for each specified value.

There are also utilities to help turn images into appropriate VORBISCOMMENT blocks, though I didn't use them, as I'd already written my own version for my prior attempts to use ffmpeg.

Matthew
  • 308
0

to edit tags, especially multiple cover artwork, besides the already named tools there are:

  • EarTag - GNOME and mutagen based GUI-editor, can do front and back cover (from version >=0.5.0) - the easiest option if one wants to add no more than 2 images
  • opustags - cli util with straightforward support to add a front cover from commandline args, needs cli-fu with a base64 encoding helper to prep the METADATA_BLOCK_PICTURE for more covers (using a pipe with all source tags + appended picture block each)
  • music-tag - mutagen wrapper with a light cli interface, you'll need to enter Pythons REPL-mode to add artwork though, but then can do multiple covers (Needs the pillow package)
  • mediafile - also mutagen based, but no cli interface at all, simple api though

There were unsuccessful merge requests of a opuspic2tag helper against both opuscomment and opustags.

wbob
  • 238