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++) {
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);
291 if (n_hmmt > len / 4)
306 uint16_t langcode = 0;
307 uint32_t data_type = 0, str_size, str_size_alloc;
313 case MKTAG(
'@',
'P',
'R',
'M'): key =
"premiere_version"; raw = 1;
break;
314 case MKTAG(
'@',
'P',
'R',
'Q'): key =
"quicktime_version"; raw = 1;
break;
315 case MKTAG(
'X',
'M',
'P',
'_'):
316 if (c->
export_xmp) { key =
"xmp"; raw = 1; }
break;
317 case MKTAG(
'a',
'A',
'R',
'T'): key =
"album_artist";
break;
318 case MKTAG(
'a',
'k',
'I',
'D'): key =
"account_type";
320 case MKTAG(
'a',
'p',
'I',
'D'): key =
"account_id";
break;
321 case MKTAG(
'c',
'a',
't',
'g'): key =
"category";
break;
322 case MKTAG(
'c',
'p',
'i',
'l'): key =
"compilation";
324 case MKTAG(
'c',
'p',
'r',
't'): key =
"copyright";
break;
325 case MKTAG(
'd',
'e',
's',
'c'): key =
"description";
break;
326 case MKTAG(
'd',
'i',
's',
'k'): key =
"disc";
328 case MKTAG(
'e',
'g',
'i',
'd'): key =
"episode_uid";
330 case MKTAG(
'F',
'I',
'R',
'M'): key =
"firmware"; raw = 1;
break;
331 case MKTAG(
'g',
'n',
'r',
'e'): key =
"genre";
333 case MKTAG(
'h',
'd',
'v',
'd'): key =
"hd_video";
335 case MKTAG(
'H',
'M',
'M',
'T'):
337 case MKTAG(
'k',
'e',
'y',
'w'): key =
"keywords";
break;
338 case MKTAG(
'l',
'd',
'e',
's'): key =
"synopsis";
break;
339 case MKTAG(
'l',
'o',
'c',
'i'):
341 case MKTAG(
'm',
'a',
'n',
'u'): key =
"make";
break;
342 case MKTAG(
'm',
'o',
'd',
'l'): key =
"model";
break;
343 case MKTAG(
'p',
'c',
's',
't'): key =
"podcast";
345 case MKTAG(
'p',
'g',
'a',
'p'): key =
"gapless_playback";
347 case MKTAG(
'p',
'u',
'r',
'd'): key =
"purchase_date";
break;
348 case MKTAG(
'r',
't',
'n',
'g'): key =
"rating";
350 case MKTAG(
's',
'o',
'a',
'a'): key =
"sort_album_artist";
break;
351 case MKTAG(
's',
'o',
'a',
'l'): key =
"sort_album";
break;
352 case MKTAG(
's',
'o',
'a',
'r'): key =
"sort_artist";
break;
353 case MKTAG(
's',
'o',
'c',
'o'): key =
"sort_composer";
break;
354 case MKTAG(
's',
'o',
'n',
'm'): key =
"sort_name";
break;
355 case MKTAG(
's',
'o',
's',
'n'): key =
"sort_show";
break;
356 case MKTAG(
's',
't',
'i',
'k'): key =
"media_type";
358 case MKTAG(
't',
'r',
'k',
'n'): key =
"track";
360 case MKTAG(
't',
'v',
'e',
'n'): key =
"episode_id";
break;
361 case MKTAG(
't',
'v',
'e',
's'): key =
"episode_sort";
363 case MKTAG(
't',
'v',
'n',
'n'): key =
"network";
break;
364 case MKTAG(
't',
'v',
's',
'h'): key =
"show";
break;
365 case MKTAG(
't',
'v',
's',
'n'): key =
"season_number";
367 case MKTAG(0xa9,
'A',
'R',
'T'): key =
"artist";
break;
368 case MKTAG(0xa9,
'P',
'R',
'D'): key =
"producer";
break;
369 case MKTAG(0xa9,
'a',
'l',
'b'): key =
"album";
break;
370 case MKTAG(0xa9,
'a',
'u',
't'): key =
"artist";
break;
371 case MKTAG(0xa9,
'c',
'h',
'p'): key =
"chapter";
break;
372 case MKTAG(0xa9,
'c',
'm',
't'): key =
"comment";
break;
373 case MKTAG(0xa9,
'c',
'o',
'm'): key =
"composer";
break;
374 case MKTAG(0xa9,
'c',
'p',
'y'): key =
"copyright";
break;
375 case MKTAG(0xa9,
'd',
'a',
'y'): key =
"date";
break;
376 case MKTAG(0xa9,
'd',
'i',
'r'): key =
"director";
break;
377 case MKTAG(0xa9,
'd',
'i',
's'): key =
"disclaimer";
break;
378 case MKTAG(0xa9,
'e',
'd',
'1'): key =
"edit_date";
break;
379 case MKTAG(0xa9,
'e',
'n',
'c'): key =
"encoder";
break;
380 case MKTAG(0xa9,
'f',
'm',
't'): key =
"original_format";
break;
381 case MKTAG(0xa9,
'g',
'e',
'n'): key =
"genre";
break;
382 case MKTAG(0xa9,
'g',
'r',
'p'): key =
"grouping";
break;
383 case MKTAG(0xa9,
'h',
's',
't'): key =
"host_computer";
break;
384 case MKTAG(0xa9,
'i',
'n',
'f'): key =
"comment";
break;
385 case MKTAG(0xa9,
'l',
'y',
'r'): key =
"lyrics";
break;
386 case MKTAG(0xa9,
'm',
'a',
'k'): key =
"make";
break;
387 case MKTAG(0xa9,
'm',
'o',
'd'): key =
"model";
break;
388 case MKTAG(0xa9,
'n',
'a',
'm'): key =
"title";
break;
389 case MKTAG(0xa9,
'o',
'p',
'e'): key =
"original_artist";
break;
390 case MKTAG(0xa9,
'p',
'r',
'd'): key =
"producer";
break;
391 case MKTAG(0xa9,
'p',
'r',
'f'): key =
"performers";
break;
392 case MKTAG(0xa9,
'r',
'e',
'q'): key =
"playback_requirements";
break;
393 case MKTAG(0xa9,
's',
'r',
'c'): key =
"original_source";
break;
394 case MKTAG(0xa9,
's',
't',
'3'): key =
"subtitle";
break;
395 case MKTAG(0xa9,
's',
'w',
'r'): key =
"encoder";
break;
396 case MKTAG(0xa9,
't',
'o',
'o'): key =
"encoder";
break;
397 case MKTAG(0xa9,
't',
'r',
'k'): key =
"track";
break;
398 case MKTAG(0xa9,
'u',
'r',
'l'): key =
"URL";
break;
399 case MKTAG(0xa9,
'w',
'r',
'n'): key =
"warning";
break;
400 case MKTAG(0xa9,
'w',
'r',
't'): key =
"composer";
break;
401 case MKTAG(0xa9,
'x',
'y',
'z'): key =
"location";
break;
407 if (tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
410 str_size = data_size - 16;
413 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r')) {
419 atom.
size -= str_size;
425 if (index < c->meta_keys_count && index > 0) {
429 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
436 if (str_size > atom.
size) {
446 str_size = atom.
size;
454 if (atom.
size < 0 || str_size >= INT_MAX/2)
459 num = (data_type >= 21 && data_type <= 23);
460 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
466 parse(c, pb, str_size, key);
468 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
470 }
else if (data_type == 21) {
474 else if (str_size == 2)
476 else if (str_size == 3)
478 else if (str_size == 4)
480 if (
snprintf(str, str_size_alloc,
"%d", val) >= str_size_alloc) {
482 "Failed to store the number (%d) in string.\n", val);
486 }
else if (data_type == 22) {
487 unsigned int val = 0;
490 else if (str_size == 2)
492 else if (str_size == 3)
494 else if (str_size == 4)
496 if (
snprintf(str, str_size_alloc,
"%u", val) >= str_size_alloc) {
498 "Failed to store the number (%u) in string.\n", val);
502 }
else if (data_type == 23 && str_size >= 4) {
504 if (
snprintf(str, str_size_alloc,
"%f", val) >= str_size_alloc) {
506 "Failed to store the float32 number (%f) in string.\n", val);
520 if (*language && strcmp(language,
"und")) {
521 snprintf(key2,
sizeof(key2),
"%s-%s", key, language);
524 if (!strcmp(key,
"encoder")) {
526 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
539 int i, nb_chapters, str_len,
version;
546 if ((atom.
size -= 5) < 0)
555 for (i = 0; i < nb_chapters; i++) {
562 if ((atom.
size -= 9+str_len) < 0)
574 #define MIN_DATA_ENTRY_BOX_SIZE 12 590 entries >= UINT_MAX /
sizeof(*sc->
drefs))
605 for (i = 0; i < entries; i++) {
616 if (dref->
type ==
MKTAG(
'a',
'l',
'i',
's') && size > 150) {
618 uint16_t volume_len,
len;
625 volume_len =
FFMIN(volume_len, 27);
629 dref->
volume[volume_len] = 0;
635 len =
FFMIN(len, 63);
652 for (type = 0; type != -1 &&
avio_tell(pb) < next; ) {
671 if (len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
673 memmove(dref->
path, dref->
path+volume_len, len);
677 for (j = len - 1; j >= 0; j--) {
678 if (dref->
path[j] == 0)
683 for (j = 0; j <
len; j++)
684 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
687 }
else if (type == 0) {
699 for (j = 0; j <
len; j++)
700 if (dref->
dir[j] ==
':')
737 if (type ==
MKTAG(
'm',
'd',
't',
'a')) {
745 if (type ==
MKTAG(
'v',
'i',
'd',
'e'))
747 else if (type ==
MKTAG(
's',
'o',
'u',
'n'))
749 else if (type ==
MKTAG(
'm',
'1',
'a',
' '))
751 else if ((type ==
MKTAG(
's',
'u',
'b',
'p')) || (type ==
MKTAG(
'c',
'l',
'c',
'p')))
758 title_size = atom.
size - 24;
759 if (title_size > 0) {
760 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
771 title_str[title_size] = 0;
773 int off = (!c->
isom && title_str[0] == title_size - 1);
792 int ac3info, acmod, lfeon, bsmod;
804 bsmod = (ac3info >> 14) & 0x7;
805 acmod = (ac3info >> 11) & 0x7;
806 lfeon = (ac3info >> 10) & 0x1;
815 #if FF_API_LAVF_AVCTX 817 st->codec->audio_service_type = *ast;
828 int eac3info, acmod, lfeon, bsmod;
844 bsmod = (eac3info >> 12) & 0x1f;
845 acmod = (eac3info >> 9) & 0x7;
846 lfeon = (eac3info >> 8) & 0x1;
855 #if FF_API_LAVF_AVCTX 857 st->codec->audio_service_type = *ast;
869 uint32_t frame_duration_code = 0;
870 uint32_t channel_layout_code = 0;
892 frame_duration_code =
get_bits(&gb, 2);
894 channel_layout_code =
get_bits(&gb, 16);
897 (frame_duration_code == 0) ? 512 :
898 (frame_duration_code == 1) ? 1024 :
899 (frame_duration_code == 2) ? 2048 :
900 (frame_duration_code == 3) ? 4096 : 0;
902 if (channel_layout_code > 0xff) {
965 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
968 }
else if (den != 0) {
984 #define DRM_BLOB_SIZE 56 993 uint8_t calculated_checksum[20];
1019 for (i = 0; i < 20; i++)
1024 if (!activation_bytes) {
1056 if (memcmp(calculated_checksum, file_checksum, 20)) {
1063 for (i = 0; i < 4; i++) {
1065 if (activation_bytes[i] != output[3 - i]) {
1071 memcpy(c->
file_key, output + 8, 16);
1072 memcpy(input, output + 26, 16);
1113 unsigned char iv[16];
1127 int comp_brand_size;
1128 char* comp_brands_str;
1134 if (strcmp(type,
"qt "))
1141 comp_brand_size = atom.
size - 8;
1142 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1144 comp_brands_str =
av_malloc(comp_brand_size + 1);
1145 if (!comp_brands_str)
1153 comp_brands_str[comp_brand_size] = 0;
1158 if (!strcmp(type,
"aaxc")) {
1192 if (index < 0 || index >= frag_index->
nb_items)
1208 if (frag_index->
current < 0 ||
1227 if (frag_index->
current < 0 ||
1242 int64_t moof_offset;
1255 if (moof_offset >= offset)
1257 if (moof_offset <= offset)
1274 int index,
int track_id)
1280 if (track_id >= 0) {
1313 m0 = m = (a +
b) >> 1;
1319 if (m < b && frag_time <= timestamp)
1336 if (index < c->frag_index.nb_items &&
1352 if (!frag_stream_info)
1371 if (index < c->frag_index.nb_items)
1387 int id,
int entries)
1394 for (i = index; i < frag_index->
nb_items; i++) {
1396 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1414 "read the mfra (may be a live ismv)\n");
1418 "seekable, can not look for mfra\n");
1430 if (time >= 2082844800)
1433 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1449 int64_t creation_time;
1494 int64_t creation_time;
1525 for (i = 0; i < 3; i++) {
1553 if (little_endian == 1) {
1578 char color_parameter_type[5] = { 0 };
1589 if (strncmp(color_parameter_type,
"nclx", 4) &&
1590 strncmp(color_parameter_type,
"nclc", 4) &&
1591 strncmp(color_parameter_type,
"prof", 4)) {
1593 color_parameter_type);
1597 if (!strncmp(color_parameter_type,
"prof", 4)) {
1610 "%s: pri %d trc %d matrix %d",
1611 color_parameter_type, color_primaries, color_trc, color_matrix);
1613 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1640 unsigned mov_field_order;
1649 if ((mov_field_order & 0xFF00) == 0x0100)
1651 else if ((mov_field_order & 0xFF00) == 0x0200) {
1652 switch (mov_field_order & 0xFF) {
1675 if (size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1698 }
else if (err < atom.
size) {
1712 uint64_t original_size;
1787 if (cid == 0xd4d || cid == 0xd4e)
1798 if (num <= 0 || den <= 0)
1802 if (den >= INT_MAX / 2)
1821 uint64_t original_size;
1826 if (atom.
size == 16) {
1831 if (length == atom.
size) {
1833 switch (range_value) {
1874 if ((uint64_t)atom.
size > (1<<30))
1884 }
else if (atom.
size > 8) {
1892 if ( (buffer & 0xFFFFFFFF) ==
MKBETAG(
'f',
'r',
'm',
'a')
1893 && buffer >> 32 <= atom.
size 1894 && buffer >> 32 >= 8) {
1898 #define ALAC_EXTRADATA_SIZE 36 1931 if ((uint64_t)atom.
size > (1<<30))
1934 if (atom.
size >= 10) {
1940 if (type ==
MKTAG(
'f',
'i',
'e',
'l') && size == atom.
size)
1971 if (atom.
size >= (1<<28) || atom.
size < 7)
1975 if ((profile_level & 0xf0) != 0xc0)
1998 if (atom.
size <= 40)
2002 if ((uint64_t)atom.
size > (1<<30))
2017 unsigned int i, entries;
2045 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2048 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2069 ((format & 0xFFFF) ==
'm' + (
's' << 8) ||
2070 (format & 0xFFFF) ==
'T' + (
'S' << 8)))
2077 format && format !=
MKTAG(
'm',
'p',
'4',
's')) {
2102 uint8_t codec_name[32] = { 0 };
2137 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2144 !strncmp(codec_name,
"Sorenson H263", 13))
2160 int bits_per_sample,
flags;
2181 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2188 }
else if (version == 2) {
2203 if (version == 0 || (version == 1 && sc->
audio_cid != -2)) {
2262 if (bits_per_sample) {
2287 y = (ycbcr >> 16) & 0xFF;
2288 cr = (ycbcr >> 8) & 0xFF;
2291 b =
av_clip_uint8((1164 * (y - 16) + 2018 * (cb - 128)) / 1000);
2292 g =
av_clip_uint8((1164 * (y - 16) - 813 * (cr - 128) - 391 * (cb - 128)) / 1000);
2293 r =
av_clip_uint8((1164 * (y - 16) + 1596 * (cr - 128) ) / 1000);
2295 return (r << 16) | (g << 8) | b;
2300 char buf[256] = {0};
2308 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2312 for (i = 0; i < 16; i++) {
2313 uint32_t yuv =
AV_RB32(src + i * 4);
2316 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba, i != 15 ?
", " :
"");
2319 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2337 if ((
int)size != size)
2350 #if FF_API_LAVF_AVCTX 2358 if (format ==
AV_RB32(
"name") && (int64_t)size >= (int64_t)len + 18) {
2360 if (str_size > 0 && size >= (
int)str_size + 30 &&
2362 char *reel_name =
av_malloc(str_size + 1);
2366 reel_name[str_size] = 0;
2389 #if CONFIG_DV_DEMUXER 2463 int codec_tag,
int format,
2469 (codec_tag != format &&
2477 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2494 int pseudo_stream_id;
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,
2560 }
else if (a.
size > 0)
2599 if (entries <= 0 || entries > atom.
size / 8 || entries > 1024) {
2606 "Duplicate stsd found in this track.\n");
2652 unsigned int i, entries;
2663 if ((uint64_t)entries * 12 + 4 > atom.
size)
2678 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2685 for (i = sc->
stsc_count - 1; i < UINT_MAX; i--) {
2686 int64_t first_min = i + 1;
2723 return index < count - 1;
2746 unsigned i, entries;
2764 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2782 unsigned int i, entries;
2804 if (entries >= UINT_MAX /
sizeof(
int))
2812 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2830 unsigned int i, entries, sample_size, field_size, num_bytes;
2843 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
2862 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
2869 if (entries >= (UINT_MAX - 4) / field_size)
2879 num_bytes = (entries*field_size+4)>>3;
2897 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2923 unsigned int i, entries, alloc_size = 0;
2925 int64_t total_sample_count = 0;
2943 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
2946 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2947 int sample_duration;
2948 unsigned int sample_count;
2949 unsigned int min_entries =
FFMIN(
FFMAX(i + 1, 1024 * 1024), entries);
2967 sample_count, sample_duration);
2969 duration+=(int64_t)sample_duration*(uint64_t)sample_count;
2970 total_sample_count+=sample_count;
2976 duration <= INT64_MAX - sc->duration_for_fps &&
2977 total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
3007 entries = atom.
size - 4;
3031 if (duration == INT_MIN) {
3043 unsigned int i, entries, ctts_count = 0;
3058 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3065 for (i = 0; i < entries && !pb->
eof_reached; i++) {
3071 "ignoring CTTS entry with count=%d duration=%d\n",
3082 if (
FFNABS(duration) < -(1<<28) && i+2<entries) {
3109 unsigned int i, entries;
3111 uint32_t grouping_type;
3121 if (grouping_type !=
MKTAG(
'r',
'a',
'p',
' '))
3137 for (i = 0; i < entries && !pb->
eof_reached; i++) {
3157 unsigned int edit_list_index,
3158 int64_t *edit_list_media_time,
3159 int64_t *edit_list_duration,
3160 int64_t global_timescale)
3165 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3169 if (global_timescale == 0) {
3202 int64_t timestamp_pts,
3205 int64_t* ctts_index,
3206 int64_t* ctts_sample)
3212 int64_t index_ctts_count;
3240 if (ctts_data && *index >= 0) {
3246 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3247 if (*ctts_index < ctts_count) {
3249 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3256 while (*index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3260 if ((e_old[*index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3266 if (*ctts_sample == 0) {
3268 if (*ctts_index >= 0)
3269 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3279 return *index >= 0 ? 0 : -1;
3302 const size_t requested_size =
3319 ie= &entries[
index];
3334 int64_t* frame_duration_buffer,
3335 int frame_duration_buffer_size) {
3337 av_assert0(end_index >= 0 && end_index <= st->internal->nb_index_entries);
3338 for (i = 0; i < frame_duration_buffer_size; i++) {
3339 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
3352 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVStts);
3353 const size_t requested_size =
3354 min_size_needed > *allocated_size ?
3355 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3358 if ((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVStts) - 1)
3361 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
3366 *ctts_data = ctts_buf_new;
3371 *ctts_count = (*ctts_count) + 1;
3375 #define MAX_REORDER_DELAY 16 3381 int ctts_sample = 0;
3384 int j,
r, num_swaps;
3387 pts_buf[j] = INT64_MIN;
3395 buf_start = (buf_start + 1);
3396 if (buf_start == MAX_REORDER_DELAY + 1)
3408 while (j != buf_start) {
3411 if (pts_buf[j] < pts_buf[r]) {
3412 FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
3470 if (range_size > current_sample) {
3474 current_sample -= range_size;
3492 int64_t ctts_index_old = 0;
3493 int64_t ctts_sample_old = 0;
3495 int64_t edit_list_media_time = 0;
3496 int64_t edit_list_duration = 0;
3497 int64_t frame_duration = 0;
3498 int64_t edit_list_dts_counter = 0;
3499 int64_t edit_list_dts_entry_end = 0;
3500 int64_t edit_list_start_ctts_sample = 0;
3502 int64_t curr_ctts = 0;
3503 int64_t empty_edits_sum_duration = 0;
3504 int64_t edit_list_index = 0;
3507 int64_t start_dts = 0;
3508 int64_t edit_list_start_encountered = 0;
3509 int64_t search_timestamp = 0;
3510 int64_t* frame_duration_buffer =
NULL;
3511 int num_discarded_begin = 0;
3512 int first_non_zero_audio_edit = -1;
3513 int packet_skip_samples = 0;
3516 int found_keyframe_after_edit = 0;
3517 int found_non_empty_edit = 0;
3550 edit_list_dts_entry_end -= msc->
dts_shift;
3554 start_dts = edit_list_dts_entry_end;
3558 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3559 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3561 edit_list_dts_counter = edit_list_dts_entry_end;
3562 edit_list_dts_entry_end += edit_list_duration;
3563 num_discarded_begin = 0;
3564 if (!found_non_empty_edit && edit_list_media_time == -1) {
3565 empty_edits_sum_duration += edit_list_duration;
3568 found_non_empty_edit = 1;
3573 if (first_non_zero_audio_edit < 0) {
3574 first_non_zero_audio_edit = 1;
3576 first_non_zero_audio_edit = 0;
3579 if (first_non_zero_audio_edit > 0)
3587 search_timestamp = edit_list_media_time;
3596 &index, &ctts_index_old, &ctts_sample_old) < 0) {
3598 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3599 st->
index, edit_list_index, search_timestamp);
3601 &index, &ctts_index_old, &ctts_sample_old) < 0) {
3603 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
3604 st->
index, edit_list_index, search_timestamp);
3607 ctts_sample_old = 0;
3610 current = e_old +
index;
3611 edit_list_start_ctts_sample = ctts_sample_old;
3614 edit_list_start_encountered = 0;
3615 found_keyframe_after_edit = 0;
3616 for (; current < e_old_end; current++, index++) {
3618 frame_duration = (current + 1 < e_old_end) ?
3619 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3621 flags = current->
flags;
3627 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3628 curr_ctts = ctts_data_old[ctts_index_old].
duration;
3629 av_log(mov->
fc,
AV_LOG_DEBUG,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
3630 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
3631 curr_cts += curr_ctts;
3633 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3636 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3637 ctts_data_old[ctts_index_old].
duration) == -1) {
3640 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3641 ctts_data_old[ctts_index_old].
duration);
3645 ctts_sample_old = 0;
3646 edit_list_start_ctts_sample = 0;
3650 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3652 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3653 first_non_zero_audio_edit > 0) {
3654 packet_skip_samples = edit_list_media_time - curr_cts;
3658 edit_list_dts_counter -= packet_skip_samples;
3659 if (edit_list_start_encountered == 0) {
3660 edit_list_start_encountered = 1;
3663 if (frame_duration_buffer) {
3665 frame_duration_buffer, num_discarded_begin);
3670 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
3673 av_log(mov->
fc,
AV_LOG_DEBUG,
"drop a frame at curr_cts: %"PRId64
" @ %"PRId64
"\n", curr_cts, index);
3675 if (edit_list_start_encountered == 0) {
3676 num_discarded_begin++;
3677 frame_duration_buffer =
av_realloc(frame_duration_buffer,
3678 num_discarded_begin *
sizeof(int64_t));
3679 if (!frame_duration_buffer) {
3683 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
3698 if (edit_list_start_encountered == 0) {
3699 edit_list_start_encountered = 1;
3702 if (frame_duration_buffer) {
3704 frame_duration_buffer, num_discarded_begin);
3717 if (current_index_range < msc->index_ranges || index != current_index_range->
end) {
3718 current_index_range++;
3721 current_index_range->
end = index + 1;
3724 if (edit_list_start_encountered > 0) {
3725 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
3729 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
3731 if (ctts_data_old) {
3736 found_keyframe_after_edit = 1;
3739 if (ctts_sample_old != 0) {
3742 ctts_sample_old - edit_list_start_ctts_sample,
3743 ctts_data_old[ctts_index_old].
duration) == -1) {
3745 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
3746 ctts_data_old[ctts_index_old].
duration);
3782 current_index_range++;
3783 current_index_range->
start = 0;
3784 current_index_range->
end = 0;
3791 int64_t current_offset;
3792 int64_t current_dts = 0;
3793 unsigned int stts_index = 0;
3794 unsigned int stsc_index = 0;
3795 unsigned int stss_index = 0;
3796 unsigned int stps_index = 0;
3798 uint64_t stream_size = 0;
3800 unsigned int ctts_count_old = sc->
ctts_count;
3803 int i, edit_start_index = 0, multiple_edits = 0;
3804 int64_t empty_duration = 0;
3809 if (i == 0 && e->
time == -1) {
3813 edit_start_index = 1;
3814 }
else if (i == edit_start_index && e->
time >= 0) {
3815 start_time = e->
time;
3823 "Use -advanced_editlist to correctly decode otherwise " 3824 "a/v desync might occur\n");
3827 if ((empty_duration || start_time) && mov->
time_scale > 0) {
3844 unsigned int current_sample = 0;
3845 unsigned int stts_sample = 0;
3846 unsigned int sample_size;
3848 unsigned int rap_group_index = 0;
3849 unsigned int rap_group_sample = 0;
3850 int64_t last_dts = 0;
3851 int64_t dts_correction = 0;
3856 last_dts = current_dts;
3870 if (ctts_data_old) {
3885 for (i = 0; i < ctts_count_old &&
3887 for (j = 0; j < ctts_data_old[
i].
count &&
3928 if (rap_group_present && rap_group_index < sc->rap_group_count) {
3931 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
3932 rap_group_sample = 0;
3938 && !rap_group_present
3947 if (sample_size > 0x3FFFFFFF) {
3952 e->
pos = current_offset;
3954 e->
size = sample_size;
3957 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", " 3958 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
3959 current_offset, current_dts, sample_size, distance, keyframe);
3964 current_offset += sample_size;
3965 stream_size += sample_size;
3971 "Invalid SampleDelta %d in STTS, at %d st:%d\n",
3978 if (!dts_correction || current_dts + dts_correction > last_dts) {
3979 current_dts += dts_correction;
3983 dts_correction += current_dts - last_dts - 1;
3984 current_dts = last_dts + 1;
3986 last_dts = current_dts;
3999 unsigned chunk_samples, total = 0;
4006 unsigned count, chunk_count;
4019 count = (chunk_samples+samples-1) /
samples;
4021 count = (chunk_samples+1023) / 1024;
4028 total += chunk_count *
count;
4050 while (chunk_samples > 0) {
4056 "Zero bytes per frame, but %d samples per frame",
4070 samples =
FFMIN(1024, chunk_samples);
4079 if (size > 0x3FFFFFFF) {
4084 e->
pos = current_offset;
4090 "size %u, duration %u\n", st->
index, i, current_offset, current_dts,
4093 current_offset +=
size;
4126 av_url_split(src_proto,
sizeof(src_proto), src_auth,
sizeof(src_auth), src_host,
sizeof(src_host), &src_port,
NULL, 0, src);
4127 av_url_split(ref_proto,
sizeof(ref_proto), ref_auth,
sizeof(ref_auth), ref_host,
sizeof(ref_host), &ref_port,
NULL, 0, ref);
4129 if (strlen(src) == 0) {
4131 }
else if (strlen(src_auth) + 1 >=
sizeof(src_auth) ||
4132 strlen(ref_auth) + 1 >=
sizeof(ref_auth) ||
4133 strlen(src_host) + 1 >=
sizeof(src_host) ||
4134 strlen(ref_host) + 1 >=
sizeof(ref_host)) {
4136 }
else if (strcmp(src_proto, ref_proto) ||
4137 strcmp(src_auth, ref_auth) ||
4138 strcmp(src_host, ref_host) ||
4139 src_port != ref_port) {
4150 char filename[1025];
4151 const char *src_path;
4155 src_path = strrchr(src,
'/');
4162 for (i = 0, l = strlen(ref->
path) - 1; l >= 0; l--)
4163 if (ref->
path[l] ==
'/') {
4171 if (i == ref->
nlvl_to - 1 && src_path - src <
sizeof(filename)) {
4172 memcpy(filename, src, src_path - src);
4173 filename[src_path -
src] = 0;
4176 av_strlcat(filename,
"../",
sizeof(filename));
4184 "Reference with mismatching origin, %s not tried for security reasons, " 4185 "set demuxer option use_absolute_path to allow it anyway\n",
4190 if (strstr(ref->
path + l + 1,
"..") ||
4191 strstr(ref->
path + l + 1,
":") ||
4192 (ref->
nlvl_from > 1 && same_origin < 0) ||
4193 (filename[0] ==
'/' && src_path == src))
4197 if (strlen(filename) + 1 ==
sizeof(filename))
4204 "this is a possible security issue\n");
4209 "Absolute path %s not tried for security reasons, " 4210 "set demuxer option use_absolute_path to allow absolute paths\n",
4234 if (!st)
return AVERROR(ENOMEM);
4237 if (!sc)
return AVERROR(ENOMEM);
4281 "stream %d, error opening alias: path='%s', dir='%s', " 4282 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
4287 "Skipped opening external track: " 4288 "stream %d, alias: path='%s', dir='%s', " 4289 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d." 4290 "Set enable_drefs to allow this.\n",
4307 #if FF_API_R_FRAME_RATE 4323 #if CONFIG_H261_DECODER 4326 #if CONFIG_H263_DECODER 4329 #if CONFIG_MPEG4_DECODER 4375 if (count > UINT_MAX /
sizeof(*c->
meta_keys) - 1) {
4377 "The 'keys' atom with the invalid key count: %"PRIu32
"\n", count);
4386 for (i = 1; i <=
count; ++
i) {
4391 "The key# %"PRIu32
" in meta has invalid size:" 4392 "%"PRIu32
"\n", i, key_size);
4396 if (type !=
MKTAG(
'm',
'd',
't',
'a')) {
4422 for (i = 0; i < 3; i++) {
4433 if (len < 12 || len - 12 > end -
avio_tell(pb))
4437 if (tag ==
MKTAG(
'm',
'e',
'a',
'n'))
4439 else if (tag ==
MKTAG(
'n',
'a',
'm',
'e'))
4441 else if (tag ==
MKTAG(
'd',
'a',
't',
'a') && len > 4) {
4464 if (mean && key && val) {
4465 if (strcmp(key,
"iTunSMPB") == 0) {
4466 int priming, remainder,
samples;
4467 if(sscanf(val,
"%*X %X %X %X", &priming, &remainder, &samples) == 3){
4468 if(priming>0 && priming<16384)
4472 if (strcmp(key,
"cdec") != 0) {
4479 "Unhandled or malformed custom metadata of size %"PRId64
"\n", atom.
size);
4491 while (atom.
size > 8) {
4497 if (tag ==
MKTAG(
'h',
'd',
'l',
'r')) {
4507 #define IS_MATRIX_IDENT(matrix) \ 4508 ( (matrix)[0][0] == (1 << 16) && \ 4509 (matrix)[1][1] == (1 << 16) && \ 4510 (matrix)[2][2] == (1 << 30) && \ 4511 !(matrix)[0][1] && !(matrix)[0][2] && \ 4512 !(matrix)[1][0] && !(matrix)[1][2] && \ 4513 !(matrix)[2][0] && !(matrix)[2][1]) 4520 int display_matrix[3][3];
4521 int res_display_matrix[3][3] = { { 0 } };
4565 for (i = 0; i < 3; i++) {
4573 sc->
width = width >> 16;
4574 sc->
height = height >> 16;
4577 for (i = 0; i < 3; i++) {
4578 const int sh[3] = { 16, 16, 30 };
4579 for (j = 0; j < 3; j++) {
4580 for (e = 0; e < 3; e++) {
4581 res_display_matrix[
i][j] +=
4582 ((int64_t) display_matrix[i][e] *
4597 for (i = 0; i < 3; i++)
4598 for (j = 0; j < 3; j++)
4603 if (!
isnan(rotate)) {
4604 char rotate_buf[64];
4608 snprintf(rotate_buf,
sizeof(rotate_buf),
"%g", rotate);
4617 double disp_transform[2];
4619 for (i = 0; i < 2; i++)
4623 if (disp_transform[0] > 0 && disp_transform[1] > 0 &&
4624 disp_transform[0] < (1<<24) && disp_transform[1] < (1<<24) &&
4625 fabs((disp_transform[0] / disp_transform[1]) - 1.0) > 0.01)
4627 disp_transform[0] / disp_transform[1],