Revision c4f8765a
libavformat/mov.c | ||
---|---|---|
2283 | 2283 |
AVStream *st = NULL; |
2284 | 2284 |
MOVStreamContext *sc; |
2285 | 2285 |
int64_t cur_pos; |
2286 |
int i; |
|
2286 |
uint8_t *title = NULL; |
|
2287 |
int i, len, i8, i16; |
|
2287 | 2288 |
|
2288 | 2289 |
for (i = 0; i < s->nb_streams; i++) |
2289 | 2290 |
if (s->streams[i]->id == mov->chapter_track) { |
... | ... | |
2302 | 2303 |
for (i = 0; i < st->nb_index_entries; i++) { |
2303 | 2304 |
AVIndexEntry *sample = &st->index_entries[i]; |
2304 | 2305 |
int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration; |
2305 |
uint8_t title[512]; |
|
2306 |
uint16_t ch; |
|
2307 |
int len; |
|
2308 | 2306 |
|
2309 | 2307 |
if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { |
2310 | 2308 |
av_log(s, AV_LOG_ERROR, "Chapter %d not found in file\n", i); |
2311 | 2309 |
goto finish; |
2312 | 2310 |
} |
2313 | 2311 |
|
2312 |
title = av_malloc(sample->size+2); |
|
2313 |
get_buffer(sc->pb, title, sample->size); |
|
2314 |
|
|
2314 | 2315 |
// the first two bytes are the length of the title |
2315 |
len = get_be16(sc->pb);
|
|
2316 |
len = AV_RB16(title);
|
|
2316 | 2317 |
if (len > sample->size-2) |
2317 | 2318 |
continue; |
2318 | 2319 |
|
2319 | 2320 |
// The samples could theoretically be in any encoding if there's an encd |
2320 | 2321 |
// atom following, but in practice are only utf-8 or utf-16, distinguished |
2321 | 2322 |
// instead by the presence of a BOM |
2322 |
if ((ch = get_be16(sc->pb)) == 0xfeff) |
|
2323 |
avio_get_str16be(sc->pb, len, title, sizeof(title)); |
|
2324 |
else { |
|
2325 |
AV_WB16(title, ch); |
|
2326 |
get_buffer(sc->pb, title + sizeof(ch), sizeof(title) - sizeof(ch)); |
|
2323 |
if (AV_RB16(title+2) == 0xfeff) { |
|
2324 |
uint8_t *utf8 = av_malloc(2*len+3); |
|
2325 |
|
|
2326 |
i8 = i16 = 0; |
|
2327 |
while (i16 < len) { |
|
2328 |
uint32_t ch; |
|
2329 |
uint8_t tmp; |
|
2330 |
GET_UTF16(ch, i16 < len ? AV_RB16(title + (i16+=2)) : 0, break;) |
|
2331 |
PUT_UTF8(ch, tmp, if (i8 < 2*len) utf8[2+i8++] = tmp;) |
|
2332 |
} |
|
2333 |
utf8[2+i8] = 0; |
|
2334 |
av_freep(&title); |
|
2335 |
title = utf8; |
|
2327 | 2336 |
} |
2328 | 2337 |
|
2329 |
ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title); |
|
2338 |
ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title+2); |
|
2339 |
av_freep(&title); |
|
2330 | 2340 |
} |
2331 | 2341 |
finish: |
2342 |
av_free(title); |
|
2332 | 2343 |
url_fseek(sc->pb, cur_pos, SEEK_SET); |
2333 | 2344 |
} |
2334 | 2345 |
|
Also available in: Unified diff