[FFmpeg-devel] [PATCH] Handle metadata in oma demuxer

Michael Niedermayer michaelni
Tue Jun 1 21:32:03 CEST 2010


On Sat, May 29, 2010 at 08:39:15PM +0200, Michael Karcher wrote:
> Hello,
> 
> the metadata in .oma (or .aa3, which is the same format) is essentially
> ID3v2, just with the "ID3" magic changed to "ea3" instead. The patch has
> been tested with http://samples.mplayerhq.hu/oma/01-Untitled(1).oma with
> the included metadata header and after removing it. It works fine in
> both cases.
> 
> The patch is available (if it's not too trivial to be licensed) under
> LGPLv2.1 or any later version.
> 
> The functions ff_id3v2_match and ff_id3v2_read have been cut-and-pasted
> to cope with the different magic string.
> 
> Regards,
>   Michael Karher
> 
> Changelog:
> Use id3v2 parser to handle for metadata in the oma demuxer.
> 

>  libavcodec/Makefile |    1 
>  libavformat/oma.c   |   74 ++++++++++++++++++++++++++++++++++------------------
>  2 files changed, 50 insertions(+), 25 deletions(-)
> 7975ba1f374c8c27b4261d6f3ffbcc11501d49a0  handle-oma-metadata.diff
> Index: libavcodec/Makefile
> ===================================================================
> --- libavcodec/Makefile	(Revision 23386)
> +++ libavcodec/Makefile	(Arbeitskopie)
> @@ -65,6 +65,7 @@
>  OBJS-$(CONFIG_ASV1_ENCODER)            += asv1.o mpeg12data.o
>  OBJS-$(CONFIG_ASV2_DECODER)            += asv1.o mpeg12data.o
>  OBJS-$(CONFIG_ASV2_ENCODER)            += asv1.o mpeg12data.o
> +OBJS-$(CONFIG_ATRAC1_DECODER)          += atrac1.o
>  OBJS-$(CONFIG_ATRAC1_DECODER)          += atrac1.o atrac.o
>  OBJS-$(CONFIG_ATRAC3_DECODER)          += atrac3.o atrac.o
>  OBJS-$(CONFIG_AURA_DECODER)            += cyuv.o
> Index: libavformat/oma.c
> ===================================================================
> --- libavformat/oma.c	(Revision 23386)
> +++ libavformat/oma.c	(Arbeitskopie)
> @@ -27,7 +27,8 @@
>   *
>   * Known file extensions: ".oma", "aa3"
>   * The format of such files consists of three parts:
> - * - "ea3" header carrying overall info and metadata.
> + * - "ea3" header carrying overall info and metadata. Except for starting with
> + *   "ea" instead of "ID", it's an ID3v2 header.
>   * - "EA3" header is a Sony-specific header containing information about
>   *   the OpenMG file: codec type (usually ATRAC, can also be MP3 or WMA),
>   *   codec specific info (packet size, sample rate, channels and so on)
> @@ -46,6 +47,7 @@
>  #include "libavutil/intreadwrite.h"
>  #include "raw.h"
>  #include "riff.h"
> +#include "id3v2.h"
>  
>  #define EA3_HEADER_SIZE 96
>  
> @@ -63,37 +65,55 @@
>      { CODEC_ID_MP3,     OMA_CODECID_MP3 },
>  };
>  
> +/* rip-off of ff_id3v2_match */
> +static int ea3_id_match(const uint8_t *buf)
> +{
> +    return  buf[0]         ==  'e' &&
> +            buf[1]         ==  'a' &&
> +            buf[2]         ==  '3' &&
> +            buf[3]         != 0xff &&
> +            buf[4]         != 0xff &&
> +           (buf[6] & 0x80) ==    0 &&
> +           (buf[7] & 0x80) ==    0 &&
> +           (buf[8] & 0x80) ==    0 &&
> +           (buf[9] & 0x80) ==    0;
> +}
> +
> +/* rip-off of ff_id3v2_read, using our private match function */
> +static void ea3_id_read(AVFormatContext *s)
> +{
> +    int len, ret;
> +    uint8_t buf[ID3v2_HEADER_SIZE];
> +
> +    ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
> +    if (ret != ID3v2_HEADER_SIZE)
> +        return;
> +    if (ea3_id_match(buf)) {
> +        /* parse ID3v2 header */
> +        len = ((buf[6] & 0x7f) << 21) |
> +            ((buf[7] & 0x7f) << 14) |
> +            ((buf[8] & 0x7f) << 7) |
> +            (buf[9] & 0x7f);
> +        ff_id3v2_parse(s, len, buf[3], buf[5]);
> +    } else {
> +        url_fseek(s->pb, 0, SEEK_SET);
> +    }
> +}

it would be nicer if existing code wuld be changed and the ea3/id3 string
or int be passed to it

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

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- 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/20100601/644ceb8c/attachment.pgp>



More information about the ffmpeg-devel mailing list