81 static int64_t
add_ctts_entry(
MOVCtts** ctts_data,
unsigned int* ctts_count,
unsigned int* allocated_size,
85 unsigned len,
const char *
key)
89 short current, total = 0;
95 snprintf(buf,
sizeof(buf),
"%d", current);
97 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
105 unsigned len,
const char *
key)
119 unsigned len,
const char *
key)
128 unsigned len,
const char *
key)
144 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
145 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
146 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
147 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
148 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
149 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
150 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
151 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
152 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
153 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
154 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
155 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
156 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
157 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
158 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
159 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
163 char *dst,
int dstlen)
166 char *end = dst+dstlen-1;
169 for (
i = 0;
i <
len;
i++) {
209 st =
c->fc->streams[
c->fc->nb_streams - 1];
228 char buf[200], place[100];
229 uint16_t langcode = 0;
230 double longitude, latitude, altitude;
231 const char *
key =
"location";
233 if (
len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
253 "loci too short (%u bytes left, need at least %d)\n",
len, 12);
261 snprintf(buf,
sizeof(buf),
"%+08.4f%+09.4f", latitude, longitude);
281 if (
c->ignore_chapters)
285 if (n_hmmt >
len / 4)
302 uint16_t langcode = 0;
303 uint32_t data_type = 0, str_size, str_size_alloc;
309 case MKTAG(
'@',
'P',
'R',
'M'):
key =
"premiere_version"; raw = 1;
break;
310 case MKTAG(
'@',
'P',
'R',
'Q'):
key =
"quicktime_version"; raw = 1;
break;
311 case MKTAG(
'X',
'M',
'P',
'_'):
312 if (
c->export_xmp) {
key =
"xmp"; raw = 1; }
break;
313 case MKTAG(
'a',
'A',
'R',
'T'):
key =
"album_artist";
break;
314 case MKTAG(
'a',
'k',
'I',
'D'):
key =
"account_type";
316 case MKTAG(
'a',
'p',
'I',
'D'):
key =
"account_id";
break;
317 case MKTAG(
'c',
'a',
't',
'g'):
key =
"category";
break;
318 case MKTAG(
'c',
'p',
'i',
'l'):
key =
"compilation";
320 case MKTAG(
'c',
'p',
'r',
't'):
key =
"copyright";
break;
321 case MKTAG(
'd',
'e',
's',
'c'):
key =
"description";
break;
322 case MKTAG(
'd',
'i',
's',
'k'):
key =
"disc";
324 case MKTAG(
'e',
'g',
'i',
'd'):
key =
"episode_uid";
326 case MKTAG(
'F',
'I',
'R',
'M'):
key =
"firmware"; raw = 1;
break;
327 case MKTAG(
'g',
'n',
'r',
'e'):
key =
"genre";
329 case MKTAG(
'h',
'd',
'v',
'd'):
key =
"hd_video";
331 case MKTAG(
'H',
'M',
'M',
'T'):
333 case MKTAG(
'k',
'e',
'y',
'w'):
key =
"keywords";
break;
334 case MKTAG(
'l',
'd',
'e',
's'):
key =
"synopsis";
break;
335 case MKTAG(
'l',
'o',
'c',
'i'):
337 case MKTAG(
'm',
'a',
'n',
'u'):
key =
"make";
break;
338 case MKTAG(
'm',
'o',
'd',
'l'):
key =
"model";
break;
339 case MKTAG(
'p',
'c',
's',
't'):
key =
"podcast";
341 case MKTAG(
'p',
'g',
'a',
'p'):
key =
"gapless_playback";
343 case MKTAG(
'p',
'u',
'r',
'd'):
key =
"purchase_date";
break;
344 case MKTAG(
'r',
't',
'n',
'g'):
key =
"rating";
346 case MKTAG(
's',
'o',
'a',
'a'):
key =
"sort_album_artist";
break;
347 case MKTAG(
's',
'o',
'a',
'l'):
key =
"sort_album";
break;
348 case MKTAG(
's',
'o',
'a',
'r'):
key =
"sort_artist";
break;
349 case MKTAG(
's',
'o',
'c',
'o'):
key =
"sort_composer";
break;
350 case MKTAG(
's',
'o',
'n',
'm'):
key =
"sort_name";
break;
351 case MKTAG(
's',
'o',
's',
'n'):
key =
"sort_show";
break;
352 case MKTAG(
's',
't',
'i',
'k'):
key =
"media_type";
354 case MKTAG(
't',
'r',
'k',
'n'):
key =
"track";
356 case MKTAG(
't',
'v',
'e',
'n'):
key =
"episode_id";
break;
357 case MKTAG(
't',
'v',
'e',
's'):
key =
"episode_sort";
359 case MKTAG(
't',
'v',
'n',
'n'):
key =
"network";
break;
360 case MKTAG(
't',
'v',
's',
'h'):
key =
"show";
break;
361 case MKTAG(
't',
'v',
's',
'n'):
key =
"season_number";
363 case MKTAG(0xa9,
'A',
'R',
'T'):
key =
"artist";
break;
364 case MKTAG(0xa9,
'P',
'R',
'D'):
key =
"producer";
break;
365 case MKTAG(0xa9,
'a',
'l',
'b'):
key =
"album";
break;
366 case MKTAG(0xa9,
'a',
'u',
't'):
key =
"artist";
break;
367 case MKTAG(0xa9,
'c',
'h',
'p'):
key =
"chapter";
break;
368 case MKTAG(0xa9,
'c',
'm',
't'):
key =
"comment";
break;
369 case MKTAG(0xa9,
'c',
'o',
'm'):
key =
"composer";
break;
370 case MKTAG(0xa9,
'c',
'p',
'y'):
key =
"copyright";
break;
371 case MKTAG(0xa9,
'd',
'a',
'y'):
key =
"date";
break;
372 case MKTAG(0xa9,
'd',
'i',
'r'):
key =
"director";
break;
373 case MKTAG(0xa9,
'd',
'i',
's'):
key =
"disclaimer";
break;
374 case MKTAG(0xa9,
'e',
'd',
'1'):
key =
"edit_date";
break;
375 case MKTAG(0xa9,
'e',
'n',
'c'):
key =
"encoder";
break;
376 case MKTAG(0xa9,
'f',
'm',
't'):
key =
"original_format";
break;
377 case MKTAG(0xa9,
'g',
'e',
'n'):
key =
"genre";
break;
378 case MKTAG(0xa9,
'g',
'r',
'p'):
key =
"grouping";
break;
379 case MKTAG(0xa9,
'h',
's',
't'):
key =
"host_computer";
break;
380 case MKTAG(0xa9,
'i',
'n',
'f'):
key =
"comment";
break;
381 case MKTAG(0xa9,
'l',
'y',
'r'):
key =
"lyrics";
break;
382 case MKTAG(0xa9,
'm',
'a',
'k'):
key =
"make";
break;
383 case MKTAG(0xa9,
'm',
'o',
'd'):
key =
"model";
break;
384 case MKTAG(0xa9,
'n',
'a',
'm'):
key =
"title";
break;
385 case MKTAG(0xa9,
'o',
'p',
'e'):
key =
"original_artist";
break;
386 case MKTAG(0xa9,
'p',
'r',
'd'):
key =
"producer";
break;
387 case MKTAG(0xa9,
'p',
'r',
'f'):
key =
"performers";
break;
388 case MKTAG(0xa9,
'r',
'e',
'q'):
key =
"playback_requirements";
break;
389 case MKTAG(0xa9,
's',
'r',
'c'):
key =
"original_source";
break;
390 case MKTAG(0xa9,
's',
't',
'3'):
key =
"subtitle";
break;
391 case MKTAG(0xa9,
's',
'w',
'r'):
key =
"encoder";
break;
392 case MKTAG(0xa9,
't',
'o',
'o'):
key =
"encoder";
break;
393 case MKTAG(0xa9,
't',
'r',
'k'):
key =
"track";
break;
394 case MKTAG(0xa9,
'u',
'r',
'l'):
key =
"URL";
break;
395 case MKTAG(0xa9,
'w',
'r',
'n'):
key =
"warning";
break;
396 case MKTAG(0xa9,
'w',
'r',
't'):
key =
"composer";
break;
397 case MKTAG(0xa9,
'x',
'y',
'z'):
key =
"location";
break;
400 if (
c->itunes_metadata && atom.
size > 8) {
403 if (
tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
406 str_size = data_size - 16;
409 if (!
key &&
c->found_hdlr_mdta &&
c->meta_keys) {
411 if (index < c->meta_keys_count &&
index > 0) {
413 }
else if (atom.
type !=
MKTAG(
'c',
'o',
'v',
'r')) {
415 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
416 index,
c->meta_keys_count);
419 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r') ||
420 (
key && !strcmp(
key,
"com.apple.quicktime.artwork"))) {
426 atom.
size -= str_size;
432 }
else if (atom.
size > 4 &&
key && !
c->itunes_metadata && !raw) {
434 if (str_size > atom.
size) {
444 str_size = atom.
size;
446 if (
c->export_all && !
key) {
452 if (atom.
size < 0 || str_size >= INT_MAX/2)
457 num = (data_type >= 21 && data_type <= 23);
458 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
466 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
468 }
else if (data_type == 21) {
472 else if (str_size == 2)
474 else if (str_size == 3)
476 else if (str_size == 4)
480 "Failed to store the number (%d) in string.\n",
val);
484 }
else if (data_type == 22) {
485 unsigned int val = 0;
488 else if (str_size == 2)
490 else if (str_size == 3)
492 else if (str_size == 4)
496 "Failed to store the number (%u) in string.\n",
val);
500 }
else if (data_type == 23 && str_size >= 4) {
504 "Failed to store the float32 number (%f) in string.\n",
val);
508 }
else if (data_type > 1 && data_type != 4) {
530 if (!strcmp(
key,
"encoder")) {
532 if (sscanf(
str,
"HandBrake %d.%d.%d", &
major, &
minor, µ) == 3) {
533 c->handbrake_version = 1000000*
major + 1000*
minor + micro;
545 int i, nb_chapters, str_len,
version;
549 if (
c->ignore_chapters)
552 if ((atom.
size -= 5) < 0)
561 for (
i = 0;
i < nb_chapters;
i++) {
568 if ((atom.
size -= 9+str_len) < 0)
580 #define MIN_DATA_ENTRY_BOX_SIZE 12
587 if (
c->fc->nb_streams < 1)
589 st =
c->fc->streams[
c->fc->nb_streams-1];
596 entries >= UINT_MAX /
sizeof(*sc->
drefs))
611 for (
i = 0;
i < entries;
i++) {
616 if (
size < 12 || next < 0 || next > INT64_MAX -
size)
626 uint16_t volume_len,
len;
633 volume_len =
FFMIN(volume_len, 27);
637 dref->
volume[volume_len] = 0;
679 if (
len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
685 for (j =
len - 1; j >= 0; j--) {
686 if (dref->
path[j] == 0)
691 for (j = 0; j <
len; j++)
692 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
695 }
else if (
type == 0) {
707 for (j = 0; j <
len; j++)
708 if (dref->
dir[j] ==
':')
744 if (
c->trak_index < 0) {
746 c->found_hdlr_mdta = 1;
751 st =
c->fc->streams[
c->fc->nb_streams-1];
766 title_size = atom.
size - 24;
767 if (title_size > 0) {
768 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
779 title_str[title_size] = 0;
781 int off = (!
c->isom && title_str[0] == title_size - 1);
800 int ac3info, acmod, lfeon, bsmod;
802 if (
c->fc->nb_streams < 1)
804 st =
c->fc->streams[
c->fc->nb_streams-1];
812 bsmod = (ac3info >> 14) & 0x7;
813 acmod = (ac3info >> 11) & 0x7;
814 lfeon = (ac3info >> 10) & 0x1;
830 int eac3info, acmod, lfeon, bsmod;
832 if (
c->fc->nb_streams < 1)
834 st =
c->fc->streams[
c->fc->nb_streams-1];
846 bsmod = (eac3info >> 12) & 0x1f;
847 acmod = (eac3info >> 9) & 0x7;
848 lfeon = (eac3info >> 8) & 0x1;
865 uint32_t frame_duration_code = 0;
866 uint32_t channel_layout_code = 0;
875 if (
c->fc->nb_streams < 1) {
878 st =
c->fc->streams[
c->fc->nb_streams-1];
888 frame_duration_code =
get_bits(&gb, 2);
890 channel_layout_code =
get_bits(&gb, 16);
893 (frame_duration_code == 0) ? 512 :
894 (frame_duration_code == 1) ? 1024 :
895 (frame_duration_code == 2) ? 2048 :
896 (frame_duration_code == 3) ? 4096 : 0;
898 if (channel_layout_code > 0xff) {
918 if (
c->fc->nb_streams < 1)
920 st =
c->fc->streams[
c->fc->nb_streams-1];
938 if (
c->fc->nb_streams < 1)
940 st =
c->fc->streams[
c->fc->nb_streams-1];
955 if (
c->fc->nb_streams < 1)
957 st =
c->fc->streams[
c->fc->nb_streams-1];
975 #define DRM_BLOB_SIZE 56
979 uint8_t intermediate_key[20];
980 uint8_t intermediate_iv[20];
983 uint8_t file_checksum[20];
984 uint8_t calculated_checksum[20];
985 char checksum_string[2 *
sizeof(file_checksum) + 1];
989 uint8_t *activation_bytes =
c->activation_bytes;
990 uint8_t *fixed_key =
c->audible_fixed_key;
999 if (!
c->aes_decrypt) {
1011 ff_data_to_hex(checksum_string, file_checksum,
sizeof(file_checksum), 1);
1015 if (!activation_bytes) {
1020 if (
c->activation_bytes_size != 4) {
1027 if (
c->audible_fixed_key_size != 16) {
1047 if (memcmp(calculated_checksum, file_checksum, 20)) {
1054 for (
i = 0;
i < 4;
i++) {
1056 if (activation_bytes[
i] !=
output[3 -
i]) {
1062 memcpy(
c->file_key,
output + 8, 16);
1078 if (
c->audible_key_size != 16) {
1083 if (
c->audible_iv_size != 16) {
1089 if (!
c->aes_decrypt) {
1093 memcpy(
c->file_key,
c->audible_key, 16);
1094 memcpy(
c->file_iv,
c->audible_iv, 16);
1104 unsigned char iv[16];
1106 memcpy(iv,
c->file_iv, 16);
1118 int comp_brand_size;
1119 char* comp_brands_str;
1120 uint8_t
type[5] = {0};
1125 if (strcmp(
type,
"qt "))
1132 comp_brand_size = atom.
size - 8;
1133 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1135 comp_brands_str =
av_malloc(comp_brand_size + 1);
1136 if (!comp_brands_str)
1144 comp_brands_str[comp_brand_size] = 0;
1149 if (!strcmp(
type,
"aaxc")) {
1161 if (
c->found_moov) {
1183 if (index < 0 || index >= frag_index->
nb_items)
1199 if (frag_index->
current < 0 ||
1218 if (frag_index->
current < 0 ||
1233 int64_t moof_offset;
1246 if (moof_offset >=
offset)
1248 if (moof_offset <=
offset)
1265 int index,
int track_id)
1271 if (track_id >= 0) {
1308 m0 = m = (
a +
b) >> 1;
1314 if (m <
b && frag_time <= timestamp)
1331 if (index < c->frag_index.nb_items &&
1338 &
c->frag_index.allocated_size,
1339 (
c->frag_index.nb_items + 1) *
1340 sizeof(*
c->frag_index.item));
1343 c->frag_index.item = item;
1347 if (!frag_stream_info)
1350 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1352 if (
c->fc->streams[
i]->id < 0) {
1357 frag_stream_info[
i].
id =
c->fc->streams[
i]->id;
1366 if (index < c->frag_index.nb_items)
1367 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1368 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1370 item = &
c->frag_index.item[
index];
1376 c->frag_index.nb_items++;
1382 int id,
int entries)
1391 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1399 c->fragment.found_tfhd = 0;
1401 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1402 c->has_looked_for_mfra = 1;
1409 "read the mfra (may be a live ismv)\n");
1413 "seekable, can not look for mfra\n");
1416 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1425 if (time >= 2082844800)
1428 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1444 int64_t creation_time;
1446 if (
c->fc->nb_streams < 1)
1448 st =
c->fc->streams[
c->fc->nb_streams-1];
1489 int64_t creation_time;
1502 if (
c->time_scale <= 0) {
1520 for (
i = 0;
i < 3;
i++) {
1542 if (
c->fc->nb_streams < 1)
1544 st =
c->fc->streams[
c->fc->nb_streams-1];
1548 if (little_endian == 1) {
1572 uint8_t *icc_profile;
1573 char color_parameter_type[5] = { 0 };
1577 if (
c->fc->nb_streams < 1)
1579 st =
c->fc->streams[
c->fc->nb_streams - 1];
1584 if (strncmp(color_parameter_type,
"nclx", 4) &&
1585 strncmp(color_parameter_type,
"nclc", 4) &&
1586 strncmp(color_parameter_type,
"prof", 4)) {
1588 color_parameter_type);
1592 if (!strncmp(color_parameter_type,
"prof", 4)) {
1605 "%s: pri %d trc %d matrix %d",
1608 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1635 unsigned mov_field_order;
1638 if (
c->fc->nb_streams < 1)
1640 st =
c->fc->streams[
c->fc->nb_streams-1];
1644 if ((mov_field_order & 0xFF00) == 0x0100)
1646 else if ((mov_field_order & 0xFF00) == 0x0200) {
1647 switch (mov_field_order & 0xFF) {
1670 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1693 }
else if (err < atom.
size) {
1707 uint64_t original_size;
1710 if (
c->fc->nb_streams < 1)
1712 st =
c->fc->streams[
c->fc->nb_streams-1];
1761 if (!
ret &&
c->fc->nb_streams >= 1) {
1773 if (
c->fc->nb_streams >= 1) {
1774 AVStream *
const st =
c->fc->streams[
c->fc->nb_streams - 1];
1785 if (
cid == 0xd4d ||
cid == 0xd4e)
1796 if (num <= 0 || den <= 0)
1800 if (den >= INT_MAX / 2)
1818 uint64_t original_size;
1819 if (
c->fc->nb_streams >= 1) {
1823 if (atom.
size == 16) {
1828 if (length == atom.
size) {
1829 const uint8_t range_value = par->
extradata[original_size + 19];
1830 switch (range_value) {
1867 if (
c->fc->nb_streams < 1)
1869 st =
c->fc->streams[
c->fc->nb_streams-1];
1871 if ((uint64_t)atom.
size > (1<<30))
1881 }
else if (atom.
size > 8) {
1895 #define ALAC_EXTRADATA_SIZE 36
1924 if (
c->fc->nb_streams < 1)
1926 st =
c->fc->streams[
c->fc->nb_streams-1];
1928 if ((uint64_t)atom.
size > (1<<30))
1931 if (atom.
size >= 10) {
1963 uint8_t profile_level;
1966 if (
c->fc->nb_streams < 1)
1968 st =
c->fc->streams[
c->fc->nb_streams-1];
1970 if (atom.
size >= (1<<28) || atom.
size < 7)
1974 if ((profile_level & 0xf0) != 0xc0)
1995 if (
c->fc->nb_streams < 1)
1997 if (atom.
size <= 40)
1999 st =
c->fc->streams[
c->fc->nb_streams-1];
2001 if ((uint64_t)atom.
size > (1<<30))
2016 unsigned int i, entries;
2018 if (
c->trak_index < 0) {
2022 if (
c->fc->nb_streams < 1)
2024 st =
c->fc->streams[
c->fc->nb_streams-1];
2046 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2049 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2070 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2071 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2103 uint8_t codec_name[32] = { 0 };
2138 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2145 !strncmp(codec_name,
"Sorenson H263", 13))
2161 int bits_per_sample,
flags;
2182 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2263 if (bits_per_sample && (bits_per_sample >> 3) * (uint64_t)st->
codecpar->
channels <= INT_MAX) {
2288 y = (ycbcr >> 16) & 0xFF;
2289 cr = (ycbcr >> 8) & 0xFF;
2296 return (
r << 16) | (
g << 8) |
b;
2301 char buf[256] = {0};
2309 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2313 for (
i = 0;
i < 16;
i++) {
2317 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba,
i != 15 ?
", " :
"");
2320 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2356 if (str_size > 0 &&
size >= (
int)str_size + 30 &&
2358 char *reel_name =
av_malloc(str_size + 1);
2362 reel_name[str_size] = 0;
2387 #if CONFIG_DV_DEMUXER
2463 int codec_tag,
int format,
2476 (
c->fc->video_codec_id ? video_codec_id !=
c->fc->video_codec_id
2477 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2494 int pseudo_stream_id;
2497 st =
c->fc->streams[
c->fc->nb_streams-1];
2500 for (pseudo_stream_id = 0;
2502 pseudo_stream_id++) {
2505 int ret, dref_id = 1;
2515 }
else if (
size <= 7) {
2517 "invalid size %"PRId64
" in stsd\n",
size);
2534 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
2564 }
else if (
a.size > 0)
2593 if (
c->fc->nb_streams < 1)
2595 st =
c->fc->streams[
c->fc->nb_streams - 1];
2603 if (entries <= 0 || entries > atom.
size / 8 || entries > 1024) {
2610 "Duplicate stsd found in this track.\n");
2656 unsigned int i, entries;
2658 if (
c->fc->nb_streams < 1)
2660 st =
c->fc->streams[
c->fc->nb_streams-1];
2667 if ((uint64_t)entries * 12 + 4 > atom.
size)
2692 int64_t first_min =
i + 1;
2752 unsigned i, entries;
2754 if (
c->fc->nb_streams < 1)
2756 st =
c->fc->streams[
c->fc->nb_streams-1];
2789 unsigned int i, entries;
2791 if (
c->fc->nb_streams < 1)
2793 st =
c->fc->streams[
c->fc->nb_streams-1];
2812 if (entries >= UINT_MAX /
sizeof(
int))
2838 unsigned int i, entries, sample_size, field_size, num_bytes;
2843 if (
c->fc->nb_streams < 1)
2845 st =
c->fc->streams[
c->fc->nb_streams-1];
2851 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
2870 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
2887 num_bytes = (entries*field_size+4)>>3;
2905 for (
i = 0;
i < entries;
i++) {
2926 unsigned int i, entries, alloc_size = 0;
2928 int64_t total_sample_count = 0;
2929 int64_t current_dts = 0;
2930 int64_t corrected_dts = 0;
2932 if (
c->fc->nb_streams < 1)
2934 st =
c->fc->streams[
c->fc->nb_streams-1];
2942 c->fc->nb_streams-1, entries);
2948 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
2952 unsigned int sample_duration;
2953 unsigned int sample_count;
2954 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
2972 sample_count, sample_duration);
2977 if (sample_duration >
c->max_stts_delta) {
2980 av_log(
c->fc,
AV_LOG_WARNING,
"Too large sample offset %u in stts entry %u with count %u in st:%d. Clipping to 1.\n",
2981 sample_duration,
i, sample_count, st->
index);
2983 corrected_dts += (delta_magnitude < 0 ? (int64_t)delta_magnitude : 1) * sample_count;
2985 corrected_dts += sample_duration * sample_count;
2990 if (current_dts > corrected_dts) {
2991 int64_t drift = (current_dts - corrected_dts)/
FFMAX(sample_count, 1);
2993 current_dts -= correction * sample_count;
3004 duration <= INT64_MAX - sc->duration_for_fps &&
3005 total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
3028 if (
c->fc->nb_streams < 1)
3030 st =
c->fc->streams[
c->fc->nb_streams - 1];
3035 entries = atom.
size - 4;
3038 c->fc->nb_streams - 1, entries);
3071 unsigned int i, entries, ctts_count = 0;
3073 if (
c->fc->nb_streams < 1)
3075 st =
c->fc->streams[
c->fc->nb_streams-1];
3086 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3099 "ignoring CTTS entry with count=%d duration=%d\n",
3137 unsigned int i, entries;
3139 uint32_t grouping_type;
3141 if (
c->fc->nb_streams < 1)
3143 st =
c->fc->streams[
c->fc->nb_streams-1];
3149 if (grouping_type !=
MKTAG(
'r',
'a',
'p',
' '))
3185 unsigned int edit_list_index,
3186 int64_t *edit_list_media_time,
3187 int64_t *edit_list_duration,
3188 int64_t global_timescale)
3193 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3197 if (global_timescale == 0) {
3230 int64_t timestamp_pts,
3233 int64_t* ctts_index,
3234 int64_t* ctts_sample)
3241 int64_t index_ctts_count;
3269 if (ctts_data && *
index >= 0) {
3275 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3276 if (*ctts_index < ctts_count) {
3278 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3285 while (*
index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3289 if ((e_old[*
index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3295 if (*ctts_sample == 0) {
3297 if (*ctts_index >= 0)
3298 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3308 return *
index >= 0 ? 0 : -1;
3332 const size_t requested_size =
3349 ie= &entries[
index];
3364 int64_t* frame_duration_buffer,
3365 int frame_duration_buffer_size) {
3368 av_assert0(end_index >= 0 && end_index <= sti->nb_index_entries);
3369 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
3370 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
3383 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVCtts);
3384 const size_t requested_size =
3385 min_size_needed > *allocated_size ?
3386 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3389 if ((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVCtts) - 1)
3392 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
3397 *ctts_data = ctts_buf_new;
3402 *ctts_count = (*ctts_count) + 1;
3406 #define MAX_REORDER_DELAY 16
3412 int ctts_sample = 0;
3415 int j,
r, num_swaps;
3418 pts_buf[j] = INT64_MIN;
3426 buf_start = (buf_start + 1);
3439 while (j != buf_start) {
3442 if (pts_buf[j] < pts_buf[
r]) {
3443 FFSWAP(int64_t, pts_buf[j], pts_buf[
r]);
3501 if (range_size > current_sample) {
3505 current_sample -= range_size;
3524 int64_t ctts_index_old = 0;
3525 int64_t ctts_sample_old = 0;
3527 int64_t edit_list_media_time = 0;
3528 int64_t edit_list_duration = 0;
3529 int64_t frame_duration = 0;
3530 int64_t edit_list_dts_counter = 0;
3531 int64_t edit_list_dts_entry_end = 0;
3532 int64_t edit_list_start_ctts_sample = 0;
3534 int64_t curr_ctts = 0;
3535 int64_t empty_edits_sum_duration = 0;
3536 int64_t edit_list_index = 0;
3539 int64_t start_dts = 0;
3540 int64_t edit_list_start_encountered = 0;
3541 int64_t search_timestamp = 0;
3542 int64_t* frame_duration_buffer =
NULL;
3543 int num_discarded_begin = 0;
3544 int first_non_zero_audio_edit = -1;
3545 int packet_skip_samples = 0;
3547 int found_keyframe_after_edit = 0;
3548 int found_non_empty_edit = 0;
3581 edit_list_dts_entry_end -= msc->
dts_shift;
3585 start_dts = edit_list_dts_entry_end;
3589 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3590 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3592 edit_list_dts_counter = edit_list_dts_entry_end;
3593 edit_list_dts_entry_end += edit_list_duration;
3594 num_discarded_begin = 0;
3595 if (!found_non_empty_edit && edit_list_media_time == -1) {
3596 empty_edits_sum_duration += edit_list_duration;
3599 found_non_empty_edit = 1;
3604 if (first_non_zero_audio_edit < 0) {
3605 first_non_zero_audio_edit = 1;
3607 first_non_zero_audio_edit = 0;
3610 if (first_non_zero_audio_edit > 0)
3618 search_timestamp = edit_list_media_time;
3627 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3629 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3630 st->
index, edit_list_index, search_timestamp);
3632 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3634 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
3635 st->
index, edit_list_index, search_timestamp);
3638 ctts_sample_old = 0;
3641 current = e_old +
index;
3642 edit_list_start_ctts_sample = ctts_sample_old;
3645 edit_list_start_encountered = 0;
3646 found_keyframe_after_edit = 0;
3647 for (; current < e_old_end; current++,
index++) {
3649 frame_duration = (current + 1 < e_old_end) ?
3650 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3658 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3659 curr_ctts = ctts_data_old[ctts_index_old].
duration;
3660 av_log(mov->
fc,
AV_LOG_TRACE,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
3661 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
3662 curr_cts += curr_ctts;
3664 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3667 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3668 ctts_data_old[ctts_index_old].
duration) == -1) {
3671 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3672 ctts_data_old[ctts_index_old].
duration);
3676 ctts_sample_old = 0;
3677 edit_list_start_ctts_sample = 0;
3681 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3683 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3684 first_non_zero_audio_edit > 0) {
3685 packet_skip_samples = edit_list_media_time - curr_cts;
3689 edit_list_dts_counter -= packet_skip_samples;
3690 if (edit_list_start_encountered == 0) {
3691 edit_list_start_encountered = 1;
3694 if (frame_duration_buffer) {
3696 frame_duration_buffer, num_discarded_begin);
3701 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
3706 if (edit_list_start_encountered == 0) {
3707 num_discarded_begin++;
3708 frame_duration_buffer =
av_realloc(frame_duration_buffer,
3709 num_discarded_begin *
sizeof(int64_t));
3710 if (!frame_duration_buffer) {
3714 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
3729 if (edit_list_start_encountered == 0) {
3730 edit_list_start_encountered = 1;
3733 if (frame_duration_buffer) {
3735 frame_duration_buffer, num_discarded_begin);
3748 if (current_index_range < msc->index_ranges ||
index != current_index_range->
end) {
3749 current_index_range++;
3752 current_index_range->
end =
index + 1;
3755 if (edit_list_start_encountered > 0) {
3756 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
3760 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
3762 if (ctts_data_old) {
3767 found_keyframe_after_edit = 1;
3770 if (ctts_sample_old != 0) {
3773 ctts_sample_old - edit_list_start_ctts_sample,
3774 ctts_data_old[ctts_index_old].
duration) == -1) {
3776 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
3777 ctts_data_old[ctts_index_old].
duration);
3812 current_index_range++;
3813 current_index_range->
start = 0;
3814 current_index_range->
end = 0;
3822 int64_t current_offset;
3823 int64_t current_dts = 0;
3824 unsigned int stts_index = 0;
3825 unsigned int stsc_index = 0;
3826 unsigned int stss_index = 0;
3827 unsigned int stps_index = 0;
3829 uint64_t stream_size = 0;
3831 unsigned int ctts_count_old = sc->
ctts_count;
3834 int i, edit_start_index = 0, multiple_edits = 0;
3835 int64_t empty_duration = 0;
3840 if (
i == 0 && e->
time == -1) {
3844 edit_start_index = 1;
3845 }
else if (
i == edit_start_index && e->
time >= 0) {
3854 "Use -advanced_editlist to correctly decode otherwise "
3855 "a/v desync might occur\n");
3879 unsigned int current_sample = 0;
3880 unsigned int stts_sample = 0;
3881 unsigned int sample_size;
3883 unsigned int rap_group_index = 0;
3884 unsigned int rap_group_sample = 0;
3902 if (ctts_data_old) {
3917 for (
i = 0;
i < ctts_count_old &&
3919 for (j = 0; j < ctts_data_old[
i].
count &&
3960 if (rap_group_present && rap_group_index < sc->rap_group_count) {
3963 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
3964 rap_group_sample = 0;
3970 && !rap_group_present
3979 if (sample_size > 0x3FFFFFFF) {
3984 e->
pos = current_offset;
3986 e->
size = sample_size;
3989 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", "
3990 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
3991 current_offset, current_dts, sample_size,
distance, keyframe);
3996 current_offset += sample_size;
3997 stream_size += sample_size;
4013 unsigned chunk_samples, total = 0;
4020 unsigned count, chunk_count;
4035 count = (chunk_samples+1023) / 1024;
4042 total += chunk_count *
count;
4064 while (chunk_samples > 0) {
4070 "Zero bytes per frame, but %d samples per frame",
4093 if (
size > 0x3FFFFFFF) {
4098 e->
pos = current_offset;
4104 "size %u, duration %u\n", st->
index,
i, current_offset, current_dts,
4107 current_offset +=
size;
4140 av_url_split(src_proto,
sizeof(src_proto), src_auth,
sizeof(src_auth), src_host,
sizeof(src_host), &src_port,
NULL, 0,
src);
4141 av_url_split(ref_proto,
sizeof(ref_proto), ref_auth,
sizeof(ref_auth), ref_host,
sizeof(ref_host), &ref_port,
NULL, 0,
ref);
4143 if (strlen(
src) == 0) {
4145 }
else if (strlen(src_auth) + 1 >=
sizeof(src_auth) ||
4146 strlen(ref_auth) + 1 >=
sizeof(ref_auth) ||
4147 strlen(src_host) + 1 >=
sizeof(src_host) ||
4148 strlen(ref_host) + 1 >=
sizeof(ref_host)) {
4150 }
else if (strcmp(src_proto, ref_proto) ||
4151 strcmp(src_auth, ref_auth) ||
4152 strcmp(src_host, ref_host) ||
4153 src_port != ref_port) {
4163 if (
ref->nlvl_to > 0 &&
ref->nlvl_from > 0) {
4164 char filename[1025];
4165 const char *src_path;
4169 src_path = strrchr(
src,
'/');
4176 for (
i = 0, l = strlen(
ref->path) - 1; l >= 0; l--)
4177 if (
ref->path[l] ==
'/') {
4178 if (
i ==
ref->nlvl_to - 1)
4185 if (
i ==
ref->nlvl_to - 1 && src_path -
src <
sizeof(filename)) {
4186 memcpy(filename,
src, src_path -
src);
4187 filename[src_path -
src] = 0;
4189 for (
i = 1;
i <
ref->nlvl_from;
i++)
4190 av_strlcat(filename,
"../",
sizeof(filename));
4193 if (!
c->use_absolute_path) {
4198 "Reference with mismatching origin, %s not tried for security reasons, "
4199 "set demuxer option use_absolute_path to allow it anyway\n",
4204 if (strstr(
ref->path + l + 1,
"..") ||
4205 strstr(
ref->path + l + 1,
":") ||
4206 (
ref->nlvl_from > 1 && same_origin < 0) ||
4207 (filename[0] ==
'/' && src_path ==
src))
4211 if (strlen(filename) + 1 ==
sizeof(filename))
4216 }
else if (
c->use_absolute_path) {
4218 "this is a possible security issue\n");
4223 "Absolute path %s not tried for security reasons, "
4224 "set demuxer option use_absolute_path to allow absolute paths\n",
4248 if (!st)
return AVERROR(ENOMEM);
4251 if (!sc)
return AVERROR(ENOMEM);
4256 c->trak_index = st->
index;
4292 if (
c->enable_drefs) {
4295 "stream %d, error opening alias: path='%s', dir='%s', "
4296 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
4301 "Skipped opening external track: "
4302 "stream %d, alias: path='%s', dir='%s', "
4303 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d."
4304 "Set enable_drefs to allow this.\n",
4321 #if FF_API_R_FRAME_RATE
4337 #if CONFIG_H261_DECODER
4340 #if CONFIG_H263_DECODER
4343 #if CONFIG_MPEG4_DECODER
4373 c->itunes_metadata = 1;
4375 c->itunes_metadata = 0;
4389 if (
count > UINT_MAX /
sizeof(*
c->meta_keys) - 1) {
4391 "The 'keys' atom with the invalid key count: %"PRIu32
"\n",
count);
4395 c->meta_keys_count =
count + 1;
4396 c->meta_keys =
av_mallocz(
c->meta_keys_count *
sizeof(*
c->meta_keys));
4405 "The key# %"PRIu32
" in meta has invalid size:"
4406 "%"PRIu32
"\n",
i, key_size);
4414 if (!
c->meta_keys[
i])
4431 if (
c->fc->nb_streams < 1)
4433 st =
c->fc->streams[
c->fc->nb_streams-1];
4436 for (
i = 0;
i < 3;
i++) {