26 #include "config_components.h"
92 unsigned len,
const char *
key)
96 short current, total = 0;
102 snprintf(buf,
sizeof(buf),
"%d", current);
104 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
112 unsigned len,
const char *
key)
126 unsigned len,
const char *
key)
135 unsigned len,
const char *
key)
151 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
152 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
153 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
154 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
155 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
156 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
157 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
158 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
159 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
160 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
161 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
162 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
163 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
164 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
165 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
166 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
170 char *
dst,
int dstlen)
173 char *end =
dst+dstlen-1;
176 for (
i = 0;
i <
len;
i++) {
198 for (
int i = 0;
i <
c->nb_heif_item;
i++) {
199 if (!
c->heif_item[
i] ||
c->heif_item[
i]->item_id !=
c->cur_item_id)
202 item =
c->heif_item[
i];
218 if (
c->fc->nb_streams < 1)
221 if (
c->cur_item_id == -1)
222 return c->fc->streams[
c->fc->nb_streams-1];
256 st =
c->fc->streams[
c->fc->nb_streams - 1];
277 char buf[200], place[100];
278 uint16_t langcode = 0;
279 double longitude, latitude, altitude;
280 const char *
key =
"location";
282 if (
len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
302 "loci too short (%u bytes left, need at least %d)\n",
len, 12);
310 snprintf(buf,
sizeof(buf),
"%+08.4f%+09.4f", latitude, longitude);
330 if (
c->ignore_chapters)
334 if (n_hmmt >
len / 4)
351 uint16_t langcode = 0;
352 uint32_t data_type = 0, str_size_alloc;
359 case MKTAG(
'@',
'P',
'R',
'M'):
key =
"premiere_version"; raw = 1;
break;
360 case MKTAG(
'@',
'P',
'R',
'Q'):
key =
"quicktime_version"; raw = 1;
break;
361 case MKTAG(
'X',
'M',
'P',
'_'):
362 if (
c->export_xmp) {
key =
"xmp"; raw = 1; }
break;
363 case MKTAG(
'a',
'A',
'R',
'T'):
key =
"album_artist";
break;
364 case MKTAG(
'a',
'k',
'I',
'D'):
key =
"account_type";
366 case MKTAG(
'a',
'p',
'I',
'D'):
key =
"account_id";
break;
367 case MKTAG(
'c',
'a',
't',
'g'):
key =
"category";
break;
368 case MKTAG(
'c',
'p',
'i',
'l'):
key =
"compilation";
370 case MKTAG(
'c',
'p',
'r',
't'):
key =
"copyright";
break;
371 case MKTAG(
'd',
'e',
's',
'c'):
key =
"description";
break;
372 case MKTAG(
'd',
'i',
's',
'k'):
key =
"disc";
374 case MKTAG(
'e',
'g',
'i',
'd'):
key =
"episode_uid";
376 case MKTAG(
'F',
'I',
'R',
'M'):
key =
"firmware"; raw = 1;
break;
377 case MKTAG(
'g',
'n',
'r',
'e'):
key =
"genre";
379 case MKTAG(
'h',
'd',
'v',
'd'):
key =
"hd_video";
381 case MKTAG(
'H',
'M',
'M',
'T'):
383 case MKTAG(
'k',
'e',
'y',
'w'):
key =
"keywords";
break;
384 case MKTAG(
'l',
'd',
'e',
's'):
key =
"synopsis";
break;
385 case MKTAG(
'l',
'o',
'c',
'i'):
387 case MKTAG(
'm',
'a',
'n',
'u'):
key =
"make";
break;
388 case MKTAG(
'm',
'o',
'd',
'l'):
key =
"model";
break;
389 case MKTAG(
'p',
'c',
's',
't'):
key =
"podcast";
391 case MKTAG(
'p',
'g',
'a',
'p'):
key =
"gapless_playback";
393 case MKTAG(
'p',
'u',
'r',
'd'):
key =
"purchase_date";
break;
394 case MKTAG(
'r',
't',
'n',
'g'):
key =
"rating";
396 case MKTAG(
's',
'o',
'a',
'a'):
key =
"sort_album_artist";
break;
397 case MKTAG(
's',
'o',
'a',
'l'):
key =
"sort_album";
break;
398 case MKTAG(
's',
'o',
'a',
'r'):
key =
"sort_artist";
break;
399 case MKTAG(
's',
'o',
'c',
'o'):
key =
"sort_composer";
break;
400 case MKTAG(
's',
'o',
'n',
'm'):
key =
"sort_name";
break;
401 case MKTAG(
's',
'o',
's',
'n'):
key =
"sort_show";
break;
402 case MKTAG(
's',
't',
'i',
'k'):
key =
"media_type";
404 case MKTAG(
't',
'r',
'k',
'n'):
key =
"track";
406 case MKTAG(
't',
'v',
'e',
'n'):
key =
"episode_id";
break;
407 case MKTAG(
't',
'v',
'e',
's'):
key =
"episode_sort";
409 case MKTAG(
't',
'v',
'n',
'n'):
key =
"network";
break;
410 case MKTAG(
't',
'v',
's',
'h'):
key =
"show";
break;
411 case MKTAG(
't',
'v',
's',
'n'):
key =
"season_number";
413 case MKTAG(0xa9,
'A',
'R',
'T'):
key =
"artist";
break;
414 case MKTAG(0xa9,
'P',
'R',
'D'):
key =
"producer";
break;
415 case MKTAG(0xa9,
'a',
'l',
'b'):
key =
"album";
break;
416 case MKTAG(0xa9,
'a',
'u',
't'):
key =
"artist";
break;
417 case MKTAG(0xa9,
'c',
'h',
'p'):
key =
"chapter";
break;
418 case MKTAG(0xa9,
'c',
'm',
't'):
key =
"comment";
break;
419 case MKTAG(0xa9,
'c',
'o',
'm'):
key =
"composer";
break;
420 case MKTAG(0xa9,
'c',
'p',
'y'):
key =
"copyright";
break;
421 case MKTAG(0xa9,
'd',
'a',
'y'):
key =
"date";
break;
422 case MKTAG(0xa9,
'd',
'i',
'r'):
key =
"director";
break;
423 case MKTAG(0xa9,
'd',
'i',
's'):
key =
"disclaimer";
break;
424 case MKTAG(0xa9,
'e',
'd',
'1'):
key =
"edit_date";
break;
425 case MKTAG(0xa9,
'e',
'n',
'c'):
key =
"encoder";
break;
426 case MKTAG(0xa9,
'f',
'm',
't'):
key =
"original_format";
break;
427 case MKTAG(0xa9,
'g',
'e',
'n'):
key =
"genre";
break;
428 case MKTAG(0xa9,
'g',
'r',
'p'):
key =
"grouping";
break;
429 case MKTAG(0xa9,
'h',
's',
't'):
key =
"host_computer";
break;
430 case MKTAG(0xa9,
'i',
'n',
'f'):
key =
"comment";
break;
431 case MKTAG(0xa9,
'l',
'y',
'r'):
key =
"lyrics";
break;
432 case MKTAG(0xa9,
'm',
'a',
'k'):
key =
"make";
break;
433 case MKTAG(0xa9,
'm',
'o',
'd'):
key =
"model";
break;
434 case MKTAG(0xa9,
'n',
'a',
'm'):
key =
"title";
break;
435 case MKTAG(0xa9,
'o',
'p',
'e'):
key =
"original_artist";
break;
436 case MKTAG(0xa9,
'p',
'r',
'd'):
key =
"producer";
break;
437 case MKTAG(0xa9,
'p',
'r',
'f'):
key =
"performers";
break;
438 case MKTAG(0xa9,
'r',
'e',
'q'):
key =
"playback_requirements";
break;
439 case MKTAG(0xa9,
's',
'r',
'c'):
key =
"original_source";
break;
440 case MKTAG(0xa9,
's',
't',
'3'):
key =
"subtitle";
break;
441 case MKTAG(0xa9,
's',
'w',
'r'):
key =
"encoder";
break;
442 case MKTAG(0xa9,
't',
'o',
'o'):
key =
"encoder";
break;
443 case MKTAG(0xa9,
't',
'r',
'k'):
key =
"track";
break;
444 case MKTAG(0xa9,
'u',
'r',
'l'):
key =
"URL";
break;
445 case MKTAG(0xa9,
'w',
'r',
'n'):
key =
"warning";
break;
446 case MKTAG(0xa9,
'w',
'r',
't'):
key =
"composer";
break;
447 case MKTAG(0xa9,
'x',
'y',
'z'):
key =
"location";
break;
450 if (
c->itunes_metadata && atom.
size > 8) {
453 if (
tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
456 str_size = data_size - 16;
459 if (!
key &&
c->found_hdlr_mdta &&
c->meta_keys) {
461 if (index < c->meta_keys_count &&
index > 0) {
463 }
else if (atom.
type !=
MKTAG(
'c',
'o',
'v',
'r')) {
465 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
466 index,
c->meta_keys_count);
469 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r') ||
470 (
key && !strcmp(
key,
"com.apple.quicktime.artwork"))) {
476 atom.
size -= str_size;
482 }
else if (atom.
size > 4 &&
key && !
c->itunes_metadata && !raw) {
484 if (str_size > atom.
size) {
494 str_size = atom.
size;
496 if (
c->export_all && !
key) {
502 if (atom.
size < 0 || str_size >= INT_MAX/2)
507 num = (data_type >= 21 && data_type <= 23);
508 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
516 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
518 }
else if (data_type == 21) {
522 else if (str_size == 2)
524 else if (str_size == 3)
526 else if (str_size == 4)
528 if (
snprintf(str, str_size_alloc,
"%d",
val) >= str_size_alloc) {
530 "Failed to store the number (%d) in string.\n",
val);
534 }
else if (data_type == 22) {
535 unsigned int val = 0;
538 else if (str_size == 2)
540 else if (str_size == 3)
542 else if (str_size == 4)
544 if (
snprintf(str, str_size_alloc,
"%u",
val) >= str_size_alloc) {
546 "Failed to store the number (%u) in string.\n",
val);
550 }
else if (data_type == 23 && str_size >= 4) {
552 if (
snprintf(str, str_size_alloc,
"%f",
val) >= str_size_alloc) {
554 "Failed to store the float32 number (%f) in string.\n",
val);
558 }
else if (data_type > 1 && data_type != 4) {
580 if (!strcmp(
key,
"encoder")) {
581 int major, minor, micro;
582 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
583 c->handbrake_version = 1000000*major + 1000*minor + micro;
595 int i, nb_chapters, str_len,
version;
599 if (
c->ignore_chapters)
602 if ((atom.
size -= 5) < 0)
611 for (
i = 0;
i < nb_chapters;
i++) {
618 if ((atom.
size -= 9+str_len) < 0)
630 #define MIN_DATA_ENTRY_BOX_SIZE 12
637 if (
c->fc->nb_streams < 1)
639 st =
c->fc->streams[
c->fc->nb_streams-1];
646 entries >= UINT_MAX /
sizeof(*sc->
drefs))
661 for (
i = 0;
i < entries;
i++) {
666 if (
size < 12 || next < 0 || next > INT64_MAX -
size)
676 uint16_t volume_len,
len;
683 volume_len =
FFMIN(volume_len, 27);
687 dref->
volume[volume_len] = 0;
729 if (
len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
735 for (j =
len - 1; j >= 0; j--) {
736 if (dref->
path[j] == 0)
741 for (j = 0; j <
len; j++)
742 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
745 }
else if (
type == 0) {
757 for (j = 0; j <
len; j++)
758 if (dref->
dir[j] ==
':')
794 if (
c->trak_index < 0) {
796 c->found_hdlr_mdta = 1;
801 st =
c->fc->streams[
c->fc->nb_streams-1];
816 title_size = atom.
size - 24;
817 if (title_size > 0) {
818 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
829 title_str[title_size] = 0;
831 int off = (!
c->isom && title_str[0] == title_size - 1);
851 int ac3info, acmod, lfeon, bsmod;
854 if (
c->fc->nb_streams < 1)
856 st =
c->fc->streams[
c->fc->nb_streams-1];
867 bsmod = (ac3info >> 14) & 0x7;
868 acmod = (ac3info >> 11) & 0x7;
869 lfeon = (ac3info >> 10) & 0x1;
894 unsigned descriptors_size;
895 int nb_frames, disposition;
901 if (
c->fc->nb_streams < 1)
912 if (!descriptors_size || descriptors_size > INT_MAX)
915 st =
c->fc->streams[
c->fc->nb_streams - 1];
934 if (
ret != descriptors_size)
938 descriptor_pb = &
b.pub;
1035 for (
int j = 0; j <
mix->nb_submixes; j++) {
1042 for (
int l = 0; l <
c->fc->nb_stream_groups; l++)
1045 audio_element =
c->fc->stream_groups[l];
1050 for (
int l = 0; l < audio_element->
nb_streams; l++) {
1076 int eac3info, acmod, lfeon, bsmod;
1079 if (
c->fc->nb_streams < 1)
1081 st =
c->fc->streams[
c->fc->nb_streams-1];
1097 bsmod = (eac3info >> 12) & 0x1f;
1098 acmod = (eac3info >> 9) & 0x7;
1099 lfeon = (eac3info >> 8) & 0x1;
1116 #define DDTS_SIZE 20
1119 uint32_t frame_duration_code = 0;
1120 uint32_t channel_layout_code = 0;
1129 if (
c->fc->nb_streams < 1) {
1132 st =
c->fc->streams[
c->fc->nb_streams-1];
1142 frame_duration_code =
get_bits(&gb, 2);
1144 channel_layout_code =
get_bits(&gb, 16);
1147 (frame_duration_code == 0) ? 512 :
1148 (frame_duration_code == 1) ? 1024 :
1149 (frame_duration_code == 2) ? 2048 :
1150 (frame_duration_code == 3) ? 4096 : 0;
1152 if (channel_layout_code > 0xff) {
1171 if (
c->fc->nb_streams < 1)
1173 st =
c->fc->streams[
c->fc->nb_streams-1];
1193 if (
c->fc->nb_streams < 1)
1195 st =
c->fc->streams[
c->fc->nb_streams-1];
1201 "Unsupported 'chnl' box with version %d, flags: %#x",
1223 if (
c->fc->nb_streams < 1)
1225 st =
c->fc->streams[
c->fc->nb_streams-1];
1239 AVRational aperture_width, aperture_height, horiz_off, vert_off;
1241 uint64_t top, bottom,
left, right;
1269 if (aperture_width.
num < 0 || aperture_width.
den < 0 ||
1270 aperture_height.
num < 0 || aperture_height.
den < 0 ||
1271 horiz_off.
den < 0 || vert_off.
den < 0) {
1276 "horizOff %d/%d vertOff %d/%d\n",
1277 aperture_width.
num, aperture_width.
den, aperture_height.
num, aperture_height.
den,
1278 horiz_off.
num, horiz_off.
den, vert_off.
num, vert_off.
den);
1295 if (bottom > (
height - 1) ||
1296 right > (
width - 1)) {
1301 bottom =
height - 1 - bottom;
1302 right =
width - 1 - right;
1304 if (!(
left | right | top | bottom))
1308 (top + bottom) >=
height) {
1316 sizeof(uint32_t) * 4, 0);
1344 if (
c->fc->nb_streams < 1)
1346 st =
c->fc->streams[
c->fc->nb_streams-1];
1367 #define DRM_BLOB_SIZE 56
1371 uint8_t intermediate_key[20];
1372 uint8_t intermediate_iv[20];
1375 uint8_t file_checksum[20];
1376 uint8_t calculated_checksum[20];
1377 char checksum_string[2 *
sizeof(file_checksum) + 1];
1381 uint8_t *activation_bytes =
c->activation_bytes;
1382 uint8_t *fixed_key =
c->audible_fixed_key;
1391 if (!
c->aes_decrypt) {
1403 ff_data_to_hex(checksum_string, file_checksum,
sizeof(file_checksum), 1);
1407 if (!activation_bytes) {
1412 if (
c->activation_bytes_size != 4) {
1419 if (
c->audible_fixed_key_size != 16) {
1439 if (memcmp(calculated_checksum, file_checksum, 20)) {
1446 for (
i = 0;
i < 4;
i++) {
1448 if (activation_bytes[
i] !=
output[3 -
i]) {
1454 memcpy(
c->file_key,
output + 8, 16);
1470 if (
c->audible_key_size != 16) {
1475 if (
c->audible_iv_size != 16) {
1481 if (!
c->aes_decrypt) {
1485 memcpy(
c->file_key,
c->audible_key, 16);
1486 memcpy(
c->file_iv,
c->audible_iv, 16);
1496 unsigned char iv[16];
1498 memcpy(iv,
c->file_iv, 16);
1510 int comp_brand_size;
1511 char* comp_brands_str;
1512 uint8_t
type[5] = {0};
1516 if (
c->fc->nb_streams) {
1523 if (strcmp(
type,
"qt "))
1530 comp_brand_size = atom.
size - 8;
1531 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1533 comp_brands_str =
av_malloc(comp_brand_size + 1);
1534 if (!comp_brands_str)
1542 comp_brands_str[comp_brand_size] = 0;
1547 if (!strcmp(
type,
"aaxc")) {
1559 if (
c->found_moov) {
1581 if (index < 0 || index >= frag_index->
nb_items)
1597 if (frag_index->
current < 0 ||
1616 if (frag_index->
current < 0 ||
1644 if (moof_offset >=
offset)
1646 if (moof_offset <=
offset)
1674 if (!frag_stream_info)
1686 for (j = 0; j <
s->nb_streams; j++) {
1688 if (sc2->
id == frag_stream_info->
id)
1689 frag_stream =
s->streams[j];
1712 m0 = m = (
a +
b) >> 1;
1718 if (m <
b && frag_time <= timestamp)
1735 if (index < c->frag_index.nb_items &&
1742 &
c->frag_index.allocated_size,
1743 (
c->frag_index.nb_items + 1) *
1744 sizeof(*
c->frag_index.item));
1747 c->frag_index.item = item;
1751 if (!frag_stream_info)
1754 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1762 frag_stream_info[
i].
id = sc->
id;
1773 if (index < c->frag_index.nb_items)
1774 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1775 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1777 item = &
c->frag_index.item[
index];
1783 c->frag_index.nb_items++;
1789 int id,
int entries)
1798 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1806 c->fragment.found_tfhd = 0;
1808 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1809 c->has_looked_for_mfra = 1;
1816 "read the mfra (may be a live ismv)\n");
1820 "seekable, can not look for mfra\n");
1823 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1842 if (time > 0 && time < 2082844800) {
1850 if ((
int64_t)(time * 1000000ULL) / 1000000 != time) {
1867 if (
c->fc->nb_streams < 1)
1869 st =
c->fc->streams[
c->fc->nb_streams-1];
1913 if (
c->time_scale <= 0) {
1927 for (
i = 0;
i < 3;
i++) {
1948 if (
fc->nb_streams < 1)
1950 st =
fc->streams[
fc->nb_streams-1];
1975 int little_endian =
avio_rb16(pb) & 0xFF;
1977 if (little_endian == 1)
1986 int pcm_sample_size;
1991 if (atom.
size < 6) {
2001 "Unsupported 'pcmC' box with version %d, flags: %x",
2007 pcm_sample_size =
avio_r8(pb);
2009 if (
fc->nb_streams < 1)
2012 st =
fc->streams[
fc->nb_streams - 1];
2016 switch (pcm_sample_size) {
2030 switch (pcm_sample_size) {
2052 if (format_flags & 1)
2063 char color_parameter_type[5] = { 0 };
2077 if (strncmp(color_parameter_type,
"nclx", 4) &&
2078 strncmp(color_parameter_type,
"nclc", 4) &&
2079 strncmp(color_parameter_type,
"prof", 4)) {
2081 color_parameter_type);
2085 if (!strncmp(color_parameter_type,
"prof", 4)) {
2087 uint8_t *icc_profile;
2095 icc_profile = sd->
data;
2114 "%s: pri %d trc %d matrix %d",
2117 if (!strncmp(color_parameter_type,
"nclx", 4)) {
2144 unsigned mov_field_order;
2147 if (
c->fc->nb_streams < 1)
2149 st =
c->fc->streams[
c->fc->nb_streams-1];
2153 if ((mov_field_order & 0xFF00) == 0x0100)
2155 else if ((mov_field_order & 0xFF00) == 0x0200) {
2156 switch (mov_field_order & 0xFF) {
2179 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
2202 }
else if (err < atom.
size) {
2216 uint64_t original_size;
2219 if (
c->fc->nb_streams < 1)
2221 st =
c->fc->streams[
c->fc->nb_streams-1];
2270 if (!
ret &&
c->fc->nb_streams >= 1) {
2282 if (
c->fc->nb_streams >= 1) {
2283 AVStream *
const st =
c->fc->streams[
c->fc->nb_streams - 1];
2294 if (
cid == 0xd4d ||
cid == 0xd4e)
2305 if (num <= 0 || den <= 0)
2309 if (den >= INT_MAX / 2)
2327 uint64_t original_size;
2328 if (
c->fc->nb_streams >= 1) {
2332 if (atom.
size == 16) {
2337 if (length == atom.
size) {
2338 const uint8_t range_value = par->
extradata[original_size + 19];
2339 switch (range_value) {
2376 if (
c->fc->nb_streams < 1)
2378 st =
c->fc->streams[
c->fc->nb_streams-1];
2380 if ((uint64_t)atom.
size > (1<<30))
2390 }
else if (atom.
size > 8) {
2404 #define ALAC_EXTRADATA_SIZE 36
2437 if ((uint64_t)atom.
size > (1<<30))
2440 if (atom.
type ==
MKTAG(
'v',
'v',
'c',
'C')) {
2445 if (atom.
size >= 10) {
2477 uint8_t profile_level;
2480 if (
c->fc->nb_streams < 1)
2482 st =
c->fc->streams[
c->fc->nb_streams-1];
2484 if (atom.
size >= (1<<28) || atom.
size < 7)
2488 if ((profile_level & 0xf0) != 0xc0)
2504 if (
c->fc->nb_streams < 1)
2510 if (atom.
size > 4) {
2515 st =
c->fc->streams[
c->fc->nb_streams - 1];
2533 if (
c->fc->nb_streams < 1)
2535 if (atom.
size <= 40)
2537 st =
c->fc->streams[
c->fc->nb_streams-1];
2539 if ((uint64_t)atom.
size > (1<<30))
2554 unsigned int i, entries;
2556 if (
c->trak_index < 0) {
2560 if (
c->fc->nb_streams < 1)
2562 st =
c->fc->streams[
c->fc->nb_streams-1];
2574 (atom.
type ==
MKTAG(
's',
't',
'c',
'o') ? 4 : 8)));
2591 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2594 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2620 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2621 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2658 uint8_t codec_name[32] = { 0 };
2693 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2700 !strncmp(codec_name,
"Sorenson H263", 13))
2716 int bits_per_sample,
flags;
2741 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2872 if (str_size > 0 &&
size >= (
int)str_size + 30 &&
2874 char *reel_name =
av_malloc(str_size + 1);
2878 reel_name[str_size] = 0;
2903 #if CONFIG_DV_DEMUXER
2993 int codec_tag,
int format,
3005 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
3022 int pseudo_stream_id;
3025 st =
c->fc->streams[
c->fc->nb_streams-1];
3028 for (pseudo_stream_id = 0;
3030 pseudo_stream_id++) {
3033 int ret, dref_id = 1;
3043 }
else if (
size <= 7) {
3045 "invalid size %"PRId64
" in stsd\n",
size);
3062 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
3092 }
else if (
a.size > 0)
3121 if (
c->fc->nb_streams < 1)
3123 st =
c->fc->streams[
c->fc->nb_streams - 1];
3131 if (entries <= 0 || entries > atom.
size / 8 || entries > 1024) {
3138 "Duplicate stsd found in this track.\n");
3184 unsigned int i, entries;
3186 if (
c->trak_index < 0) {
3191 if (
c->fc->nb_streams < 1)
3193 st =
c->fc->streams[
c->fc->nb_streams-1];
3200 if ((uint64_t)entries * 12 + 4 > atom.
size)
3285 unsigned i, entries;
3287 if (
c->trak_index < 0) {
3292 if (
c->fc->nb_streams < 1)
3294 st =
c->fc->streams[
c->fc->nb_streams-1];
3327 unsigned int i, entries;
3329 if (
c->trak_index < 0) {
3334 if (
c->fc->nb_streams < 1)
3336 st =
c->fc->streams[
c->fc->nb_streams-1];
3355 if (entries >= UINT_MAX /
sizeof(
int))
3381 unsigned int i, entries, sample_size, field_size, num_bytes;
3386 if (
c->trak_index < 0) {
3391 if (
c->fc->nb_streams < 1)
3393 st =
c->fc->streams[
c->fc->nb_streams-1];
3399 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
3418 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
3435 num_bytes = (entries*field_size+4)>>3;
3453 for (
i = 0;
i < entries;
i++) {
3474 unsigned int i, entries;
3476 int64_t total_sample_count = 0;
3480 if (
c->trak_index < 0) {
3485 if (
c->fc->nb_streams < 1)
3487 st =
c->fc->streams[
c->fc->nb_streams-1];
3495 c->fc->nb_streams-1, entries);
3501 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
3505 unsigned int sample_duration;
3506 unsigned int sample_count;
3507 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
3525 sample_count, sample_duration);
3530 if (sample_duration >
c->max_stts_delta) {
3533 av_log(
c->fc,
AV_LOG_WARNING,
"Too large sample offset %u in stts entry %u with count %u in st:%d. Clipping to 1.\n",
3534 sample_duration,
i, sample_count, st->
index);
3536 corrected_dts += (delta_magnitude < 0 ? (
int64_t)delta_magnitude : 1) * sample_count;
3538 corrected_dts += sample_duration * (uint64_t)sample_count;
3543 if (current_dts > corrected_dts) {
3544 int64_t drift = (current_dts - corrected_dts)/
FFMAX(sample_count, 1);
3546 current_dts -= correction * (uint64_t)sample_count;
3557 duration <= INT64_MAX - sc->duration_for_fps &&
3558 total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
3580 "All samples in data stream index:id [%d:%d] have zero "
3581 "duration, stream set to be discarded by default. Override "
3582 "using AVStream->discard or -discard for ffmpeg command.\n",
3596 if (
c->fc->nb_streams < 1)
3598 st =
c->fc->streams[
c->fc->nb_streams - 1];
3603 entries = atom.
size - 4;
3606 c->fc->nb_streams - 1, entries);
3639 unsigned int i, entries, ctts_count = 0;
3641 if (
c->trak_index < 0) {
3646 if (
c->fc->nb_streams < 1)
3648 st =
c->fc->streams[
c->fc->nb_streams-1];
3659 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3668 const size_t min_size_needed = (ctts_count + 1) *
sizeof(
MOVCtts);
3669 const size_t requested_size =
3678 "ignoring CTTS entry with count=%d duration=%d\n",
3683 if (ctts_count >= UINT_MAX /
sizeof(
MOVCtts) - 1)
3728 uint32_t grouping_type;
3729 uint32_t default_length;
3730 av_unused uint32_t default_group_description_index;
3731 uint32_t entry_count;
3733 if (
c->fc->nb_streams < 1)
3735 st =
c->fc->streams[
c->fc->nb_streams - 1];
3746 if (grouping_type !=
MKTAG(
's',
'y',
'n',
'c'))
3760 uint32_t description_length = default_length;
3761 if (
version >= 1 && default_length == 0)
3763 if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3764 const uint8_t nal_unit_type =
avio_r8(pb) & 0x3f;
3766 description_length -= 1;
3783 unsigned int i, entries;
3785 uint32_t grouping_type;
3789 if (
c->fc->nb_streams < 1)
3791 st =
c->fc->streams[
c->fc->nb_streams-1];
3798 if (grouping_type ==
MKTAG(
'r',
'a',
'p',
' ')) {
3801 }
else if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3842 unsigned int edit_list_index,
3843 int64_t *edit_list_media_time,
3850 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3854 if (global_timescale == 0) {
3861 if (*edit_list_duration + (uint64_t)*edit_list_media_time > INT64_MAX)
3862 *edit_list_duration = 0;
3935 for (
int64_t index_tts_count = 0; index_tts_count < *
index; index_tts_count++) {
3936 if (*tts_index < tts_count) {
3938 if (tts_data[*tts_index].
count == *tts_sample) {
3945 while (*
index >= 0 && (*tts_index) >= 0 && (*tts_index) < tts_count) {
3949 if ((e_old[*
index].timestamp + tts_data[*tts_index].
offset) <= timestamp_pts &&
3955 if (*tts_sample == 0) {
3957 if (*tts_index >= 0)
3958 *tts_sample = tts_data[*tts_index].
count - 1;
3968 return *
index >= 0 ? 0 : -1;
3992 const size_t requested_size =
4009 ie= &entries[
index];
4024 int64_t* frame_duration_buffer,
4025 int frame_duration_buffer_size) {
4028 av_assert0(end_index >= 0 && end_index <= sti->nb_index_entries);
4029 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
4030 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
4039 const size_t min_size_needed = (*tts_count + 1) *
sizeof(
MOVTimeToSample);
4040 const size_t requested_size =
4041 min_size_needed > *allocated_size ?
4042 FFMAX(min_size_needed, 2 * (*allocated_size)) :
4048 tts_buf_new =
av_fast_realloc(*tts_data, allocated_size, requested_size);
4053 *tts_data = tts_buf_new;
4059 *tts_count = (*tts_count) + 1;
4063 #define MAX_REORDER_DELAY 16
4069 int ctts_sample = 0;
4072 int j,
r, num_swaps;
4075 pts_buf[j] = INT64_MIN;
4083 buf_start = (buf_start + 1);
4096 while (j != buf_start) {
4099 if (pts_buf[j] < pts_buf[
r]) {
4158 if (range_size > current_sample) {
4162 current_sample -= range_size;
4184 int64_t edit_list_media_time = 0;
4185 int64_t edit_list_duration = 0;
4187 int64_t edit_list_dts_counter = 0;
4188 int64_t edit_list_dts_entry_end = 0;
4189 int64_t edit_list_start_tts_sample = 0;
4192 int64_t empty_edits_sum_duration = 0;
4197 int64_t edit_list_start_encountered = 0;
4200 int num_discarded_begin = 0;
4201 int first_non_zero_audio_edit = -1;
4202 int packet_skip_samples = 0;
4204 int found_keyframe_after_edit = 0;
4205 int found_non_empty_edit = 0;
4238 edit_list_dts_entry_end -= msc->
dts_shift;
4242 start_dts = edit_list_dts_entry_end;
4246 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
4247 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
4249 edit_list_dts_counter = edit_list_dts_entry_end;
4250 edit_list_dts_entry_end += edit_list_duration;
4251 num_discarded_begin = 0;
4252 if (!found_non_empty_edit && edit_list_media_time == -1) {
4253 empty_edits_sum_duration += edit_list_duration;
4256 found_non_empty_edit = 1;
4261 if (first_non_zero_audio_edit < 0) {
4262 first_non_zero_audio_edit = 1;
4264 first_non_zero_audio_edit = 0;
4267 if (first_non_zero_audio_edit > 0)
4275 search_timestamp = edit_list_media_time;
4284 &
index, &tts_index_old, &tts_sample_old) < 0) {
4286 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
4287 st->
index, edit_list_index, search_timestamp);
4289 &
index, &tts_index_old, &tts_sample_old) < 0) {
4291 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
4292 st->
index, edit_list_index, search_timestamp);
4298 current = e_old +
index;
4299 edit_list_start_tts_sample = tts_sample_old;
4302 edit_list_start_encountered = 0;
4303 found_keyframe_after_edit = 0;
4304 for (; current < e_old_end; current++,
index++) {
4306 frame_duration = (current + 1 < e_old_end) ?
4307 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
4315 if (tts_data_old && tts_index_old < tts_count_old) {
4316 curr_ctts = tts_data_old[tts_index_old].
offset;
4317 av_log(mov->
fc,
AV_LOG_TRACE,
"stts: %"PRId64
" ctts: %"PRId64
", tts_index: %"PRId64
", tts_count: %"PRId64
"\n",
4318 curr_cts, curr_ctts, tts_index_old, tts_count_old);
4319 curr_cts += curr_ctts;
4321 if (tts_sample_old == tts_data_old[tts_index_old].
count) {
4324 tts_data_old[tts_index_old].
count - edit_list_start_tts_sample,
4325 tts_data_old[tts_index_old].
offset, tts_data_old[tts_index_old].
duration) == -1) {
4328 tts_data_old[tts_index_old].
count - edit_list_start_tts_sample,
4329 tts_data_old[tts_index_old].
offset);
4334 edit_list_start_tts_sample = 0;
4338 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
4340 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
4341 first_non_zero_audio_edit > 0) {
4342 packet_skip_samples = edit_list_media_time - curr_cts;
4346 edit_list_dts_counter -= packet_skip_samples;
4347 if (edit_list_start_encountered == 0) {
4348 edit_list_start_encountered = 1;
4351 if (frame_duration_buffer) {
4353 frame_duration_buffer, num_discarded_begin);
4358 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
4363 if (edit_list_start_encountered == 0) {
4364 num_discarded_begin++;
4365 frame_duration_buffer =
av_realloc(frame_duration_buffer,
4366 num_discarded_begin *
sizeof(
int64_t));
4367 if (!frame_duration_buffer) {
4371 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
4386 if (edit_list_start_encountered == 0) {
4387 edit_list_start_encountered = 1;
4390 if (frame_duration_buffer) {
4392 frame_duration_buffer, num_discarded_begin);
4405 if (!current_index_range ||
index != current_index_range->
end) {
4406 current_index_range = current_index_range ? current_index_range + 1
4410 current_index_range->
end =
index + 1;
4413 if (edit_list_start_encountered > 0) {
4414 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
4418 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
4425 found_keyframe_after_edit = 1;
4428 if (tts_sample_old != 0) {
4431 tts_sample_old - edit_list_start_tts_sample,
4432 tts_data_old[tts_index_old].
offset, tts_data_old[tts_index_old].
duration) == -1) {
4434 tts_index_old, tts_sample_old - edit_list_start_tts_sample,
4435 tts_data_old[tts_index_old].
offset);
4470 current_index_range = current_index_range ? current_index_range + 1
4472 current_index_range->
start = 0;
4473 current_index_range->
end = 0;