Mercurial > libavformat.hg
comparison mov.c @ 4933:fc6288f47467 libavformat
parse 'stps' atom to set keyframe, partial sync sample for mpeg-2 open gop
author | bcoudurier |
---|---|
date | Wed, 13 May 2009 08:31:22 +0000 |
parents | c4c2ed0868cf |
children | 02e9151a011e |
comparison
equal
deleted
inserted
replaced
4932:af0ca3f0643f | 4933:fc6288f47467 |
---|---|
1100 sc->stsc_data[i].id = get_be32(pb); | 1100 sc->stsc_data[i].id = get_be32(pb); |
1101 } | 1101 } |
1102 return 0; | 1102 return 0; |
1103 } | 1103 } |
1104 | 1104 |
1105 static int mov_read_stps(MOVContext *c, ByteIOContext *pb, MOVAtom atom) | |
1106 { | |
1107 AVStream *st; | |
1108 MOVStreamContext *sc; | |
1109 unsigned i, entries; | |
1110 | |
1111 if (c->fc->nb_streams < 1) | |
1112 return 0; | |
1113 st = c->fc->streams[c->fc->nb_streams-1]; | |
1114 sc = st->priv_data; | |
1115 | |
1116 get_be32(pb); // version + flags | |
1117 | |
1118 entries = get_be32(pb); | |
1119 if (entries >= UINT_MAX / sizeof(*sc->stps_data)) | |
1120 return -1; | |
1121 sc->stps_data = av_malloc(entries * sizeof(*sc->stps_data)); | |
1122 if (!sc->stps_data) | |
1123 return AVERROR(ENOMEM); | |
1124 sc->stps_count = entries; | |
1125 | |
1126 for (i = 0; i < entries; i++) { | |
1127 sc->stps_data[i] = get_be32(pb); | |
1128 //dprintf(c->fc, "stps %d\n", sc->stps_data[i]); | |
1129 } | |
1130 | |
1131 return 0; | |
1132 } | |
1133 | |
1105 static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOVAtom atom) | 1134 static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1106 { | 1135 { |
1107 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | 1136 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
1108 MOVStreamContext *sc = st->priv_data; | 1137 MOVStreamContext *sc = st->priv_data; |
1109 unsigned int i, entries; | 1138 unsigned int i, entries; |
1298 int64_t current_offset; | 1327 int64_t current_offset; |
1299 int64_t current_dts = 0; | 1328 int64_t current_dts = 0; |
1300 unsigned int stts_index = 0; | 1329 unsigned int stts_index = 0; |
1301 unsigned int stsc_index = 0; | 1330 unsigned int stsc_index = 0; |
1302 unsigned int stss_index = 0; | 1331 unsigned int stss_index = 0; |
1332 unsigned int stps_index = 0; | |
1303 unsigned int i, j; | 1333 unsigned int i, j; |
1304 | 1334 |
1305 /* adjust first dts according to edit list */ | 1335 /* adjust first dts according to edit list */ |
1306 if (sc->time_offset) { | 1336 if (sc->time_offset) { |
1307 int rescaled = sc->time_offset < 0 ? av_rescale(sc->time_offset, sc->time_scale, mov->time_scale) : sc->time_offset; | 1337 int rescaled = sc->time_offset < 0 ? av_rescale(sc->time_offset, sc->time_scale, mov->time_scale) : sc->time_offset; |
1318 /* only use old uncompressed audio chunk demuxing when stts specifies it */ | 1348 /* only use old uncompressed audio chunk demuxing when stts specifies it */ |
1319 if (!(st->codec->codec_type == CODEC_TYPE_AUDIO && | 1349 if (!(st->codec->codec_type == CODEC_TYPE_AUDIO && |
1320 sc->stts_count == 1 && sc->stts_data[0].duration == 1)) { | 1350 sc->stts_count == 1 && sc->stts_data[0].duration == 1)) { |
1321 unsigned int current_sample = 0; | 1351 unsigned int current_sample = 0; |
1322 unsigned int stts_sample = 0; | 1352 unsigned int stts_sample = 0; |
1323 unsigned int keyframe, sample_size; | 1353 unsigned int sample_size; |
1324 unsigned int distance = 0; | 1354 unsigned int distance = 0; |
1325 int key_off = sc->keyframes && sc->keyframes[0] == 1; | 1355 int key_off = sc->keyframes && sc->keyframes[0] == 1; |
1326 | 1356 |
1327 sc->dts_shift /= sc->time_rate; | 1357 sc->dts_shift /= sc->time_rate; |
1328 current_dts -= sc->dts_shift; | 1358 current_dts -= sc->dts_shift; |
1332 current_offset = sc->chunk_offsets[i]; | 1362 current_offset = sc->chunk_offsets[i]; |
1333 if (stsc_index + 1 < sc->stsc_count && | 1363 if (stsc_index + 1 < sc->stsc_count && |
1334 i + 1 == sc->stsc_data[stsc_index + 1].first) | 1364 i + 1 == sc->stsc_data[stsc_index + 1].first) |
1335 stsc_index++; | 1365 stsc_index++; |
1336 for (j = 0; j < sc->stsc_data[stsc_index].count; j++) { | 1366 for (j = 0; j < sc->stsc_data[stsc_index].count; j++) { |
1367 int keyframe = 0; | |
1337 if (current_sample >= sc->sample_count) { | 1368 if (current_sample >= sc->sample_count) { |
1338 av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n"); | 1369 av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n"); |
1339 return; | 1370 return; |
1340 } | 1371 } |
1341 keyframe = !sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index]; | 1372 |
1342 if (keyframe) { | 1373 if (!sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index]) { |
1343 distance = 0; | 1374 keyframe = 1; |
1344 if (stss_index + 1 < sc->keyframe_count) | 1375 if (stss_index + 1 < sc->keyframe_count) |
1345 stss_index++; | 1376 stss_index++; |
1377 } else if (sc->stps_count && current_sample+key_off == sc->stps_data[stps_index]) { | |
1378 keyframe = 1; | |
1379 if (stps_index + 1 < sc->stps_count) | |
1380 stps_index++; | |
1346 } | 1381 } |
1382 if (keyframe) | |
1383 distance = 0; | |
1347 sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; | 1384 sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; |
1348 if(sc->pseudo_stream_id == -1 || | 1385 if(sc->pseudo_stream_id == -1 || |
1349 sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) { | 1386 sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) { |
1350 av_add_index_entry(st, current_offset, current_dts, sample_size, distance, | 1387 av_add_index_entry(st, current_offset, current_dts, sample_size, distance, |
1351 keyframe ? AVINDEX_KEYFRAME : 0); | 1388 keyframe ? AVINDEX_KEYFRAME : 0); |
1490 av_freep(&sc->chunk_offsets); | 1527 av_freep(&sc->chunk_offsets); |
1491 av_freep(&sc->stsc_data); | 1528 av_freep(&sc->stsc_data); |
1492 av_freep(&sc->sample_sizes); | 1529 av_freep(&sc->sample_sizes); |
1493 av_freep(&sc->keyframes); | 1530 av_freep(&sc->keyframes); |
1494 av_freep(&sc->stts_data); | 1531 av_freep(&sc->stts_data); |
1532 av_freep(&sc->stps_data); | |
1495 | 1533 |
1496 return 0; | 1534 return 0; |
1497 } | 1535 } |
1498 | 1536 |
1499 static int mov_read_ilst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) | 1537 static int mov_read_ilst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1859 { MKTAG('a','l','a','c'), mov_read_extradata }, /* alac specific atom */ | 1897 { MKTAG('a','l','a','c'), mov_read_extradata }, /* alac specific atom */ |
1860 { MKTAG('a','v','c','C'), mov_read_glbl }, | 1898 { MKTAG('a','v','c','C'), mov_read_glbl }, |
1861 { MKTAG('p','a','s','p'), mov_read_pasp }, | 1899 { MKTAG('p','a','s','p'), mov_read_pasp }, |
1862 { MKTAG('s','t','b','l'), mov_read_default }, | 1900 { MKTAG('s','t','b','l'), mov_read_default }, |
1863 { MKTAG('s','t','c','o'), mov_read_stco }, | 1901 { MKTAG('s','t','c','o'), mov_read_stco }, |
1902 { MKTAG('s','t','p','s'), mov_read_stps }, | |
1864 { MKTAG('s','t','s','c'), mov_read_stsc }, | 1903 { MKTAG('s','t','s','c'), mov_read_stsc }, |
1865 { MKTAG('s','t','s','d'), mov_read_stsd }, /* sample description */ | 1904 { MKTAG('s','t','s','d'), mov_read_stsd }, /* sample description */ |
1866 { MKTAG('s','t','s','s'), mov_read_stss }, /* sync sample */ | 1905 { MKTAG('s','t','s','s'), mov_read_stss }, /* sync sample */ |
1867 { MKTAG('s','t','s','z'), mov_read_stsz }, /* sample size */ | 1906 { MKTAG('s','t','s','z'), mov_read_stsz }, /* sample size */ |
1868 { MKTAG('s','t','t','s'), mov_read_stts }, | 1907 { MKTAG('s','t','t','s'), mov_read_stts }, |