comparison mov.c @ 4033:836e25632f0b libavformat

read itunes metadata, code based on Reimar's patch
author bcoudurier
date Sun, 16 Nov 2008 01:59:35 +0000
parents 7d6ed3692203
children 5d5238798d59
comparison
equal deleted inserted replaced
4032:7c85b7921e61 4033:836e25632f0b
147 AVFormatContext *dv_fctx; 147 AVFormatContext *dv_fctx;
148 int isom; /* 1 if file is ISO Media (mp4/3gp) */ 148 int isom; /* 1 if file is ISO Media (mp4/3gp) */
149 MOVFragment fragment; ///< current fragment in moof atom 149 MOVFragment fragment; ///< current fragment in moof atom
150 MOVTrackExt *trex_data; 150 MOVTrackExt *trex_data;
151 unsigned trex_count; 151 unsigned trex_count;
152 int itunes_metadata; ///< metadata are itunes style
152 } MOVContext; 153 } MOVContext;
153 154
154 155
155 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */ 156 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
156 157
1364 av_freep(&sc->stts_data); 1365 av_freep(&sc->stts_data);
1365 1366
1366 return 0; 1367 return 0;
1367 } 1368 }
1368 1369
1370 static int mov_read_ilst(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1371 {
1372 int ret;
1373 c->itunes_metadata = 1;
1374 ret = mov_read_default(c, pb, atom);
1375 c->itunes_metadata = 0;
1376 return ret;
1377 }
1378
1379 static int mov_read_meta(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1380 {
1381 url_fskip(pb, 4);
1382 return mov_read_default(c, pb, atom);
1383 }
1384
1385 static int mov_read_trkn(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1386 {
1387 get_be32(pb); // type
1388 get_be32(pb); // unknown
1389 c->fc->track = get_be32(pb);
1390 dprintf(c->fc, "%.4s %d\n", (char*)&atom.type, c->fc->track);
1391 return 0;
1392 }
1393
1369 static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) 1394 static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1370 { 1395 {
1371 char *str = NULL; 1396 char *str = NULL;
1372 int size; 1397 int size;
1373 uint16_t str_size = get_be16(pb); /* string length */; 1398 uint16_t str_size;
1374 1399
1400 if (c->itunes_metadata) {
1401 int data_size = get_be32(pb);
1402 int tag = get_le32(pb);
1403 if (tag == MKTAG('d','a','t','a')) {
1404 get_be32(pb); // type
1405 get_be32(pb); // unknown
1406 str_size = data_size - 16;
1407 } else return 0;
1408 } else {
1409 str_size = get_be16(pb); // string length
1410 get_be16(pb); // language
1411 }
1375 switch (atom.type) { 1412 switch (atom.type) {
1376 case MKTAG(0xa9,'n','a','m'): 1413 case MKTAG(0xa9,'n','a','m'):
1377 str = c->fc->title; size = sizeof(c->fc->title); break; 1414 str = c->fc->title; size = sizeof(c->fc->title); break;
1415 case MKTAG(0xa9,'A','R','T'):
1378 case MKTAG(0xa9,'w','r','t'): 1416 case MKTAG(0xa9,'w','r','t'):
1379 str = c->fc->author; size = sizeof(c->fc->author); break; 1417 str = c->fc->author; size = sizeof(c->fc->author); break;
1380 case MKTAG(0xa9,'c','p','y'): 1418 case MKTAG(0xa9,'c','p','y'):
1381 str = c->fc->copyright; size = sizeof(c->fc->copyright); break; 1419 str = c->fc->copyright; size = sizeof(c->fc->copyright); break;
1420 case MKTAG(0xa9,'c','m','t'):
1382 case MKTAG(0xa9,'i','n','f'): 1421 case MKTAG(0xa9,'i','n','f'):
1383 str = c->fc->comment; size = sizeof(c->fc->comment); break; 1422 str = c->fc->comment; size = sizeof(c->fc->comment); break;
1423 case MKTAG(0xa9,'a','l','b'):
1424 str = c->fc->album; size = sizeof(c->fc->album); break;
1384 } 1425 }
1385 if (!str) 1426 if (!str)
1386 return 0; 1427 return 0;
1387 get_be16(pb); /* skip language */
1388 get_buffer(pb, str, FFMIN(size, str_size)); 1428 get_buffer(pb, str, FFMIN(size, str_size));
1429 dprintf(c->fc, "%.4s %s\n", (char*)&atom.type, str);
1389 return 0; 1430 return 0;
1390 } 1431 }
1391 1432
1392 static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) 1433 static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1393 { 1434 {
1693 { MKTAG('e','n','d','a'), mov_read_enda }, 1734 { MKTAG('e','n','d','a'), mov_read_enda },
1694 { MKTAG('f','i','e','l'), mov_read_extradata }, 1735 { MKTAG('f','i','e','l'), mov_read_extradata },
1695 { MKTAG('f','t','y','p'), mov_read_ftyp }, 1736 { MKTAG('f','t','y','p'), mov_read_ftyp },
1696 { MKTAG('g','l','b','l'), mov_read_glbl }, 1737 { MKTAG('g','l','b','l'), mov_read_glbl },
1697 { MKTAG('h','d','l','r'), mov_read_hdlr }, 1738 { MKTAG('h','d','l','r'), mov_read_hdlr },
1739 { MKTAG('i','l','s','t'), mov_read_ilst },
1698 { MKTAG('j','p','2','h'), mov_read_extradata }, 1740 { MKTAG('j','p','2','h'), mov_read_extradata },
1699 { MKTAG('m','d','a','t'), mov_read_mdat }, 1741 { MKTAG('m','d','a','t'), mov_read_mdat },
1700 { MKTAG('m','d','h','d'), mov_read_mdhd }, 1742 { MKTAG('m','d','h','d'), mov_read_mdhd },
1701 { MKTAG('m','d','i','a'), mov_read_default }, 1743 { MKTAG('m','d','i','a'), mov_read_default },
1744 { MKTAG('m','e','t','a'), mov_read_meta },
1702 { MKTAG('m','i','n','f'), mov_read_default }, 1745 { MKTAG('m','i','n','f'), mov_read_default },
1703 { MKTAG('m','o','o','f'), mov_read_moof }, 1746 { MKTAG('m','o','o','f'), mov_read_moof },
1704 { MKTAG('m','o','o','v'), mov_read_moov }, 1747 { MKTAG('m','o','o','v'), mov_read_moov },
1705 { MKTAG('m','v','e','x'), mov_read_default }, 1748 { MKTAG('m','v','e','x'), mov_read_default },
1706 { MKTAG('m','v','h','d'), mov_read_mvhd }, 1749 { MKTAG('m','v','h','d'), mov_read_mvhd },
1717 { MKTAG('t','k','h','d'), mov_read_tkhd }, /* track header */ 1760 { MKTAG('t','k','h','d'), mov_read_tkhd }, /* track header */
1718 { MKTAG('t','f','h','d'), mov_read_tfhd }, /* track fragment header */ 1761 { MKTAG('t','f','h','d'), mov_read_tfhd }, /* track fragment header */
1719 { MKTAG('t','r','a','k'), mov_read_trak }, 1762 { MKTAG('t','r','a','k'), mov_read_trak },
1720 { MKTAG('t','r','a','f'), mov_read_default }, 1763 { MKTAG('t','r','a','f'), mov_read_default },
1721 { MKTAG('t','r','e','x'), mov_read_trex }, 1764 { MKTAG('t','r','e','x'), mov_read_trex },
1765 { MKTAG('t','r','k','n'), mov_read_trkn },
1722 { MKTAG('t','r','u','n'), mov_read_trun }, 1766 { MKTAG('t','r','u','n'), mov_read_trun },
1723 { MKTAG('u','d','t','a'), mov_read_default }, 1767 { MKTAG('u','d','t','a'), mov_read_default },
1724 { MKTAG('w','a','v','e'), mov_read_wave }, 1768 { MKTAG('w','a','v','e'), mov_read_wave },
1725 { MKTAG('e','s','d','s'), mov_read_esds }, 1769 { MKTAG('e','s','d','s'), mov_read_esds },
1726 { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */ 1770 { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */
1727 { MKTAG('c','m','o','v'), mov_read_cmov }, 1771 { MKTAG('c','m','o','v'), mov_read_cmov },
1728 { MKTAG(0xa9,'n','a','m'), mov_read_udta_string }, 1772 { MKTAG(0xa9,'n','a','m'), mov_read_udta_string },
1729 { MKTAG(0xa9,'w','r','t'), mov_read_udta_string }, 1773 { MKTAG(0xa9,'w','r','t'), mov_read_udta_string },
1730 { MKTAG(0xa9,'c','p','y'), mov_read_udta_string }, 1774 { MKTAG(0xa9,'c','p','y'), mov_read_udta_string },
1731 { MKTAG(0xa9,'i','n','f'), mov_read_udta_string }, 1775 { MKTAG(0xa9,'i','n','f'), mov_read_udta_string },
1776 { MKTAG(0xa9,'i','n','f'), mov_read_udta_string },
1777 { MKTAG(0xa9,'A','R','T'), mov_read_udta_string },
1778 { MKTAG(0xa9,'a','l','b'), mov_read_udta_string },
1779 { MKTAG(0xa9,'c','m','t'), mov_read_udta_string },
1732 { 0, NULL } 1780 { 0, NULL }
1733 }; 1781 };
1734 1782
1735 static int mov_probe(AVProbeData *p) 1783 static int mov_probe(AVProbeData *p)
1736 { 1784 {