[FFmpeg-devel] [PATCH] Ogg: discard non-essential metadata from Vorbis header when creating extradata.

Reimar Döffinger Reimar.Doeffinger
Mon Jan 31 20:16:38 CET 2011


On Mon, Jan 31, 2011 at 06:30:02PM +0000, M?ns Rullg?rd wrote:
> Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:
> > What would be the point of a realloc besides wasting CPU time?
> > The point is that priv->len is smaller and thus the amount
> > of data that is copied into extradata is smaller.
> > I can't imagine we have to optimize for a few 100 kB during header
> > parsing.
> 
> You're right of course.  I overlooked the second copying.  Please send
> a properly formatted patch and we'll apply it.

I'd do that more often if I had an efficient way to make git work
with a mail-client instead of it trying to be (a really sucky) one.
The idiocy of having the commit message in the subject line will
probably reliably prevent that though.

--8<--
The first part of the metadata, the "vendor" string, is required by
libvorbis, it will refuse to play when it is not available.
Also we do not currently parse that part into metadata so it would also
be lost if we removed it as well.
---
 libavformat/oggparsevorbis.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index d743d25..34ae2fc 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -256,8 +256,16 @@ vorbis_header (AVFormatContext * s, int idx)
             st->time_base.den = srate;
         }
     } else if (os->buf[os->pstart] == 3) {
-        if (os->psize > 8)
-            ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 7, os->psize - 8);
+        if (os->psize > 8 &&
+            ff_vorbis_comment(s, &st->metadata, os->buf + os->pstart + 7, os->psize - 8) >= 0) {
+            // drop all metadata we parsed and which is not required by libvorbis
+            unsigned new_len = 7 + 4 + AV_RL32(priv->packet[1] + 7) + 4 + 1;
+            if (new_len >= 16 && new_len < os->psize) {
+                AV_WL32(priv->packet[1] + new_len - 5, 0);
+                priv->packet[1][new_len - 1] = 1;
+                priv->len[1] = new_len;
+            }
+        }
     } else {
         st->codec->extradata_size =
             fixup_vorbis_headers(s, priv, &st->codec->extradata);
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list