26 #include "config_components.h"
93 unsigned len,
const char *
key)
97 short current, total = 0;
103 snprintf(buf,
sizeof(buf),
"%d", current);
105 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
113 unsigned len,
const char *
key)
127 unsigned len,
const char *
key)
136 unsigned len,
const char *
key)
152 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
153 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
154 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
155 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
156 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
157 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
158 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
159 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
160 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
161 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
162 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
163 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
164 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
165 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
166 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
167 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
171 char *
dst,
int dstlen)
174 char *end =
dst+dstlen-1;
177 for (
i = 0;
i <
len;
i++) {
199 for (
int i = 0;
i <
c->nb_heif_item;
i++) {
200 if (
c->heif_item[
i].item_id !=
c->cur_item_id)
203 item = &
c->heif_item[
i];
219 if (
c->fc->nb_streams < 1)
222 if (
c->cur_item_id == -1)
223 return c->fc->streams[
c->fc->nb_streams-1];
257 st =
c->fc->streams[
c->fc->nb_streams - 1];
278 char buf[200], place[100];
279 uint16_t langcode = 0;
280 double longitude, latitude, altitude;
281 const char *
key =
"location";
283 if (
len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
303 "loci too short (%u bytes left, need at least %d)\n",
len, 12);
311 snprintf(buf,
sizeof(buf),
"%+08.4f%+09.4f", latitude, longitude);
331 if (
c->ignore_chapters)
335 if (n_hmmt >
len / 4)
352 uint16_t langcode = 0;
353 uint32_t data_type = 0, str_size_alloc;
360 case MKTAG(
'@',
'P',
'R',
'M'):
key =
"premiere_version"; raw = 1;
break;
361 case MKTAG(
'@',
'P',
'R',
'Q'):
key =
"quicktime_version"; raw = 1;
break;
362 case MKTAG(
'X',
'M',
'P',
'_'):
363 if (
c->export_xmp) {
key =
"xmp"; raw = 1; }
break;
364 case MKTAG(
'a',
'A',
'R',
'T'):
key =
"album_artist";
break;
365 case MKTAG(
'a',
'k',
'I',
'D'):
key =
"account_type";
367 case MKTAG(
'a',
'p',
'I',
'D'):
key =
"account_id";
break;
368 case MKTAG(
'c',
'a',
't',
'g'):
key =
"category";
break;
369 case MKTAG(
'c',
'p',
'i',
'l'):
key =
"compilation";
371 case MKTAG(
'c',
'p',
'r',
't'):
key =
"copyright";
break;
372 case MKTAG(
'd',
'e',
's',
'c'):
key =
"description";
break;
373 case MKTAG(
'd',
'i',
's',
'k'):
key =
"disc";
375 case MKTAG(
'e',
'g',
'i',
'd'):
key =
"episode_uid";
377 case MKTAG(
'F',
'I',
'R',
'M'):
key =
"firmware"; raw = 1;
break;
378 case MKTAG(
'g',
'n',
'r',
'e'):
key =
"genre";
380 case MKTAG(
'h',
'd',
'v',
'd'):
key =
"hd_video";
382 case MKTAG(
'H',
'M',
'M',
'T'):
384 case MKTAG(
'k',
'e',
'y',
'w'):
key =
"keywords";
break;
385 case MKTAG(
'l',
'd',
'e',
's'):
key =
"synopsis";
break;
386 case MKTAG(
'l',
'o',
'c',
'i'):
388 case MKTAG(
'm',
'a',
'n',
'u'):
key =
"make";
break;
389 case MKTAG(
'm',
'o',
'd',
'l'):
key =
"model";
break;
390 case MKTAG(
'p',
'c',
's',
't'):
key =
"podcast";
392 case MKTAG(
'p',
'g',
'a',
'p'):
key =
"gapless_playback";
394 case MKTAG(
'p',
'u',
'r',
'd'):
key =
"purchase_date";
break;
395 case MKTAG(
'r',
't',
'n',
'g'):
key =
"rating";
397 case MKTAG(
's',
'o',
'a',
'a'):
key =
"sort_album_artist";
break;
398 case MKTAG(
's',
'o',
'a',
'l'):
key =
"sort_album";
break;
399 case MKTAG(
's',
'o',
'a',
'r'):
key =
"sort_artist";
break;
400 case MKTAG(
's',
'o',
'c',
'o'):
key =
"sort_composer";
break;
401 case MKTAG(
's',
'o',
'n',
'm'):
key =
"sort_name";
break;
402 case MKTAG(
's',
'o',
's',
'n'):
key =
"sort_show";
break;
403 case MKTAG(
's',
't',
'i',
'k'):
key =
"media_type";
405 case MKTAG(
't',
'r',
'k',
'n'):
key =
"track";
407 case MKTAG(
't',
'v',
'e',
'n'):
key =
"episode_id";
break;
408 case MKTAG(
't',
'v',
'e',
's'):
key =
"episode_sort";
410 case MKTAG(
't',
'v',
'n',
'n'):
key =
"network";
break;
411 case MKTAG(
't',
'v',
's',
'h'):
key =
"show";
break;
412 case MKTAG(
't',
'v',
's',
'n'):
key =
"season_number";
414 case MKTAG(0xa9,
'A',
'R',
'T'):
key =
"artist";
break;
415 case MKTAG(0xa9,
'P',
'R',
'D'):
key =
"producer";
break;
416 case MKTAG(0xa9,
'a',
'l',
'b'):
key =
"album";
break;
417 case MKTAG(0xa9,
'a',
'u',
't'):
key =
"artist";
break;
418 case MKTAG(0xa9,
'c',
'h',
'p'):
key =
"chapter";
break;
419 case MKTAG(0xa9,
'c',
'm',
't'):
key =
"comment";
break;
420 case MKTAG(0xa9,
'c',
'o',
'm'):
key =
"composer";
break;
421 case MKTAG(0xa9,
'c',
'p',
'y'):
key =
"copyright";
break;
422 case MKTAG(0xa9,
'd',
'a',
'y'):
key =
"date";
break;
423 case MKTAG(0xa9,
'd',
'i',
'r'):
key =
"director";
break;
424 case MKTAG(0xa9,
'd',
'i',
's'):
key =
"disclaimer";
break;
425 case MKTAG(0xa9,
'e',
'd',
'1'):
key =
"edit_date";
break;
426 case MKTAG(0xa9,
'e',
'n',
'c'):
key =
"encoder";
break;
427 case MKTAG(0xa9,
'f',
'm',
't'):
key =
"original_format";
break;
428 case MKTAG(0xa9,
'g',
'e',
'n'):
key =
"genre";
break;
429 case MKTAG(0xa9,
'g',
'r',
'p'):
key =
"grouping";
break;
430 case MKTAG(0xa9,
'h',
's',
't'):
key =
"host_computer";
break;
431 case MKTAG(0xa9,
'i',
'n',
'f'):
key =
"comment";
break;
432 case MKTAG(0xa9,
'l',
'y',
'r'):
key =
"lyrics";
break;
433 case MKTAG(0xa9,
'm',
'a',
'k'):
key =
"make";
break;
434 case MKTAG(0xa9,
'm',
'o',
'd'):
key =
"model";
break;
435 case MKTAG(0xa9,
'n',
'a',
'm'):
key =
"title";
break;
436 case MKTAG(0xa9,
'o',
'p',
'e'):
key =
"original_artist";
break;
437 case MKTAG(0xa9,
'p',
'r',
'd'):
key =
"producer";
break;
438 case MKTAG(0xa9,
'p',
'r',
'f'):
key =
"performers";
break;
439 case MKTAG(0xa9,
'r',
'e',
'q'):
key =
"playback_requirements";
break;
440 case MKTAG(0xa9,
's',
'r',
'c'):
key =
"original_source";
break;
441 case MKTAG(0xa9,
's',
't',
'3'):
key =
"subtitle";
break;
442 case MKTAG(0xa9,
's',
'w',
'r'):
key =
"encoder";
break;
443 case MKTAG(0xa9,
't',
'o',
'o'):
key =
"encoder";
break;
444 case MKTAG(0xa9,
't',
'r',
'k'):
key =
"track";
break;
445 case MKTAG(0xa9,
'u',
'r',
'l'):
key =
"URL";
break;
446 case MKTAG(0xa9,
'w',
'r',
'n'):
key =
"warning";
break;
447 case MKTAG(0xa9,
'w',
'r',
't'):
key =
"composer";
break;
448 case MKTAG(0xa9,
'x',
'y',
'z'):
key =
"location";
break;
451 if (
c->itunes_metadata && atom.
size > 8) {
454 if (
tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
457 str_size = data_size - 16;
460 if (!
key &&
c->found_hdlr_mdta &&
c->meta_keys) {
462 if (index < c->meta_keys_count &&
index > 0) {
464 }
else if (atom.
type !=
MKTAG(
'c',
'o',
'v',
'r')) {
466 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
467 index,
c->meta_keys_count);
470 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r') ||
471 (
key && !strcmp(
key,
"com.apple.quicktime.artwork"))) {
477 atom.
size -= str_size;
483 }
else if (atom.
size > 4 &&
key && !
c->itunes_metadata && !raw) {
485 if (str_size > atom.
size) {
495 str_size = atom.
size;
497 if (
c->export_all && !
key) {
503 if (atom.
size < 0 || str_size >= INT_MAX/2)
508 num = (data_type >= 21 && data_type <= 23);
509 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
517 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
519 }
else if (data_type == 21) {
523 else if (str_size == 2)
525 else if (str_size == 3)
527 else if (str_size == 4)
529 if (
snprintf(str, str_size_alloc,
"%d",
val) >= str_size_alloc) {
531 "Failed to store the number (%d) in string.\n",
val);
535 }
else if (data_type == 22) {
536 unsigned int val = 0;
539 else if (str_size == 2)
541 else if (str_size == 3)
543 else if (str_size == 4)
545 if (
snprintf(str, str_size_alloc,
"%u",
val) >= str_size_alloc) {
547 "Failed to store the number (%u) in string.\n",
val);
551 }
else if (data_type == 23 && str_size >= 4) {
553 if (
snprintf(str, str_size_alloc,
"%f",
val) >= str_size_alloc) {
555 "Failed to store the float32 number (%f) in string.\n",
val);
559 }
else if (data_type > 1 && data_type != 4) {
581 if (!strcmp(
key,
"encoder")) {
582 int major, minor, micro;
583 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
584 c->handbrake_version = 1000000*major + 1000*minor + micro;
596 int i, nb_chapters, str_len,
version;
600 if (
c->ignore_chapters)
603 if ((atom.
size -= 5) < 0)
612 for (
i = 0;
i < nb_chapters;
i++) {
619 if ((atom.
size -= 9+str_len) < 0)
631 #define MIN_DATA_ENTRY_BOX_SIZE 12
638 if (
c->fc->nb_streams < 1)
640 st =
c->fc->streams[
c->fc->nb_streams-1];
647 entries >= UINT_MAX /
sizeof(*sc->
drefs))
662 for (
i = 0;
i < entries;
i++) {
667 if (
size < 12 || next < 0 || next > INT64_MAX -
size)
677 uint16_t volume_len,
len;
684 volume_len =
FFMIN(volume_len, 27);
688 dref->
volume[volume_len] = 0;
730 if (
len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
736 for (j =
len - 1; j >= 0; j--) {
737 if (dref->
path[j] == 0)
742 for (j = 0; j <
len; j++)
743 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
746 }
else if (
type == 0) {
758 for (j = 0; j <
len; j++)
759 if (dref->
dir[j] ==
':')
795 if (
c->trak_index < 0) {
797 c->found_hdlr_mdta = 1;
802 st =
c->fc->streams[
c->fc->nb_streams-1];
817 title_size = atom.
size - 24;
818 if (title_size > 0) {
819 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
830 title_str[title_size] = 0;
832 int off = (!
c->isom && title_str[0] == title_size - 1);
852 int ac3info, acmod, lfeon, bsmod;
855 if (
c->fc->nb_streams < 1)
857 st =
c->fc->streams[
c->fc->nb_streams-1];
868 bsmod = (ac3info >> 14) & 0x7;
869 acmod = (ac3info >> 11) & 0x7;
870 lfeon = (ac3info >> 10) & 0x1;
895 unsigned descriptors_size;
896 int nb_frames, disposition;
902 if (
c->fc->nb_streams < 1)
913 if (!descriptors_size || descriptors_size > INT_MAX)
916 st =
c->fc->streams[
c->fc->nb_streams - 1];
935 if (
ret != descriptors_size)
939 descriptor_pb = &
b.pub;
1036 for (
int j = 0; j <
mix->nb_submixes; j++) {
1043 for (
int l = 0; l <
c->fc->nb_stream_groups; l++)
1046 audio_element =
c->fc->stream_groups[l];
1051 for (
int l = 0; l < audio_element->
nb_streams; l++) {
1077 int eac3info, acmod, lfeon, bsmod;
1080 if (
c->fc->nb_streams < 1)
1082 st =
c->fc->streams[
c->fc->nb_streams-1];
1098 bsmod = (eac3info >> 12) & 0x1f;
1099 acmod = (eac3info >> 9) & 0x7;
1100 lfeon = (eac3info >> 8) & 0x1;
1117 #define DDTS_SIZE 20
1120 uint32_t frame_duration_code = 0;
1121 uint32_t channel_layout_code = 0;
1130 if (
c->fc->nb_streams < 1) {
1133 st =
c->fc->streams[
c->fc->nb_streams-1];
1143 frame_duration_code =
get_bits(&gb, 2);
1145 channel_layout_code =
get_bits(&gb, 16);
1148 (frame_duration_code == 0) ? 512 :
1149 (frame_duration_code == 1) ? 1024 :
1150 (frame_duration_code == 2) ? 2048 :
1151 (frame_duration_code == 3) ? 4096 : 0;
1153 if (channel_layout_code > 0xff) {
1172 if (
c->fc->nb_streams < 1)
1174 st =
c->fc->streams[
c->fc->nb_streams-1];
1194 if (
c->fc->nb_streams < 1)
1196 st =
c->fc->streams[
c->fc->nb_streams-1];
1202 "Unsupported 'chnl' box with version %d, flags: %#x",
1224 if (
c->fc->nb_streams < 1)
1226 st =
c->fc->streams[
c->fc->nb_streams-1];
1240 AVRational aperture_width, aperture_height, horiz_off, vert_off;
1242 uint64_t top, bottom,
left, right;
1270 if (aperture_width.
num < 0 || aperture_width.
den < 0 ||
1271 aperture_height.
num < 0 || aperture_height.
den < 0 ||
1272 horiz_off.
den < 0 || vert_off.
den < 0) {
1277 "horizOff %d/%d vertOff %d/%d\n",
1278 aperture_width.
num, aperture_width.
den, aperture_height.
num, aperture_height.
den,
1279 horiz_off.
num, horiz_off.
den, vert_off.
num, vert_off.
den);
1296 if (bottom > (
height - 1) ||
1297 right > (
width - 1)) {
1302 bottom =
height - 1 - bottom;
1303 right =
width - 1 - right;
1305 if (!(
left | right | top | bottom))
1309 (top + bottom) >=
height) {
1317 sizeof(uint32_t) * 4, 0);
1345 if (
c->fc->nb_streams < 1)
1347 st =
c->fc->streams[
c->fc->nb_streams-1];
1368 #define DRM_BLOB_SIZE 56
1372 uint8_t intermediate_key[20];
1373 uint8_t intermediate_iv[20];
1376 uint8_t file_checksum[20];
1377 uint8_t calculated_checksum[20];
1378 char checksum_string[2 *
sizeof(file_checksum) + 1];
1382 uint8_t *activation_bytes =
c->activation_bytes;
1383 uint8_t *fixed_key =
c->audible_fixed_key;
1392 if (!
c->aes_decrypt) {
1404 ff_data_to_hex(checksum_string, file_checksum,
sizeof(file_checksum), 1);
1408 if (!activation_bytes) {
1413 if (
c->activation_bytes_size != 4) {
1420 if (
c->audible_fixed_key_size != 16) {
1440 if (memcmp(calculated_checksum, file_checksum, 20)) {
1447 for (
i = 0;
i < 4;
i++) {
1449 if (activation_bytes[
i] !=
output[3 -
i]) {
1455 memcpy(
c->file_key,
output + 8, 16);
1471 if (
c->audible_key_size != 16) {
1476 if (
c->audible_iv_size != 16) {
1482 if (!
c->aes_decrypt) {
1486 memcpy(
c->file_key,
c->audible_key, 16);
1487 memcpy(
c->file_iv,
c->audible_iv, 16);
1497 unsigned char iv[16];
1499 memcpy(iv,
c->file_iv, 16);
1511 int comp_brand_size;
1512 char* comp_brands_str;
1513 uint8_t
type[5] = {0};
1517 if (
c->fc->nb_streams) {
1524 if (strcmp(
type,
"qt "))
1531 comp_brand_size = atom.
size - 8;
1532 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1534 comp_brands_str =
av_malloc(comp_brand_size + 1);
1535 if (!comp_brands_str)
1543 comp_brands_str[comp_brand_size] = 0;
1548 if (!strcmp(
type,
"aaxc")) {
1560 if (
c->found_moov) {
1582 if (index < 0 || index >= frag_index->
nb_items)
1598 if (frag_index->
current < 0 ||
1617 if (frag_index->
current < 0 ||
1645 if (moof_offset >=
offset)
1647 if (moof_offset <=
offset)
1685 for (j = 0; j <
s->nb_streams; j++) {
1687 if (sc2->
id == frag_stream_info->
id)
1688 frag_stream =
s->streams[j];
1711 m0 = m = (
a +
b) >> 1;
1717 if (m <
b && frag_time <= timestamp)
1734 if (index < c->frag_index.nb_items &&
1741 &
c->frag_index.allocated_size,
1742 (
c->frag_index.nb_items + 1) *
1743 sizeof(*
c->frag_index.item));
1746 c->frag_index.item = item;
1750 if (!frag_stream_info)
1753 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1761 frag_stream_info[
i].
id = sc->
id;
1772 if (index < c->frag_index.nb_items)
1773 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1774 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1776 item = &
c->frag_index.item[
index];
1782 c->frag_index.nb_items++;
1788 int id,
int entries)
1797 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1805 c->fragment.found_tfhd = 0;
1807 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1808 c->has_looked_for_mfra = 1;
1815 "read the mfra (may be a live ismv)\n");
1819 "seekable, can not look for mfra\n");
1822 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1841 if (time > 0 && time < 2082844800) {
1849 if ((
int64_t)(time * 1000000ULL) / 1000000 != time) {
1866 if (
c->fc->nb_streams < 1)
1868 st =
c->fc->streams[
c->fc->nb_streams-1];
1912 if (
c->time_scale <= 0) {
1926 for (
i = 0;
i < 3;
i++) {
1947 if (
fc->nb_streams < 1)
1949 st =
fc->streams[
fc->nb_streams-1];
1974 int little_endian =
avio_rb16(pb) & 0xFF;
1976 if (little_endian == 1)
1985 int pcm_sample_size;
1990 if (atom.
size < 6) {
2000 "Unsupported 'pcmC' box with version %d, flags: %x",
2006 pcm_sample_size =
avio_r8(pb);
2008 if (
fc->nb_streams < 1)
2011 st =
fc->streams[
fc->nb_streams - 1];
2015 switch (pcm_sample_size) {
2029 switch (pcm_sample_size) {
2051 if (format_flags & 1)
2062 char color_parameter_type[5] = { 0 };
2076 if (strncmp(color_parameter_type,
"nclx", 4) &&
2077 strncmp(color_parameter_type,
"nclc", 4) &&
2078 strncmp(color_parameter_type,
"prof", 4)) {
2080 color_parameter_type);
2084 if (!strncmp(color_parameter_type,
"prof", 4)) {
2086 uint8_t *icc_profile;
2094 icc_profile = sd->
data;
2113 "%s: pri %d trc %d matrix %d",
2116 if (!strncmp(color_parameter_type,
"nclx", 4)) {
2143 unsigned mov_field_order;
2146 if (
c->fc->nb_streams < 1)
2148 st =
c->fc->streams[
c->fc->nb_streams-1];
2152 if ((mov_field_order & 0xFF00) == 0x0100)
2154 else if ((mov_field_order & 0xFF00) == 0x0200) {
2155 switch (mov_field_order & 0xFF) {
2178 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
2201 }
else if (err < atom.
size) {
2215 uint64_t original_size;
2218 if (
c->fc->nb_streams < 1)
2220 st =
c->fc->streams[
c->fc->nb_streams-1];
2269 if (!
ret &&
c->fc->nb_streams >= 1) {
2281 if (
c->fc->nb_streams >= 1) {
2282 AVStream *
const st =
c->fc->streams[
c->fc->nb_streams - 1];
2293 if (
cid == 0xd4d ||
cid == 0xd4e)
2304 if (num <= 0 || den <= 0)
2308 if (den >= INT_MAX / 2)
2326 uint64_t original_size;
2327 if (
c->fc->nb_streams >= 1) {
2331 if (atom.
size == 16) {
2336 if (length == atom.
size) {
2337 const uint8_t range_value = par->
extradata[original_size + 19];
2338 switch (range_value) {
2375 if (
c->fc->nb_streams < 1)
2377 st =
c->fc->streams[
c->fc->nb_streams-1];
2379 if ((uint64_t)atom.
size > (1<<30))
2389 }
else if (atom.
size > 8) {
2403 #define ALAC_EXTRADATA_SIZE 36
2436 if ((uint64_t)atom.
size > (1<<30))
2439 if (atom.
type ==
MKTAG(
'v',
'v',
'c',
'C')) {
2444 if (atom.
size >= 10) {
2476 uint8_t profile_level;
2479 if (
c->fc->nb_streams < 1)
2481 st =
c->fc->streams[
c->fc->nb_streams-1];
2483 if (atom.
size >= (1<<28) || atom.
size < 7)
2487 if ((profile_level & 0xf0) != 0xc0)
2503 if (
c->fc->nb_streams < 1)
2509 if (atom.
size > 4) {
2514 st =
c->fc->streams[
c->fc->nb_streams - 1];
2532 if (
c->fc->nb_streams < 1)
2534 if (atom.
size <= 40)
2536 st =
c->fc->streams[
c->fc->nb_streams-1];
2538 if ((uint64_t)atom.
size > (1<<30))
2553 unsigned int i, entries;
2555 if (
c->trak_index < 0) {
2559 if (
c->fc->nb_streams < 1)
2561 st =
c->fc->streams[
c->fc->nb_streams-1];
2573 (atom.
type ==
MKTAG(
's',
't',
'c',
'o') ? 4 : 8)));
2590 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2593 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2619 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2620 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2657 uint8_t codec_name[32] = { 0 };
2692 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2699 !strncmp(codec_name,
"Sorenson H263", 13))
2715 int bits_per_sample,
flags;
2740 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2850 y = (ycbcr >> 16) & 0xFF;
2851 cr = (ycbcr >> 8) & 0xFF;
2858 return (
r << 16) | (
g << 8) |
b;
2863 char buf[256] = {0};
2871 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2875 for (
i = 0;
i < 16;
i++) {
2879 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba,
i != 15 ?
", " :
"");
2882 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2919 if (str_size > 0 &&
size >= (
int)str_size + 30 &&
2921 char *reel_name =
av_malloc(str_size + 1);
2925 reel_name[str_size] = 0;
2950 #if CONFIG_DV_DEMUXER
3040 int codec_tag,
int format,
3052 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
3069 int pseudo_stream_id;
3072 st =
c->fc->streams[
c->fc->nb_streams-1];
3075 for (pseudo_stream_id = 0;
3077 pseudo_stream_id++) {
3080 int ret, dref_id = 1;
3090 }
else if (
size <= 7) {
3092 "invalid size %"PRId64
" in stsd\n",
size);
3109 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
3139 }
else if (
a.size > 0)
3168 if (
c->fc->nb_streams < 1)
3170 st =
c->fc->streams[
c->fc->nb_streams - 1];
3178 if (entries <= 0 || entries > atom.
size / 8 || entries > 1024) {
3185 "Duplicate stsd found in this track.\n");
3231 unsigned int i, entries;
3233 if (
c->trak_index < 0) {
3238 if (
c->fc->nb_streams < 1)
3240 st =
c->fc->streams[
c->fc->nb_streams-1];
3247 if ((uint64_t)entries * 12 + 4 > atom.
size)
3332 unsigned i, entries;
3334 if (
c->trak_index < 0) {
3339 if (
c->fc->nb_streams < 1)
3341 st =
c->fc->streams[
c->fc->nb_streams-1];
3374 unsigned int i, entries;
3376 if (
c->trak_index < 0) {
3381 if (
c->fc->nb_streams < 1)
3383 st =
c->fc->streams[
c->fc->nb_streams-1];
3402 if (entries >= UINT_MAX /
sizeof(
int))
3428 unsigned int i, entries, sample_size, field_size, num_bytes;
3433 if (
c->trak_index < 0) {
3438 if (
c->fc->nb_streams < 1)
3440 st =
c->fc->streams[
c->fc->nb_streams-1];
3446 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
3465 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
3482 num_bytes = (entries*field_size+4)>>3;
3500 for (
i = 0;
i < entries;
i++) {
3521 unsigned int i, entries, alloc_size = 0;
3523 int64_t total_sample_count = 0;
3527 if (
c->trak_index < 0) {
3532 if (
c->fc->nb_streams < 1)
3534 st =
c->fc->streams[
c->fc->nb_streams-1];
3542 c->fc->nb_streams-1, entries);
3548 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
3552 unsigned int sample_duration;
3553 unsigned int sample_count;
3554 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
3572 sample_count, sample_duration);
3577 if (sample_duration >
c->max_stts_delta) {
3580 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",
3581 sample_duration,
i, sample_count, st->
index);
3583 corrected_dts += (delta_magnitude < 0 ? (
int64_t)delta_magnitude : 1) * sample_count;
3585 corrected_dts += sample_duration * (uint64_t)sample_count;
3590 if (current_dts > corrected_dts) {
3591 int64_t drift = (current_dts - corrected_dts)/
FFMAX(sample_count, 1);
3593 current_dts -= correction * (uint64_t)sample_count;
3604 duration <= INT64_MAX - sc->duration_for_fps &&
3605 total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
3627 "All samples in data stream index:id [%d:%d] have zero "
3628 "duration, stream set to be discarded by default. Override "
3629 "using AVStream->discard or -discard for ffmpeg command.\n",
3643 if (
c->fc->nb_streams < 1)
3645 st =
c->fc->streams[
c->fc->nb_streams - 1];
3650 entries = atom.
size - 4;
3653 c->fc->nb_streams - 1, entries);
3686 unsigned int i, entries, ctts_count = 0;
3688 if (
c->trak_index < 0) {
3693 if (
c->fc->nb_streams < 1)
3695 st =
c->fc->streams[
c->fc->nb_streams-1];
3706 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3719 "ignoring CTTS entry with count=%d duration=%d\n",
3758 uint32_t grouping_type;
3759 uint32_t default_length;
3760 av_unused uint32_t default_group_description_index;
3761 uint32_t entry_count;
3763 if (
c->fc->nb_streams < 1)
3765 st =
c->fc->streams[
c->fc->nb_streams - 1];
3776 if (grouping_type !=
MKTAG(
's',
'y',
'n',
'c'))
3790 uint32_t description_length = default_length;
3791 if (
version >= 1 && default_length == 0)
3793 if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3794 const uint8_t nal_unit_type =
avio_r8(pb) & 0x3f;
3796 description_length -= 1;
3813 unsigned int i, entries;
3815 uint32_t grouping_type;
3819 if (
c->fc->nb_streams < 1)
3821 st =
c->fc->streams[
c->fc->nb_streams-1];
3828 if (grouping_type ==
MKTAG(
'r',
'a',
'p',
' ')) {
3831 }
else if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3872 unsigned int edit_list_index,
3873 int64_t *edit_list_media_time,
3880 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3884 if (global_timescale == 0) {
3891 if (*edit_list_duration + (uint64_t)*edit_list_media_time > INT64_MAX)
3892 *edit_list_duration = 0;
3960 if (ctts_data && *
index >= 0) {
3966 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3967 if (*ctts_index < ctts_count) {
3969 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3976 while (*
index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3980 if ((e_old[*
index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3986 if (*ctts_sample == 0) {
3988 if (*ctts_index >= 0)
3989 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3999 return *
index >= 0 ? 0 : -1;
4023 const size_t requested_size =
4040 ie= &entries[
index];
4055 int64_t* frame_duration_buffer,
4056 int frame_duration_buffer_size) {
4059 av_assert0(end_index >= 0 && end_index <= sti->nb_index_entries);
4060 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
4061 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
4074 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVCtts);
4075 const size_t requested_size =
4076 min_size_needed > *allocated_size ?
4077 FFMAX(min_size_needed, 2 * (*allocated_size)) :
4080 if ((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVCtts) - 1)
4083 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
4088 *ctts_data = ctts_buf_new;
4093 *ctts_count = (*ctts_count) + 1;
4097 #define MAX_REORDER_DELAY 16
4103 int ctts_sample = 0;
4106 int j,
r, num_swaps;
4109 pts_buf[j] = INT64_MIN;
4117 buf_start = (buf_start + 1);
4130 while (j != buf_start) {
4133 if (pts_buf[j] < pts_buf[
r]) {
4192 if (range_size > current_sample) {
4196 current_sample -= range_size;
4218 int64_t edit_list_media_time = 0;
4219 int64_t edit_list_duration = 0;
4221 int64_t edit_list_dts_counter = 0;
4222 int64_t edit_list_dts_entry_end = 0;
4223 int64_t edit_list_start_ctts_sample = 0;
4226 int64_t empty_edits_sum_duration = 0;
4231 int64_t edit_list_start_encountered = 0;
4234 int num_discarded_begin = 0;
4235 int first_non_zero_audio_edit = -1;
4236 int packet_skip_samples = 0;
4238 int found_keyframe_after_edit = 0;
4239 int found_non_empty_edit = 0;
4272 edit_list_dts_entry_end -= msc->
dts_shift;
4276 start_dts = edit_list_dts_entry_end;
4280 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
4281 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
4283 edit_list_dts_counter = edit_list_dts_entry_end;
4284 edit_list_dts_entry_end += edit_list_duration;
4285 num_discarded_begin = 0;
4286 if (!found_non_empty_edit && edit_list_media_time == -1) {
4287 empty_edits_sum_duration += edit_list_duration;
4290 found_non_empty_edit = 1;
4295 if (first_non_zero_audio_edit < 0) {
4296 first_non_zero_audio_edit = 1;
4298 first_non_zero_audio_edit = 0;
4301 if (first_non_zero_audio_edit > 0)
4309 search_timestamp = edit_list_media_time;
4318 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
4320 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
4321 st->
index, edit_list_index, search_timestamp);
4323 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
4325 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
4326 st->
index, edit_list_index, search_timestamp);
4329 ctts_sample_old = 0;
4332 current = e_old +
index;
4333 edit_list_start_ctts_sample = ctts_sample_old;
4336 edit_list_start_encountered = 0;
4337 found_keyframe_after_edit = 0;
4338 for (; current < e_old_end; current++,
index++) {
4340 frame_duration = (current + 1 < e_old_end) ?
4341 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
4349 if (ctts_data_old && ctts_index_old < ctts_count_old) {
4350 curr_ctts = ctts_data_old[ctts_index_old].
duration;
4351 av_log(mov->
fc,
AV_LOG_TRACE,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
4352 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
4353 curr_cts += curr_ctts;
4355 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
4358 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
4359 ctts_data_old[ctts_index_old].
duration) == -1) {
4362 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
4363 ctts_data_old[ctts_index_old].
duration);
4367 ctts_sample_old = 0;
4368 edit_list_start_ctts_sample = 0;
4372 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
4374 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
4375 first_non_zero_audio_edit > 0) {
4376 packet_skip_samples = edit_list_media_time - curr_cts;
4380 edit_list_dts_counter -= packet_skip_samples;
4381 if (edit_list_start_encountered == 0) {
4382 edit_list_start_encountered = 1;
4385 if (frame_duration_buffer) {
4387 frame_duration_buffer, num_discarded_begin);
4392 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
4397 if (edit_list_start_encountered == 0) {
4398 num_discarded_begin++;
4399 frame_duration_buffer =
av_realloc(frame_duration_buffer,
4400 num_discarded_begin *
sizeof(
int64_t));
4401 if (!frame_duration_buffer) {
4405 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
4420 if (edit_list_start_encountered == 0) {
4421 edit_list_start_encountered = 1;
4424 if (frame_duration_buffer) {
4426 frame_duration_buffer, num_discarded_begin);
4439 if (!current_index_range ||
index != current_index_range->
end) {
4440 current_index_range = current_index_range ? current_index_range + 1
4444 current_index_range->
end =
index + 1;
4447 if (edit_list_start_encountered > 0) {
4448 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
4452 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
4454 if (ctts_data_old) {
4459 found_keyframe_after_edit = 1;
4462 if (ctts_sample_old != 0) {
4465 ctts_sample_old - edit_list_start_ctts_sample,
4466 ctts_data_old[ctts_index_old].
duration) == -1) {
4468 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
4469 ctts_data_old[ctts_index_old].
duration);