79 static int64_t
add_ctts_entry(
MOVStts** ctts_data,
unsigned int* ctts_count,
unsigned int* allocated_size,
83 unsigned len,
const char *
key)
87 short current, total = 0;
93 snprintf(buf,
sizeof(buf),
"%d", current);
95 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
103 unsigned len,
const char *
key)
117 unsigned len,
const char *
key)
126 unsigned len,
const char *
key)
142 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
143 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
144 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
145 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
146 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
147 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
148 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
149 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
150 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
151 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
152 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
153 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
154 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
155 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
156 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
157 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
161 char *dst,
int dstlen)
164 char *
end = dst+dstlen-1;
167 for (
i = 0;
i <
len;
i++) {
236 char buf[200], place[100];
237 uint16_t langcode = 0;
238 double longitude, latitude, altitude;
239 const char *
key =
"location";
241 if (
len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
261 "loci too short (%u bytes left, need at least %d)\n",
len, 12);
269 snprintf(buf,
sizeof(buf),
"%+08.4f%+09.4f", latitude, longitude);
289 if (
c->ignore_chapters)
293 if (n_hmmt >
len / 4)
310 uint16_t langcode = 0;
311 uint32_t data_type = 0, str_size, str_size_alloc;
317 case MKTAG(
'@',
'P',
'R',
'M'):
key =
"premiere_version"; raw = 1;
break;
318 case MKTAG(
'@',
'P',
'R',
'Q'):
key =
"quicktime_version"; raw = 1;
break;
319 case MKTAG(
'X',
'M',
'P',
'_'):
320 if (
c->export_xmp) {
key =
"xmp"; raw = 1; }
break;
321 case MKTAG(
'a',
'A',
'R',
'T'):
key =
"album_artist";
break;
322 case MKTAG(
'a',
'k',
'I',
'D'):
key =
"account_type";
324 case MKTAG(
'a',
'p',
'I',
'D'):
key =
"account_id";
break;
325 case MKTAG(
'c',
'a',
't',
'g'):
key =
"category";
break;
326 case MKTAG(
'c',
'p',
'i',
'l'):
key =
"compilation";
328 case MKTAG(
'c',
'p',
'r',
't'):
key =
"copyright";
break;
329 case MKTAG(
'd',
'e',
's',
'c'):
key =
"description";
break;
330 case MKTAG(
'd',
'i',
's',
'k'):
key =
"disc";
332 case MKTAG(
'e',
'g',
'i',
'd'):
key =
"episode_uid";
334 case MKTAG(
'F',
'I',
'R',
'M'):
key =
"firmware"; raw = 1;
break;
335 case MKTAG(
'g',
'n',
'r',
'e'):
key =
"genre";
337 case MKTAG(
'h',
'd',
'v',
'd'):
key =
"hd_video";
339 case MKTAG(
'H',
'M',
'M',
'T'):
341 case MKTAG(
'k',
'e',
'y',
'w'):
key =
"keywords";
break;
342 case MKTAG(
'l',
'd',
'e',
's'):
key =
"synopsis";
break;
343 case MKTAG(
'l',
'o',
'c',
'i'):
345 case MKTAG(
'm',
'a',
'n',
'u'):
key =
"make";
break;
346 case MKTAG(
'm',
'o',
'd',
'l'):
key =
"model";
break;
347 case MKTAG(
'p',
'c',
's',
't'):
key =
"podcast";
349 case MKTAG(
'p',
'g',
'a',
'p'):
key =
"gapless_playback";
351 case MKTAG(
'p',
'u',
'r',
'd'):
key =
"purchase_date";
break;
352 case MKTAG(
'r',
't',
'n',
'g'):
key =
"rating";
354 case MKTAG(
's',
'o',
'a',
'a'):
key =
"sort_album_artist";
break;
355 case MKTAG(
's',
'o',
'a',
'l'):
key =
"sort_album";
break;
356 case MKTAG(
's',
'o',
'a',
'r'):
key =
"sort_artist";
break;
357 case MKTAG(
's',
'o',
'c',
'o'):
key =
"sort_composer";
break;
358 case MKTAG(
's',
'o',
'n',
'm'):
key =
"sort_name";
break;
359 case MKTAG(
's',
'o',
's',
'n'):
key =
"sort_show";
break;
360 case MKTAG(
's',
't',
'i',
'k'):
key =
"media_type";
362 case MKTAG(
't',
'r',
'k',
'n'):
key =
"track";
364 case MKTAG(
't',
'v',
'e',
'n'):
key =
"episode_id";
break;
365 case MKTAG(
't',
'v',
'e',
's'):
key =
"episode_sort";
367 case MKTAG(
't',
'v',
'n',
'n'):
key =
"network";
break;
368 case MKTAG(
't',
'v',
's',
'h'):
key =
"show";
break;
369 case MKTAG(
't',
'v',
's',
'n'):
key =
"season_number";
371 case MKTAG(0xa9,
'A',
'R',
'T'):
key =
"artist";
break;
372 case MKTAG(0xa9,
'P',
'R',
'D'):
key =
"producer";
break;
373 case MKTAG(0xa9,
'a',
'l',
'b'):
key =
"album";
break;
374 case MKTAG(0xa9,
'a',
'u',
't'):
key =
"artist";
break;
375 case MKTAG(0xa9,
'c',
'h',
'p'):
key =
"chapter";
break;
376 case MKTAG(0xa9,
'c',
'm',
't'):
key =
"comment";
break;
377 case MKTAG(0xa9,
'c',
'o',
'm'):
key =
"composer";
break;
378 case MKTAG(0xa9,
'c',
'p',
'y'):
key =
"copyright";
break;
379 case MKTAG(0xa9,
'd',
'a',
'y'):
key =
"date";
break;
380 case MKTAG(0xa9,
'd',
'i',
'r'):
key =
"director";
break;
381 case MKTAG(0xa9,
'd',
'i',
's'):
key =
"disclaimer";
break;
382 case MKTAG(0xa9,
'e',
'd',
'1'):
key =
"edit_date";
break;
383 case MKTAG(0xa9,
'e',
'n',
'c'):
key =
"encoder";
break;
384 case MKTAG(0xa9,
'f',
'm',
't'):
key =
"original_format";
break;
385 case MKTAG(0xa9,
'g',
'e',
'n'):
key =
"genre";
break;
386 case MKTAG(0xa9,
'g',
'r',
'p'):
key =
"grouping";
break;
387 case MKTAG(0xa9,
'h',
's',
't'):
key =
"host_computer";
break;
388 case MKTAG(0xa9,
'i',
'n',
'f'):
key =
"comment";
break;
389 case MKTAG(0xa9,
'l',
'y',
'r'):
key =
"lyrics";
break;
390 case MKTAG(0xa9,
'm',
'a',
'k'):
key =
"make";
break;
391 case MKTAG(0xa9,
'm',
'o',
'd'):
key =
"model";
break;
392 case MKTAG(0xa9,
'n',
'a',
'm'):
key =
"title";
break;
393 case MKTAG(0xa9,
'o',
'p',
'e'):
key =
"original_artist";
break;
394 case MKTAG(0xa9,
'p',
'r',
'd'):
key =
"producer";
break;
395 case MKTAG(0xa9,
'p',
'r',
'f'):
key =
"performers";
break;
396 case MKTAG(0xa9,
'r',
'e',
'q'):
key =
"playback_requirements";
break;
397 case MKTAG(0xa9,
's',
'r',
'c'):
key =
"original_source";
break;
398 case MKTAG(0xa9,
's',
't',
'3'):
key =
"subtitle";
break;
399 case MKTAG(0xa9,
's',
'w',
'r'):
key =
"encoder";
break;
400 case MKTAG(0xa9,
't',
'o',
'o'):
key =
"encoder";
break;
401 case MKTAG(0xa9,
't',
'r',
'k'):
key =
"track";
break;
402 case MKTAG(0xa9,
'u',
'r',
'l'):
key =
"URL";
break;
403 case MKTAG(0xa9,
'w',
'r',
'n'):
key =
"warning";
break;
404 case MKTAG(0xa9,
'w',
'r',
't'):
key =
"composer";
break;
405 case MKTAG(0xa9,
'x',
'y',
'z'):
key =
"location";
break;
408 if (
c->itunes_metadata && atom.
size > 8) {
411 if (
tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
414 str_size = data_size - 16;
417 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r')) {
423 atom.
size -= str_size;
427 }
else if (!
key &&
c->found_hdlr_mdta &&
c->meta_keys) {
429 if (index < c->meta_keys_count &&
index > 0) {
433 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
434 index,
c->meta_keys_count);
438 }
else if (atom.
size > 4 &&
key && !
c->itunes_metadata && !raw) {
440 if (str_size > atom.
size) {
450 str_size = atom.
size;
452 if (
c->export_all && !
key) {
459 if (atom.
size < 0 || str_size >= INT_MAX/2)
464 num = (data_type >= 21 && data_type <= 23);
465 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
473 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
475 }
else if (data_type == 21) {
479 else if (str_size == 2)
481 else if (str_size == 3)
483 else if (str_size == 4)
487 "Failed to store the number (%d) in string.\n",
val);
491 }
else if (data_type == 22) {
492 unsigned int val = 0;
495 else if (str_size == 2)
497 else if (str_size == 3)
499 else if (str_size == 4)
503 "Failed to store the number (%u) in string.\n",
val);
507 }
else if (data_type == 23 && str_size >= 4) {
511 "Failed to store the float32 number (%f) in string.\n",
val);
529 if (!strcmp(
key,
"encoder")) {
531 if (sscanf(
str,
"HandBrake %d.%d.%d", &
major, &
minor, µ) == 3) {
532 c->handbrake_version = 1000000*
major + 1000*
minor + micro;
544 int i, nb_chapters, str_len,
version;
548 if (
c->ignore_chapters)
551 if ((atom.
size -= 5) < 0)
560 for (
i = 0;
i < nb_chapters;
i++) {
567 if ((atom.
size -= 9+str_len) < 0)
579 #define MIN_DATA_ENTRY_BOX_SIZE 12
586 if (
c->fc->nb_streams < 1)
588 st =
c->fc->streams[
c->fc->nb_streams-1];
595 entries >= UINT_MAX /
sizeof(*sc->
drefs))
605 for (
i = 0;
i < entries;
i++) {
610 if (
size < 12 || next < 0 || next > INT64_MAX -
size)
620 uint16_t volume_len,
len;
627 volume_len =
FFMIN(volume_len, 27);
631 dref->
volume[volume_len] = 0;
673 if (
len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
679 for (j =
len - 1; j >= 0; j--) {
680 if (dref->
path[j] == 0)
685 for (j = 0; j <
len; j++)
686 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
689 }
else if (
type == 0) {
701 for (j = 0; j <
len; j++)
702 if (dref->
dir[j] ==
':')
738 if (
c->trak_index < 0) {
740 c->found_hdlr_mdta = 1;
745 st =
c->fc->streams[
c->fc->nb_streams-1];
760 title_size = atom.
size - 24;
761 if (title_size > 0) {
762 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
773 title_str[title_size] = 0;
775 int off = (!
c->isom && title_str[0] == title_size - 1);
794 int ac3info, acmod, lfeon, bsmod;
796 if (
c->fc->nb_streams < 1)
798 st =
c->fc->streams[
c->fc->nb_streams-1];
806 bsmod = (ac3info >> 14) & 0x7;
807 acmod = (ac3info >> 11) & 0x7;
808 lfeon = (ac3info >> 10) & 0x1;
817 #if FF_API_LAVF_AVCTX
819 st->codec->audio_service_type = *ast;
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;
857 #if FF_API_LAVF_AVCTX
859 st->codec->audio_service_type = *ast;
868 const uint32_t ddts_size = 20;
871 uint32_t frame_duration_code = 0;
872 uint32_t channel_layout_code = 0;
879 if (
avio_read(pb, buf, ddts_size) < ddts_size) {
886 if (
c->fc->nb_streams < 1) {
890 st =
c->fc->streams[
c->fc->nb_streams-1];
901 frame_duration_code =
get_bits(&gb, 2);
903 channel_layout_code =
get_bits(&gb, 16);
906 (frame_duration_code == 0) ? 512 :
907 (frame_duration_code == 1) ? 1024 :
908 (frame_duration_code == 2) ? 2048 :
909 (frame_duration_code == 3) ? 4096 : 0;
911 if (channel_layout_code > 0xff) {
932 if (
c->fc->nb_streams < 1)
934 st =
c->fc->streams[
c->fc->nb_streams-1];
952 if (
c->fc->nb_streams < 1)
954 st =
c->fc->streams[
c->fc->nb_streams-1];
968 if (
c->fc->nb_streams < 1)
970 st =
c->fc->streams[
c->fc->nb_streams-1];
975 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
978 }
else if (den != 0) {
994 #define DRM_BLOB_SIZE 56
1003 uint8_t calculated_checksum[20];
1007 uint8_t *activation_bytes =
c->activation_bytes;
1008 uint8_t *fixed_key =
c->audible_fixed_key;
1017 if (!
c->aes_decrypt) {
1029 for (
i = 0;
i < 20;
i++)
1034 if (!activation_bytes) {
1039 if (
c->activation_bytes_size != 4) {
1046 if (
c->audible_fixed_key_size != 16) {
1066 if (memcmp(calculated_checksum, file_checksum, 20)) {
1073 for (
i = 0;
i < 4;
i++) {
1075 if (activation_bytes[
i] !=
output[3 -
i]) {
1081 memcpy(
c->file_key,
output + 8, 16);
1099 unsigned char iv[16];
1101 memcpy(iv,
c->file_iv, 16);
1113 int comp_brand_size;
1114 char* comp_brands_str;
1120 if (strcmp(
type,
"qt "))
1127 comp_brand_size = atom.
size - 8;
1128 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1130 comp_brands_str =
av_malloc(comp_brand_size + 1);
1131 if (!comp_brands_str)
1139 comp_brands_str[comp_brand_size] = 0;
1151 if (
c->found_moov) {
1173 if (index < 0 || index >= frag_index->
nb_items)
1189 if (frag_index->
current < 0 ||
1208 if (frag_index->
current < 0 ||
1223 int64_t moof_offset;
1236 if (moof_offset >=
offset)
1238 if (moof_offset <=
offset)
1255 int index,
int track_id)
1261 if (track_id >= 0) {
1294 m0 = m = (
a +
b) >> 1;
1300 if (m <
b && frag_time <= timestamp)
1317 if (index < c->frag_index.nb_items &&
1324 &
c->frag_index.allocated_size,
1325 (
c->frag_index.nb_items + 1) *
1326 sizeof(*
c->frag_index.item));
1329 c->frag_index.item = item;
1333 if (!frag_stream_info)
1336 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1338 if (
c->fc->streams[
i]->id < 0) {
1343 frag_stream_info[
i].
id =
c->fc->streams[
i]->id;
1352 if (index < c->frag_index.nb_items)
1353 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1354 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1356 item = &
c->frag_index.item[
index];
1362 c->frag_index.nb_items++;
1368 int id,
int entries)
1377 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1385 c->fragment.found_tfhd = 0;
1387 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1388 c->has_looked_for_mfra = 1;
1395 "read the mfra (may be a live ismv)\n");
1399 "seekable, can not look for mfra\n");
1402 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1411 if(time >= 2082844800)
1414 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1430 int64_t creation_time;
1432 if (
c->fc->nb_streams < 1)
1434 st =
c->fc->streams[
c->fc->nb_streams-1];
1475 int64_t creation_time;
1488 if (
c->time_scale <= 0) {
1497 if (
c->time_scale > 0 && !
c->trex_data)
1506 for (
i = 0;
i < 3;
i++) {
1528 if (
c->fc->nb_streams < 1)
1530 st =
c->fc->streams[
c->fc->nb_streams-1];
1534 if (little_endian == 1) {
1559 char color_parameter_type[5] = { 0 };
1563 if (
c->fc->nb_streams < 1)
1565 st =
c->fc->streams[
c->fc->nb_streams - 1];
1570 if (strncmp(color_parameter_type,
"nclx", 4) &&
1571 strncmp(color_parameter_type,
"nclc", 4) &&
1572 strncmp(color_parameter_type,
"prof", 4)) {
1574 color_parameter_type);
1578 if (!strncmp(color_parameter_type,
"prof", 4)) {
1592 "%s: pri %d trc %d matrix %d",
1595 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1622 unsigned mov_field_order;
1625 if (
c->fc->nb_streams < 1)
1627 st =
c->fc->streams[
c->fc->nb_streams-1];
1631 if ((mov_field_order & 0xFF00) == 0x0100)
1633 else if ((mov_field_order & 0xFF00) == 0x0200) {
1634 switch (mov_field_order & 0xFF) {
1657 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1680 }
else if (err < atom.
size) {
1694 uint64_t original_size;
1697 if (
c->fc->nb_streams < 1)
1699 st =
c->fc->streams[
c->fc->nb_streams-1];
1748 if (!
ret &&
c->fc->nb_streams >= 1) {
1760 if (
c->fc->nb_streams >= 1) {
1769 if (
cid == 0xd4d ||
cid == 0xd4e)
1780 if (num <= 0 || den <= 0)
1784 if (den >= INT_MAX / 2)
1788 c->fc->streams[
c->fc->nb_streams-1]->display_aspect_ratio.num = num;
1789 c->fc->streams[
c->fc->nb_streams-1]->display_aspect_ratio.den = den;
1803 uint64_t original_size;
1804 if (
c->fc->nb_streams >= 1) {
1808 if (atom.
size == 16) {
1813 if (length == atom.
size) {
1815 switch (range_value) {
1852 if (
c->fc->nb_streams < 1)
1854 st =
c->fc->streams[
c->fc->nb_streams-1];
1856 if ((uint64_t)atom.
size > (1<<30))
1866 }
else if (atom.
size > 8) {
1880 #define ALAC_EXTRADATA_SIZE 36
1909 if (
c->fc->nb_streams < 1)
1911 st =
c->fc->streams[
c->fc->nb_streams-1];
1913 if ((uint64_t)atom.
size > (1<<30))
1916 if (atom.
size >= 10) {
1951 if (
c->fc->nb_streams < 1)
1953 st =
c->fc->streams[
c->fc->nb_streams-1];
1955 if (atom.
size >= (1<<28) || atom.
size < 7)
1959 if ((profile_level & 0xf0) != 0xc0)
1980 if (
c->fc->nb_streams < 1)
1982 if (atom.
size <= 40)
1984 st =
c->fc->streams[
c->fc->nb_streams-1];
1986 if ((uint64_t)atom.
size > (1<<30))
2001 unsigned int i, entries;
2003 if (
c->trak_index < 0) {
2007 if (
c->fc->nb_streams < 1)
2009 st =
c->fc->streams[
c->fc->nb_streams-1];
2031 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2034 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2055 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2056 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2088 uint8_t codec_name[32] = { 0 };
2121 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2128 !strncmp(codec_name,
"Sorenson H263", 13))
2144 int bits_per_sample,
flags;
2163 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2244 if (bits_per_sample && (bits_per_sample >> 3) * (uint64_t)st->
codecpar->
channels <= INT_MAX) {
2269 y = (ycbcr >> 16) & 0xFF;
2270 cr = (ycbcr >> 8) & 0xFF;
2273 b = av_clip_uint8((1164 * (y - 16) + 2018 * (
cb - 128)) / 1000);
2274 g = av_clip_uint8((1164 * (y - 16) - 813 * (
cr - 128) - 391 * (
cb - 128)) / 1000);
2275 r = av_clip_uint8((1164 * (y - 16) + 1596 * (
cr - 128) ) / 1000);
2277 return (
r << 16) | (
g << 8) |
b;
2282 char buf[256] = {0};
2290 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2294 for (
i = 0;
i < 16;
i++) {
2298 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba,
i != 15 ?
", " :
"");
2301 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2332 #if FF_API_LAVF_AVCTX
2342 #if FF_API_LAVF_AVCTX
2353 if (str_size > 0 &&
size >= (
int)str_size + 30) {
2354 char *reel_name =
av_malloc(str_size + 1);
2358 reel_name[str_size] = 0;
2360 if (*reel_name == 0) {
2385 #if CONFIG_DV_DEMUXER
2456 int codec_tag,
int format,
2469 (
c->fc->video_codec_id ? video_codec_id !=
c->fc->video_codec_id
2470 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2487 int pseudo_stream_id;
2490 st =
c->fc->streams[
c->fc->nb_streams-1];
2493 for (pseudo_stream_id = 0;
2495 pseudo_stream_id++) {
2498 int ret, dref_id = 1;
2508 }
else if (
size <= 7) {
2510 "invalid size %"PRId64
" in stsd\n",
size);
2527 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
2557 }
else if (
a.size > 0)
2589 if (
c->fc->nb_streams < 1)
2591 st =
c->fc->streams[
c->fc->nb_streams - 1];
2599 if (entries <= 0 || entries > atom.
size / 8) {
2606 "Duplicate stsd found in this track.\n");
2652 unsigned int i, entries;
2654 if (
c->fc->nb_streams < 1)
2656 st =
c->fc->streams[
c->fc->nb_streams-1];
2663 if ((uint64_t)entries * 12 + 4 > atom.
size)
2688 int64_t first_min =
i + 1;
2748 unsigned i, entries;
2750 if (
c->fc->nb_streams < 1)
2752 st =
c->fc->streams[
c->fc->nb_streams-1];
2784 unsigned int i, entries;
2786 if (
c->fc->nb_streams < 1)
2788 st =
c->fc->streams[
c->fc->nb_streams-1];
2807 if (entries >= UINT_MAX /
sizeof(
int))
2833 unsigned int i, entries, sample_size, field_size, num_bytes;
2838 if (
c->fc->nb_streams < 1)
2840 st =
c->fc->streams[
c->fc->nb_streams-1];
2846 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
2865 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
2872 if (entries >= (UINT_MAX - 4) / field_size)
2882 num_bytes = (entries*field_size+4)>>3;
2926 unsigned int i, entries, alloc_size = 0;
2928 int64_t total_sample_count=0;
2930 if (
c->fc->nb_streams < 1)
2932 st =
c->fc->streams[
c->fc->nb_streams-1];
2940 c->fc->nb_streams-1, entries);
2946 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
2950 int sample_duration;
2951 unsigned int sample_count;
2952 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
2970 sample_count, sample_duration);
2972 duration+=(int64_t)sample_duration*(uint64_t)sample_count;
2973 total_sample_count+=sample_count;
2979 duration <= INT64_MAX - sc->duration_for_fps &&
2980 total_sample_count <= INT_MAX - sc->nb_frames_for_fps
3004 if (
c->fc->nb_streams < 1)
3006 st =
c->fc->streams[
c->fc->nb_streams - 1];
3011 entries = atom.
size - 4;
3014 c->fc->nb_streams - 1, entries);
3047 unsigned int i, entries, ctts_count = 0;
3049 if (
c->fc->nb_streams < 1)
3051 st =
c->fc->streams[
c->fc->nb_streams-1];
3062 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3075 "ignoring CTTS entry with count=%d duration=%d\n",
3113 unsigned int i, entries;
3115 uint32_t grouping_type;
3117 if (
c->fc->nb_streams < 1)
3119 st =
c->fc->streams[
c->fc->nb_streams-1];
3125 if (grouping_type !=
MKTAG(
'r',
'a',
'p',
' '))
3161 unsigned int edit_list_index,
3162 int64_t *edit_list_media_time,
3163 int64_t *edit_list_duration,
3164 int64_t global_timescale)
3169 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3173 if (global_timescale == 0) {
3206 int64_t timestamp_pts,
3209 int64_t* ctts_index,
3210 int64_t* ctts_sample)
3216 int64_t index_ctts_count;
3244 if (ctts_data && *
index >= 0) {
3250 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3251 if (*ctts_index < ctts_count) {
3253 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3260 while (*
index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3264 if ((e_old[*
index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3270 if (*ctts_sample == 0) {
3272 if (*ctts_index >= 0)
3273 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3283 return *
index >= 0 ? 0 : -1;
3306 const size_t requested_size =
3323 ie= &entries[
index];
3338 int64_t* frame_duration_buffer,
3339 int frame_duration_buffer_size) {
3341 av_assert0(end_index >= 0 && end_index <= st->nb_index_entries);
3342 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
3343 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
3356 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVStts);
3357 const size_t requested_size =
3358 min_size_needed > *allocated_size ?
3359 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3362 if((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVStts) - 1)
3365 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
3370 *ctts_data = ctts_buf_new;
3375 *ctts_count = (*ctts_count) + 1;
3379 #define MAX_REORDER_DELAY 16
3384 int ctts_sample = 0;
3387 int j,
r, num_swaps;
3390 pts_buf[j] = INT64_MIN;
3398 buf_start = (buf_start + 1);
3411 while (j != buf_start) {
3414 if (pts_buf[j] < pts_buf[
r]) {
3415 FFSWAP(int64_t, pts_buf[j], pts_buf[
r]);
3473 if (range_size > current_sample) {
3477 current_sample -= range_size;
3495 int64_t ctts_index_old = 0;
3496 int64_t ctts_sample_old = 0;
3498 int64_t edit_list_media_time = 0;
3499 int64_t edit_list_duration = 0;
3500 int64_t frame_duration = 0;
3501 int64_t edit_list_dts_counter = 0;
3502 int64_t edit_list_dts_entry_end = 0;
3503 int64_t edit_list_start_ctts_sample = 0;
3505 int64_t curr_ctts = 0;
3506 int64_t empty_edits_sum_duration = 0;
3507 int64_t edit_list_index = 0;
3510 int64_t start_dts = 0;
3511 int64_t edit_list_start_encountered = 0;
3512 int64_t search_timestamp = 0;
3513 int64_t* frame_duration_buffer =
NULL;
3514 int num_discarded_begin = 0;
3515 int first_non_zero_audio_edit = -1;
3516 int packet_skip_samples = 0;
3519 int found_keyframe_after_edit = 0;
3520 int found_non_empty_edit = 0;
3553 edit_list_dts_entry_end -= msc->
dts_shift;
3557 start_dts = edit_list_dts_entry_end;
3561 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3562 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3564 edit_list_dts_counter = edit_list_dts_entry_end;
3565 edit_list_dts_entry_end += edit_list_duration;
3566 num_discarded_begin = 0;
3567 if (!found_non_empty_edit && edit_list_media_time == -1) {
3568 empty_edits_sum_duration += edit_list_duration;
3571 found_non_empty_edit = 1;
3576 if (first_non_zero_audio_edit < 0) {
3577 first_non_zero_audio_edit = 1;
3579 first_non_zero_audio_edit = 0;
3582 if (first_non_zero_audio_edit > 0)
3590 search_timestamp = edit_list_media_time;
3599 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3601 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3602 st->
index, edit_list_index, search_timestamp);
3604 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3606 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
3607 st->
index, edit_list_index, search_timestamp);
3610 ctts_sample_old = 0;
3613 current = e_old +
index;
3614 edit_list_start_ctts_sample = ctts_sample_old;
3617 edit_list_start_encountered = 0;
3618 found_keyframe_after_edit = 0;
3619 for (; current < e_old_end; current++,
index++) {
3621 frame_duration = (current + 1 < e_old_end) ?
3622 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3630 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3631 curr_ctts = ctts_data_old[ctts_index_old].
duration;
3632 av_log(mov->
fc,
AV_LOG_DEBUG,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
3633 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
3634 curr_cts += curr_ctts;
3636 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3639 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3640 ctts_data_old[ctts_index_old].
duration) == -1) {
3643 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3644 ctts_data_old[ctts_index_old].
duration);
3648 ctts_sample_old = 0;
3649 edit_list_start_ctts_sample = 0;
3653 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3655 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3656 first_non_zero_audio_edit > 0) {
3657 packet_skip_samples = edit_list_media_time - curr_cts;
3661 edit_list_dts_counter -= packet_skip_samples;
3662 if (edit_list_start_encountered == 0) {
3663 edit_list_start_encountered = 1;
3666 if (frame_duration_buffer) {
3668 frame_duration_buffer, num_discarded_begin);
3673 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
3678 if (edit_list_start_encountered == 0) {
3679 num_discarded_begin++;
3680 frame_duration_buffer =
av_realloc(frame_duration_buffer,
3681 num_discarded_begin *
sizeof(int64_t));
3682 if (!frame_duration_buffer) {
3686 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
3701 if (edit_list_start_encountered == 0) {
3702 edit_list_start_encountered = 1;
3705 if (frame_duration_buffer) {
3707 frame_duration_buffer, num_discarded_begin);
3720 if (current_index_range < msc->index_ranges ||
index != current_index_range->
end) {
3721 current_index_range++;
3724 current_index_range->
end =
index + 1;
3727 if (edit_list_start_encountered > 0) {
3728 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
3732 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
3734 if (ctts_data_old) {
3739 found_keyframe_after_edit = 1;
3742 if (ctts_sample_old != 0) {
3745 ctts_sample_old - edit_list_start_ctts_sample,
3746 ctts_data_old[ctts_index_old].
duration) == -1) {
3748 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
3749 ctts_data_old[ctts_index_old].
duration);
3785 current_index_range++;
3786 current_index_range->
start = 0;
3787 current_index_range->
end = 0;
3794 int64_t current_offset;
3795 int64_t current_dts = 0;
3796 unsigned int stts_index = 0;
3797 unsigned int stsc_index = 0;
3798 unsigned int stss_index = 0;
3799 unsigned int stps_index = 0;
3801 uint64_t stream_size = 0;
3803 unsigned int ctts_count_old = sc->
ctts_count;
3806 int i, edit_start_index = 0, multiple_edits = 0;
3807 int64_t empty_duration = 0;
3812 if (
i == 0 && e->
time == -1) {
3816 edit_start_index = 1;
3817 }
else if (
i == edit_start_index && e->
time >= 0) {
3826 "Use -advanced_editlist to correctly decode otherwise "
3827 "a/v desync might occur\n");
3851 unsigned int current_sample = 0;
3852 unsigned int stts_sample = 0;
3853 unsigned int sample_size;
3855 unsigned int rap_group_index = 0;
3856 unsigned int rap_group_sample = 0;
3857 int64_t last_dts = 0;
3858 int64_t dts_correction = 0;
3863 last_dts = current_dts;
3877 if (ctts_data_old) {
3892 for (
i = 0;
i < ctts_count_old &&
3894 for (j = 0; j < ctts_data_old[
i].
count &&
3935 if (rap_group_present && rap_group_index < sc->rap_group_count) {
3938 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
3939 rap_group_sample = 0;
3945 && !rap_group_present
3954 if (sample_size > 0x3FFFFFFF) {
3959 e->
pos = current_offset;
3961 e->
size = sample_size;
3964 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", "
3965 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
3966 current_offset, current_dts, sample_size,
distance, keyframe);
3971 current_offset += sample_size;
3972 stream_size += sample_size;
3978 "Invalid SampleDelta %d in STTS, at %d st:%d\n",
3985 if (!dts_correction || current_dts + dts_correction > last_dts) {
3986 current_dts += dts_correction;
3990 dts_correction += current_dts - last_dts - 1;
3991 current_dts = last_dts + 1;
3993 last_dts = current_dts;
4006 unsigned chunk_samples, total = 0;
4013 unsigned count, chunk_count;
4028 count = (chunk_samples+1023) / 1024;
4035 total += chunk_count *
count;
4057 while (chunk_samples > 0) {
4063 "Zero bytes per frame, but %d samples per frame",
4086 if (
size > 0x3FFFFFFF) {
4091 e->
pos = current_offset;
4097 "size %u, duration %u\n", st->
index,
i, current_offset, current_dts,
4100 current_offset +=
size;
4133 av_url_split(src_proto,
sizeof(src_proto), src_auth,
sizeof(src_auth), src_host,
sizeof(src_host), &src_port,
NULL, 0,
src);
4134 av_url_split(ref_proto,
sizeof(ref_proto), ref_auth,
sizeof(ref_auth), ref_host,
sizeof(ref_host), &ref_port,
NULL, 0,
ref);
4136 if (strlen(
src) == 0) {
4138 }
else if (strlen(src_auth) + 1 >=
sizeof(src_auth) ||
4139 strlen(ref_auth) + 1 >=
sizeof(ref_auth) ||
4140 strlen(src_host) + 1 >=
sizeof(src_host) ||
4141 strlen(ref_host) + 1 >=
sizeof(ref_host)) {
4143 }
else if (strcmp(src_proto, ref_proto) ||
4144 strcmp(src_auth, ref_auth) ||
4145 strcmp(src_host, ref_host) ||
4146 src_port != ref_port) {
4156 if (
ref->nlvl_to > 0 &&
ref->nlvl_from > 0) {
4157 char filename[1025];
4158 const char *src_path;
4162 src_path = strrchr(
src,
'/');
4169 for (
i = 0, l = strlen(
ref->path) - 1; l >= 0; l--)
4170 if (
ref->path[l] ==
'/') {
4171 if (
i ==
ref->nlvl_to - 1)
4178 if (
i ==
ref->nlvl_to - 1 && src_path -
src <
sizeof(filename)) {
4179 memcpy(filename,
src, src_path -
src);
4180 filename[src_path -
src] = 0;
4182 for (
i = 1;
i <
ref->nlvl_from;
i++)
4183 av_strlcat(filename,
"../",
sizeof(filename));
4186 if (!
c->use_absolute_path) {
4191 "Reference with mismatching origin, %s not tried for security reasons, "
4192 "set demuxer option use_absolute_path to allow it anyway\n",
4197 if(strstr(
ref->path + l + 1,
"..") ||
4198 strstr(
ref->path + l + 1,
":") ||
4199 (
ref->nlvl_from > 1 && same_origin < 0) ||
4200 (filename[0] ==
'/' && src_path ==
src))
4204 if (strlen(filename) + 1 ==
sizeof(filename))
4209 }
else if (
c->use_absolute_path) {
4211 "this is a possible security issue\n");
4216 "Absolute path %s not tried for security reasons, "
4217 "set demuxer option use_absolute_path to allow absolute paths\n",
4241 if (!st)
return AVERROR(ENOMEM);
4244 if (!sc)
return AVERROR(ENOMEM);
4249 c->trak_index = st->
index;
4285 if (
c->enable_drefs) {
4288 "stream %d, error opening alias: path='%s', dir='%s', "
4289 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
4294 "Skipped opening external track: "
4295 "stream %d, alias: path='%s', dir='%s', "
4296 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d."
4297 "Set enable_drefs to allow this.\n",
4314 #if FF_API_R_FRAME_RATE
4330 #if CONFIG_H261_DECODER
4333 #if CONFIG_H263_DECODER
4336 #if CONFIG_MPEG4_DECODER
4366 c->itunes_metadata = 1;
4368 c->itunes_metadata = 0;
4382 if (
count > UINT_MAX /
sizeof(*
c->meta_keys) - 1) {
4384 "The 'keys' atom with the invalid key count: %"PRIu32
"\n",
count);
4388 c->meta_keys_count =
count + 1;
4389 c->meta_keys =
av_mallocz(
c->meta_keys_count *
sizeof(*
c->meta_keys));
4398 "The key# %"PRIu32
" in meta has invalid size:"
4399 "%"PRIu32
"\n",
i, key_size);
4407 if (!
c->meta_keys[
i])
4424 if (
c->fc->nb_streams < 1)
4426 st =
c->fc->streams[
c->fc->nb_streams-1];
4429 for (
i = 0;
i < 3;
i++) {