[FFmpeg-devel] [PATCH] MP3 ID3V2 year and comment tags

phgiroud at free.fr phgiroud
Sat Dec 15 18:13:43 CET 2007


Hello to all,
This is my first contibution, I hope I'm not breaking any rules. I've
implemented support for MP3 ID3V2 (for now, only reading) tags "comment" and
"year"
Modifications:

static void id3v2_read_ttag(AVFormatContext *s, int taglen, char *dst, int
dstlen)
{
    char *q;
    int len;

    if(taglen < 1)
        return;

    taglen--; /* account for encoding type byte */
    dstlen--; /* Leave space for zero terminator */
    if (dst == s->comment) //We have to skip the "lang" stream
        dst = dst - 4;
    switch(get_byte(s->pb)) { /* encoding type */

    case 0:  /* ISO-8859-1 (0 - 255 maps directly into unicode) */
        q = dst ;
        while(taglen--) {
            uint8_t tmp;
            PUT_UTF8(get_byte(s->pb), tmp, if (q - dst < dstlen - 1) *q++ =
tmp;)
        }
        *q = '\0';
        break;

    case 3:  /* UTF-8 */
        len = FFMIN(taglen, dstlen);
        get_buffer(s->pb, dst, len);
        dst[len] = 0;
        break;
    }
}


and the function id3v2_parse is modified that way:

        case MKBETAG('C', 'O', 'M', 'M'):
        case MKBETAG(0,   'C', 'O', 'M'):
            id3v2_read_ttag(s, tlen, s->comment, sizeof(s->comment));
            break;
        case MKBETAG('T', 'Y', 'E', 'R'):
        case MKBETAG(0,   'T', 'Y', 'E'):
            id3v2_read_ttag(s, tlen, tmp, sizeof(tmp));
            s->year = atoi(tmp);
            break;

just before "case 0".

Greetings,




More information about the ffmpeg-devel mailing list