79 unsigned len,
const char *key)
83 short current, total = 0;
89 snprintf(buf,
sizeof(buf),
"%d", current);
91 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
99 unsigned len,
const char *key)
113 unsigned len,
const char *key)
122 unsigned len,
const char *key)
138 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
139 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
140 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
141 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
142 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
143 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
144 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
145 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
146 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
147 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
148 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
149 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
150 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
151 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
152 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
153 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
157 char *dst,
int dstlen)
160 char *
end = dst+dstlen-1;
163 for (i = 0; i <
len; i++) {
165 if (c < 0x80 && p < end)
227 char language[4] = { 0 };
228 char buf[200], place[100];
229 uint16_t langcode = 0;
230 double longitude, latitude, altitude;
231 const char *key =
"location";
233 if (len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
253 "loci too short (%u bytes left, need at least %d)\n", len, 12);
261 snprintf(buf,
sizeof(buf),
"%+08.4f%+09.4f", latitude, longitude);
266 if (*language && strcmp(language,
"und")) {
268 snprintf(key2,
sizeof(key2),
"%s-%s", key, language);
295 char key2[32], language[4] = {0};
297 const char *key =
NULL;
298 uint16_t langcode = 0;
299 uint32_t data_type = 0, str_size, str_size_alloc;
305 case MKTAG(
'@',
'P',
'R',
'M'): key =
"premiere_version"; raw = 1;
break;
306 case MKTAG(
'@',
'P',
'R',
'Q'): key =
"quicktime_version"; raw = 1;
break;
307 case MKTAG(
'X',
'M',
'P',
'_'):
308 if (c->
export_xmp) { key =
"xmp"; raw = 1; }
break;
309 case MKTAG(
'a',
'A',
'R',
'T'): key =
"album_artist";
break;
310 case MKTAG(
'a',
'k',
'I',
'D'): key =
"account_type";
312 case MKTAG(
'a',
'p',
'I',
'D'): key =
"account_id";
break;
313 case MKTAG(
'c',
'a',
't',
'g'): key =
"category";
break;
314 case MKTAG(
'c',
'p',
'i',
'l'): key =
"compilation";
316 case MKTAG(
'c',
'p',
'r',
't'): key =
"copyright";
break;
317 case MKTAG(
'd',
'e',
's',
'c'): key =
"description";
break;
318 case MKTAG(
'd',
'i',
's',
'k'): key =
"disc";
320 case MKTAG(
'e',
'g',
'i',
'd'): key =
"episode_uid";
322 case MKTAG(
'F',
'I',
'R',
'M'): key =
"firmware"; raw = 1;
break;
323 case MKTAG(
'g',
'n',
'r',
'e'): key =
"genre";
325 case MKTAG(
'h',
'd',
'v',
'd'): key =
"hd_video";
327 case MKTAG(
'H',
'M',
'M',
'T'):
329 case MKTAG(
'k',
'e',
'y',
'w'): key =
"keywords";
break;
330 case MKTAG(
'l',
'd',
'e',
's'): key =
"synopsis";
break;
331 case MKTAG(
'l',
'o',
'c',
'i'):
333 case MKTAG(
'p',
'c',
's',
't'): key =
"podcast";
335 case MKTAG(
'p',
'g',
'a',
'p'): key =
"gapless_playback";
337 case MKTAG(
'p',
'u',
'r',
'd'): key =
"purchase_date";
break;
338 case MKTAG(
'r',
't',
'n',
'g'): key =
"rating";
340 case MKTAG(
's',
'o',
'a',
'a'): key =
"sort_album_artist";
break;
341 case MKTAG(
's',
'o',
'a',
'l'): key =
"sort_album";
break;
342 case MKTAG(
's',
'o',
'a',
'r'): key =
"sort_artist";
break;
343 case MKTAG(
's',
'o',
'c',
'o'): key =
"sort_composer";
break;
344 case MKTAG(
's',
'o',
'n',
'm'): key =
"sort_name";
break;
345 case MKTAG(
's',
'o',
's',
'n'): key =
"sort_show";
break;
346 case MKTAG(
's',
't',
'i',
'k'): key =
"media_type";
348 case MKTAG(
't',
'r',
'k',
'n'): key =
"track";
350 case MKTAG(
't',
'v',
'e',
'n'): key =
"episode_id";
break;
351 case MKTAG(
't',
'v',
'e',
's'): key =
"episode_sort";
353 case MKTAG(
't',
'v',
'n',
'n'): key =
"network";
break;
354 case MKTAG(
't',
'v',
's',
'h'): key =
"show";
break;
355 case MKTAG(
't',
'v',
's',
'n'): key =
"season_number";
357 case MKTAG(0xa9,
'A',
'R',
'T'): key =
"artist";
break;
358 case MKTAG(0xa9,
'P',
'R',
'D'): key =
"producer";
break;
359 case MKTAG(0xa9,
'a',
'l',
'b'): key =
"album";
break;
360 case MKTAG(0xa9,
'a',
'u',
't'): key =
"artist";
break;
361 case MKTAG(0xa9,
'c',
'h',
'p'): key =
"chapter";
break;
362 case MKTAG(0xa9,
'c',
'm',
't'): key =
"comment";
break;
363 case MKTAG(0xa9,
'c',
'o',
'm'): key =
"composer";
break;
364 case MKTAG(0xa9,
'c',
'p',
'y'): key =
"copyright";
break;
365 case MKTAG(0xa9,
'd',
'a',
'y'): key =
"date";
break;
366 case MKTAG(0xa9,
'd',
'i',
'r'): key =
"director";
break;
367 case MKTAG(0xa9,
'd',
'i',
's'): key =
"disclaimer";
break;
368 case MKTAG(0xa9,
'e',
'd',
'1'): key =
"edit_date";
break;
369 case MKTAG(0xa9,
'e',
'n',
'c'): key =
"encoder";
break;
370 case MKTAG(0xa9,
'f',
'm',
't'): key =
"original_format";
break;
371 case MKTAG(0xa9,
'g',
'e',
'n'): key =
"genre";
break;
372 case MKTAG(0xa9,
'g',
'r',
'p'): key =
"grouping";
break;
373 case MKTAG(0xa9,
'h',
's',
't'): key =
"host_computer";
break;
374 case MKTAG(0xa9,
'i',
'n',
'f'): key =
"comment";
break;
375 case MKTAG(0xa9,
'l',
'y',
'r'): key =
"lyrics";
break;
376 case MKTAG(0xa9,
'm',
'a',
'k'): key =
"make";
break;
377 case MKTAG(0xa9,
'm',
'o',
'd'): key =
"model";
break;
378 case MKTAG(0xa9,
'n',
'a',
'm'): key =
"title";
break;
379 case MKTAG(0xa9,
'o',
'p',
'e'): key =
"original_artist";
break;
380 case MKTAG(0xa9,
'p',
'r',
'd'): key =
"producer";
break;
381 case MKTAG(0xa9,
'p',
'r',
'f'): key =
"performers";
break;
382 case MKTAG(0xa9,
'r',
'e',
'q'): key =
"playback_requirements";
break;
383 case MKTAG(0xa9,
's',
'r',
'c'): key =
"original_source";
break;
384 case MKTAG(0xa9,
's',
't',
'3'): key =
"subtitle";
break;
385 case MKTAG(0xa9,
's',
'w',
'r'): key =
"encoder";
break;
386 case MKTAG(0xa9,
't',
'o',
'o'): key =
"encoder";
break;
387 case MKTAG(0xa9,
't',
'r',
'k'): key =
"track";
break;
388 case MKTAG(0xa9,
'u',
'r',
'l'): key =
"URL";
break;
389 case MKTAG(0xa9,
'w',
'r',
'n'): key =
"warning";
break;
390 case MKTAG(0xa9,
'w',
'r',
't'): key =
"composer";
break;
391 case MKTAG(0xa9,
'x',
'y',
'z'): key =
"location";
break;
397 if (tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.
size) {
400 str_size = data_size - 16;
403 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r')) {
411 if (index < c->meta_keys_count && index > 0) {
415 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
422 if (str_size > atom.
size) {
432 str_size = atom.
size;
441 if (atom.
size < 0 || str_size >= INT_MAX/2)
446 num = (data_type >= 21 && data_type <= 23);
447 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
453 parse(c, pb, str_size, key);
455 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
457 }
else if (data_type == 21) {
461 else if (str_size == 2)
463 else if (str_size == 3)
465 else if (str_size == 4)
467 if (
snprintf(str, str_size_alloc,
"%d", val) >= str_size_alloc) {
469 "Failed to store the number (%d) in string.\n", val);
473 }
else if (data_type == 22) {
474 unsigned int val = 0;
477 else if (str_size == 2)
479 else if (str_size == 3)
481 else if (str_size == 4)
483 if (
snprintf(str, str_size_alloc,
"%u", val) >= str_size_alloc) {
485 "Failed to store the number (%u) in string.\n", val);
489 }
else if (data_type == 23 && str_size >= 4) {
491 if (
snprintf(str, str_size_alloc,
"%f", val) >= str_size_alloc) {
493 "Failed to store the float32 number (%f) in string.\n", val);
507 if (*language && strcmp(language,
"und")) {
508 snprintf(key2,
sizeof(key2),
"%s-%s", key, language);
511 if (!strcmp(key,
"encoder")) {
512 int major, minor, micro;
513 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
526 int i, nb_chapters, str_len,
version;
533 if ((atom.
size -= 5) < 0)
542 for (i = 0; i < nb_chapters; i++) {
549 if ((atom.
size -= 9+str_len) < 0)
561 #define MIN_DATA_ENTRY_BOX_SIZE 12
577 entries >= UINT_MAX /
sizeof(*sc->
drefs))
587 for (i = 0; i < entries; i++) {
598 if (dref->
type ==
MKTAG(
'a',
'l',
'i',
's') && size > 150) {
600 uint16_t volume_len,
len;
607 volume_len =
FFMIN(volume_len, 27);
611 dref->
volume[volume_len] = 0;
617 len =
FFMIN(len, 63);
634 for (type = 0; type != -1 &&
avio_tell(pb) < next; ) {
653 if (len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
655 memmove(dref->
path, dref->
path+volume_len, len);
659 for (j = len - 1; j >= 0; j--) {
660 if (dref->
path[j] == 0)
665 for (j = 0; j <
len; j++)
666 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
669 }
else if (type == 0) {
681 for (j = 0; j <
len; j++)
682 if (dref->
dir[j] ==
':')
719 if (type ==
MKTAG(
'm',
'd',
't',
'a')) {
727 if (type ==
MKTAG(
'v',
'i',
'd',
'e'))
729 else if (type ==
MKTAG(
's',
'o',
'u',
'n'))
731 else if (type ==
MKTAG(
'm',
'1',
'a',
' '))
733 else if ((type ==
MKTAG(
's',
'u',
'b',
'p')) || (type ==
MKTAG(
'c',
'l',
'c',
'p')))
740 title_size = atom.
size - 24;
741 if (title_size > 0) {
742 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
753 title_str[title_size] = 0;
755 int off = (!c->
isom && title_str[0] == title_size - 1);
795 int ac3info, acmod, lfeon, bsmod;
807 bsmod = (ac3info >> 14) & 0x7;
808 acmod = (ac3info >> 11) & 0x7;
809 lfeon = (ac3info >> 10) & 0x1;
818 #if FF_API_LAVF_AVCTX
820 st->codec->audio_service_type = *ast;
831 int eac3info, acmod, lfeon, bsmod;
847 bsmod = (eac3info >> 12) & 0x1f;
848 acmod = (eac3info >> 9) & 0x7;
849 lfeon = (eac3info >> 8) & 0x1;
858 #if FF_API_LAVF_AVCTX
860 st->codec->audio_service_type = *ast;
869 const uint32_t ddts_size = 20;
872 uint32_t frame_duration_code = 0;
873 uint32_t channel_layout_code = 0;
880 if (
avio_read(pb, buf, ddts_size) < ddts_size) {
900 frame_duration_code =
get_bits(&gb, 2);
902 channel_layout_code =
get_bits(&gb, 16);
905 (frame_duration_code == 0) ? 512 :
906 (frame_duration_code == 1) ? 1024 :
907 (frame_duration_code == 2) ? 2048 :
908 (frame_duration_code == 3) ? 4096 : 0;
910 if (channel_layout_code > 0xff) {
973 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
976 }
else if (den != 0) {
992 #define DRM_BLOB_SIZE 56
1001 uint8_t calculated_checksum[20];
1026 for (i = 0; i < 20; i++)
1031 if (!activation_bytes) {
1063 if (memcmp(calculated_checksum, file_checksum, 20)) {
1070 for (i = 0; i < 4; i++) {
1072 if (activation_bytes[i] != output[3 - i]) {
1078 memcpy(c->
file_key, output + 8, 16);
1079 memcpy(input, output + 26, 16);
1096 unsigned char iv[16];
1110 int comp_brand_size;
1111 char* comp_brands_str;
1117 if (strcmp(type,
"qt "))
1124 comp_brand_size = atom.
size - 8;
1125 if (comp_brand_size < 0)
1127 comp_brands_str =
av_malloc(comp_brand_size + 1);
1128 if (!comp_brands_str)
1136 comp_brands_str[comp_brand_size] = 0;
1172 "read the mfra (may be a live ismv)\n");
1176 "seekable, can not look for mfra\n");
1187 if(time >= 2082844800)
1190 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1204 char language[4] = {0};
1206 int64_t creation_time;
1251 int64_t creation_time;
1282 for (i = 0; i < 3; i++) {
1310 if (little_endian == 1) {
1334 char color_parameter_type[5] = { 0 };
1345 if (strncmp(color_parameter_type,
"nclx", 4) &&
1346 strncmp(color_parameter_type,
"nclc", 4)) {
1348 color_parameter_type);
1357 "%s: pri %d trc %d matrix %d",
1358 color_parameter_type, color_primaries, color_trc, color_matrix);
1360 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1387 unsigned mov_field_order;
1396 if ((mov_field_order & 0xFF00) == 0x0100)
1398 else if ((mov_field_order & 0xFF00) == 0x0200) {
1399 switch (mov_field_order & 0xFF) {
1422 if (size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1436 int64_t result = atom.
size;
1445 }
else if (err < atom.
size) {
1459 uint64_t original_size;
1534 if (cid == 0xd4d || cid == 0xd4e)
1544 if (num <= 0 || den <= 0)
1548 if (den >= INT_MAX / 2)
1567 uint64_t original_size;
1572 if (atom.
size == 16) {
1577 if (length == atom.
size) {
1579 switch (range_value) {
1620 if ((uint64_t)atom.
size > (1<<30))
1631 }
else if (atom.
size > 8) {
1639 if ( (buffer & 0xFFFFFFFF) ==
MKBETAG(
'f',
'r',
'm',
'a')
1640 && buffer >> 32 <= atom.
size
1641 && buffer >> 32 >= 8) {
1645 #define ALAC_EXTRADATA_SIZE 36
1678 if ((uint64_t)atom.
size > (1<<30))
1681 if (atom.
size >= 10) {
1687 if (type ==
MKTAG(
'f',
'i',
'e',
'l') && size == atom.
size)
1712 if (atom.
size >= (1<<28) || atom.
size < 7)
1716 if ((profile_level & 0xf0) != 0xc0)
1740 if (atom.
size <= 40)
1744 if ((uint64_t)atom.
size > (1<<30))
1760 unsigned int i, entries;
1784 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
1787 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
1820 ((format & 0xFFFF) ==
'm' + (
's' << 8) ||
1821 (format & 0xFFFF) ==
'T' + (
'S' << 8)))
1828 format && format !=
MKTAG(
'm',
'p',
'4',
's')) {
1851 uint8_t codec_name[32] = { 0 };
1884 if (!memcmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
1891 !memcmp(codec_name,
"Sorenson H263", 13))
1907 int bits_per_sample,
flags;
1926 (compatible_brands && strstr(compatible_brands->
value,
"qt "))) {
1933 }
else if (version == 2) {
1948 if (version == 0 || (version == 1 && sc->
audio_cid != -2)) {
2007 if (bits_per_sample) {
2032 y = (ycbcr >> 16) & 0xFF;
2033 cr = (ycbcr >> 8) & 0xFF;
2036 b = av_clip_uint8((1164 * (y - 16) + 2018 * (cb - 128)) / 1000);
2037 g = av_clip_uint8((1164 * (y - 16) - 813 * (cr - 128) - 391 * (cb - 128)) / 1000);
2038 r = av_clip_uint8((1164 * (y - 16) + 1596 * (cr - 128) ) / 1000);
2040 return (r << 16) | (g << 8) | b;
2045 char buf[256] = {0};
2053 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2057 for (i = 0; i < 16; i++) {
2058 uint32_t yuv =
AV_RB32(src + i * 4);
2061 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba, i != 15 ?
", " :
"");
2064 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2085 if ((
int)size != size)
2098 #if FF_API_LAVF_AVCTX
2109 #if FF_API_LAVF_AVCTX
2119 if (format ==
AV_RB32(
"name") && (int64_t)size >= (int64_t)len + 18) {
2121 if (str_size > 0 && size >= (
int)str_size + 26) {
2122 char *reel_name =
av_malloc(str_size + 1);
2126 reel_name[str_size] = 0;
2128 if (*reel_name == 0) {
2153 #if CONFIG_DV_DEMUXER
2223 int codec_tag,
int format,
2229 (codec_tag != format &&
2237 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2254 int pseudo_stream_id;
2261 for (pseudo_stream_id = 0;
2263 pseudo_stream_id++) {
2266 int ret, dref_id = 1;
2276 }
else if (size <= 7) {
2278 "invalid size %"PRId64
" in stsd\n", size);
2293 "size=%"PRId64
" 4CC=%s codec_type=%d\n", size,
2321 }
else if (a.
size > 0)
2403 unsigned int i, entries;
2414 if ((uint64_t)entries * 12 + 4 > atom.
size)
2429 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2443 #define mov_stsc_index_valid(index, count) ((index) < (count) - 1)
2462 unsigned i, entries;
2480 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2496 unsigned int i, entries;
2519 if (entries >= UINT_MAX /
sizeof(
int))
2527 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2543 unsigned int i, entries, sample_size, field_size, num_bytes;
2556 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
2575 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
2582 if (entries >= (UINT_MAX - 4) / field_size)
2592 num_bytes = (entries*field_size+4)>>3;
2609 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2628 unsigned int i, entries;
2630 int64_t total_sample_count=0;
2652 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2653 int sample_duration;
2659 if (sample_count < 0) {
2667 sample_count, sample_duration);
2671 && sample_count == 1
2672 && total_sample_count > 100
2673 && sample_duration/10 > duration / total_sample_count)
2674 sample_duration = duration / total_sample_count;
2675 duration+=(int64_t)sample_duration*sample_count;
2676 total_sample_count+=sample_count;
2697 if (duration == INT_MIN) {
2709 unsigned int i, entries, ctts_count = 0;
2724 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
2731 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2737 "ignoring CTTS entry with count=%d duration=%d\n",
2749 if (
FFNABS(duration) < -(1<<28) && i+2<entries) {
2774 unsigned int i, entries;
2776 uint32_t grouping_type;
2786 if (grouping_type !=
MKTAG(
'r',
'a',
'p',
' '))
2802 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2817 unsigned int edit_list_index,
2818 int64_t *edit_list_media_time,
2819 int64_t *edit_list_duration,
2820 int64_t global_timescale)
2825 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
2829 if (global_timescale == 0) {
2897 const size_t requested_size =
2914 ie= &entries[
index];
2929 int64_t* frame_duration_buffer,
2930 int frame_duration_buffer_size) {
2932 av_assert0(end_index >= 0 && end_index <= st->nb_index_entries);
2933 for (i = 0; i < frame_duration_buffer_size; i++) {
2934 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 - i];
2947 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVStts);
2948 const size_t requested_size =
2949 min_size_needed > *allocated_size ?
2950 FFMAX(min_size_needed, 2 * (*allocated_size)) :
2953 if((
unsigned)(*ctts_count) + 1 >= UINT_MAX /
sizeof(
MOVStts))
2956 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
2961 *ctts_data = ctts_buf_new;
2966 *ctts_count = (*ctts_count) + 1;
3008 if (range_size > current_sample) {
3012 current_sample -= range_size;
3030 int64_t ctts_index_old = 0;
3031 int64_t ctts_sample_old = 0;
3033 int64_t edit_list_media_time = 0;
3034 int64_t edit_list_duration = 0;
3035 int64_t frame_duration = 0;
3036 int64_t edit_list_dts_counter = 0;
3037 int64_t edit_list_dts_entry_end = 0;
3038 int64_t edit_list_start_ctts_sample = 0;
3040 int64_t edit_list_index = 0;
3042 int64_t index_ctts_count;
3044 unsigned int ctts_allocated_size = 0;
3045 int64_t start_dts = 0;
3046 int64_t edit_list_media_time_dts = 0;
3047 int64_t edit_list_start_encountered = 0;
3048 int64_t search_timestamp = 0;
3049 int64_t* frame_duration_buffer =
NULL;
3050 int num_discarded_begin = 0;
3051 int first_non_zero_audio_edit = -1;
3052 int packet_skip_samples = 0;
3082 edit_list_dts_entry_end -= msc->
dts_shift;
3085 if (ctts_data_old && ctts_count_old > 0) {
3086 edit_list_dts_entry_end -= ctts_data_old[0].
duration;
3090 start_dts = edit_list_dts_entry_end;
3094 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3095 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3097 edit_list_dts_counter = edit_list_dts_entry_end;
3098 edit_list_dts_entry_end += edit_list_duration;
3099 num_discarded_begin = 0;
3100 if (edit_list_media_time == -1) {
3107 if (first_non_zero_audio_edit < 0) {
3108 first_non_zero_audio_edit = 1;
3110 first_non_zero_audio_edit = 0;
3113 if (first_non_zero_audio_edit > 0)
3118 edit_list_media_time_dts = edit_list_media_time;
3120 edit_list_media_time_dts -= msc->
dts_shift;
3127 search_timestamp = edit_list_media_time_dts;
3138 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3139 st->
index, edit_list_index, search_timestamp);
3144 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n"
3145 "Rounding edit list media time to zero.\n",
3146 st->
index, edit_list_index, search_timestamp);
3148 edit_list_media_time = 0;
3151 current = e_old +
index;
3154 ctts_sample_old = 0;
3157 for (index_ctts_count = 0; index_ctts_count <
index; index_ctts_count++) {
3158 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3160 if (ctts_data_old[ctts_index_old].
count == ctts_sample_old) {
3162 ctts_sample_old = 0;
3167 edit_list_start_ctts_sample = ctts_sample_old;
3170 edit_list_start_encountered = 0;
3171 for (; current < e_old_end; current++, index++) {
3173 frame_duration = (current + 1 < e_old_end) ?
3174 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3176 flags = current->
flags;
3181 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3182 av_log(mov->
fc,
AV_LOG_DEBUG,
"shifted frame pts, curr_cts: %"PRId64
" @ %"PRId64
", ctts: %d, ctts_count: %"PRId64
"\n",
3183 curr_cts, ctts_index_old, ctts_data_old[ctts_index_old].
duration, ctts_count_old);
3184 curr_cts += ctts_data_old[ctts_index_old].
duration;
3186 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3188 &ctts_allocated_size,
3189 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3190 ctts_data_old[ctts_index_old].
duration) == -1) {
3193 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3194 ctts_data_old[ctts_index_old].
duration);
3198 ctts_sample_old = 0;
3199 edit_list_start_ctts_sample = 0;
3203 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3205 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3206 first_non_zero_audio_edit > 0) {
3207 packet_skip_samples = edit_list_media_time - curr_cts;
3211 edit_list_dts_counter -= packet_skip_samples;
3212 if (edit_list_start_encountered == 0) {
3213 edit_list_start_encountered = 1;
3216 if (frame_duration_buffer) {
3218 frame_duration_buffer, num_discarded_begin);
3223 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
3226 av_log(mov->
fc,
AV_LOG_DEBUG,
"drop a frame at curr_cts: %"PRId64
" @ %"PRId64
"\n", curr_cts, index);
3229 num_discarded_begin++;
3230 frame_duration_buffer =
av_realloc(frame_duration_buffer,
3231 num_discarded_begin *
sizeof(int64_t));
3232 if (!frame_duration_buffer) {
3236 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
3245 }
else if (edit_list_start_encountered == 0) {
3246 edit_list_start_encountered = 1;
3251 frame_duration_buffer, num_discarded_begin);
3263 if (current_index_range < msc->index_ranges || index != current_index_range->
end) {
3264 current_index_range++;
3267 current_index_range->
end = index + 1;
3270 if (edit_list_start_encountered > 0) {
3271 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
3275 if (((curr_cts + frame_duration) >= (edit_list_duration + edit_list_media_time)) &&
3278 if (ctts_data_old && ctts_sample_old != 0) {
3280 &ctts_allocated_size,
3281 ctts_sample_old - edit_list_start_ctts_sample,
3282 ctts_data_old[ctts_index_old].
duration) == -1) {
3284 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
3285 ctts_data_old[ctts_index_old].
duration);
3294 st->
duration = edit_list_dts_entry_end - start_dts;
3302 current_index_range++;
3303 current_index_range->
start = 0;
3304 current_index_range->
end = 0;
3311 int64_t current_offset;
3312 int64_t current_dts = 0;
3313 unsigned int stts_index = 0;
3314 unsigned int stsc_index = 0;
3315 unsigned int stss_index = 0;
3316 unsigned int stps_index = 0;
3318 uint64_t stream_size = 0;
3321 int i, edit_start_index = 0, multiple_edits = 0;
3322 int64_t empty_duration = 0;
3327 if (i == 0 && e->
time == -1) {
3331 edit_start_index = 1;
3332 }
else if (i == edit_start_index && e->
time >= 0) {
3333 start_time = e->
time;
3341 "Use -advanced_editlist to correctly decode otherwise "
3342 "a/v desync might occur\n");
3345 if ((empty_duration || start_time) && mov->
time_scale > 0) {
3361 unsigned int current_sample = 0;
3362 unsigned int stts_sample = 0;
3363 unsigned int sample_size;
3365 unsigned int rap_group_index = 0;
3366 unsigned int rap_group_sample = 0;
3367 int64_t last_dts = 0;
3368 int64_t dts_correction = 0;
3373 last_dts = current_dts;
3420 if (rap_group_present && rap_group_index < sc->rap_group_count) {
3423 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
3424 rap_group_sample = 0;
3430 && !rap_group_present
3439 if (sample_size > 0x3FFFFFFF) {
3444 e->
pos = current_offset;
3446 e->
size = sample_size;
3449 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", "
3450 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
3451 current_offset, current_dts, sample_size, distance, keyframe);
3456 current_offset += sample_size;
3457 stream_size += sample_size;
3463 "Invalid SampleDelta %d in STTS, at %d st:%d\n",
3470 if (!dts_correction || current_dts + dts_correction > last_dts) {
3471 current_dts += dts_correction;
3475 dts_correction += current_dts - last_dts - 1;
3476 current_dts = last_dts + 1;
3478 last_dts = current_dts;
3491 unsigned chunk_samples, total = 0;
3495 unsigned count, chunk_count;
3508 count = (chunk_samples+samples-1) / samples;
3510 count = (chunk_samples+1023) / 1024;
3517 total += chunk_count *
count;
3539 while (chunk_samples > 0) {
3541 unsigned size, samples;
3545 "Zero bytes per frame, but %d samples per frame",
3559 samples =
FFMIN(1024, chunk_samples);
3568 if (size > 0x3FFFFFFF) {
3573 e->
pos = current_offset;
3579 "size %u, duration %u\n", st->
index, i, current_offset, current_dts,
3582 current_offset +=
size;
3583 current_dts += samples;
3584 chunk_samples -= samples;
3605 av_url_split(src_proto,
sizeof(src_proto), src_auth,
sizeof(src_auth), src_host,
sizeof(src_host), &src_port,
NULL, 0, src);
3606 av_url_split(ref_proto,
sizeof(ref_proto), ref_auth,
sizeof(ref_auth), ref_host,
sizeof(ref_host), &ref_port,
NULL, 0, ref);
3608 if (strlen(src) == 0) {
3610 }
else if (strlen(src_auth) + 1 >=
sizeof(src_auth) ||
3611 strlen(ref_auth) + 1 >=
sizeof(ref_auth) ||
3612 strlen(src_host) + 1 >=
sizeof(src_host) ||
3613 strlen(ref_host) + 1 >=
sizeof(ref_host)) {
3615 }
else if (strcmp(src_proto, ref_proto) ||
3616 strcmp(src_auth, ref_auth) ||
3617 strcmp(src_host, ref_host) ||
3618 src_port != ref_port) {
3629 char filename[1025];
3630 const char *src_path;
3634 src_path = strrchr(src,
'/');
3641 for (i = 0, l = strlen(ref->
path) - 1; l >= 0; l--)
3642 if (ref->
path[l] ==
'/') {
3650 if (i == ref->
nlvl_to - 1 && src_path - src <
sizeof(filename)) {
3651 memcpy(filename, src, src_path - src);
3652 filename[src_path -
src] = 0;
3655 av_strlcat(filename,
"../",
sizeof(filename));
3663 "Reference with mismatching origin, %s not tried for security reasons, "
3664 "set demuxer option use_absolute_path to allow it anyway\n",
3669 if(strstr(ref->
path + l + 1,
"..") ||
3670 strstr(ref->
path + l + 1,
":") ||
3671 (ref->
nlvl_from > 1 && same_origin < 0) ||
3672 (filename[0] ==
'/' && src_path == src))
3676 if (strlen(filename) + 1 ==
sizeof(filename))
3683 "this is a possible security issue\n");
3688 "Absolute path %s not tried for security reasons, "
3689 "set demuxer option use_absolute_path to allow absolute paths\n",
3713 if (!st)
return AVERROR(ENOMEM);
3716 if (!sc)
return AVERROR(ENOMEM);
3747 "stream %d, error opening alias: path='%s', dir='%s', "
3748 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
3753 "Skipped opening external track: "
3754 "stream %d, alias: path='%s', dir='%s', "
3755 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d."
3756 "Set enable_drefs to allow this.\n",
3773 #if FF_API_R_FRAME_RATE
3789 #if CONFIG_H261_DECODER
3792 #if CONFIG_H263_DECODER
3795 #if CONFIG_MPEG4_DECODER
3841 if (count > UINT_MAX /
sizeof(*c->
meta_keys) - 1) {
3843 "The 'keys' atom with the invalid key count: %"PRIu32
"\n", count);
3852 for (i = 1; i <=
count; ++i) {
3857 "The key# %"PRIu32
" in meta has invalid size:"
3858 "%"PRIu32
"\n", i, key_size);
3862 if (type !=
MKTAG(
'm',
'd',
't',
'a')) {
3888 for (i = 0; i < 3; i++) {
3899 if (len < 12 || len - 12 > end -
avio_tell(pb))
3903 if (tag ==
MKTAG(
'm',
'e',
'a',
'n'))
3905 else if (tag ==
MKTAG(
'n',
'a',
'm',
'e'))
3907 else if (tag ==
MKTAG(
'd',
'a',
't',
'a') && len > 4) {
3925 if (mean && key && val) {
3926 if (strcmp(key,
"iTunSMPB") == 0) {
3927 int priming, remainder, samples;
3928 if(sscanf(val,
"%*X %X %X %X", &priming, &remainder, &samples) == 3){
3929 if(priming>0 && priming<16384)
3933 if (strcmp(key,
"cdec") != 0) {
3940 "Unhandled or malformed custom metadata of size %"PRId64
"\n", atom.
size);
3952 while (atom.
size > 8) {
3955 if (tag ==
MKTAG(
'h',
'd',
'l',
'r')) {
3965 #define IS_MATRIX_IDENT(matrix) \
3966 ( (matrix)[0][0] == (1 << 16) && \
3967 (matrix)[1][1] == (1 << 16) && \
3968 (matrix)[2][2] == (1 << 30) && \
3969 !(matrix)[0][1] && !(matrix)[0][2] && \
3970 !(matrix)[1][0] && !(matrix)[1][2] && \
3971 !(matrix)[2][0] && !(matrix)[2][1])
3978 int display_matrix[3][3];
3979 int res_display_matrix[3][3] = { { 0 } };
4018 for (i = 0; i < 3; i++) {
4026 sc->
width = width >> 16;
4027 sc->
height = height >> 16;
4030 for (i = 0; i < 3; i++) {
4031 const int sh[3] = { 16, 16, 30 };
4032 for (j = 0; j < 3; j++) {
4033 for (e = 0; e < 3; e++) {
4034 res_display_matrix[i][j] +=
4035 ((int64_t) display_matrix[i][e] *
4050 for (i = 0; i < 3; i++)
4051 for (j = 0; j < 3; j++)
4056 if (!
isnan(rotate)) {
4057 char rotate_buf[64];
4061 snprintf(rotate_buf,
sizeof(rotate_buf),
"%g", rotate);
4070 double disp_transform[2];
4072 for (i = 0; i < 2; i++)
4076 if (disp_transform[0] > 0 && disp_transform[1] > 0 &&
4077 disp_transform[0] < (1<<24) && disp_transform[1] < (1<<24) &&
4078 fabs((disp_transform[0] / disp_transform[1]) - 1.0) > 0.01)
4080 disp_transform[0] / disp_transform[1],
4091 int flags, track_id, i, found = 0;
4127 "found fragment index for track %u\n", frag->
track_id);
4129 for (j = index->
current_item; j < index->item_count; j++) {
4132 "for track %u and moof_offset %"PRId64
"\n",
4144 if (index && !found) {
4146 "it doesn't have an (in-order) entry for moof_offset "
4158 num = atom.
size / 4;
4236 int data_offset = 0;
4237 unsigned entries, first_sample_flags = frag->
flags;
4287 for (i = 0; i < entries && !pb->
eof_reached; i++) {
4288 unsigned sample_size = frag->
size;
4289 int sample_flags = i ? frag->
flags : first_sample_flags;
4290 unsigned sample_duration = frag->
duration;
4304 " sc->dts_shift %d ctts.duration %d"
4305 " sc->time_offset %"PRId64
" flags & MOV_TRUN_SAMPLE_CTS %d\n", pts,
4309 if (flags & MOV_TRUN_SAMPLE_CTS) {
4318 ", using it for dts\n", dts);
4338 offset, dts, sample_size, distance, keyframe);
4340 dts += sample_duration;
4341 offset += sample_size;
4363 unsigned i, track_id;
4395 if (timescale.
den <= 0) {
4419 if (!index->
items) {
4427 if (size & 0x80000000) {
4492 if (atom.
type !=
MKTAG(
'm',
'd',
'a',
't')) {
4506 long cmov_len, moov_len;
4520 cmov_len = atom.
size - 6 * 4;
4532 goto free_and_return;
4534 if (uncompress (moov_data, (uLongf *) &moov_len, (
const Bytef *)cmov_data, cmov_len) != Z_OK)
4535 goto free_and_return;
4537 goto free_and_return;
4540 atom.
size = moov_len;
4577 for (i = 0; i < edit_count && !pb->
eof_reached; i++) {
4591 if (e->
time < 0 && e->
time != -1 &&
4627 if (atom.
size < 5) {
4663 uint32_t l = 0, t = 0,
r = 0,
b = 0;
4664 uint32_t
tag, padding = 0;
4673 if (atom.
size < 8) {
4683 if (tag !=
MKTAG(
's',
'v',
'h',
'd')) {
4691 if (size > atom.
size)
4695 if (tag !=
MKTAG(
'p',
'r',
'o',
'j')) {
4701 if (size > atom.
size)
4705 if (tag !=
MKTAG(
'p',
'r',
'h',
'd')) {