Revision bbe46bc4

View differences:

libavformat/isom.h
106 106
    unsigned int keyframe_count;
107 107
    int *keyframes;
108 108
    int time_scale;
109
    int time_rate;
110 109
    int time_offset;      ///< time offset of the first edit list entry
111 110
    int current_sample;
112 111
    unsigned int bytes_per_frame;
libavformat/mov.c
1253 1253
        sc->stts_data[i].count= sample_count;
1254 1254
        sc->stts_data[i].duration= sample_duration;
1255 1255

  
1256
        sc->time_rate= av_gcd(sc->time_rate, sample_duration);
1257

  
1258 1256
        dprintf(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
1259 1257

  
1260 1258
        duration+=(int64_t)sample_duration*sample_count;
......
1282 1280
    sc->dts_shift = get_be32(pb);
1283 1281
    dprintf(c->fc, "dts shift %d\n", sc->dts_shift);
1284 1282

  
1285
    sc->time_rate= av_gcd(sc->time_rate, FFABS(sc->dts_shift));
1286

  
1287 1283
    get_be32(pb); // least dts to pts delta
1288 1284
    get_be32(pb); // greatest dts to pts delta
1289 1285
    get_be32(pb); // pts start
......
1317 1313

  
1318 1314
        sc->ctts_data[i].count   = count;
1319 1315
        sc->ctts_data[i].duration= duration;
1320

  
1321
        sc->time_rate= av_gcd(sc->time_rate, FFABS(duration));
1322 1316
    }
1323 1317
    return 0;
1324 1318
}
......
1337 1331
    /* adjust first dts according to edit list */
1338 1332
    if (sc->time_offset) {
1339 1333
        int rescaled = sc->time_offset < 0 ? av_rescale(sc->time_offset, sc->time_scale, mov->time_scale) : sc->time_offset;
1340
        assert(sc->time_offset % sc->time_rate == 0);
1341
        current_dts = - (rescaled / sc->time_rate);
1334
        current_dts = -rescaled;
1342 1335
        if (sc->ctts_data && sc->ctts_data[0].duration / sc->stts_data[0].duration > 16) {
1343 1336
            /* more than 16 frames delay, dts are likely wrong
1344 1337
               this happens with files created by iMovie */
......
1356 1349
        unsigned int distance = 0;
1357 1350
        int key_off = sc->keyframes && sc->keyframes[0] == 1;
1358 1351

  
1359
        sc->dts_shift /= sc->time_rate;
1360 1352
        current_dts -= sc->dts_shift;
1361 1353

  
1362 1354
        st->nb_frames = sc->sample_count;
......
1394 1386
                }
1395 1387

  
1396 1388
                current_offset += sample_size;
1397
                assert(sc->stts_data[stts_index].duration % sc->time_rate == 0);
1398
                current_dts += sc->stts_data[stts_index].duration / sc->time_rate;
1389
                current_dts += sc->stts_data[stts_index].duration;
1399 1390
                distance++;
1400 1391
                stts_sample++;
1401 1392
                current_sample++;
......
1443 1434
                        size, samples);
1444 1435

  
1445 1436
                current_offset += size;
1446
                assert(samples % sc->time_rate == 0);
1447
                current_dts += samples / sc->time_rate;
1437
                current_dts += samples;
1448 1438
                chunk_samples -= samples;
1449 1439
            }
1450 1440
        }
......
1477 1467
        return 0;
1478 1468
    }
1479 1469

  
1480
    if (!sc->time_rate)
1481
        sc->time_rate = 1;
1482 1470
    if (!sc->time_scale)
1483 1471
        sc->time_scale = c->time_scale;
1484 1472

  
1485
    av_set_pts_info(st, 64, sc->time_rate, sc->time_scale);
1473
    av_set_pts_info(st, 64, 1, sc->time_scale);
1486 1474

  
1487 1475
    if (st->codec->codec_type == CODEC_TYPE_AUDIO &&
1488 1476
        !st->codec->frame_size && sc->stts_count == 1) {
......
1491 1479
        dprintf(c->fc, "frame size %d\n", st->codec->frame_size);
1492 1480
    }
1493 1481

  
1494
    if (st->duration != AV_NOPTS_VALUE) {
1495
        assert(st->duration % sc->time_rate == 0);
1496
        st->duration /= sc->time_rate;
1497
    }
1498

  
1499 1482
    mov_build_index(c, st);
1500 1483

  
1501 1484
    if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {
......
1754 1737
                "size %d, distance %d, keyframe %d\n", st->index, sc->sample_count+i,
1755 1738
                offset, dts, sample_size, distance, keyframe);
1756 1739
        distance++;
1757
        assert(sample_duration % sc->time_rate == 0);
1758
        dts += sample_duration / sc->time_rate;
1740
        dts += sample_duration;
1759 1741
        offset += sample_size;
1760 1742
    }
1761 1743
    frag->moof_offset = offset;
......
1856 1838
        get_be32(pb); /* Media rate */
1857 1839
        if (i == 0 && time >= -1) {
1858 1840
            sc->time_offset = time != -1 ? time : -duration;
1859
            sc->time_rate = av_gcd(sc->time_rate, FFABS(sc->time_offset));
1860 1841
        }
1861 1842
    }
1862 1843

  
......
2006 1987
        MOVStreamContext *msc = st->priv_data;
2007 1988
        if (st->discard != AVDISCARD_ALL && msc->pb && msc->current_sample < st->nb_index_entries) {
2008 1989
            AVIndexEntry *current_sample = &st->index_entries[msc->current_sample];
2009
            int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate,
2010
                                     AV_TIME_BASE, msc->time_scale);
1990
            int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
2011 1991
            dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
2012 1992
            if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) ||
2013 1993
                (!url_is_streamed(s->pb) &&
......
2051 2031
    pkt->stream_index = sc->ffindex;
2052 2032
    pkt->dts = sample->timestamp;
2053 2033
    if (sc->ctts_data) {
2054
        assert(sc->ctts_data[sc->ctts_index].duration % sc->time_rate == 0);
2055
        pkt->pts = pkt->dts + sc->dts_shift + sc->ctts_data[sc->ctts_index].duration / sc->time_rate;
2034
        pkt->pts = pkt->dts + sc->dts_shift + sc->ctts_data[sc->ctts_index].duration;
2056 2035
        /* update ctts context */
2057 2036
        sc->ctts_sample++;
2058 2037
        if (sc->ctts_index < sc->ctts_count &&

Also available in: Unified diff