diff options
author | Aurelien Jacobs <aurel@gnuage.org> | 2009-01-06 03:09:23 +0300 |
---|---|---|
committer | Aurelien Jacobs <aurel@gnuage.org> | 2009-01-06 03:09:23 +0300 |
commit | 176aee8282c7d53b658de07ddf5bc4b0b3e5a7fc (patch) | |
tree | b64b2df5abf9aa8082ccf6da44dcce3450323290 /libavformat | |
parent | e232c2529e61844890c77c8e6426be233e2e07be (diff) |
Add a metadata compatibility layer, so that when a user application set
metadata using old API, it is automatically converted to new API before
muxing.
Originally committed as revision 16447 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/metadata.c | 37 | ||||
-rw-r--r-- | libavformat/metadata.h | 4 | ||||
-rw-r--r-- | libavformat/utils.c | 4 |
3 files changed, 45 insertions, 0 deletions
diff --git a/libavformat/metadata.c b/libavformat/metadata.c index fec80d9822..8a25782f29 100644 --- a/libavformat/metadata.c +++ b/libavformat/metadata.c @@ -73,3 +73,40 @@ int av_metadata_set(AVMetadata **pm, AVMetadataTag elem) return 0; } + +#if LIBAVFORMAT_VERSION_MAJOR < 53 +#define FILL_METADATA(s, key, value) { \ + if (value && *value && \ + !av_metadata_get(s->metadata, #key, NULL, AV_METADATA_IGNORE_CASE)) \ + av_metadata_set(&s->metadata, (const AVMetadataTag){#key, value}); \ + } +#define FILL_METADATA_STR(s, key) FILL_METADATA(s, key, s->key) +#define FILL_METADATA_INT(s, key) { \ + char number[10]; \ + snprintf(number, sizeof(number), "%d", s->key); \ + FILL_METADATA(s, key, number) } + +void ff_metadata_sync_compat(AVFormatContext *ctx) +{ + int i; + + FILL_METADATA_STR(ctx, title); + FILL_METADATA_STR(ctx, author); + FILL_METADATA_STR(ctx, copyright); + FILL_METADATA_STR(ctx, comment); + FILL_METADATA_STR(ctx, album); + FILL_METADATA_INT(ctx, year); + FILL_METADATA_INT(ctx, track); + FILL_METADATA_STR(ctx, genre); + for (i=0; i<ctx->nb_chapters; i++) + FILL_METADATA_STR(ctx->chapters[i], title); + for (i=0; i<ctx->nb_programs; i++) { + FILL_METADATA_STR(ctx->programs[i], name); + FILL_METADATA_STR(ctx->programs[i], provider_name); + } + for (i=0; i<ctx->nb_streams; i++) { + FILL_METADATA_STR(ctx->streams[i], language); + FILL_METADATA_STR(ctx->streams[i], filename); + } +} +#endif diff --git a/libavformat/metadata.h b/libavformat/metadata.h index 515b6cdb3b..2826ecc72e 100644 --- a/libavformat/metadata.h +++ b/libavformat/metadata.h @@ -35,4 +35,8 @@ struct AVMetadata{ AVMetadataTag *elems; }; +#if LIBAVFORMAT_VERSION_MAJOR < 53 +void ff_metadata_sync_compat(AVFormatContext *s); +#endif + #endif /* AVFORMAT_METADATA_H */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 68cb0da6c4..e3fdd7f744 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2501,6 +2501,10 @@ int av_write_header(AVFormatContext *s) return AVERROR(ENOMEM); } +#if LIBAVFORMAT_VERSION_MAJOR < 53 + ff_metadata_sync_compat(s); +#endif + if(s->oformat->write_header){ ret = s->oformat->write_header(s); if (ret < 0) |