436
static int mov_read_pasp(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
438
const int num = get_be32(pb);
439
const int den = get_be32(pb);
440
AVStream * const st = c->fc->streams[c->fc->nb_streams-1];
442
if ((st->sample_aspect_ratio.den && den != st->sample_aspect_ratio.den) ||
443
(st->sample_aspect_ratio.num && num != st->sample_aspect_ratio.num))
444
av_log(c->fc, AV_LOG_WARNING,
445
"sample aspect ratio already set, overriding by 'pasp' atom\n");
446
st->sample_aspect_ratio.num = num;
447
st->sample_aspect_ratio.den = den;
432
452
/* this atom contains actual media data */
433
static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
453
static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
435
455
if(atom.size == 0) /* wrong one (MP4) */
461
481
return 0; /* now go for mdat */
464
static int mov_read_moof(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
484
static int mov_read_moof(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
466
486
c->fragment.moof_offset = url_ftell(pb) - 8;
467
487
dprintf(c->fc, "moof offset %llx\n", c->fragment.moof_offset);
468
488
return mov_read_default(c, pb, atom);
471
static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
491
static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
473
493
AVStream *st = c->fc->streams[c->fc->nb_streams-1];
474
494
MOVStreamContext *sc = st->priv_data;
954
980
sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;
956
982
} else if(st->codec->codec_type==CODEC_TYPE_SUBTITLE){
983
// ttxt stsd contains display flags, justification, background
984
// color, fonts, and default styles, so fake an atom to read it
985
MOVAtom fake_atom = { .size = size - (url_ftell(pb) - start_pos) };
986
mov_read_glbl(c, pb, fake_atom);
957
987
st->codec->codec_id= id;
988
st->codec->width = sc->width;
989
st->codec->height = sc->height;
959
991
/* other codec type, just skip (rtp, mp4s, tmcd ...) */
960
992
url_fskip(pb, size - (url_ftell(pb) - start_pos));
1369
static void mov_parse_udta_string(ByteIOContext *pb, char *str, int size)
1371
uint16_t str_size = get_be16(pb); /* string length */;
1373
get_be16(pb); /* skip language */
1407
static int mov_read_ilst(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
1410
c->itunes_metadata = 1;
1411
ret = mov_read_default(c, pb, atom);
1412
c->itunes_metadata = 0;
1416
static int mov_read_meta(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
1418
url_fskip(pb, 4); // version + flags
1420
return mov_read_default(c, pb, atom);
1423
static int mov_read_trkn(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
1425
get_be32(pb); // type
1426
get_be32(pb); // unknown
1427
c->fc->track = get_be32(pb);
1428
dprintf(c->fc, "%.4s %d\n", (char*)&atom.type, c->fc->track);
1432
static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
1438
if (c->itunes_metadata) {
1439
int data_size = get_be32(pb);
1440
int tag = get_le32(pb);
1441
if (tag == MKTAG('d','a','t','a')) {
1442
get_be32(pb); // type
1443
get_be32(pb); // unknown
1444
str_size = data_size - 16;
1447
str_size = get_be16(pb); // string length
1448
get_be16(pb); // language
1450
switch (atom.type) {
1451
case MKTAG(0xa9,'n','a','m'):
1452
str = c->fc->title; size = sizeof(c->fc->title); break;
1453
case MKTAG(0xa9,'A','R','T'):
1454
case MKTAG(0xa9,'w','r','t'):
1455
str = c->fc->author; size = sizeof(c->fc->author); break;
1456
case MKTAG(0xa9,'c','p','y'):
1457
str = c->fc->copyright; size = sizeof(c->fc->copyright); break;
1458
case MKTAG(0xa9,'c','m','t'):
1459
case MKTAG(0xa9,'i','n','f'):
1460
str = c->fc->comment; size = sizeof(c->fc->comment); break;
1461
case MKTAG(0xa9,'a','l','b'):
1462
str = c->fc->album; size = sizeof(c->fc->album); break;
1374
1466
get_buffer(pb, str, FFMIN(size, str_size));
1377
static int mov_read_udta(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1379
uint64_t end = url_ftell(pb) + atom.size;
1381
while (url_ftell(pb) + 8 < end) {
1382
uint32_t tag_size = get_be32(pb);
1383
uint32_t tag = get_le32(pb);
1384
uint64_t next = url_ftell(pb) + tag_size - 8;
1386
if (tag_size < 8 || next > end) // stop if tag_size is wrong
1390
case MKTAG(0xa9,'n','a','m'):
1391
mov_parse_udta_string(pb, c->fc->title, sizeof(c->fc->title));
1393
case MKTAG(0xa9,'w','r','t'):
1394
mov_parse_udta_string(pb, c->fc->author, sizeof(c->fc->author));
1396
case MKTAG(0xa9,'c','p','y'):
1397
mov_parse_udta_string(pb, c->fc->copyright, sizeof(c->fc->copyright));
1399
case MKTAG(0xa9,'i','n','f'):
1400
mov_parse_udta_string(pb, c->fc->comment, sizeof(c->fc->comment));
1406
url_fseek(pb, next, SEEK_SET);
1467
dprintf(c->fc, "%.4s %s\n", (char*)&atom.type, str);
1412
static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1471
static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
1715
1777
{ MKTAG('f','t','y','p'), mov_read_ftyp },
1716
1778
{ MKTAG('g','l','b','l'), mov_read_glbl },
1717
1779
{ MKTAG('h','d','l','r'), mov_read_hdlr },
1780
{ MKTAG('i','l','s','t'), mov_read_ilst },
1718
1781
{ MKTAG('j','p','2','h'), mov_read_extradata },
1719
1782
{ MKTAG('m','d','a','t'), mov_read_mdat },
1720
1783
{ MKTAG('m','d','h','d'), mov_read_mdhd },
1721
1784
{ MKTAG('m','d','i','a'), mov_read_default },
1785
{ MKTAG('m','e','t','a'), mov_read_meta },
1722
1786
{ MKTAG('m','i','n','f'), mov_read_default },
1723
1787
{ MKTAG('m','o','o','f'), mov_read_moof },
1724
1788
{ MKTAG('m','o','o','v'), mov_read_moov },
1727
1791
{ MKTAG('S','M','I',' '), mov_read_smi }, /* Sorenson extension ??? */
1728
1792
{ MKTAG('a','l','a','c'), mov_read_extradata }, /* alac specific atom */
1729
1793
{ MKTAG('a','v','c','C'), mov_read_glbl },
1794
{ MKTAG('p','a','s','p'), mov_read_pasp },
1730
1795
{ MKTAG('s','t','b','l'), mov_read_default },
1731
1796
{ MKTAG('s','t','c','o'), mov_read_stco },
1732
1797
{ MKTAG('s','t','s','c'), mov_read_stsc },
1739
1804
{ MKTAG('t','r','a','k'), mov_read_trak },
1740
1805
{ MKTAG('t','r','a','f'), mov_read_default },
1741
1806
{ MKTAG('t','r','e','x'), mov_read_trex },
1807
{ MKTAG('t','r','k','n'), mov_read_trkn },
1742
1808
{ MKTAG('t','r','u','n'), mov_read_trun },
1743
{ MKTAG('u','d','t','a'), mov_read_udta },
1809
{ MKTAG('u','d','t','a'), mov_read_default },
1744
1810
{ MKTAG('w','a','v','e'), mov_read_wave },
1745
1811
{ MKTAG('e','s','d','s'), mov_read_esds },
1746
1812
{ MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */
1747
1813
{ MKTAG('c','m','o','v'), mov_read_cmov },
1814
{ MKTAG(0xa9,'n','a','m'), mov_read_udta_string },
1815
{ MKTAG(0xa9,'w','r','t'), mov_read_udta_string },
1816
{ MKTAG(0xa9,'c','p','y'), mov_read_udta_string },
1817
{ MKTAG(0xa9,'i','n','f'), mov_read_udta_string },
1818
{ MKTAG(0xa9,'i','n','f'), mov_read_udta_string },
1819
{ MKTAG(0xa9,'A','R','T'), mov_read_udta_string },
1820
{ MKTAG(0xa9,'a','l','b'), mov_read_udta_string },
1821
{ MKTAG(0xa9,'c','m','t'), mov_read_udta_string },