[FFmpeg-cvslog] r26330 - in trunk: ffmpeg.c libavformat/avformat.h libavformat/metadata.c

rbultje subversion
Fri Jan 14 20:30:56 CET 2011


Author: rbultje
Date: Fri Jan 14 20:30:55 2011
New Revision: 26330

Log:
Introduce av_metadata_copy() to copy metadata from one struct to another.

Modified:
   trunk/ffmpeg.c
   trunk/libavformat/avformat.h
   trunk/libavformat/metadata.c

Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c	Fri Jan 14 20:04:59 2011	(r26329)
+++ trunk/ffmpeg.c	Fri Jan 14 20:30:55 2011	(r26330)
@@ -1862,7 +1862,6 @@ static int copy_chapters(int infile, int
 
     for (i = 0; i < is->nb_chapters; i++) {
         AVChapter *in_ch = is->chapters[i], *out_ch;
-        AVMetadataTag *t = NULL;
         int64_t ts_off   = av_rescale_q(start_time - input_files_ts_offset[infile],
                                       AV_TIME_BASE_Q, in_ch->time_base);
         int64_t rt       = (recording_time == INT64_MAX) ? INT64_MAX :
@@ -1884,8 +1883,7 @@ static int copy_chapters(int infile, int
         out_ch->end       = FFMIN(rt, in_ch->end   - ts_off);
 
         if (metadata_chapters_autocopy)
-            while ((t = av_metadata_get(in_ch->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
-                av_metadata_set2(&out_ch->metadata, t->key, t->value, 0);
+            av_metadata_copy(&out_ch->metadata, in_ch->metadata, 0);
 
         os->nb_chapters++;
         os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters);
@@ -2105,7 +2103,6 @@ static int transcode(AVFormatContext **o
 
     /* for each output stream, we compute the right encoding parameters */
     for(i=0;i<nb_ostreams;i++) {
-        AVMetadataTag *t = NULL;
         ost = ost_table[i];
         os = output_files[ost->file_index];
         ist = ist_table[ost->source_index];
@@ -2114,9 +2111,8 @@ static int transcode(AVFormatContext **o
         icodec = ist->st->codec;
 
         if (metadata_streams_autocopy)
-            while ((t = av_metadata_get(ist->st->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) {
-                av_metadata_set2(&ost->st->metadata, t->key, t->value, AV_METADATA_DONT_OVERWRITE);
-            }
+            av_metadata_copy(&ost->st->metadata, ist->st->metadata,
+                             AV_METADATA_DONT_OVERWRITE);
 
         ost->st->disposition = ist->st->disposition;
         codec->bits_per_raw_sample= icodec->bits_per_raw_sample;
@@ -2368,7 +2364,6 @@ static int transcode(AVFormatContext **o
     for (i=0;i<nb_meta_data_maps;i++) {
         AVFormatContext *files[2];
         AVMetadata      **meta[2];
-        AVMetadataTag *mtag;
         int j;
 
 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
@@ -2411,18 +2406,15 @@ static int transcode(AVFormatContext **o
             }
         }
 
-        mtag=NULL;
-        while((mtag=av_metadata_get(*meta[1], "", mtag, AV_METADATA_IGNORE_SUFFIX)))
-            av_metadata_set2(meta[0], mtag->key, mtag->value, AV_METADATA_DONT_OVERWRITE);
+        av_metadata_copy(meta[0], *meta[1], AV_METADATA_DONT_OVERWRITE);
     }
 
     /* copy global metadata by default */
     if (metadata_global_autocopy) {
-        AVMetadataTag *t = NULL;
 
-        while ((t = av_metadata_get(input_files[0]->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
             for (i = 0; i < nb_output_files; i++)
-                av_metadata_set2(&output_files[i]->metadata, t->key, t->value, AV_METADATA_DONT_OVERWRITE);
+            av_metadata_copy(&output_files[i]->metadata, input_files[0]->metadata,
+                             AV_METADATA_DONT_OVERWRITE);
     }
 
     /* copy chapters according to chapter maps */
@@ -3692,7 +3684,6 @@ static void opt_output_file(const char *
     int input_has_video, input_has_audio, input_has_subtitle;
     AVFormatParameters params, *ap = ¶ms;
     AVOutputFormat *file_oformat;
-    AVMetadataTag *tag = NULL;
 
     if (!strcmp(filename, "-"))
         filename = "pipe:";
@@ -3760,8 +3751,7 @@ static void opt_output_file(const char *
 
         oc->timestamp = recording_timestamp;
 
-        while ((tag = av_metadata_get(metadata, "", tag, AV_METADATA_IGNORE_SUFFIX)))
-            av_metadata_set2(&oc->metadata, tag->key, tag->value, 0);
+        av_metadata_copy(&oc->metadata, metadata, 0);
         av_metadata_free(&metadata);
     }
 

Modified: trunk/libavformat/avformat.h
==============================================================================
--- trunk/libavformat/avformat.h	Fri Jan 14 20:04:59 2011	(r26329)
+++ trunk/libavformat/avformat.h	Fri Jan 14 20:30:55 2011	(r26330)
@@ -22,7 +22,7 @@
 #define AVFORMAT_AVFORMAT_H
 
 #define LIBAVFORMAT_VERSION_MAJOR 52
-#define LIBAVFORMAT_VERSION_MINOR 92
+#define LIBAVFORMAT_VERSION_MINOR 93
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -227,6 +227,16 @@ attribute_deprecated void av_metadata_co
 #endif
 
 /**
+ * Copy metadata from one AVMetadata struct into another.
+ * @param dst pointer to a pointer to a AVMetadata struct. If *dst is NULL,
+ *            this function will allocate a struct for you and put it in *dst
+ * @param src pointer to source AVMetadata struct
+ * @param flags flags to use when setting metadata in *dst
+ * @note metadata is read using the AV_METADATA_IGNORE_SUFFIX flag
+ */
+void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags);
+
+/**
  * Free all the memory allocated for an AVMetadata struct.
  */
 void av_metadata_free(AVMetadata **m);

Modified: trunk/libavformat/metadata.c
==============================================================================
--- trunk/libavformat/metadata.c	Fri Jan 14 20:04:59 2011	(r26329)
+++ trunk/libavformat/metadata.c	Fri Jan 14 20:30:55 2011	(r26330)
@@ -158,3 +158,11 @@ void ff_metadata_conv_ctx(AVFormatContex
     for (i=0; i<ctx->nb_programs; i++)
         ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
 }
+
+void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags)
+{
+    AVMetadataTag *t = NULL;
+
+    while ((t = av_metadata_get(src, "", t, AV_METADATA_IGNORE_SUFFIX)))
+        av_metadata_set2(dst, t->key, t->value, flags);
+}



More information about the ffmpeg-cvslog mailing list