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;
91 snprintf(buf,
sizeof(buf),
"%d", current);
93 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
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++) {
233 char language[4] = { 0 };
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);
272 if (*language && strcmp(language,
"und")) {
274 snprintf(key2,
sizeof(key2),
"%s-%s", key, language);
301 char key2[32], language[4] = {0};
304 uint16_t langcode = 0;
305 uint32_t data_type = 0, str_size, str_size_alloc;
311 case MKTAG(
'@',
'P',
'R',
'M'): key =
"premiere_version"; raw = 1;
break;
312 case MKTAG(
'@',
'P',
'R',
'Q'): key =
"quicktime_version"; raw = 1;
break;
313 case MKTAG(
'X',
'M',
'P',
'_'):
314 if (c->
export_xmp) { key =
"xmp"; raw = 1; }
break;
315 case MKTAG(
'a',
'A',
'R',
'T'): key =
"album_artist";
break;
316 case MKTAG(
'a',
'k',
'I',
'D'): key =
"account_type";
318 case MKTAG(
'a',
'p',
'I',
'D'): key =
"account_id";
break;
319 case MKTAG(
'c',
'a',
't',
'g'): key =
"category";
break;
320 case MKTAG(
'c',
'p',
'i',
'l'): key =
"compilation";
322 case MKTAG(
'c',
'p',
'r',
't'): key =
"copyright";
break;
323 case MKTAG(
'd',
'e',
's',
'c'): key =
"description";
break;
324 case MKTAG(
'd',
'i',
's',
'k'): key =
"disc";
326 case MKTAG(
'e',
'g',
'i',
'd'): key =
"episode_uid";
328 case MKTAG(
'F',
'I',
'R',
'M'): key =
"firmware"; raw = 1;
break;
329 case MKTAG(
'g',
'n',
'r',
'e'): key =
"genre";
331 case MKTAG(
'h',
'd',
'v',
'd'): key =
"hd_video";
333 case MKTAG(
'H',
'M',
'M',
'T'):
335 case MKTAG(
'k',
'e',
'y',
'w'): key =
"keywords";
break;
336 case MKTAG(
'l',
'd',
'e',
's'): key =
"synopsis";
break;
337 case MKTAG(
'l',
'o',
'c',
'i'):
339 case MKTAG(
'm',
'a',
'n',
'u'): key =
"make";
break;
340 case MKTAG(
'm',
'o',
'd',
'l'): key =
"model";
break;
341 case MKTAG(
'p',
'c',
's',
't'): key =
"podcast";
343 case MKTAG(
'p',
'g',
'a',
'p'): key =
"gapless_playback";
345 case MKTAG(
'p',
'u',
'r',
'd'): key =
"purchase_date";
break;
346 case MKTAG(
'r',
't',
'n',
'g'): key =
"rating";
348 case MKTAG(
's',
'o',
'a',
'a'): key =
"sort_album_artist";
break;
349 case MKTAG(
's',
'o',
'a',
'l'): key =
"sort_album";
break;
350 case MKTAG(
's',
'o',
'a',
'r'): key =
"sort_artist";
break;
351 case MKTAG(
's',
'o',
'c',
'o'): key =
"sort_composer";
break;
352 case MKTAG(
's',
'o',
'n',
'm'): key =
"sort_name";
break;
353 case MKTAG(
's',
'o',
's',
'n'): key =
"sort_show";
break;
354 case MKTAG(
's',
't',
'i',
'k'): key =
"media_type";
356 case MKTAG(
't',
'r',
'k',
'n'): key =
"track";
358 case MKTAG(
't',
'v',
'e',
'n'): key =
"episode_id";
break;
359 case MKTAG(
't',
'v',
'e',
's'): key =
"episode_sort";
361 case MKTAG(
't',
'v',
'n',
'n'): key =
"network";
break;
362 case MKTAG(
't',
'v',
's',
'h'): key =
"show";
break;
363 case MKTAG(
't',
'v',
's',
'n'): key =
"season_number";
365 case MKTAG(0xa9,
'A',
'R',
'T'): key =
"artist";
break;
366 case MKTAG(0xa9,
'P',
'R',
'D'): key =
"producer";
break;
367 case MKTAG(0xa9,
'a',
'l',
'b'): key =
"album";
break;
368 case MKTAG(0xa9,
'a',
'u',
't'): key =
"artist";
break;
369 case MKTAG(0xa9,
'c',
'h',
'p'): key =
"chapter";
break;
370 case MKTAG(0xa9,
'c',
'm',
't'): key =
"comment";
break;
371 case MKTAG(0xa9,
'c',
'o',
'm'): key =
"composer";
break;
372 case MKTAG(0xa9,
'c',
'p',
'y'): key =
"copyright";
break;
373 case MKTAG(0xa9,
'd',
'a',
'y'): key =
"date";
break;
374 case MKTAG(0xa9,
'd',
'i',
'r'): key =
"director";
break;
375 case MKTAG(0xa9,
'd',
'i',
's'): key =
"disclaimer";
break;
376 case MKTAG(0xa9,
'e',
'd',
'1'): key =
"edit_date";
break;
377 case MKTAG(0xa9,
'e',
'n',
'c'): key =
"encoder";
break;
378 case MKTAG(0xa9,
'f',
'm',
't'): key =
"original_format";
break;
379 case MKTAG(0xa9,
'g',
'e',
'n'): key =
"genre";
break;
380 case MKTAG(0xa9,
'g',
'r',
'p'): key =
"grouping";
break;
381 case MKTAG(0xa9,
'h',
's',
't'): key =
"host_computer";
break;
382 case MKTAG(0xa9,
'i',
'n',
'f'): key =
"comment";
break;
383 case MKTAG(0xa9,
'l',
'y',
'r'): key =
"lyrics";
break;
384 case MKTAG(0xa9,
'm',
'a',
'k'): key =
"make";
break;
385 case MKTAG(0xa9,
'm',
'o',
'd'): key =
"model";
break;
386 case MKTAG(0xa9,
'n',
'a',
'm'): key =
"title";
break;
387 case MKTAG(0xa9,
'o',
'p',
'e'): key =
"original_artist";
break;
388 case MKTAG(0xa9,
'p',
'r',
'd'): key =
"producer";
break;
389 case MKTAG(0xa9,
'p',
'r',
'f'): key =
"performers";
break;
390 case MKTAG(0xa9,
'r',
'e',
'q'): key =
"playback_requirements";
break;
391 case MKTAG(0xa9,
's',
'r',
'c'): key =
"original_source";
break;
392 case MKTAG(0xa9,
's',
't',
'3'): key =
"subtitle";
break;
393 case MKTAG(0xa9,
's',
'w',
'r'): key =
"encoder";
break;
394 case MKTAG(0xa9,
't',
'o',
'o'): key =
"encoder";
break;
395 case MKTAG(0xa9,
't',
'r',
'k'): key =
"track";
break;
396 case MKTAG(0xa9,
'u',
'r',
'l'): key =
"URL";
break;
397 case MKTAG(0xa9,
'w',
'r',
'n'): key =
"warning";
break;
398 case MKTAG(0xa9,
'w',
'r',
't'): key =
"composer";
break;
399 case MKTAG(0xa9,
'x',
'y',
'z'): key =
"location";
break;
405 if (tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.
size) {
408 str_size = data_size - 16;
411 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r')) {
417 atom.
size -= str_size;
423 if (index < c->meta_keys_count && index > 0) {
427 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
434 if (str_size > atom.
size) {
444 str_size = atom.
size;
453 if (atom.
size < 0 || str_size >= INT_MAX/2)
458 num = (data_type >= 21 && data_type <= 23);
459 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
465 parse(c, pb, str_size, key);
467 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
469 }
else if (data_type == 21) {
473 else if (str_size == 2)
475 else if (str_size == 3)
477 else if (str_size == 4)
479 if (
snprintf(str, str_size_alloc,
"%d", val) >= str_size_alloc) {
481 "Failed to store the number (%d) in string.\n", val);
485 }
else if (data_type == 22) {
486 unsigned int val = 0;
489 else if (str_size == 2)
491 else if (str_size == 3)
493 else if (str_size == 4)
495 if (
snprintf(str, str_size_alloc,
"%u", val) >= str_size_alloc) {
497 "Failed to store the number (%u) in string.\n", val);
501 }
else if (data_type == 23 && str_size >= 4) {
503 if (
snprintf(str, str_size_alloc,
"%f", val) >= str_size_alloc) {
505 "Failed to store the float32 number (%f) in string.\n", val);
519 if (*language && strcmp(language,
"und")) {
520 snprintf(key2,
sizeof(key2),
"%s-%s", key, language);
523 if (!strcmp(key,
"encoder")) {
524 int major, minor, micro;
525 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
538 int i, nb_chapters, str_len,
version;
545 if ((atom.
size -= 5) < 0)
554 for (i = 0; i < nb_chapters; i++) {
561 if ((atom.
size -= 9+str_len) < 0)
573 #define MIN_DATA_ENTRY_BOX_SIZE 12
589 entries >= UINT_MAX /
sizeof(*sc->
drefs))
599 for (i = 0; i < entries; i++) {
610 if (dref->
type ==
MKTAG(
'a',
'l',
'i',
's') && size > 150) {
612 uint16_t volume_len,
len;
619 volume_len =
FFMIN(volume_len, 27);
623 dref->
volume[volume_len] = 0;
629 len =
FFMIN(len, 63);
646 for (type = 0; type != -1 &&
avio_tell(pb) < next; ) {
665 if (len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
667 memmove(dref->
path, dref->
path+volume_len, len);
671 for (j = len - 1; j >= 0; j--) {
672 if (dref->
path[j] == 0)
677 for (j = 0; j <
len; j++)
678 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
681 }
else if (type == 0) {
693 for (j = 0; j <
len; j++)
694 if (dref->
dir[j] ==
':')
731 if (type ==
MKTAG(
'm',
'd',
't',
'a')) {
739 if (type ==
MKTAG(
'v',
'i',
'd',
'e'))
741 else if (type ==
MKTAG(
's',
'o',
'u',
'n'))
743 else if (type ==
MKTAG(
'm',
'1',
'a',
' '))
745 else if ((type ==
MKTAG(
's',
'u',
'b',
'p')) || (type ==
MKTAG(
'c',
'l',
'c',
'p')))
752 title_size = atom.
size - 24;
753 if (title_size > 0) {
754 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
765 title_str[title_size] = 0;
767 int off = (!c->
isom && title_str[0] == title_size - 1);
786 int ac3info, acmod, lfeon, bsmod;
798 bsmod = (ac3info >> 14) & 0x7;
799 acmod = (ac3info >> 11) & 0x7;
800 lfeon = (ac3info >> 10) & 0x1;
809 #if FF_API_LAVF_AVCTX
811 st->codec->audio_service_type = *ast;
822 int eac3info, acmod, lfeon, bsmod;
838 bsmod = (eac3info >> 12) & 0x1f;
839 acmod = (eac3info >> 9) & 0x7;
840 lfeon = (eac3info >> 8) & 0x1;
849 #if FF_API_LAVF_AVCTX
851 st->codec->audio_service_type = *ast;
860 const uint32_t ddts_size = 20;
863 uint32_t frame_duration_code = 0;
864 uint32_t channel_layout_code = 0;
871 if (
avio_read(pb, buf, ddts_size) < ddts_size) {
893 frame_duration_code =
get_bits(&gb, 2);
895 channel_layout_code =
get_bits(&gb, 16);
898 (frame_duration_code == 0) ? 512 :
899 (frame_duration_code == 1) ? 1024 :
900 (frame_duration_code == 2) ? 2048 :
901 (frame_duration_code == 3) ? 4096 : 0;
903 if (channel_layout_code > 0xff) {
967 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
970 }
else if (den != 0) {
986 #define DRM_BLOB_SIZE 56
995 uint8_t calculated_checksum[20];
1020 for (i = 0; i < 20; i++)
1025 if (!activation_bytes) {
1057 if (memcmp(calculated_checksum, file_checksum, 20)) {
1064 for (i = 0; i < 4; i++) {
1066 if (activation_bytes[i] != output[3 - i]) {
1072 memcpy(c->
file_key, output + 8, 16);
1073 memcpy(input, output + 26, 16);
1090 unsigned char iv[16];
1104 int comp_brand_size;
1105 char* comp_brands_str;
1111 if (strcmp(type,
"qt "))
1118 comp_brand_size = atom.
size - 8;
1119 if (comp_brand_size < 0)
1121 comp_brands_str =
av_malloc(comp_brand_size + 1);
1122 if (!comp_brands_str)
1130 comp_brands_str[comp_brand_size] = 0;
1164 if (index < 0 || index >= frag_index->
nb_items)
1180 if (frag_index->
current < 0 ||
1199 if (frag_index->
current < 0 ||
1214 int64_t moof_offset;
1227 if (moof_offset >= offset)
1229 if (moof_offset <= offset)
1238 if (frag_stream_info) {
1250 int index,
int track_id)
1256 if (track_id >= 0) {
1292 if (frag_time >= timestamp)
1294 if (frag_time <= timestamp)
1309 if (index < c->frag_index.nb_items &&
1325 if (!frag_stream_info)
1337 if (index < c->frag_index.nb_items)
1353 int id,
int entries)
1360 for (i = index; i < frag_index->
nb_items; i++) {
1362 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1377 "read the mfra (may be a live ismv)\n");
1381 "seekable, can not look for mfra\n");
1393 if(time >= 2082844800)
1396 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1410 char language[4] = {0};
1412 int64_t creation_time;
1457 int64_t creation_time;
1488 for (i = 0; i < 3; i++) {
1516 if (little_endian == 1) {
1540 char color_parameter_type[5] = { 0 };
1551 if (strncmp(color_parameter_type,
"nclx", 4) &&
1552 strncmp(color_parameter_type,
"nclc", 4)) {
1554 color_parameter_type);
1563 "%s: pri %d trc %d matrix %d",
1564 color_parameter_type, color_primaries, color_trc, color_matrix);
1566 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1593 unsigned mov_field_order;
1602 if ((mov_field_order & 0xFF00) == 0x0100)
1604 else if ((mov_field_order & 0xFF00) == 0x0200) {
1605 switch (mov_field_order & 0xFF) {
1628 if (size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1642 int64_t result = atom.
size;
1651 }
else if (err < atom.
size) {
1665 uint64_t original_size;
1740 if (cid == 0xd4d || cid == 0xd4e)
1751 if (num <= 0 || den <= 0)
1755 if (den >= INT_MAX / 2)
1774 uint64_t original_size;
1779 if (atom.
size == 16) {
1784 if (length == atom.
size) {
1786 switch (range_value) {
1827 if ((uint64_t)atom.
size > (1<<30))
1838 }
else if (atom.
size > 8) {
1846 if ( (buffer & 0xFFFFFFFF) ==
MKBETAG(
'f',
'r',
'm',
'a')
1847 && buffer >> 32 <= atom.
size
1848 && buffer >> 32 >= 8) {
1852 #define ALAC_EXTRADATA_SIZE 36
1885 if ((uint64_t)atom.
size > (1<<30))
1888 if (atom.
size >= 10) {
1894 if (type ==
MKTAG(
'f',
'i',
'e',
'l') && size == atom.
size)
1921 if (atom.
size >= (1<<28) || atom.
size < 7)
1925 if ((profile_level & 0xf0) != 0xc0)
1949 if (atom.
size <= 40)
1953 if ((uint64_t)atom.
size > (1<<30))
1969 unsigned int i, entries;
1993 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
1996 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2017 ((format & 0xFFFF) ==
'm' + (
's' << 8) ||
2018 (format & 0xFFFF) ==
'T' + (
'S' << 8)))
2025 format && format !=
MKTAG(
'm',
'p',
'4',
's')) {
2050 uint8_t codec_name[32] = { 0 };
2083 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2090 !strncmp(codec_name,
"Sorenson H263", 13))
2106 int bits_per_sample,
flags;
2125 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2132 }
else if (version == 2) {
2147 if (version == 0 || (version == 1 && sc->
audio_cid != -2)) {
2206 if (bits_per_sample) {
2231 y = (ycbcr >> 16) & 0xFF;
2232 cr = (ycbcr >> 8) & 0xFF;
2235 b = av_clip_uint8((1164 * (y - 16) + 2018 * (cb - 128)) / 1000);
2236 g = av_clip_uint8((1164 * (y - 16) - 813 * (cr - 128) - 391 * (cb - 128)) / 1000);
2237 r = av_clip_uint8((1164 * (y - 16) + 1596 * (cr - 128) ) / 1000);
2239 return (r << 16) | (g << 8) | b;
2244 char buf[256] = {0};
2252 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2256 for (i = 0; i < 16; i++) {
2257 uint32_t yuv =
AV_RB32(src + i * 4);
2260 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba, i != 15 ?
", " :
"");
2263 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2284 if ((
int)size != size)
2297 #if FF_API_LAVF_AVCTX
2308 #if FF_API_LAVF_AVCTX
2318 if (format ==
AV_RB32(
"name") && (int64_t)size >= (int64_t)len + 18) {
2320 if (str_size > 0 && size >= (
int)str_size + 26) {
2321 char *reel_name =
av_malloc(str_size + 1);
2325 reel_name[str_size] = 0;
2327 if (*reel_name == 0) {
2352 #if CONFIG_DV_DEMUXER
2423 int codec_tag,
int format,
2429 (codec_tag != format &&
2437 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2454 int pseudo_stream_id;
2460 for (pseudo_stream_id = 0;
2462 pseudo_stream_id++) {
2465 int ret, dref_id = 1;
2475 }
else if (size <= 7) {
2477 "invalid size %"PRId64
" in stsd\n", size);
2494 "size=%"PRId64
" 4CC=%s codec_type=%d\n", size,
2520 }
else if (a.
size > 0)
2562 if (entries <= 0 || entries > atom.
size / 8) {
2569 "Duplicate stsd found in this track.\n");
2615 unsigned int i, entries;
2626 if ((uint64_t)entries * 12 + 4 > atom.
size)
2641 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2648 for (i = sc->
stsc_count - 1; i < UINT_MAX; i--) {
2649 int64_t first_min = i + 1;
2682 return index < count - 1;
2702 unsigned i, entries;
2720 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2738 unsigned int i, entries;
2761 if (entries >= UINT_MAX /
sizeof(
int))
2769 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2787 unsigned int i, entries, sample_size, field_size, num_bytes;
2800 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
2819 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
2826 if (entries >= (UINT_MAX - 4) / field_size)
2836 num_bytes = (entries*field_size+4)>>3;
2854 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2875 unsigned int i, entries, alloc_size = 0;
2877 int64_t total_sample_count=0;
2895 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
2898 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2899 int sample_duration;
2900 unsigned int sample_count;
2901 unsigned int min_entries =
FFMIN(
FFMAX(i + 1, 1024 * 1024), entries);
2919 sample_count, sample_duration);
2923 && sample_count == 1
2924 && total_sample_count > 100
2925 && sample_duration/10 > duration / total_sample_count)
2926 sample_duration = duration / total_sample_count;
2927 duration+=(int64_t)sample_duration*(uint64_t)sample_count;
2928 total_sample_count+=sample_count;
2934 duration <= INT64_MAX - sc->duration_for_fps &&
2935 total_sample_count <= INT64_MAX - sc->nb_frames_for_fps
2956 if (duration == INT_MIN) {
2968 unsigned int i, entries, ctts_count = 0;
2983 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
2990 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2996 "ignoring CTTS entry with count=%d duration=%d\n",
3007 if (
FFNABS(duration) < -(1<<28) && i+2<entries) {
3034 unsigned int i, entries;
3036 uint32_t grouping_type;
3046 if (grouping_type !=
MKTAG(
'r',
'a',
'p',
' '))
3062 for (i = 0; i < entries && !pb->
eof_reached; i++) {
3082 unsigned int edit_list_index,
3083 int64_t *edit_list_media_time,
3084 int64_t *edit_list_duration,
3085 int64_t global_timescale)
3090 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3094 if (global_timescale == 0) {
3127 int64_t timestamp_pts,
3130 int64_t* ctts_index,
3131 int64_t* ctts_sample)
3137 int64_t index_ctts_count;
3165 if (ctts_data && *index >= 0) {
3171 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3172 if (*ctts_index < ctts_count) {
3174 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3181 while (*index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3185 if ((e_old[*index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3191 if (*ctts_sample == 0) {
3193 if (*ctts_index >= 0)
3194 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3204 return *index >= 0 ? 0 : -1;
3227 const size_t requested_size =
3244 ie= &entries[
index];
3259 int64_t* frame_duration_buffer,
3260 int frame_duration_buffer_size) {
3262 av_assert0(end_index >= 0 && end_index <= st->nb_index_entries);
3263 for (i = 0; i < frame_duration_buffer_size; i++) {
3264 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 - i];
3277 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVStts);
3278 const size_t requested_size =
3279 min_size_needed > *allocated_size ?
3280 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3283 if((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVStts) - 1)
3286 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
3291 *ctts_data = ctts_buf_new;
3296 *ctts_count = (*ctts_count) + 1;
3300 #define MAX_REORDER_DELAY 16
3305 int ctts_sample = 0;
3308 int j,
r, num_swaps;
3311 pts_buf[j] = INT64_MIN;
3319 buf_start = (buf_start + 1);
3320 if (buf_start == MAX_REORDER_DELAY + 1)
3332 while (j != buf_start) {
3335 if (pts_buf[j] < pts_buf[r]) {
3336 FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
3394 if (range_size > current_sample) {
3398 current_sample -= range_size;
3416 int64_t ctts_index_old = 0;
3417 int64_t ctts_sample_old = 0;
3419 int64_t edit_list_media_time = 0;
3420 int64_t edit_list_duration = 0;
3421 int64_t frame_duration = 0;
3422 int64_t edit_list_dts_counter = 0;
3423 int64_t edit_list_dts_entry_end = 0;
3424 int64_t edit_list_start_ctts_sample = 0;
3426 int64_t curr_ctts = 0;
3427 int64_t empty_edits_sum_duration = 0;
3428 int64_t edit_list_index = 0;
3431 int64_t start_dts = 0;
3432 int64_t edit_list_start_encountered = 0;
3433 int64_t search_timestamp = 0;
3434 int64_t* frame_duration_buffer =
NULL;
3435 int num_discarded_begin = 0;
3436 int first_non_zero_audio_edit = -1;
3437 int packet_skip_samples = 0;
3440 int found_keyframe_after_edit = 0;
3473 edit_list_dts_entry_end -= msc->
dts_shift;
3477 start_dts = edit_list_dts_entry_end;
3481 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3482 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3484 edit_list_dts_counter = edit_list_dts_entry_end;
3485 edit_list_dts_entry_end += edit_list_duration;
3486 num_discarded_begin = 0;
3487 if (edit_list_media_time == -1) {
3488 empty_edits_sum_duration += edit_list_duration;
3495 if (first_non_zero_audio_edit < 0) {
3496 first_non_zero_audio_edit = 1;
3498 first_non_zero_audio_edit = 0;
3501 if (first_non_zero_audio_edit > 0)
3509 search_timestamp = edit_list_media_time;
3518 &index, &ctts_index_old, &ctts_sample_old) < 0) {
3520 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3521 st->
index, edit_list_index, search_timestamp);
3523 &index, &ctts_index_old, &ctts_sample_old) < 0) {
3525 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
3526 st->
index, edit_list_index, search_timestamp);
3529 ctts_sample_old = 0;
3532 current = e_old +
index;
3533 edit_list_start_ctts_sample = ctts_sample_old;
3536 edit_list_start_encountered = 0;
3537 found_keyframe_after_edit = 0;
3538 for (; current < e_old_end; current++, index++) {
3540 frame_duration = (current + 1 < e_old_end) ?
3541 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3543 flags = current->
flags;
3549 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3550 curr_ctts = ctts_data_old[ctts_index_old].
duration;
3551 av_log(mov->
fc,
AV_LOG_DEBUG,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
3552 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
3553 curr_cts += curr_ctts;
3555 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3558 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3559 ctts_data_old[ctts_index_old].
duration) == -1) {
3562 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3563 ctts_data_old[ctts_index_old].
duration);
3567 ctts_sample_old = 0;
3568 edit_list_start_ctts_sample = 0;
3572 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3574 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3575 first_non_zero_audio_edit > 0) {
3576 packet_skip_samples = edit_list_media_time - curr_cts;
3580 edit_list_dts_counter -= packet_skip_samples;
3581 if (edit_list_start_encountered == 0) {
3582 edit_list_start_encountered = 1;
3585 if (frame_duration_buffer) {
3587 frame_duration_buffer, num_discarded_begin);
3592 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
3595 av_log(mov->
fc,
AV_LOG_DEBUG,
"drop a frame at curr_cts: %"PRId64
" @ %"PRId64
"\n", curr_cts, index);
3597 if (edit_list_start_encountered == 0) {
3598 num_discarded_begin++;
3599 frame_duration_buffer =
av_realloc(frame_duration_buffer,
3600 num_discarded_begin *
sizeof(int64_t));
3601 if (!frame_duration_buffer) {
3605 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
3620 if (edit_list_start_encountered == 0) {
3621 edit_list_start_encountered = 1;
3624 if (frame_duration_buffer) {
3626 frame_duration_buffer, num_discarded_begin);
3639 if (current_index_range < msc->index_ranges || index != current_index_range->
end) {
3640 current_index_range++;
3643 current_index_range->
end = index + 1;
3646 if (edit_list_start_encountered > 0) {
3647 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
3651 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
3653 if (ctts_data_old) {
3658 found_keyframe_after_edit = 1;
3661 if (ctts_sample_old != 0) {
3664 ctts_sample_old - edit_list_start_ctts_sample,
3665 ctts_data_old[ctts_index_old].
duration) == -1) {
3667 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
3668 ctts_data_old[ctts_index_old].
duration);
3704 current_index_range++;
3705 current_index_range->
start = 0;
3706 current_index_range->
end = 0;
3713 int64_t current_offset;
3714 int64_t current_dts = 0;
3715 unsigned int stts_index = 0;
3716 unsigned int stsc_index = 0;
3717 unsigned int stss_index = 0;
3718 unsigned int stps_index = 0;
3720 uint64_t stream_size = 0;
3722 unsigned int ctts_count_old = sc->
ctts_count;
3725 int i, edit_start_index = 0, multiple_edits = 0;
3726 int64_t empty_duration = 0;
3731 if (i == 0 && e->
time == -1) {
3735 edit_start_index = 1;
3736 }
else if (i == edit_start_index && e->
time >= 0) {
3737 start_time = e->
time;
3745 "Use -advanced_editlist to correctly decode otherwise "
3746 "a/v desync might occur\n");
3749 if ((empty_duration || start_time) && mov->
time_scale > 0) {
3766 unsigned int current_sample = 0;
3767 unsigned int stts_sample = 0;
3768 unsigned int sample_size;
3770 unsigned int rap_group_index = 0;
3771 unsigned int rap_group_sample = 0;
3772 int64_t last_dts = 0;
3773 int64_t dts_correction = 0;
3778 last_dts = current_dts;
3792 if (ctts_data_old) {
3807 for (i = 0; i < ctts_count_old &&
3809 for (j = 0; j < ctts_data_old[i].
count &&
3850 if (rap_group_present && rap_group_index < sc->rap_group_count) {
3853 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
3854 rap_group_sample = 0;
3860 && !rap_group_present
3869 if (sample_size > 0x3FFFFFFF) {
3874 e->
pos = current_offset;
3876 e->
size = sample_size;
3879 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", "
3880 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
3881 current_offset, current_dts, sample_size, distance, keyframe);
3886 current_offset += sample_size;
3887 stream_size += sample_size;
3893 "Invalid SampleDelta %d in STTS, at %d st:%d\n",
3900 if (!dts_correction || current_dts + dts_correction > last_dts) {
3901 current_dts += dts_correction;
3905 dts_correction += current_dts - last_dts - 1;
3906 current_dts = last_dts + 1;
3908 last_dts = current_dts;
3921 unsigned chunk_samples, total = 0;
3928 unsigned count, chunk_count;
3941 count = (chunk_samples+samples-1) / samples;
3943 count = (chunk_samples+1023) / 1024;
3950 total += chunk_count *
count;
3972 while (chunk_samples > 0) {
3974 unsigned size, samples;
3978 "Zero bytes per frame, but %d samples per frame",
3992 samples =
FFMIN(1024, chunk_samples);
4001 if (size > 0x3FFFFFFF) {
4006 e->
pos = current_offset;
4012 "size %u, duration %u\n", st->
index, i, current_offset, current_dts,
4015 current_offset +=
size;
4016 current_dts += samples;
4017 chunk_samples -= samples;
4048 av_url_split(src_proto,
sizeof(src_proto), src_auth,
sizeof(src_auth), src_host,
sizeof(src_host), &src_port,
NULL, 0, src);
4049 av_url_split(ref_proto,
sizeof(ref_proto), ref_auth,
sizeof(ref_auth), ref_host,
sizeof(ref_host), &ref_port,
NULL, 0, ref);
4051 if (strlen(src) == 0) {
4053 }
else if (strlen(src_auth) + 1 >=
sizeof(src_auth) ||
4054 strlen(ref_auth) + 1 >=
sizeof(ref_auth) ||
4055 strlen(src_host) + 1 >=
sizeof(src_host) ||
4056 strlen(ref_host) + 1 >=
sizeof(ref_host)) {
4058 }
else if (strcmp(src_proto, ref_proto) ||
4059 strcmp(src_auth, ref_auth) ||
4060 strcmp(src_host, ref_host) ||
4061 src_port != ref_port) {
4072 char filename[1025];
4073 const char *src_path;
4077 src_path = strrchr(src,
'/');
4084 for (i = 0, l = strlen(ref->
path) - 1; l >= 0; l--)
4085 if (ref->
path[l] ==
'/') {
4093 if (i == ref->
nlvl_to - 1 && src_path - src <
sizeof(filename)) {
4094 memcpy(filename, src, src_path - src);
4095 filename[src_path -
src] = 0;
4098 av_strlcat(filename,
"../",
sizeof(filename));
4106 "Reference with mismatching origin, %s not tried for security reasons, "
4107 "set demuxer option use_absolute_path to allow it anyway\n",
4112 if(strstr(ref->
path + l + 1,
"..") ||
4113 strstr(ref->
path + l + 1,
":") ||
4114 (ref->
nlvl_from > 1 && same_origin < 0) ||
4115 (filename[0] ==
'/' && src_path == src))
4119 if (strlen(filename) + 1 ==
sizeof(filename))
4126 "this is a possible security issue\n");
4131 "Absolute path %s not tried for security reasons, "
4132 "set demuxer option use_absolute_path to allow absolute paths\n",
4156 if (!st)
return AVERROR(ENOMEM);
4159 if (!sc)
return AVERROR(ENOMEM);
4196 "stream %d, error opening alias: path='%s', dir='%s', "
4197 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
4202 "Skipped opening external track: "
4203 "stream %d, alias: path='%s', dir='%s', "
4204 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d."
4205 "Set enable_drefs to allow this.\n",
4222 #if FF_API_R_FRAME_RATE
4238 #if CONFIG_H261_DECODER
4241 #if CONFIG_H263_DECODER
4244 #if CONFIG_MPEG4_DECODER
4290 if (count > UINT_MAX /
sizeof(*c->
meta_keys) - 1) {
4292 "The 'keys' atom with the invalid key count: %"PRIu32
"\n", count);
4301 for (i = 1; i <=
count; ++i) {
4306 "The key# %"PRIu32
" in meta has invalid size:"
4307 "%"PRIu32
"\n", i, key_size);
4311 if (type !=
MKTAG(
'm',
'd',
't',
'a')) {
4337 for (i = 0; i < 3; i++) {
4348 if (len < 12 || len - 12 > end -
avio_tell(pb))
4352 if (tag ==
MKTAG(
'm',
'e',
'a',
'n'))
4354 else if (tag ==
MKTAG(
'n',
'a',
'm',
'e'))
4356 else if (tag ==
MKTAG(
'd',
'a',
't',
'a') && len > 4) {
4376 if (mean && key && val) {
4377 if (strcmp(key,
"iTunSMPB") == 0) {
4378 int priming, remainder, samples;
4379 if(sscanf(val,
"%*X %X %X %X", &priming, &remainder, &samples) == 3){
4380 if(priming>0 && priming<16384)
4384 if (strcmp(key,
"cdec") != 0) {
4391 "Unhandled or malformed custom metadata of size %"PRId64
"\n", atom.
size);
4403 while (atom.
size > 8) {
4406 if (tag ==
MKTAG(
'h',
'd',
'l',
'r')) {
4416 #define IS_MATRIX_IDENT(matrix) \
4417 ( (matrix)[0][0] == (1 << 16) && \
4418 (matrix)[1][1] == (1 << 16) && \
4419 (matrix)[2][2] == (1 << 30) && \
4420 !(matrix)[0][1] && !(matrix)[0][2] && \
4421 !(matrix)[1][0] && !(matrix)[1][2] && \
4422 !(matrix)[2][0] && !(matrix)[2][1])
4429 int display_matrix[3][3];
4430 int res_display_matrix[3][3] = { { 0 } };
4469 for (i = 0; i < 3; i++) {
4477 sc->
width = width >> 16;
4478 sc->
height = height >> 16;
4481 for (i = 0; i < 3; i++) {
4482 const int sh[3] = { 16, 16, 30 };
4483 for (j = 0; j < 3; j++) {
4484 for (e = 0; e < 3; e++) {
4485 res_display_matrix[i][j] +=
4486 ((int64_t) display_matrix[i][e] *
4501 for (i = 0; i < 3; i++)
4502 for (j = 0; j < 3; j++)
4507 if (!
isnan(rotate)) {
4508 char rotate_buf[64];
4512 snprintf(rotate_buf,
sizeof(rotate_buf),
"%g", rotate);
4521 double disp_transform[2];
4523 for (i = 0; i < 2; i++)
4527 if (disp_transform[0] > 0 && disp_transform[1] > 0 &&
4528 disp_transform[0] < (1<<24) && disp_transform[1] < (1<<24) &&
4529 fabs((disp_transform[0] / disp_transform[1]) - 1.0) > 0.01)
4531 disp_transform[0] / disp_transform[1],
4541 int flags, track_id, i;
4582 num = atom.
size / 4;
4629 int64_t base_media_decode_time;
4653 if (frag_stream_info)
4654 frag_stream_info->
tfdt_dts = base_media_decode_time;
4668 int data_offset = 0;
4669 unsigned entries, first_sample_flags = frag->
flags;
4672 int next_frag_index = -1, index_entry_pos;
4673 size_t requested_size;
4674 size_t old_ctts_allocated_size;
4701 if (frag_stream_info && frag_stream_info->
index_entry >= 0) {
4702 next_frag_index = i;