]> git.sesse.net Git - mlt/commitdiff
Add support for FFmpeg AVMetadata API.
authorDan Dennedy <dan@dennedy.org>
Mon, 28 Feb 2011 05:27:44 +0000 (21:27 -0800)
committerDan Dennedy <dan@dennedy.org>
Mon, 28 Feb 2011 05:27:44 +0000 (21:27 -0800)
src/modules/avformat/consumer_avformat.c
src/modules/avformat/producer_avformat.c

index 3482149aa562d05143dec59f54c62f1f595eb84d..3d1bc18546b2dfa80e7a7ca8967cdcdebe0cc8db 100644 (file)
@@ -1052,6 +1052,28 @@ static void *consumer_thread( void *arg )
        }
 
        // Write metadata
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
+       for ( i = 0; i < mlt_properties_count( properties ); i++ )
+       {
+               char *name = mlt_properties_get_name( properties, i );
+               if ( name && !strncmp( name, "meta.attr.", 10 ) )
+               {
+                       char *key = strdup( name + 10 );
+                       char *markup = strrchr( key, '.' );
+                       if ( markup && !strcmp( markup, ".markup") )
+                       {
+                               markup[0] = '\0';
+                               if ( !strstr( key, ".stream." ) )
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(43<<8)+0)
+                                       av_metadata_set2( &oc->metadata, key, mlt_properties_get_value( properties, i ), 0 );
+#else
+                                       av_metadata_set( &oc->metadata, key, mlt_properties_get_value( properties, i ) );
+#endif
+                       }
+                       free( key );
+               }
+       }
+#else
        char *tmp = NULL;
        int metavalue;
 
@@ -1075,6 +1097,7 @@ static void *consumer_thread( void *arg )
 
        metavalue = mlt_properties_get_int( properties, "meta.attr.track.markup");
        if (metavalue != 0) oc->track = metavalue;
+#endif
 
        oc->oformat = fmt;
        snprintf( oc->filename, sizeof(oc->filename), "%s", filename );
index e6fb022a70a909e39fce4047a3f7276f2209ec08..917791699a678ca529fe2d9a21451a573e6679d2 100644 (file)
@@ -243,6 +243,7 @@ static mlt_properties find_default_streams( mlt_properties meta_media, AVFormatC
 {
        int i;
        char key[200];
+       AVMetadataTag *tag = NULL;
 
        mlt_properties_set_int( meta_media, "meta.media.nb_streams", context->nb_streams );
 
@@ -339,7 +340,44 @@ static mlt_properties find_default_streams( mlt_properties meta_media, AVFormatC
 //             mlt_properties_set_int( meta_media, key, codec_context->profile );
 //             snprintf( key, sizeof(key), "meta.media.%d.codec.level", i );
 //             mlt_properties_set_int( meta_media, key, codec_context->level );
+
+               // Read Metadata
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
+               while ( ( tag = av_metadata_get( stream->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX ) ) )
+               {
+                       if ( tag->value && strcmp( tag->value, "" ) && strcmp( tag->value, "und" ) )
+                       {
+                               snprintf( key, sizeof(key), "meta.attr.%d.stream.%s.markup", i, tag->key );
+                               mlt_properties_set( meta_media, key, tag->value );
+                       }
+               }
+#endif
        }
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
+       while ( ( tag = av_metadata_get( context->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX ) ) )
+       {
+               if ( tag->value && strcmp( tag->value, "" ) && strcmp( tag->value, "und" ) )
+               {
+                       snprintf( key, sizeof(key), "meta.attr.%s.markup", tag->key );
+                       mlt_properties_set( meta_media, key, tag->value );
+               }
+       }
+#else
+       if ( context->title && strcmp( context->title, "" ) )
+               mlt_properties_set(properties, "meta.attr.title.markup", context->title );
+       if ( context->author && strcmp( context->author, "" ) )
+               mlt_properties_set(properties, "meta.attr.author.markup", context->author );
+       if ( context->copyright && strcmp( context->copyright, "" ) )
+               mlt_properties_set(properties, "meta.attr.copyright.markup", context->copyright );
+       if ( context->comment )
+               mlt_properties_set(properties, "meta.attr.comment.markup", context->comment );
+       if ( context->album )
+               mlt_properties_set(properties, "meta.attr.album.markup", context->album );
+       if ( context->year )
+               mlt_properties_set_int(properties, "meta.attr.year.markup", context->year );
+       if ( context->track )
+               mlt_properties_set_int(properties, "meta.attr.track.markup", context->track );
+#endif
 
        return meta_media;
 }
@@ -666,22 +704,6 @@ static int producer_open( producer_avformat this, mlt_profile profile, char *fil
 #endif
                        }
 
-                       // Read Metadata
-                       if ( context->title )
-                               mlt_properties_set(properties, "meta.attr.title.markup", context->title );
-                       if ( context->author )
-                               mlt_properties_set(properties, "meta.attr.author.markup", context->author );
-                       if ( context->copyright )
-                               mlt_properties_set(properties, "meta.attr.copyright.markup", context->copyright );
-                       if ( context->comment )
-                               mlt_properties_set(properties, "meta.attr.comment.markup", context->comment );
-                       if ( context->album )
-                               mlt_properties_set(properties, "meta.attr.album.markup", context->album );
-                       if ( context->year )
-                               mlt_properties_set_int(properties, "meta.attr.year.markup", context->year );
-                       if ( context->track )
-                               mlt_properties_set_int(properties, "meta.attr.track.markup", context->track );
-
                        // We're going to cheat here - for a/v files, we will have two contexts (reasoning will be clear later)
                        if ( av == 0 && audio_index != -1 && video_index != -1 )
                        {