fmang / opustags

Ogg Opus tags editor
BSD 3-Clause "New" or "Revised" License
75 stars 10 forks source link

Trim opustags away when -D --set-vendor "" is used? #71

Closed TheThing closed 3 months ago

TheThing commented 3 months ago

Hi there.

Me and friend were experimenting with trying to create smallest header size for opus. we reached down to roughly 130 bytes using this option: opustags --set-vendor "" -D test.opus -o test.trimmed.opus

However when viewing the file in hex editor, there's still a lot of plain text stuff:

mynd

Are these required or would it be possible to trim it further?

fmang commented 3 months ago

The OggS text fragments mark the beginning of an Ogg page. You need at least two, as per https://datatracker.ietf.org/doc/html/rfc7845.html#section-3. If you don’t mind having an empty stream, you might be able to drop the third page. The Ogg page headers make a minimal 28 bytes length. https://en.wikipedia.org/wiki/Ogg_page

Concerning the Opus header packets themselves, one starts with OpusHead and the other with OpusTags. Their contents start at Opus and end at OggS. The first packet, OpusHead, requires at least 19 bytes. See https://datatracker.ietf.org/doc/html/rfc7845.html#section-5.1. The second packet, OpusTags, requires at least 16 bytes. See https://datatracker.ietf.org/doc/html/rfc7845.html#section-5.2.

In total you get a 28 + 19 + 28 + 16 = 91 bytes theoretical minimum size. In your stream, if you exclude the last page, you get a size of 91 bytes, so it looks like you managed to attain the minimum possible header size possible. Congratulations!

As to the third page (the first and only audio data packet), if you want to remove it, you need to put the Ogg end-of-stream flag on the OpusTags page and recompute the checksum. If you learn to use libogg a bit it could do that for you. Feel free to look at opustags’s code too. In case the packet is required, maybe you could look at https://www.rfc-editor.org/rfc/rfc6716#section-3.2 to make it even smaller.

As far as opustags itself is concerned, I’m glad to see it did generate the smallest packet possible. You won’t be able to save any more bytes there.

Have fun!

TheThing commented 3 months ago

Thanks, that answered all my questions :D And yaeh the example had a small audio stream as placeholder to work with :)