From 94d89cf9e14fa846474d7eb71277621c0f5676a8 Mon Sep 17 00:00:00 2001 From: j-b-m Date: Sun, 31 Dec 2006 16:06:35 +0000 Subject: [PATCH] Read metadata from avformat and vorbis producers, using basic structure like: meta.attr.metadata_name.markup=metadata_value git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@943 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/modules/avformat/producer_avformat.c | 16 ++++++++++++ src/modules/vorbis/producer_vorbis.c | 39 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 0 deletions(-) diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index a800708..78c0d48 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -299,6 +299,22 @@ static int producer_open( mlt_producer this, char *file ) mlt_properties_set_int( properties, "height", codec_context->height ); mlt_properties_set_double( properties, "aspect_ratio", av_q2d( codec_context->sample_aspect_ratio ) ); } + + // Read Metadata + if (context->title != NULL) + mlt_properties_set(properties, "meta.attr.title.markup", context->title ); + if (context->author != NULL) + mlt_properties_set(properties, "meta.attr.author.markup", context->author ); + if (context->copyright != NULL) + mlt_properties_set(properties, "meta.attr.copyright.markup", context->copyright ); + if (context->comment != NULL) + mlt_properties_set(properties, "meta.attr.comment.markup", context->comment ); + if (context->album != NULL) + mlt_properties_set(properties, "meta.attr.album.markup", context->album ); + if (context->year != 0) + mlt_properties_set_int(properties, "meta.attr.year.markup", context->year ); + if (context->track != 0) + 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 && !av_bypass && audio_index != -1 && video_index != -1 ) diff --git a/src/modules/vorbis/producer_vorbis.c b/src/modules/vorbis/producer_vorbis.c index d69fc82..3e2218c 100644 --- a/src/modules/vorbis/producer_vorbis.c +++ b/src/modules/vorbis/producer_vorbis.c @@ -36,6 +36,35 @@ static int producer_open( mlt_producer this, char *file ); static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index ); +/** Structure for metadata reading +*/ + +typedef struct _sw_metadata sw_metadata; + +struct _sw_metadata { + char * name; + char * content; +}; + +static sw_metadata *vorbis_metadata_from_str (char * str) +{ + sw_metadata * meta = NULL; + int i; + + for (i = 0; str[i]; i++) { + str[i] = tolower(str[i]); + if (str[i] == '=') { + str[i] = '\0'; + meta = malloc (sizeof (sw_metadata)); + meta->name = malloc( strlen(str) + 18 ); + sprintf(meta->name, "meta.attr.%s.markup", str); + meta->content = strdup (&str[i+1]); + break; + } + } + return meta; +} + /** Constructor for libvorbis. */ @@ -118,6 +147,16 @@ static int producer_open( mlt_producer this, char *file ) // Assign the ov structure mlt_properties_set_data( properties, "ogg_vorbis_file", ov, 0, producer_file_close, NULL ); + // Read metadata + sw_metadata * metadata = NULL; + char **ptr = ov_comment(ov, -1)->user_comments; + while(*ptr) { + metadata = vorbis_metadata_from_str (*ptr); + if (metadata != NULL) + mlt_properties_set(properties, metadata->name, metadata->content); + ++ptr; + } + if ( ov_seekable( ov ) ) { // Get the length of the file -- 1.7.4.4