[FFmpeg-devel] [PATCH] nut metadata conversion table

Michael Niedermayer michaelni
Mon Feb 15 23:59:42 CET 2010


On Sat, Feb 06, 2010 at 05:48:30PM +0100, Anton Khirnov wrote:
> Hi,
> attached patch adds $subj+makes nutenc write all available metadata.
> 
> i've removed the code that sets muxer ident string for now because of my
> other patch that moves it to a higher level. i'll restore it if that is
> rejected.
> 
> Anton Khirnov
> 

>  nut.c    |   13 +++++++++++++
>  nut.h    |    8 ++++++++
>  nutdec.c |    1 +
>  nutenc.c |   34 ++++++++++++++++++++++++----------
>  4 files changed, 46 insertions(+), 10 deletions(-)
> 4dfbcaa7940f58725c64480ddaab915764f196d6  0001-Add-NUT-metadata-conv-table.patch
> From 34aa7a4dd7a15c3594f8eba7b94fd9a18756fa24 Mon Sep 17 00:00:00 2001
> From: Anton Khirnov <wyskas at gmail.com>
> Date: Fri, 5 Feb 2010 19:53:10 +0100
> Subject: [PATCH] Add NUT metadata conv table.
> 
> ---
>  libavformat/nut.c    |   13 +++++++++++++
>  libavformat/nut.h    |    8 ++++++++
>  libavformat/nutdec.c |    1 +
>  libavformat/nutenc.c |   34 ++++++++++++++++++++++++----------
>  4 files changed, 46 insertions(+), 10 deletions(-)
> 
> diff --git a/libavformat/nut.c b/libavformat/nut.c
> index 6fdc298..e52baab 100644
> --- a/libavformat/nut.c
> +++ b/libavformat/nut.c
> @@ -79,3 +79,16 @@ const Dispositions ff_nut_dispositions[] = {
>      {""            , 0}
>  };
>  
> +const AVMetadataConv ff_nut_metadata_conv[] = {
> +    { "Author",         "artist"    },
> +    { "CreationTime",   "date"      },
> +    { "SourceFilename", "filename"  },
> +    { 0 },
> +};
> +
> +const char *ff_nut_tags[] = {
> +    "Author", "CaptureDevice", "CreationTime", "Copyright", "Description",
> +    "Encoder", "Keywords", "Language", "Source", "SourceCodecTag",
> +    "SourceContainer", "SourceFilename", "Title",
> +    NULL
> +};
> diff --git a/libavformat/nut.h b/libavformat/nut.h
> index a1081ed..d8aebd8 100644
> --- a/libavformat/nut.h
> +++ b/libavformat/nut.h
> @@ -27,6 +27,7 @@
>  //#include "libavcodec/mpegaudio.h"
>  #include "avformat.h"
>  #include "riff.h"
> +#include "metadata.h"
>  
>  #define      MAIN_STARTCODE (0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48))
>  #define    STREAM_STARTCODE (0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48))
> @@ -112,4 +113,11 @@ void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts);
>  
>  extern const Dispositions ff_nut_dispositions[];
>  
> +extern const AVMetadataConv ff_nut_metadata_conv[];
> +
> +/**
> + * A list of standard NUT tags.
> + */
> +extern const char *ff_nut_tags[];
> +
>  #endif /* AVFORMAT_NUT_H */
> diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
> index 564faf2..ea2ac86 100644
> --- a/libavformat/nutdec.c
> +++ b/libavformat/nutdec.c
> @@ -915,5 +915,6 @@ AVInputFormat nut_demuxer = {
>      nut_read_close,
>      read_seek,
>      .extensions = "nut",
> +    .metadata_conv = ff_nut_metadata_conv,
>  };
>  #endif
> diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
> index 47d2dc5..555f801 100644
> --- a/libavformat/nutenc.c
> +++ b/libavformat/nutenc.c
> @@ -19,8 +19,10 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> +#include <strings.h>
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/tree.h"
> +#include "libavutil/avstring.h"
>  #include "libavcodec/mpegaudiodata.h"
>  #include "nut.h"
>  
> @@ -448,23 +450,34 @@ static int add_info(ByteIOContext *bc, const char *type, const char *value){
>  
>  static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){
>      AVFormatContext *s= nut->avf;
> -    AVMetadataTag *title, *author, *copyright;
> +    AVMetadataTag *t = NULL;
>      ByteIOContext *dyn_bc;
>      uint8_t *dyn_buf=NULL;
> -    int count=0, dyn_size;
> +    int count=0, dyn_size, i;
>      int ret = url_open_dyn_buf(&dyn_bc);
>      if(ret < 0)
>          return ret;
>  
> -    title     = av_metadata_get(s->metadata, "Title"    , NULL, 0);
> -    author    = av_metadata_get(s->metadata, "Author"   , NULL, 0);
> -    copyright = av_metadata_get(s->metadata, "Copyright", NULL, 0);
> +    while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) {
> +        for (i = 0; ff_nut_tags[i]; i++) {
> +            if (!strcasecmp(ff_nut_tags[i], t->key)) {
> +                count += add_info(dyn_bc, t->key, t->value);
> +                break;
> +            }
> +        }
>  
> -    if(title    ) count+= add_info(dyn_bc, "Title"    , title->value);
> -    if(author   ) count+= add_info(dyn_bc, "Author"   , author->value);
> -    if(copyright) count+= add_info(dyn_bc, "Copyright", copyright->value);
> -    if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
> -                        count+= add_info(dyn_bc, "Encoder"  , LIBAVFORMAT_IDENT);
> +        if (!ff_nut_tags[i]) {
> +            /* unknown tag, write with X- prefix */

The "X-" prefix is not meant in the form of
if user provided tag doesnt use a key from the standard list 
prefix by "X-"
that would be majorly pointless

The idea was definitly in the form of
That elements that are not prefixed by X- must conform to the spec
in that sense the author of "lord of the rings" is tolkien not some
actor of the movie. and the time and language must conform to the
specs not be in some arbitrary form
"X-" is free form, where you can store anything
"" must be strictly conforming



> +            char *key;
> +            int len = strlen(t->key);

> +            len = FFMIN(len, 62);   /* nut specs allows max 64-byte keys */

elaborate

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100215/1ec4869f/attachment.pgp>



More information about the ffmpeg-devel mailing list