77 static int64_t
add_ctts_entry(
MOVStts** ctts_data,
unsigned int* ctts_count,
unsigned int* allocated_size,
81 unsigned len,
const char *
key)
85 short current, total = 0;
101 unsigned len,
const char *
key)
115 unsigned len,
const char *
key)
124 unsigned len,
const char *
key)
140 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
141 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
142 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
143 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
144 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
145 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
146 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
147 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
148 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
149 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
150 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
151 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
152 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
153 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
154 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
155 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
159 char *dst,
int dstlen)
162 char *
end = dst+dstlen-1;
165 for (
i = 0;
i <
len;
i++) {
234 char buf[200], place[100];
235 uint16_t langcode = 0;
236 double longitude, latitude, altitude;
237 const char *
key =
"location";
239 if (
len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
259 "loci too short (%u bytes left, need at least %d)\n",
len, 12);
267 snprintf(
buf,
sizeof(
buf),
"%+08.4f%+09.4f", latitude, longitude);
287 if (
c->ignore_chapters)
291 if (n_hmmt >
len / 4)
308 uint16_t langcode = 0;
309 uint32_t data_type = 0, str_size, str_size_alloc;
315 case MKTAG(
'@',
'P',
'R',
'M'):
key =
"premiere_version"; raw = 1;
break;
316 case MKTAG(
'@',
'P',
'R',
'Q'):
key =
"quicktime_version"; raw = 1;
break;
317 case MKTAG(
'X',
'M',
'P',
'_'):
318 if (
c->export_xmp) {
key =
"xmp"; raw = 1; }
break;
319 case MKTAG(
'a',
'A',
'R',
'T'):
key =
"album_artist";
break;
320 case MKTAG(
'a',
'k',
'I',
'D'):
key =
"account_type";
322 case MKTAG(
'a',
'p',
'I',
'D'):
key =
"account_id";
break;
323 case MKTAG(
'c',
'a',
't',
'g'):
key =
"category";
break;
324 case MKTAG(
'c',
'p',
'i',
'l'):
key =
"compilation";
326 case MKTAG(
'c',
'p',
'r',
't'):
key =
"copyright";
break;
327 case MKTAG(
'd',
'e',
's',
'c'):
key =
"description";
break;
328 case MKTAG(
'd',
'i',
's',
'k'):
key =
"disc";
330 case MKTAG(
'e',
'g',
'i',
'd'):
key =
"episode_uid";
332 case MKTAG(
'F',
'I',
'R',
'M'):
key =
"firmware"; raw = 1;
break;
333 case MKTAG(
'g',
'n',
'r',
'e'):
key =
"genre";
335 case MKTAG(
'h',
'd',
'v',
'd'):
key =
"hd_video";
337 case MKTAG(
'H',
'M',
'M',
'T'):
339 case MKTAG(
'k',
'e',
'y',
'w'):
key =
"keywords";
break;
340 case MKTAG(
'l',
'd',
'e',
's'):
key =
"synopsis";
break;
341 case MKTAG(
'l',
'o',
'c',
'i'):
343 case MKTAG(
'm',
'a',
'n',
'u'):
key =
"make";
break;
344 case MKTAG(
'm',
'o',
'd',
'l'):
key =
"model";
break;
345 case MKTAG(
'p',
'c',
's',
't'):
key =
"podcast";
347 case MKTAG(
'p',
'g',
'a',
'p'):
key =
"gapless_playback";
349 case MKTAG(
'p',
'u',
'r',
'd'):
key =
"purchase_date";
break;
350 case MKTAG(
'r',
't',
'n',
'g'):
key =
"rating";
352 case MKTAG(
's',
'o',
'a',
'a'):
key =
"sort_album_artist";
break;
353 case MKTAG(
's',
'o',
'a',
'l'):
key =
"sort_album";
break;
354 case MKTAG(
's',
'o',
'a',
'r'):
key =
"sort_artist";
break;
355 case MKTAG(
's',
'o',
'c',
'o'):
key =
"sort_composer";
break;
356 case MKTAG(
's',
'o',
'n',
'm'):
key =
"sort_name";
break;
357 case MKTAG(
's',
'o',
's',
'n'):
key =
"sort_show";
break;
358 case MKTAG(
's',
't',
'i',
'k'):
key =
"media_type";
360 case MKTAG(
't',
'r',
'k',
'n'):
key =
"track";
362 case MKTAG(
't',
'v',
'e',
'n'):
key =
"episode_id";
break;
363 case MKTAG(
't',
'v',
'e',
's'):
key =
"episode_sort";
365 case MKTAG(
't',
'v',
'n',
'n'):
key =
"network";
break;
366 case MKTAG(
't',
'v',
's',
'h'):
key =
"show";
break;
367 case MKTAG(
't',
'v',
's',
'n'):
key =
"season_number";
369 case MKTAG(0xa9,
'A',
'R',
'T'):
key =
"artist";
break;
370 case MKTAG(0xa9,
'P',
'R',
'D'):
key =
"producer";
break;
371 case MKTAG(0xa9,
'a',
'l',
'b'):
key =
"album";
break;
372 case MKTAG(0xa9,
'a',
'u',
't'):
key =
"artist";
break;
373 case MKTAG(0xa9,
'c',
'h',
'p'):
key =
"chapter";
break;
374 case MKTAG(0xa9,
'c',
'm',
't'):
key =
"comment";
break;
375 case MKTAG(0xa9,
'c',
'o',
'm'):
key =
"composer";
break;
376 case MKTAG(0xa9,
'c',
'p',
'y'):
key =
"copyright";
break;
377 case MKTAG(0xa9,
'd',
'a',
'y'):
key =
"date";
break;
378 case MKTAG(0xa9,
'd',
'i',
'r'):
key =
"director";
break;
379 case MKTAG(0xa9,
'd',
'i',
's'):
key =
"disclaimer";
break;
380 case MKTAG(0xa9,
'e',
'd',
'1'):
key =
"edit_date";
break;
381 case MKTAG(0xa9,
'e',
'n',
'c'):
key =
"encoder";
break;
382 case MKTAG(0xa9,
'f',
'm',
't'):
key =
"original_format";
break;
383 case MKTAG(0xa9,
'g',
'e',
'n'):
key =
"genre";
break;
384 case MKTAG(0xa9,
'g',
'r',
'p'):
key =
"grouping";
break;
385 case MKTAG(0xa9,
'h',
's',
't'):
key =
"host_computer";
break;
386 case MKTAG(0xa9,
'i',
'n',
'f'):
key =
"comment";
break;
387 case MKTAG(0xa9,
'l',
'y',
'r'):
key =
"lyrics";
break;
388 case MKTAG(0xa9,
'm',
'a',
'k'):
key =
"make";
break;
389 case MKTAG(0xa9,
'm',
'o',
'd'):
key =
"model";
break;
390 case MKTAG(0xa9,
'n',
'a',
'm'):
key =
"title";
break;
391 case MKTAG(0xa9,
'o',
'p',
'e'):
key =
"original_artist";
break;
392 case MKTAG(0xa9,
'p',
'r',
'd'):
key =
"producer";
break;
393 case MKTAG(0xa9,
'p',
'r',
'f'):
key =
"performers";
break;
394 case MKTAG(0xa9,
'r',
'e',
'q'):
key =
"playback_requirements";
break;
395 case MKTAG(0xa9,
's',
'r',
'c'):
key =
"original_source";
break;
396 case MKTAG(0xa9,
's',
't',
'3'):
key =
"subtitle";
break;
397 case MKTAG(0xa9,
's',
'w',
'r'):
key =
"encoder";
break;
398 case MKTAG(0xa9,
't',
'o',
'o'):
key =
"encoder";
break;
399 case MKTAG(0xa9,
't',
'r',
'k'):
key =
"track";
break;
400 case MKTAG(0xa9,
'u',
'r',
'l'):
key =
"URL";
break;
401 case MKTAG(0xa9,
'w',
'r',
'n'):
key =
"warning";
break;
402 case MKTAG(0xa9,
'w',
'r',
't'):
key =
"composer";
break;
403 case MKTAG(0xa9,
'x',
'y',
'z'):
key =
"location";
break;
406 if (
c->itunes_metadata && atom.
size > 8) {
409 if (
tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
412 str_size = data_size - 16;
415 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r')) {
421 atom.
size -= str_size;
425 }
else if (!
key &&
c->found_hdlr_mdta &&
c->meta_keys) {
427 if (index < c->meta_keys_count &&
index > 0) {
431 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
432 index,
c->meta_keys_count);
436 }
else if (atom.
size > 4 &&
key && !
c->itunes_metadata && !raw) {
438 if (str_size > atom.
size) {
448 str_size = atom.
size;
450 if (
c->export_all && !
key) {
457 if (atom.
size < 0 || str_size >= INT_MAX/2)
462 num = (data_type >= 21 && data_type <= 23);
463 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
471 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
473 }
else if (data_type == 21) {
477 else if (str_size == 2)
479 else if (str_size == 3)
481 else if (str_size == 4)
483 if (
snprintf(str, str_size_alloc,
"%d",
val) >= str_size_alloc) {
485 "Failed to store the number (%d) in string.\n",
val);
489 }
else if (data_type == 22) {
490 unsigned int val = 0;
493 else if (str_size == 2)
495 else if (str_size == 3)
497 else if (str_size == 4)
499 if (
snprintf(str, str_size_alloc,
"%u",
val) >= str_size_alloc) {
501 "Failed to store the number (%u) in string.\n",
val);
505 }
else if (data_type == 23 && str_size >= 4) {
507 if (
snprintf(str, str_size_alloc,
"%f",
val) >= str_size_alloc) {
509 "Failed to store the float32 number (%f) in string.\n",
val);
527 if (!strcmp(
key,
"encoder")) {
528 int major, minor, micro;
529 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
530 c->handbrake_version = 1000000*major + 1000*minor + micro;
542 int i, nb_chapters, str_len,
version;
546 if (
c->ignore_chapters)
549 if ((atom.
size -= 5) < 0)
558 for (
i = 0;
i < nb_chapters;
i++) {
565 if ((atom.
size -= 9+str_len) < 0)
577 #define MIN_DATA_ENTRY_BOX_SIZE 12
584 if (
c->fc->nb_streams < 1)
586 st =
c->fc->streams[
c->fc->nb_streams-1];
593 entries >= UINT_MAX /
sizeof(*sc->
drefs))
603 for (
i = 0;
i < entries;
i++) {
608 if (
size < 12 || next < 0 || next > INT64_MAX -
size)
618 uint16_t volume_len,
len;
625 volume_len =
FFMIN(volume_len, 27);
629 dref->
volume[volume_len] = 0;
671 if (
len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
677 for (j =
len - 1; j >= 0; j--) {
678 if (dref->
path[j] == 0)
683 for (j = 0; j <
len; j++)
684 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
687 }
else if (
type == 0) {
699 for (j = 0; j <
len; j++)
700 if (dref->
dir[j] ==
':')
736 if (
c->trak_index < 0) {
738 c->found_hdlr_mdta = 1;
743 st =
c->fc->streams[
c->fc->nb_streams-1];
758 title_size = atom.
size - 24;
759 if (title_size > 0) {
760 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
771 title_str[title_size] = 0;
773 int off = (!
c->isom && title_str[0] == title_size - 1);
792 int ac3info, acmod, lfeon, bsmod;
794 if (
c->fc->nb_streams < 1)
796 st =
c->fc->streams[
c->fc->nb_streams-1];
804 bsmod = (ac3info >> 14) & 0x7;
805 acmod = (ac3info >> 11) & 0x7;
806 lfeon = (ac3info >> 10) & 0x1;
815 #if FF_API_LAVF_AVCTX
817 st->codec->audio_service_type = *ast;
828 int eac3info, acmod, lfeon, bsmod;
830 if (
c->fc->nb_streams < 1)
832 st =
c->fc->streams[
c->fc->nb_streams-1];
844 bsmod = (eac3info >> 12) & 0x1f;
845 acmod = (eac3info >> 9) & 0x7;
846 lfeon = (eac3info >> 8) & 0x1;
855 #if FF_API_LAVF_AVCTX
857 st->codec->audio_service_type = *ast;
866 const uint32_t ddts_size = 20;
869 uint32_t frame_duration_code = 0;
870 uint32_t channel_layout_code = 0;
884 if (
c->fc->nb_streams < 1) {
888 st =
c->fc->streams[
c->fc->nb_streams-1];
899 frame_duration_code =
get_bits(&gb, 2);
901 channel_layout_code =
get_bits(&gb, 16);
904 (frame_duration_code == 0) ? 512 :
905 (frame_duration_code == 1) ? 1024 :
906 (frame_duration_code == 2) ? 2048 :
907 (frame_duration_code == 3) ? 4096 : 0;
909 if (channel_layout_code > 0xff) {
930 if (
c->fc->nb_streams < 1)
932 st =
c->fc->streams[
c->fc->nb_streams-1];
950 if (
c->fc->nb_streams < 1)
952 st =
c->fc->streams[
c->fc->nb_streams-1];
966 if (
c->fc->nb_streams < 1)
968 st =
c->fc->streams[
c->fc->nb_streams-1];
973 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
976 }
else if (den != 0) {
992 #define DRM_BLOB_SIZE 56
1001 uint8_t calculated_checksum[20];
1005 uint8_t *activation_bytes =
c->activation_bytes;
1006 uint8_t *fixed_key =
c->audible_fixed_key;
1015 if (!
c->aes_decrypt) {
1027 for (
i = 0;
i < 20;
i++)
1032 if (!activation_bytes) {
1037 if (
c->activation_bytes_size != 4) {
1044 if (
c->audible_fixed_key_size != 16) {
1064 if (memcmp(calculated_checksum, file_checksum, 20)) {
1071 for (
i = 0;
i < 4;
i++) {
1073 if (activation_bytes[
i] !=
output[3 -
i]) {
1079 memcpy(
c->file_key,
output + 8, 16);
1097 unsigned char iv[16];
1099 memcpy(iv,
c->file_iv, 16);
1111 int comp_brand_size;
1112 char* comp_brands_str;
1118 if (strcmp(
type,
"qt "))
1125 comp_brand_size = atom.
size - 8;
1126 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1128 comp_brands_str =
av_malloc(comp_brand_size + 1);
1129 if (!comp_brands_str)
1137 comp_brands_str[comp_brand_size] = 0;
1138 av_dict_set(&
c->fc->metadata,
"compatible_brands", comp_brands_str, 0);
1149 if (
c->found_moov) {
1171 if (index < 0 || index >= frag_index->
nb_items)
1187 if (frag_index->
current < 0 ||
1206 if (frag_index->
current < 0 ||
1221 int64_t moof_offset;
1234 if (moof_offset >=
offset)
1236 if (moof_offset <=
offset)
1253 int index,
int track_id)
1259 if (track_id >= 0) {
1292 m0 = m = (
a +
b) >> 1;
1298 if (m <
b && frag_time <= timestamp)
1315 if (index < c->frag_index.nb_items &&
1322 &
c->frag_index.allocated_size,
1323 (
c->frag_index.nb_items + 1) *
1324 sizeof(*
c->frag_index.item));
1327 c->frag_index.item = item;
1331 if (!frag_stream_info)
1334 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1336 if (
c->fc->streams[
i]->id < 0) {
1341 frag_stream_info[
i].
id =
c->fc->streams[
i]->id;
1349 if (index < c->frag_index.nb_items)
1350 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1351 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1353 item = &
c->frag_index.item[
index];
1359 c->frag_index.nb_items++;
1365 int id,
int entries)
1374 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1382 c->fragment.found_tfhd = 0;
1384 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1385 c->has_looked_for_mfra = 1;
1392 "read the mfra (may be a live ismv)\n");
1396 "seekable, can not look for mfra\n");
1399 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1408 if(time >= 2082844800)
1411 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1427 int64_t creation_time;
1429 if (
c->fc->nb_streams < 1)
1431 st =
c->fc->streams[
c->fc->nb_streams-1];
1472 int64_t creation_time;
1485 if (
c->time_scale <= 0) {
1494 if (
c->time_scale > 0 && !
c->trex_data)
1503 for (
i = 0;
i < 3;
i++) {
1525 if (
c->fc->nb_streams < 1)
1527 st =
c->fc->streams[
c->fc->nb_streams-1];
1531 if (little_endian == 1) {
1555 char color_parameter_type[5] = { 0 };
1559 if (
c->fc->nb_streams < 1)
1561 st =
c->fc->streams[
c->fc->nb_streams - 1];
1566 if (strncmp(color_parameter_type,
"nclx", 4) &&
1567 strncmp(color_parameter_type,
"nclc", 4)) {
1569 color_parameter_type);
1578 "%s: pri %d trc %d matrix %d",
1581 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1608 unsigned mov_field_order;
1611 if (
c->fc->nb_streams < 1)
1613 st =
c->fc->streams[
c->fc->nb_streams-1];
1617 if ((mov_field_order & 0xFF00) == 0x0100)
1619 else if ((mov_field_order & 0xFF00) == 0x0200) {
1620 switch (mov_field_order & 0xFF) {
1643 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1666 }
else if (err < atom.
size) {
1680 uint64_t original_size;
1683 if (
c->fc->nb_streams < 1)
1685 st =
c->fc->streams[
c->fc->nb_streams-1];
1734 if (!
ret &&
c->fc->nb_streams >= 1) {
1746 if (
c->fc->nb_streams >= 1) {
1755 if (
cid == 0xd4d ||
cid == 0xd4e)
1766 if (num <= 0 || den <= 0)
1770 if (den >= INT_MAX / 2)
1774 c->fc->streams[
c->fc->nb_streams-1]->display_aspect_ratio.num = num;
1775 c->fc->streams[
c->fc->nb_streams-1]->display_aspect_ratio.den = den;
1789 uint64_t original_size;
1790 if (
c->fc->nb_streams >= 1) {
1794 if (atom.
size == 16) {
1801 switch (range_value) {
1838 if (
c->fc->nb_streams < 1)
1840 st =
c->fc->streams[
c->fc->nb_streams-1];
1842 if ((uint64_t)atom.
size > (1<<30))
1853 }
else if (atom.
size > 8) {
1867 #define ALAC_EXTRADATA_SIZE 36
1896 if (
c->fc->nb_streams < 1)
1898 st =
c->fc->streams[
c->fc->nb_streams-1];
1900 if ((uint64_t)atom.
size > (1<<30))
1903 if (atom.
size >= 10) {
1939 if (
c->fc->nb_streams < 1)
1941 st =
c->fc->streams[
c->fc->nb_streams-1];
1943 if (atom.
size >= (1<<28) || atom.
size < 7)
1947 if ((profile_level & 0xf0) != 0xc0)
1969 if (
c->fc->nb_streams < 1)
1971 if (atom.
size <= 40)
1973 st =
c->fc->streams[
c->fc->nb_streams-1];
1975 if ((uint64_t)atom.
size > (1<<30))
1991 unsigned int i, entries;
1993 if (
c->trak_index < 0) {
1997 if (
c->fc->nb_streams < 1)
1999 st =
c->fc->streams[
c->fc->nb_streams-1];
2021 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2024 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2045 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2046 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2078 uint8_t codec_name[32] = { 0 };
2111 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2118 !strncmp(codec_name,
"Sorenson H263", 13))
2134 int bits_per_sample,
flags;
2153 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2234 if (bits_per_sample && (bits_per_sample >> 3) * (uint64_t)st->
codecpar->
channels <= INT_MAX) {
2259 y = (ycbcr >> 16) & 0xFF;
2260 cr = (ycbcr >> 8) & 0xFF;
2263 b = av_clip_uint8((1164 * (y - 16) + 2018 * (
cb - 128)) / 1000);
2264 g = av_clip_uint8((1164 * (y - 16) - 813 * (
cr - 128) - 391 * (
cb - 128)) / 1000);
2265 r = av_clip_uint8((1164 * (y - 16) + 1596 * (
cr - 128) ) / 1000);
2267 return (
r << 16) | (
g << 8) |
b;
2272 char buf[256] = {0};
2284 for (
i = 0;
i < 16;
i++) {
2325 #if FF_API_LAVF_AVCTX
2335 #if FF_API_LAVF_AVCTX
2346 if (str_size > 0 &&
size >= (
int)str_size + 30) {
2347 char *reel_name =
av_malloc(str_size + 1);
2351 reel_name[str_size] = 0;
2353 if (*reel_name == 0) {
2378 #if CONFIG_DV_DEMUXER
2449 int codec_tag,
int format,
2462 (
c->fc->video_codec_id ? video_codec_id !=
c->fc->video_codec_id
2463 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2480 int pseudo_stream_id;
2483 st =
c->fc->streams[
c->fc->nb_streams-1];
2486 for (pseudo_stream_id = 0;
2488 pseudo_stream_id++) {
2491 int ret, dref_id = 1;
2501 }
else if (
size <= 7) {
2503 "invalid size %"PRId64
" in stsd\n",
size);
2520 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
2550 }
else if (
a.size > 0)
2582 if (
c->fc->nb_streams < 1)
2584 st =
c->fc->streams[
c->fc->nb_streams - 1];
2592 if (entries <= 0 || entries > atom.
size / 8) {
2599 "Duplicate stsd found in this track.\n");
2645 unsigned int i, entries;
2647 if (
c->fc->nb_streams < 1)
2649 st =
c->fc->streams[
c->fc->nb_streams-1];
2656 if ((uint64_t)entries * 12 + 4 > atom.
size)
2681 int64_t first_min =
i + 1;
2737 unsigned i, entries;
2739 if (
c->fc->nb_streams < 1)
2741 st =
c->fc->streams[
c->fc->nb_streams-1];
2773 unsigned int i, entries;
2775 if (
c->fc->nb_streams < 1)
2777 st =
c->fc->streams[
c->fc->nb_streams-1];
2796 if (entries >= UINT_MAX /
sizeof(
int))
2822 unsigned int i, entries, sample_size, field_size, num_bytes;
2827 if (
c->fc->nb_streams < 1)
2829 st =
c->fc->streams[
c->fc->nb_streams-1];
2835 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
2854 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
2861 if (entries >= (UINT_MAX - 4) / field_size)
2871 num_bytes = (entries*field_size+4)>>3;
2915 unsigned int i, entries, alloc_size = 0;
2917 int64_t total_sample_count=0;
2919 if (
c->fc->nb_streams < 1)
2921 st =
c->fc->streams[
c->fc->nb_streams-1];
2929 c->fc->nb_streams-1, entries);
2935 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
2939 int sample_duration;
2940 unsigned int sample_count;
2941 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
2959 sample_count, sample_duration);
2961 duration+=(int64_t)sample_duration*(uint64_t)sample_count;
2962 total_sample_count+=sample_count;
2968 duration <= INT64_MAX - sc->duration_for_fps &&
2969 total_sample_count <= INT_MAX - sc->nb_frames_for_fps
3002 unsigned int i, entries, ctts_count = 0;
3004 if (
c->fc->nb_streams < 1)
3006 st =
c->fc->streams[
c->fc->nb_streams-1];
3017 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3030 "ignoring CTTS entry with count=%d duration=%d\n",
3068 unsigned int i, entries;
3070 uint32_t grouping_type;
3072 if (
c->fc->nb_streams < 1)
3074 st =
c->fc->streams[
c->fc->nb_streams-1];
3080 if (grouping_type !=
MKTAG(
'r',
'a',
'p',
' '))
3116 unsigned int edit_list_index,
3117 int64_t *edit_list_media_time,
3118 int64_t *edit_list_duration,
3119 int64_t global_timescale)
3124 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3128 if (global_timescale == 0) {
3161 int64_t timestamp_pts,
3164 int64_t* ctts_index,
3165 int64_t* ctts_sample)
3171 int64_t index_ctts_count;
3199 if (ctts_data && *
index >= 0) {
3205 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3206 if (*ctts_index < ctts_count) {
3208 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3215 while (*
index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3219 if ((e_old[*
index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3225 if (*ctts_sample == 0) {
3227 if (*ctts_index >= 0)
3228 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3238 return *
index >= 0 ? 0 : -1;
3261 const size_t requested_size =
3278 ie= &entries[
index];
3293 int64_t* frame_duration_buffer,
3294 int frame_duration_buffer_size) {
3296 av_assert0(end_index >= 0 && end_index <= st->nb_index_entries);
3297 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
3298 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
3311 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVStts);
3312 const size_t requested_size =
3313 min_size_needed > *allocated_size ?
3314 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3317 if((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVStts) - 1)
3320 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
3325 *ctts_data = ctts_buf_new;
3330 *ctts_count = (*ctts_count) + 1;
3334 #define MAX_REORDER_DELAY 16
3339 int ctts_sample = 0;
3342 int j,
r, num_swaps;
3345 pts_buf[j] = INT64_MIN;
3353 buf_start = (buf_start + 1);
3366 while (j != buf_start) {
3369 if (pts_buf[j] < pts_buf[
r]) {
3370 FFSWAP(int64_t, pts_buf[j], pts_buf[
r]);
3428 if (range_size > current_sample) {
3432 current_sample -= range_size;
3450 int64_t ctts_index_old = 0;
3451 int64_t ctts_sample_old = 0;
3453 int64_t edit_list_media_time = 0;
3454 int64_t edit_list_duration = 0;
3455 int64_t frame_duration = 0;
3456 int64_t edit_list_dts_counter = 0;
3457 int64_t edit_list_dts_entry_end = 0;
3458 int64_t edit_list_start_ctts_sample = 0;
3460 int64_t curr_ctts = 0;
3461 int64_t empty_edits_sum_duration = 0;
3462 int64_t edit_list_index = 0;
3465 int64_t start_dts = 0;
3466 int64_t edit_list_start_encountered = 0;
3467 int64_t search_timestamp = 0;
3468 int64_t* frame_duration_buffer =
NULL;
3469 int num_discarded_begin = 0;
3470 int first_non_zero_audio_edit = -1;
3471 int packet_skip_samples = 0;
3474 int found_keyframe_after_edit = 0;
3475 int found_non_empty_edit = 0;
3508 edit_list_dts_entry_end -= msc->
dts_shift;
3512 start_dts = edit_list_dts_entry_end;
3516 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3517 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3519 edit_list_dts_counter = edit_list_dts_entry_end;
3520 edit_list_dts_entry_end += edit_list_duration;
3521 num_discarded_begin = 0;
3522 if (!found_non_empty_edit && edit_list_media_time == -1) {
3523 empty_edits_sum_duration += edit_list_duration;
3526 found_non_empty_edit = 1;
3531 if (first_non_zero_audio_edit < 0) {
3532 first_non_zero_audio_edit = 1;
3534 first_non_zero_audio_edit = 0;
3537 if (first_non_zero_audio_edit > 0)
3545 search_timestamp = edit_list_media_time;
3554 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3556 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3557 st->
index, edit_list_index, search_timestamp);
3559 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3561 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
3562 st->
index, edit_list_index, search_timestamp);
3565 ctts_sample_old = 0;
3568 current = e_old +
index;
3569 edit_list_start_ctts_sample = ctts_sample_old;
3572 edit_list_start_encountered = 0;
3573 found_keyframe_after_edit = 0;
3574 for (; current < e_old_end; current++,
index++) {
3576 frame_duration = (current + 1 < e_old_end) ?
3577 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3585 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3586 curr_ctts = ctts_data_old[ctts_index_old].
duration;
3587 av_log(mov->
fc,
AV_LOG_DEBUG,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
3588 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
3589 curr_cts += curr_ctts;
3591 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3594 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3595 ctts_data_old[ctts_index_old].
duration) == -1) {
3598 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3599 ctts_data_old[ctts_index_old].
duration);
3603 ctts_sample_old = 0;
3604 edit_list_start_ctts_sample = 0;
3608 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3610 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3611 first_non_zero_audio_edit > 0) {
3612 packet_skip_samples = edit_list_media_time - curr_cts;
3616 edit_list_dts_counter -= packet_skip_samples;
3617 if (edit_list_start_encountered == 0) {
3618 edit_list_start_encountered = 1;
3621 if (frame_duration_buffer) {
3623 frame_duration_buffer, num_discarded_begin);
3628 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
3633 if (edit_list_start_encountered == 0) {
3634 num_discarded_begin++;
3635 frame_duration_buffer =
av_realloc(frame_duration_buffer,
3636 num_discarded_begin *
sizeof(int64_t));
3637 if (!frame_duration_buffer) {
3641 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
3656 if (edit_list_start_encountered == 0) {
3657 edit_list_start_encountered = 1;
3660 if (frame_duration_buffer) {
3662 frame_duration_buffer, num_discarded_begin);
3675 if (current_index_range < msc->index_ranges ||
index != current_index_range->
end) {
3676 current_index_range++;
3679 current_index_range->
end =
index + 1;
3682 if (edit_list_start_encountered > 0) {
3683 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
3687 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
3689 if (ctts_data_old) {
3694 found_keyframe_after_edit = 1;
3697 if (ctts_sample_old != 0) {
3700 ctts_sample_old - edit_list_start_ctts_sample,
3701 ctts_data_old[ctts_index_old].
duration) == -1) {
3703 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
3704 ctts_data_old[ctts_index_old].
duration);
3740 current_index_range++;
3741 current_index_range->
start = 0;
3742 current_index_range->
end = 0;
3749 int64_t current_offset;
3750 int64_t current_dts = 0;
3751 unsigned int stts_index = 0;
3752 unsigned int stsc_index = 0;
3753 unsigned int stss_index = 0;
3754 unsigned int stps_index = 0;
3756 uint64_t stream_size = 0;
3758 unsigned int ctts_count_old = sc->
ctts_count;
3761 int i, edit_start_index = 0, multiple_edits = 0;
3762 int64_t empty_duration = 0;
3767 if (
i == 0 && e->
time == -1) {
3771 edit_start_index = 1;
3772 }
else if (
i == edit_start_index && e->
time >= 0) {
3781 "Use -advanced_editlist to correctly decode otherwise "
3782 "a/v desync might occur\n");
3802 unsigned int current_sample = 0;
3803 unsigned int stts_sample = 0;
3804 unsigned int sample_size;
3806 unsigned int rap_group_index = 0;
3807 unsigned int rap_group_sample = 0;
3808 int64_t last_dts = 0;
3809 int64_t dts_correction = 0;
3814 last_dts = current_dts;
3828 if (ctts_data_old) {
3843 for (
i = 0;
i < ctts_count_old &&
3845 for (j = 0; j < ctts_data_old[
i].
count &&
3886 if (rap_group_present && rap_group_index < sc->rap_group_count) {
3889 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
3890 rap_group_sample = 0;
3896 && !rap_group_present
3905 if (sample_size > 0x3FFFFFFF) {
3910 e->
pos = current_offset;
3912 e->
size = sample_size;
3915 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", "
3916 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
3917 current_offset, current_dts, sample_size,
distance, keyframe);
3922 current_offset += sample_size;
3923 stream_size += sample_size;
3929 "Invalid SampleDelta %d in STTS, at %d st:%d\n",
3936 if (!dts_correction || current_dts + dts_correction > last_dts) {
3937 current_dts += dts_correction;
3941 dts_correction += current_dts - last_dts - 1;
3942 current_dts = last_dts + 1;
3944 last_dts = current_dts;
3957 unsigned chunk_samples, total = 0;
3964 unsigned count, chunk_count;
3979 count = (chunk_samples+1023) / 1024;
3986 total += chunk_count *
count;
4008 while (chunk_samples > 0) {
4014 "Zero bytes per frame, but %d samples per frame",
4037 if (
size > 0x3FFFFFFF) {
4042 e->
pos = current_offset;
4048 "size %u, duration %u\n", st->
index,
i, current_offset, current_dts,
4051 current_offset +=
size;
4084 av_url_split(src_proto,
sizeof(src_proto), src_auth,
sizeof(src_auth), src_host,
sizeof(src_host), &src_port,
NULL, 0,
src);
4085 av_url_split(ref_proto,
sizeof(ref_proto), ref_auth,
sizeof(ref_auth), ref_host,
sizeof(ref_host), &ref_port,
NULL, 0,
ref);
4087 if (strlen(
src) == 0) {
4089 }
else if (strlen(src_auth) + 1 >=
sizeof(src_auth) ||
4090 strlen(ref_auth) + 1 >=
sizeof(ref_auth) ||
4091 strlen(src_host) + 1 >=
sizeof(src_host) ||
4092 strlen(ref_host) + 1 >=
sizeof(ref_host)) {
4094 }
else if (strcmp(src_proto, ref_proto) ||
4095 strcmp(src_auth, ref_auth) ||
4096 strcmp(src_host, ref_host) ||
4097 src_port != ref_port) {
4107 if (
ref->nlvl_to > 0 &&
ref->nlvl_from > 0) {
4108 char filename[1025];
4109 const char *src_path;
4113 src_path = strrchr(
src,
'/');
4120 for (
i = 0, l = strlen(
ref->path) - 1; l >= 0; l--)
4121 if (
ref->path[l] ==
'/') {
4122 if (
i ==
ref->nlvl_to - 1)
4129 if (
i ==
ref->nlvl_to - 1 && src_path -
src <
sizeof(filename)) {
4130 memcpy(filename,
src, src_path -
src);
4131 filename[src_path -
src] = 0;
4133 for (
i = 1;
i <
ref->nlvl_from;
i++)
4134 av_strlcat(filename,
"../",
sizeof(filename));
4137 if (!
c->use_absolute_path) {
4142 "Reference with mismatching origin, %s not tried for security reasons, "
4143 "set demuxer option use_absolute_path to allow it anyway\n",
4148 if(strstr(
ref->path + l + 1,
"..") ||
4149 strstr(
ref->path + l + 1,
":") ||
4150 (
ref->nlvl_from > 1 && same_origin < 0) ||
4151 (filename[0] ==
'/' && src_path ==
src))
4155 if (strlen(filename) + 1 ==
sizeof(filename))
4160 }
else if (
c->use_absolute_path) {
4162 "this is a possible security issue\n");
4167 "Absolute path %s not tried for security reasons, "
4168 "set demuxer option use_absolute_path to allow absolute paths\n",
4192 if (!st)
return AVERROR(ENOMEM);
4195 if (!sc)
return AVERROR(ENOMEM);
4200 c->trak_index = st->
index;
4236 if (
c->enable_drefs) {
4239 "stream %d, error opening alias: path='%s', dir='%s', "
4240 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
4245 "Skipped opening external track: "
4246 "stream %d, alias: path='%s', dir='%s', "
4247 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d."
4248 "Set enable_drefs to allow this.\n",
4265 #if FF_API_R_FRAME_RATE
4281 #if CONFIG_H261_DECODER
4284 #if CONFIG_H263_DECODER
4287 #if CONFIG_MPEG4_DECODER
4317 c->itunes_metadata = 1;
4319 c->itunes_metadata = 0;
4333 if (
count > UINT_MAX /
sizeof(*
c->meta_keys) - 1) {
4335 "The 'keys' atom with the invalid key count: %"PRIu32
"\n",
count);
4339 c->meta_keys_count =
count + 1;
4340 c->meta_keys =
av_mallocz(
c->meta_keys_count *
sizeof(*
c->meta_keys));
4349 "The key# %"PRIu32
" in meta has invalid size:"
4350 "%"PRIu32
"\n",
i, key_size);
4358 if (!
c->meta_keys[
i])
4375 if (
c->fc->nb_streams < 1)
4377 st =
c->fc->streams[
c->fc->nb_streams-1];
4380 for (
i = 0;
i < 3;
i++) {
4395 if (
tag ==
MKTAG(
'm',
'e',
'a',
'n'))
4397 else if (
tag ==
MKTAG(
'n',
'a',
'm',
'e'))
4399 else if (
tag ==
MKTAG(
'd',
'a',
't',
'a') &&
len > 4) {
4422 if (mean &&
key &&
val) {
4423 if (strcmp(
key,
"iTunSMPB") == 0) {
4424 int priming, remainder,
samples;
4425 if(sscanf(
val,
"%*X %X %X %X", &priming, &remainder, &
samples) == 3){
4426 if(priming>0 && priming<16384)
4430 if (strcmp(
key,
"cdec") != 0) {