[FFmpeg-cvslog] r22606 - in trunk/libavformat: Makefile oggenc.c

jbr subversion
Sat Mar 20 14:39:22 CET 2010


Author: jbr
Date: Sat Mar 20 14:39:22 2010
New Revision: 22606

Log:
Add VorbisComment writing to Ogg/FLAC and Ogg/Speex files.
Patch by James Darnley <james darnley at gmail>

Modified:
   trunk/libavformat/Makefile
   trunk/libavformat/oggenc.c

Modified: trunk/libavformat/Makefile
==============================================================================
--- trunk/libavformat/Makefile	Sat Mar 20 14:36:43 2010	(r22605)
+++ trunk/libavformat/Makefile	Sat Mar 20 14:39:22 2010	(r22606)
@@ -151,7 +151,8 @@ OBJS-$(CONFIG_OGG_DEMUXER)              
                                             oggparsevorbis.o \
                                             riff.o \
                                             vorbiscomment.o
-OBJS-$(CONFIG_OGG_MUXER)                 += oggenc.o
+OBJS-$(CONFIG_OGG_MUXER)                 += oggenc.o \
+                                            vorbiscomment.o
 OBJS-$(CONFIG_OMA_DEMUXER)               += oma.o raw.o
 OBJS-$(CONFIG_PCM_ALAW_DEMUXER)          += raw.o
 OBJS-$(CONFIG_PCM_ALAW_MUXER)            += raw.o

Modified: trunk/libavformat/oggenc.c
==============================================================================
--- trunk/libavformat/oggenc.c	Sat Mar 20 14:36:43 2010	(r22605)
+++ trunk/libavformat/oggenc.c	Sat Mar 20 14:39:22 2010	(r22606)
@@ -25,6 +25,7 @@
 #include "libavcodec/flac.h"
 #include "avformat.h"
 #include "internal.h"
+#include "vorbiscomment.h"
 
 typedef struct {
     int64_t duration;
@@ -84,29 +85,29 @@ static int ogg_write_page(AVFormatContex
 }
 
 static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
-                                        int *header_len)
+                                        int *header_len, AVMetadata *m)
 {
     const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT;
     int size;
     uint8_t *p, *p0;
+    unsigned int count;
 
-    size = offset + 4 + strlen(vendor) + 4;
+    size = offset + ff_vorbiscomment_length(m, vendor, &count);
     p = av_mallocz(size);
     if (!p)
         return NULL;
     p0 = p;
 
     p += offset;
-    bytestream_put_le32(&p, strlen(vendor));
-    bytestream_put_buffer(&p, vendor, strlen(vendor));
-    bytestream_put_le32(&p, 0); // user comment list length
+    ff_vorbiscomment_write(&p, m, vendor, count);
 
     *header_len = size;
     return p0;
 }
 
 static int ogg_build_flac_headers(AVCodecContext *avctx,
-                                  OGGStreamContext *oggstream, int bitexact)
+                                  OGGStreamContext *oggstream, int bitexact,
+                                  AVMetadata *m)
 {
     enum FLACExtradataFormat format;
     uint8_t *streaminfo;
@@ -132,7 +133,7 @@ static int ogg_build_flac_headers(AVCode
     bytestream_put_buffer(&p, streaminfo, FLAC_STREAMINFO_SIZE);
 
     // second packet: VorbisComment
-    p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1]);
+    p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m);
     if (!p)
         return AVERROR_NOMEM;
     oggstream->header[1] = p;
@@ -145,7 +146,8 @@ static int ogg_build_flac_headers(AVCode
 #define SPEEX_HEADER_SIZE 80
 
 static int ogg_build_speex_headers(AVCodecContext *avctx,
-                                   OGGStreamContext *oggstream, int bitexact)
+                                   OGGStreamContext *oggstream, int bitexact,
+                                   AVMetadata *m)
 {
     uint8_t *p;
 
@@ -162,7 +164,7 @@ static int ogg_build_speex_headers(AVCod
     AV_WL32(&oggstream->header[0][68], 0);  // set extra_headers to 0
 
     // second packet: VorbisComment
-    p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1]);
+    p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m);
     if (!p)
         return AVERROR_NOMEM;
     oggstream->header[1] = p;
@@ -196,7 +198,8 @@ static int ogg_write_header(AVFormatCont
         st->priv_data = oggstream;
         if (st->codec->codec_id == CODEC_ID_FLAC) {
             int err = ogg_build_flac_headers(st->codec, oggstream,
-                                             st->codec->flags & CODEC_FLAG_BITEXACT);
+                                             st->codec->flags & CODEC_FLAG_BITEXACT,
+                                             s->metadata);
             if (err) {
                 av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
                 av_freep(&st->priv_data);
@@ -204,7 +207,8 @@ static int ogg_write_header(AVFormatCont
             }
         } else if (st->codec->codec_id == CODEC_ID_SPEEX) {
             int err = ogg_build_speex_headers(st->codec, oggstream,
-                                              st->codec->flags & CODEC_FLAG_BITEXACT);
+                                              st->codec->flags & CODEC_FLAG_BITEXACT,
+                                              s->metadata);
             if (err) {
                 av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
                 av_freep(&st->priv_data);
@@ -355,4 +359,5 @@ AVOutputFormat ogg_muxer = {
     ogg_write_packet,
     ogg_write_trailer,
     .interleave_packet = ogg_interleave_per_granule,
+    .metadata_conv = ff_vorbiscomment_metadata_conv,
 };



More information about the ffmpeg-cvslog mailing list