[Vorbis] edit comment

Ian Malone ibmalone at gmail.com
Tue Nov 6 05:27:49 PST 2007


On 06/11/2007, Ulrich Windl <ulrich.windl at rz.uni-regensburg.de> wrote:
> On 5 Nov 2007 at 18:07, Ivo Emanuel Gonçalves wrote:
>
> > On 11/5/07, Rafa Zafra Fuentes <rafa_zafra_fuentes at hotmail.com> wrote:
> > > How i can edit the comments of a vorbis file?
> >
> > You need a player compatible with the VorbisComment standard.  If you
> > use Microsoft Windows, you may edit those fields in Winamp or
> > foobar2000.
>
> Reminds me of: I had some large (40MB) TIFF image files where the metadata had a
> problem, and I wanted to batch-fix them. Reading the file into memory, change
> them, and then re-write them seemed to inefficient. So I wrote a program that
> replaces the metadata in-place whenever possible, leaving the image data where
> they are. OK, TIFF structure makes it rather easy. Actually I had tried to do a
> similar thing with Vorbis, but that seems quite tricky (I wanted to _locate_ the
> position where the comments are, and then overwrite them in place). Did anybody
> try such a thing?
>

It's been discussed before, adjusting comments in place is possible
(provided the new comments are the same length as or shorter than
the ones they're replacing). However to do it on an arbitrary Ogg Vorbis
file you have to do some repackaging, as the page(s) containing the
comment packet may also contain the start of the setup header,
so the full algorithm goes:
1. Read until you find the start of the Ogg page which starts the
   comment header packet, loading the Vorbis BOS packet into
   an Ogg stream state with the correct serial number.
2. Get the comment packet (potentially it spans multiple pages,
   see the next step), check it's big enough to modify as you want,
   make your changes.  The packet can be padded with zero bytes,
   the length should remain the same.
3a. If the comment packet ends the Ogg page then load it into
   the stream, output the BOS page (you don't need to re-write
   that page, but this keeps the page numbers correct), then get
   the pages containing the comment packet.  Check they have the
   same size and re-write them in place.
3b. If the comment packet ends on a page beginning the setup
   header packet then you need to keep reading until you have the
   entire setup header packet and load it into the stream state too.
   ogg_stream_pageout should then give you the last comment
   page, again check sizes and rewrite the pages in place.

The above doesn't integrate well with the way the vorbiscomment
tool works, so you'd need a separate tool.

Of course you could ensure when creating the file to start with
that the comment packet ends a page (by using ogg_stream_flush),
and construct a tool that would only agree to write-in-place files for
which this was the case.  Oggenc2 allows you to incorporate
padding when encoding files, but I don't know if it does this page
flush.

-- 
imalone


More information about the Vorbis mailing list