[FFmpeg-devel] MetaData in Sun AU format

miniupnp miniupnp at free.fr
Wed Jun 8 16:16:31 CEST 2016


Le 08/06/2016 15:37, Michael Niedermayer a écrit :
> On Wed, Jun 08, 2016 at 12:03:10AM +0200, miniupnp wrote:
>>>> On 6/1/16, miniupnp <miniupnp at free.fr> wrote:
>>>>> Hello,
>>>>>
>>>>> I'm using the .AU audio file format and noticed that FFmpeg always put 8
>>>>> zero's in the annotation field.
>>>>> SOX does use the annotation field to put metadata
>>>>> (Title/Author/Album/Genre/Track)
>>>>>
>>>>> I don't think there is any precise specification for this AU annotation
>>>>> field as long as it is a null terminated character string, but what SOX
>>>>> does looks good.
>>>>>
>>>>> Attached are my patches to write metadata to AU files.
>>>> look fine to me.
>>> applied
>>> thx
>> And now is the patch to READ theses metadata in AU files.
>>
>> Regards,
>>
>> Thomas Bernard
>>
>>
>>  au.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
>>  1 file changed, 67 insertions(+), 2 deletions(-)
>> 501f81b2747e0758344d189918af2863d76c774d  0001-Read-MetaData-from-AU-Sun-audio-file-header.patch
>> From 10ca03e6a944b6a5385a92d72f633e98a0c1b57f Mon Sep 17 00:00:00 2001
>> From: Thomas Bernard <miniupnp at free.fr>
>> Date: Tue, 7 Jun 2016 00:25:38 +0200
>> Subject: [PATCH] Read MetaData from AU Sun audio file header
>>
>> recognize title= album= artist= genre= track=
>> ---
>>  libavformat/au.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>>  1 file changed, 67 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/au.c b/libavformat/au.c
>> index 4a0400b..dba2a83 100644
>> --- a/libavformat/au.c
>> +++ b/libavformat/au.c
>> @@ -66,6 +66,71 @@ static int au_probe(AVProbeData *p)
>>          return 0;
>>  }
>>  
>> +static int au_read_annotation(AVFormatContext *s, int size)
>> +{
>> +    static const char * keys[] = {
>> +        "title",
>> +        "artist",
>> +        "album",
>> +        "track",
>> +        "genre",
>> +        NULL };
>> +    AVIOContext *pb = s->pb;
>> +    enum { PARSE_KEY, PARSE_VALUE, PARSE_FINISHED } state = PARSE_KEY;
>> +    char c;
>> +    AVBPrint bprint;
>> +    char * key = NULL;
>> +    char * value = NULL;
>> +    int i;
>> +
>> +    av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
>> +
>> +    while (size-- > 0) {
>> +        c = avio_r8(pb);
>> +        switch(state) {
>> +        case PARSE_KEY:
>> +            if (c == '\0') {
>> +                state = PARSE_FINISHED;
>> +            } else if (c == '=') {
>> +                av_bprint_finalize(&bprint, &key);
>> +                av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
>> +                state = PARSE_VALUE;
>> +            } else {
>> +                av_bprint_chars(&bprint, c, 1);
>> +            }
>> +            break;
>> +        case PARSE_VALUE:
>> +            if (c == '\0' || c == '\n') {
>> +                if (av_bprint_finalize(&bprint, &value) != 0) {
>> +                    av_log(s, AV_LOG_ERROR, "Memory error while parsing AU metadata.\n");
>> +                } else {
>> +                    av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
>> +                    for (i = 0; keys[i] != NULL && key != NULL; i++) {
>> +                        if (av_strcasecmp(keys[i], key) == 0) {
>> +                            av_dict_set(&(s->metadata), keys[i], value, AV_DICT_DONT_STRDUP_VAL);
>> +                            av_freep(&key);
>> +                            value = NULL;
>> +                        }
>> +                    }
>> +                }
>> +                if (key != NULL) av_freep(&key);
>> +                if (value != NULL) av_freep(&value);
> redundant if()

I was not sure of what av_freep(&key) does when key==NULL.

here is the patch, plus a potential memory leak fix.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Read-MetaData-from-AU-Sun-audio-file-header.patch
Type: text/x-patch
Size: 3188 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160608/1cba7998/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-AU-metadata-remove-redundant-if-and-fix-potential-me.patch
Type: text/x-patch
Size: 1096 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160608/1cba7998/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160608/1cba7998/attachment.sig>


More information about the ffmpeg-devel mailing list