Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Questions about Opus tagging (Read 5771 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Questions about Opus tagging

Normally the way I tag an Ogg Opus file is to just tag the FLAC file I use as the source. The opusenc encoder then carries the flac tags over to the opus file.

First of all, I have come to the understanding that the replaygain tags in the FLAC file may not be correct for an opus encoded version of the file and that it could result in clipping as a result. Is there an open source command line utility for calculating the proper replaygain of an opus encoded file so I can update those tags after encoding?

Secondly - when I need to retag a file, for opus right now I use mutagen to do so - it seems that vorbiscomment on my machine (CentOS 7) doesn't like Opus.

I can't for the life of me figure out how to change cover art on an Opus file with mutagen. The tags with string content are easy, but I can't figure out how to change the cover art if it needs to be changed.

For m4a files it is easy with mutagen and for mp3 files I actually just use eyeD3 but opus is not so easy, at least I can't find out how it is done.

Thank you for suggestions.

Has to be command line - retagging is to be automated on the server if something about the audio requires a tag change (e.g. a typo in the title or the cover art needs to be changed)

I suppose I could just retag the flac and re-encode but the flac files are archived off the server, and seems like a waste of CPU just to change some tags.

Re: Questions about Opus tagging

Reply #1
Okay reading some of the posts here, it seems that maybe the best thing to remove the replaygain from the flac. The flac are archival anyway and not meant to be played, it looks like there are some issues with some players applying both replaygain and the R128 that opusenc uses resulting in audio too quiet in some players.

Is that correct assessment?

The Ogg Opus files are normally played by browsers (html5 audio) which I believe don't care about replaygain, but if users want to download the file Ogg Opus is one of the codec options (I personally really like the codec) and there I suppose it could be a problem if the replaygain tags are present.

Re: Questions about Opus tagging

Reply #2
If you don't mind using Wine, foobar2000 supports the opus format, for playback, editing tags and replaygain. Since I haven't used linux for a long time, I can't give you native OS advices.

Also, note that replaygain in opus is a bit like the scalefactor band gains of MP3 as in it is supposed to be part of the format itself, not a tag. (Said that, some software might ignore it)

Re: Questions about Opus tagging

Reply #3
Wine is not an option.

User uploads an audio (speech).
Audio is decoded into wave and resampled with sox

resulting wave file is then archived with flac and encoded into Ogg Opus, AAC-HEv1, and MP3 and tagged according to info the user submitted with the audio.

re-tagging is necessary when the user realizes they made a mistake in the info they submitted and cares enough to want them fixed.

It's all automated, and it all works, except changing the cover art they want is what I can't figure out how to do from a command line utility with Ogg Opus.

I'm guessing there is a way with mutagen but I didn't see it in the docs. I suppose I could uuencode and use the COVERART vorbis comment but that's deprecated and I'm not sure that Opus actually supports it anyway.


Re: Questions about Opus tagging

Reply #5
Indeed it does work, so this thread is resolved. Relevant parts of python

Code: [Select]
import base64
from mutagen.oggopus import OggOpus
from mutagen.flac import Picture
from PIL import Image

audio = OggOpus(sys.argv[1])

im = Image.open(sys.argv[3])
width, height = im.size
with open(sys.argv[3], "rb") as c:
    data = c.read()
picture = Picture()
picture.data = data
picture.type = 17
picture.desc = u"Cover Art"
picture.mime = u"image/jpeg"
picture.width = width
picture.height = height
picture.depth = 24
picture_data = picture.write()
encoded_data = base64.b64encode(picture_data)
vcomment_value = encoded_data.decode("ascii")
audio["metadata_block_picture"] = [vcomment_value]

audio.save()

I suppose I should detect color depth instead of assuming 24 but the server creates that from uploaded image so I know it is 24.

Re: Questions about Opus tagging

Reply #6
Opus replaygain is different to anything you ever saw before :)  Or maybe not, because you can in practice just keep the standard REPLYGAIN* tags and most decoders will respect that.

In Opus, the "proper" way to encode replaygain is to use the tags R128_TRACK_GAIN and R128_ALBUM_GAIN, and the special Opus gain header field.  It is recommended that you set the desired playback level using the header gain field so that it will be automatically applied by (pretty much) all decoders.  The intended use of the R128_TRACK_GAIN tag is that it will contain a delta between the album gain and track gain, while the album gain will be in the Opus header field.  Recommended use for the R128_ALBUM_GAIN tag is "don't", but for applications which allow the user to turn off replaygain it would be required.  Application support for the R128* tags is mixed.

opusenc will convert flac replaygain tags, incorporating the gain into the Opus header so that it is always decoded at that level.  It places any album gain into the header (adjusted to R128), and places the difference between the album gain and track gain in the tag.  So playback will always have album gain applied, and optionally also have track gain if your play supports the R128 tags.

Re: Questions about Opus tagging

Reply #7
The gain in the header field is better, that survives retagging - that's why I like the --replaygain-accurate switch to lame, I can always retrieve it from the mpeg header if some tagging software nukes it. Not that I play MP3s very often anymore.

Anyway thanks for the explanation, that also explains why some of my opus tags have the R128_TRACK_GAIN and others don't - they don't need it if it is a delta between track and album and the source flac didn't have an album gain.