Mercurial > libavformat.hg
comparison mp3.c @ 2098:b51b57909b5f libavformat
id3v2 writer
patch by Andreas ?man andreas olebyn nu
original thread: [FFmpeg-devel] [Ffmpeg-devel] ID3v2
author | benoit |
---|---|
date | Tue, 22 May 2007 08:28:32 +0000 |
parents | cab3fcb34077 |
children | da71207a7cf1 |
comparison
equal
deleted
inserted
replaced
2097:cab3fcb34077 | 2098:b51b57909b5f |
---|---|
496 return 0; | 496 return 0; |
497 } | 497 } |
498 | 498 |
499 #ifdef CONFIG_MUXERS | 499 #ifdef CONFIG_MUXERS |
500 /* simple formats */ | 500 /* simple formats */ |
501 | |
502 static void id3v2_put_size(AVFormatContext *s, int size) | |
503 { | |
504 put_byte(&s->pb, size >> 21 & 0x7f); | |
505 put_byte(&s->pb, size >> 14 & 0x7f); | |
506 put_byte(&s->pb, size >> 7 & 0x7f); | |
507 put_byte(&s->pb, size & 0x7f); | |
508 } | |
509 | |
510 static void id3v2_put_ttag(AVFormatContext *s, char *string, uint32_t tag) | |
511 { | |
512 int len = strlen(string); | |
513 put_be32(&s->pb, tag); | |
514 id3v2_put_size(s, len + 1); | |
515 put_be16(&s->pb, 0); | |
516 put_byte(&s->pb, 3); /* UTF-8 */ | |
517 put_buffer(&s->pb, string, len); | |
518 } | |
519 | |
520 | |
521 /** | |
522 * Write an ID3v2.4 header at beginning of stream | |
523 */ | |
524 | |
501 static int mp3_write_header(struct AVFormatContext *s) | 525 static int mp3_write_header(struct AVFormatContext *s) |
502 { | 526 { |
527 int totlen = 0; | |
528 char tracktxt[10]; | |
529 | |
530 if(s->track) | |
531 snprintf(tracktxt, sizeof(tracktxt) - 1, "%d", s->track); | |
532 | |
533 if(s->title[0]) totlen += 11 + strlen(s->title); | |
534 if(s->author[0]) totlen += 11 + strlen(s->author); | |
535 if(s->album[0]) totlen += 11 + strlen(s->album); | |
536 if(s->genre[0]) totlen += 11 + strlen(s->genre); | |
537 if(s->copyright[0]) totlen += 11 + strlen(s->copyright); | |
538 if(s->track) totlen += 11 + strlen(tracktxt); | |
539 if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) | |
540 totlen += strlen(LIBAVFORMAT_IDENT) + 11; | |
541 | |
542 if(totlen == 0) | |
543 return 0; | |
544 | |
545 put_be32(&s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */ | |
546 put_byte(&s->pb, 0); | |
547 put_byte(&s->pb, 0); /* flags */ | |
548 | |
549 id3v2_put_size(s, totlen); | |
550 | |
551 if(s->title[0]) id3v2_put_ttag(s, s->title, MKBETAG('T', 'I', 'T', '2')); | |
552 if(s->author[0]) id3v2_put_ttag(s, s->author, MKBETAG('T', 'P', 'E', '1')); | |
553 if(s->album[0]) id3v2_put_ttag(s, s->album, MKBETAG('T', 'A', 'L', 'B')); | |
554 if(s->genre[0]) id3v2_put_ttag(s, s->genre, MKBETAG('T', 'C', 'O', 'N')); | |
555 if(s->copyright[0]) id3v2_put_ttag(s, s->copyright, MKBETAG('T', 'C', 'O', 'P')); | |
556 if(s->track) id3v2_put_ttag(s, tracktxt, MKBETAG('T', 'R', 'C', 'K')); | |
557 if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) | |
558 id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C')); | |
503 return 0; | 559 return 0; |
504 } | 560 } |
505 | 561 |
506 static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt) | 562 static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
507 { | 563 { |