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++) {
195 if (
c->fc->nb_streams < 1)
198 for (
int i = 0;
i <
c->nb_heif_item;
i++) {
203 if (item->
st->
id !=
c->cur_item_id)
210 st =
c->fc->streams[
c->fc->nb_streams-1];
240 st =
c->fc->streams[
c->fc->nb_streams - 1];
261 char buf[200], place[100];
262 uint16_t langcode = 0;
263 double longitude, latitude, altitude;
264 const char *
key =
"location";
266 if (
len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
286 "loci too short (%u bytes left, need at least %d)\n",
len, 12);
294 snprintf(buf,
sizeof(buf),
"%+08.4f%+09.4f", latitude, longitude);
314 if (
c->ignore_chapters)
318 if (n_hmmt >
len / 4)
335 uint16_t langcode = 0;
336 uint32_t data_type = 0, str_size_alloc;
343 case MKTAG(
'@',
'P',
'R',
'M'):
key =
"premiere_version"; raw = 1;
break;
344 case MKTAG(
'@',
'P',
'R',
'Q'):
key =
"quicktime_version"; raw = 1;
break;
345 case MKTAG(
'X',
'M',
'P',
'_'):
346 if (
c->export_xmp) {
key =
"xmp"; raw = 1; }
break;
347 case MKTAG(
'a',
'A',
'R',
'T'):
key =
"album_artist";
break;
348 case MKTAG(
'a',
'k',
'I',
'D'):
key =
"account_type";
350 case MKTAG(
'a',
'p',
'I',
'D'):
key =
"account_id";
break;
351 case MKTAG(
'c',
'a',
't',
'g'):
key =
"category";
break;
352 case MKTAG(
'c',
'p',
'i',
'l'):
key =
"compilation";
354 case MKTAG(
'c',
'p',
'r',
't'):
key =
"copyright";
break;
355 case MKTAG(
'd',
'e',
's',
'c'):
key =
"description";
break;
356 case MKTAG(
'd',
'i',
's',
'k'):
key =
"disc";
358 case MKTAG(
'e',
'g',
'i',
'd'):
key =
"episode_uid";
360 case MKTAG(
'F',
'I',
'R',
'M'):
key =
"firmware"; raw = 1;
break;
361 case MKTAG(
'g',
'n',
'r',
'e'):
key =
"genre";
363 case MKTAG(
'h',
'd',
'v',
'd'):
key =
"hd_video";
365 case MKTAG(
'H',
'M',
'M',
'T'):
367 case MKTAG(
'k',
'e',
'y',
'w'):
key =
"keywords";
break;
368 case MKTAG(
'l',
'd',
'e',
's'):
key =
"synopsis";
break;
369 case MKTAG(
'l',
'o',
'c',
'i'):
371 case MKTAG(
'm',
'a',
'n',
'u'):
key =
"make";
break;
372 case MKTAG(
'm',
'o',
'd',
'l'):
key =
"model";
break;
373 case MKTAG(
'p',
'c',
's',
't'):
key =
"podcast";
375 case MKTAG(
'p',
'g',
'a',
'p'):
key =
"gapless_playback";
377 case MKTAG(
'p',
'u',
'r',
'd'):
key =
"purchase_date";
break;
378 case MKTAG(
'r',
't',
'n',
'g'):
key =
"rating";
380 case MKTAG(
's',
'o',
'a',
'a'):
key =
"sort_album_artist";
break;
381 case MKTAG(
's',
'o',
'a',
'l'):
key =
"sort_album";
break;
382 case MKTAG(
's',
'o',
'a',
'r'):
key =
"sort_artist";
break;
383 case MKTAG(
's',
'o',
'c',
'o'):
key =
"sort_composer";
break;
384 case MKTAG(
's',
'o',
'n',
'm'):
key =
"sort_name";
break;
385 case MKTAG(
's',
'o',
's',
'n'):
key =
"sort_show";
break;
386 case MKTAG(
's',
't',
'i',
'k'):
key =
"media_type";
388 case MKTAG(
't',
'r',
'k',
'n'):
key =
"track";
390 case MKTAG(
't',
'v',
'e',
'n'):
key =
"episode_id";
break;
391 case MKTAG(
't',
'v',
'e',
's'):
key =
"episode_sort";
393 case MKTAG(
't',
'v',
'n',
'n'):
key =
"network";
break;
394 case MKTAG(
't',
'v',
's',
'h'):
key =
"show";
break;
395 case MKTAG(
't',
'v',
's',
'n'):
key =
"season_number";
397 case MKTAG(0xa9,
'A',
'R',
'T'):
key =
"artist";
break;
398 case MKTAG(0xa9,
'P',
'R',
'D'):
key =
"producer";
break;
399 case MKTAG(0xa9,
'a',
'l',
'b'):
key =
"album";
break;
400 case MKTAG(0xa9,
'a',
'u',
't'):
key =
"artist";
break;
401 case MKTAG(0xa9,
'c',
'h',
'p'):
key =
"chapter";
break;
402 case MKTAG(0xa9,
'c',
'm',
't'):
key =
"comment";
break;
403 case MKTAG(0xa9,
'c',
'o',
'm'):
key =
"composer";
break;
404 case MKTAG(0xa9,
'c',
'p',
'y'):
key =
"copyright";
break;
405 case MKTAG(0xa9,
'd',
'a',
'y'):
key =
"date";
break;
406 case MKTAG(0xa9,
'd',
'i',
'r'):
key =
"director";
break;
407 case MKTAG(0xa9,
'd',
'i',
's'):
key =
"disclaimer";
break;
408 case MKTAG(0xa9,
'e',
'd',
'1'):
key =
"edit_date";
break;
409 case MKTAG(0xa9,
'e',
'n',
'c'):
key =
"encoder";
break;
410 case MKTAG(0xa9,
'f',
'm',
't'):
key =
"original_format";
break;
411 case MKTAG(0xa9,
'g',
'e',
'n'):
key =
"genre";
break;
412 case MKTAG(0xa9,
'g',
'r',
'p'):
key =
"grouping";
break;
413 case MKTAG(0xa9,
'h',
's',
't'):
key =
"host_computer";
break;
414 case MKTAG(0xa9,
'i',
'n',
'f'):
key =
"comment";
break;
415 case MKTAG(0xa9,
'l',
'y',
'r'):
key =
"lyrics";
break;
416 case MKTAG(0xa9,
'm',
'a',
'k'):
key =
"make";
break;
417 case MKTAG(0xa9,
'm',
'o',
'd'):
key =
"model";
break;
418 case MKTAG(0xa9,
'n',
'a',
'm'):
key =
"title";
break;
419 case MKTAG(0xa9,
'o',
'p',
'e'):
key =
"original_artist";
break;
420 case MKTAG(0xa9,
'p',
'r',
'd'):
key =
"producer";
break;
421 case MKTAG(0xa9,
'p',
'r',
'f'):
key =
"performers";
break;
422 case MKTAG(0xa9,
'r',
'e',
'q'):
key =
"playback_requirements";
break;
423 case MKTAG(0xa9,
's',
'r',
'c'):
key =
"original_source";
break;
424 case MKTAG(0xa9,
's',
't',
'3'):
key =
"subtitle";
break;
425 case MKTAG(0xa9,
's',
'w',
'r'):
key =
"encoder";
break;
426 case MKTAG(0xa9,
't',
'o',
'o'):
key =
"encoder";
break;
427 case MKTAG(0xa9,
't',
'r',
'k'):
key =
"track";
break;
428 case MKTAG(0xa9,
'u',
'r',
'l'):
key =
"URL";
break;
429 case MKTAG(0xa9,
'w',
'r',
'n'):
key =
"warning";
break;
430 case MKTAG(0xa9,
'w',
'r',
't'):
key =
"composer";
break;
431 case MKTAG(0xa9,
'x',
'y',
'z'):
key =
"location";
break;
434 if (
c->itunes_metadata && atom.
size > 8) {
437 if (
tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
440 str_size = data_size - 16;
443 if (!
key &&
c->found_hdlr_mdta &&
c->meta_keys) {
445 if (index < c->meta_keys_count &&
index > 0) {
447 }
else if (atom.
type !=
MKTAG(
'c',
'o',
'v',
'r')) {
449 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
450 index,
c->meta_keys_count);
453 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r') ||
454 (
key && !strcmp(
key,
"com.apple.quicktime.artwork"))) {
460 atom.
size -= str_size;
466 }
else if (atom.
size > 4 &&
key && !
c->itunes_metadata && !raw) {
468 if (str_size > atom.
size) {
478 str_size = atom.
size;
480 if (
c->export_all && !
key) {
486 if (atom.
size < 0 || str_size >= INT_MAX/2)
491 num = (data_type >= 21 && data_type <= 23);
492 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
500 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
502 }
else if (data_type == 21) {
506 else if (str_size == 2)
508 else if (str_size == 3)
510 else if (str_size == 4)
512 if (
snprintf(str, str_size_alloc,
"%d",
val) >= str_size_alloc) {
514 "Failed to store the number (%d) in string.\n",
val);
518 }
else if (data_type == 22) {
519 unsigned int val = 0;
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,
"%u",
val) >= str_size_alloc) {
530 "Failed to store the number (%u) in string.\n",
val);
534 }
else if (data_type == 23 && str_size >= 4) {
536 if (
snprintf(str, str_size_alloc,
"%f",
val) >= str_size_alloc) {
538 "Failed to store the float32 number (%f) in string.\n",
val);
542 }
else if (data_type > 1 && data_type != 4) {
564 if (!strcmp(
key,
"encoder")) {
565 int major, minor, micro;
566 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
567 c->handbrake_version = 1000000*major + 1000*minor + micro;
579 int i, nb_chapters, str_len,
version;
583 if (
c->ignore_chapters)
586 if ((atom.
size -= 5) < 0)
595 for (
i = 0;
i < nb_chapters;
i++) {
602 if ((atom.
size -= 9+str_len) < 0)
614 #define MIN_DATA_ENTRY_BOX_SIZE 12
621 if (
c->fc->nb_streams < 1)
623 st =
c->fc->streams[
c->fc->nb_streams-1];
630 entries >= UINT_MAX /
sizeof(*sc->
drefs))
645 for (
i = 0;
i < entries;
i++) {
650 if (
size < 12 || next < 0 || next > INT64_MAX -
size)
660 uint16_t volume_len,
len;
667 volume_len =
FFMIN(volume_len, 27);
671 dref->
volume[volume_len] = 0;
713 if (
len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
719 for (j =
len - 1; j >= 0; j--) {
720 if (dref->
path[j] == 0)
725 for (j = 0; j <
len; j++)
726 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
729 }
else if (
type == 0) {
741 for (j = 0; j <
len; j++)
742 if (dref->
dir[j] ==
':')
778 if (
c->trak_index < 0) {
780 c->found_hdlr_mdta = 1;
785 st =
c->fc->streams[
c->fc->nb_streams-1];
800 title_size = atom.
size - 24;
801 if (title_size > 0) {
802 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
813 title_str[title_size] = 0;
815 int off = (!
c->isom && title_str[0] == title_size - 1);
835 int ac3info, acmod, lfeon, bsmod;
838 if (
c->fc->nb_streams < 1)
840 st =
c->fc->streams[
c->fc->nb_streams-1];
851 bsmod = (ac3info >> 14) & 0x7;
852 acmod = (ac3info >> 11) & 0x7;
853 lfeon = (ac3info >> 10) & 0x1;
878 unsigned descriptors_size;
879 int nb_frames, disposition;
885 if (
c->fc->nb_streams < 1)
896 if (!descriptors_size || descriptors_size > INT_MAX)
899 st =
c->fc->streams[
c->fc->nb_streams - 1];
918 if (
ret != descriptors_size)
922 descriptor_pb = &
b.pub;
1019 for (
int j = 0; j <
mix->nb_submixes; j++) {
1026 for (
int l = 0; l <
c->fc->nb_stream_groups; l++)
1029 audio_element =
c->fc->stream_groups[l];
1034 for (
int l = 0; l < audio_element->
nb_streams; l++) {
1060 int eac3info, acmod, lfeon, bsmod;
1063 if (
c->fc->nb_streams < 1)
1065 st =
c->fc->streams[
c->fc->nb_streams-1];
1081 bsmod = (eac3info >> 12) & 0x1f;
1082 acmod = (eac3info >> 9) & 0x7;
1083 lfeon = (eac3info >> 8) & 0x1;
1100 #define DDTS_SIZE 20
1103 uint32_t frame_duration_code = 0;
1104 uint32_t channel_layout_code = 0;
1113 if (
c->fc->nb_streams < 1) {
1116 st =
c->fc->streams[
c->fc->nb_streams-1];
1126 frame_duration_code =
get_bits(&gb, 2);
1128 channel_layout_code =
get_bits(&gb, 16);
1131 (frame_duration_code == 0) ? 512 :
1132 (frame_duration_code == 1) ? 1024 :
1133 (frame_duration_code == 2) ? 2048 :
1134 (frame_duration_code == 3) ? 4096 : 0;
1136 if (channel_layout_code > 0xff) {
1155 if (
c->fc->nb_streams < 1)
1157 st =
c->fc->streams[
c->fc->nb_streams-1];
1177 if (
c->fc->nb_streams < 1)
1179 st =
c->fc->streams[
c->fc->nb_streams-1];
1185 "Unsupported 'chnl' box with version %d, flags: %#x",
1207 if (
c->fc->nb_streams < 1)
1209 st =
c->fc->streams[
c->fc->nb_streams-1];
1221 AVRational aperture_width, aperture_height, horiz_off, vert_off;
1223 uint64_t top, bottom,
left, right;
1225 if (
c->fc->nb_streams < 1)
1227 st =
c->fc->streams[
c->fc->nb_streams-1];
1239 if (aperture_width.
num < 0 || aperture_width.
den < 0 ||
1240 aperture_height.
num < 0 || aperture_height.
den < 0 ||
1241 horiz_off.
den < 0 || vert_off.
den < 0)
1245 "horizOff %d/%d vertOff %d/%d\n",
1246 aperture_width.
num, aperture_width.
den, aperture_height.
num, aperture_height.
den,
1247 horiz_off.
num, horiz_off.
den, vert_off.
num, vert_off.
den);
1271 if (!(
left | right | top | bottom))
1281 sizeof(uint32_t) * 4, 0);
1301 if (
c->fc->nb_streams < 1)
1303 st =
c->fc->streams[
c->fc->nb_streams-1];
1324 #define DRM_BLOB_SIZE 56
1328 uint8_t intermediate_key[20];
1329 uint8_t intermediate_iv[20];
1332 uint8_t file_checksum[20];
1333 uint8_t calculated_checksum[20];
1334 char checksum_string[2 *
sizeof(file_checksum) + 1];
1338 uint8_t *activation_bytes =
c->activation_bytes;
1339 uint8_t *fixed_key =
c->audible_fixed_key;
1348 if (!
c->aes_decrypt) {
1360 ff_data_to_hex(checksum_string, file_checksum,
sizeof(file_checksum), 1);
1364 if (!activation_bytes) {
1369 if (
c->activation_bytes_size != 4) {
1376 if (
c->audible_fixed_key_size != 16) {
1396 if (memcmp(calculated_checksum, file_checksum, 20)) {
1403 for (
i = 0;
i < 4;
i++) {
1405 if (activation_bytes[
i] !=
output[3 -
i]) {
1411 memcpy(
c->file_key,
output + 8, 16);
1427 if (
c->audible_key_size != 16) {
1432 if (
c->audible_iv_size != 16) {
1438 if (!
c->aes_decrypt) {
1442 memcpy(
c->file_key,
c->audible_key, 16);
1443 memcpy(
c->file_iv,
c->audible_iv, 16);
1453 unsigned char iv[16];
1455 memcpy(iv,
c->file_iv, 16);
1467 int comp_brand_size;
1468 char* comp_brands_str;
1469 uint8_t
type[5] = {0};
1473 if (
c->fc->nb_streams) {
1480 if (strcmp(
type,
"qt "))
1487 comp_brand_size = atom.
size - 8;
1488 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1490 comp_brands_str =
av_malloc(comp_brand_size + 1);
1491 if (!comp_brands_str)
1499 comp_brands_str[comp_brand_size] = 0;
1504 if (!strcmp(
type,
"aaxc")) {
1516 if (
c->found_moov) {
1538 if (index < 0 || index >= frag_index->
nb_items)
1554 if (frag_index->
current < 0 ||
1573 if (frag_index->
current < 0 ||
1601 if (moof_offset >=
offset)
1603 if (moof_offset <=
offset)
1641 for (j = 0; j <
s->nb_streams; j++) {
1643 if (sc2->
id == frag_stream_info->
id)
1644 frag_stream =
s->streams[j];
1667 m0 = m = (
a +
b) >> 1;
1673 if (m <
b && frag_time <= timestamp)
1690 if (index < c->frag_index.nb_items &&
1697 &
c->frag_index.allocated_size,
1698 (
c->frag_index.nb_items + 1) *
1699 sizeof(*
c->frag_index.item));
1702 c->frag_index.item = item;
1706 if (!frag_stream_info)
1709 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1717 frag_stream_info[
i].
id = sc->
id;
1728 if (index < c->frag_index.nb_items)
1729 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1730 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1732 item = &
c->frag_index.item[
index];
1738 c->frag_index.nb_items++;
1744 int id,
int entries)
1753 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1761 c->fragment.found_tfhd = 0;
1763 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1764 c->has_looked_for_mfra = 1;
1771 "read the mfra (may be a live ismv)\n");
1775 "seekable, can not look for mfra\n");
1778 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1797 if (time > 0 && time < 2082844800) {
1805 if ((
int64_t)(time * 1000000ULL) / 1000000 != time) {
1822 if (
c->fc->nb_streams < 1)
1824 st =
c->fc->streams[
c->fc->nb_streams-1];
1868 if (
c->time_scale <= 0) {
1882 for (
i = 0;
i < 3;
i++) {
1903 if (
fc->nb_streams < 1)
1905 st =
fc->streams[
fc->nb_streams-1];
1930 int little_endian =
avio_rb16(pb) & 0xFF;
1932 if (little_endian == 1)
1941 int pcm_sample_size;
1946 if (atom.
size < 6) {
1956 "Unsupported 'pcmC' box with version %d, flags: %x",
1962 pcm_sample_size =
avio_r8(pb);
1964 if (
fc->nb_streams < 1)
1967 st =
fc->streams[
fc->nb_streams - 1];
1971 switch (pcm_sample_size) {
1985 switch (pcm_sample_size) {
2007 if (format_flags & 1)
2017 char color_parameter_type[5] = { 0 };
2028 if (strncmp(color_parameter_type,
"nclx", 4) &&
2029 strncmp(color_parameter_type,
"nclc", 4) &&
2030 strncmp(color_parameter_type,
"prof", 4)) {
2032 color_parameter_type);
2036 if (!strncmp(color_parameter_type,
"prof", 4)) {
2052 "%s: pri %d trc %d matrix %d",
2055 if (!strncmp(color_parameter_type,
"nclx", 4)) {
2082 unsigned mov_field_order;
2085 if (
c->fc->nb_streams < 1)
2087 st =
c->fc->streams[
c->fc->nb_streams-1];
2091 if ((mov_field_order & 0xFF00) == 0x0100)
2093 else if ((mov_field_order & 0xFF00) == 0x0200) {
2094 switch (mov_field_order & 0xFF) {
2117 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
2140 }
else if (err < atom.
size) {
2154 uint64_t original_size;
2157 if (
c->fc->nb_streams < 1)
2159 st =
c->fc->streams[
c->fc->nb_streams-1];
2208 if (!
ret &&
c->fc->nb_streams >= 1) {
2220 if (
c->fc->nb_streams >= 1) {
2221 AVStream *
const st =
c->fc->streams[
c->fc->nb_streams - 1];
2232 if (
cid == 0xd4d ||
cid == 0xd4e)
2243 if (num <= 0 || den <= 0)
2247 if (den >= INT_MAX / 2)
2265 uint64_t original_size;
2266 if (
c->fc->nb_streams >= 1) {
2270 if (atom.
size == 16) {
2275 if (length == atom.
size) {
2276 const uint8_t range_value = par->
extradata[original_size + 19];
2277 switch (range_value) {
2314 if (
c->fc->nb_streams < 1)
2316 st =
c->fc->streams[
c->fc->nb_streams-1];
2318 if ((uint64_t)atom.
size > (1<<30))
2328 }
else if (atom.
size > 8) {
2342 #define ALAC_EXTRADATA_SIZE 36
2375 if ((uint64_t)atom.
size > (1<<30))
2378 if (atom.
type ==
MKTAG(
'v',
'v',
'c',
'C')) {
2383 if (atom.
size >= 10) {
2415 uint8_t profile_level;
2418 if (
c->fc->nb_streams < 1)
2420 st =
c->fc->streams[
c->fc->nb_streams-1];
2422 if (atom.
size >= (1<<28) || atom.
size < 7)
2426 if ((profile_level & 0xf0) != 0xc0)
2447 if (
c->fc->nb_streams < 1)
2449 if (atom.
size <= 40)
2451 st =
c->fc->streams[
c->fc->nb_streams-1];
2453 if ((uint64_t)atom.
size > (1<<30))
2468 unsigned int i, entries;
2470 if (
c->trak_index < 0) {
2474 if (
c->fc->nb_streams < 1)
2476 st =
c->fc->streams[
c->fc->nb_streams-1];
2488 (atom.
type ==
MKTAG(
's',
't',
'c',
'o') ? 4 : 8)));
2505 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2508 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2534 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2535 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2572 uint8_t codec_name[32] = { 0 };
2607 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2614 !strncmp(codec_name,
"Sorenson H263", 13))
2630 int bits_per_sample,
flags;
2655 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2765 y = (ycbcr >> 16) & 0xFF;
2766 cr = (ycbcr >> 8) & 0xFF;
2773 return (
r << 16) | (
g << 8) |
b;
2778 char buf[256] = {0};
2786 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2790 for (
i = 0;
i < 16;
i++) {
2794 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba,
i != 15 ?
", " :
"");
2797 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2834 if (str_size > 0 &&
size >= (
int)str_size + 30 &&
2836 char *reel_name =
av_malloc(str_size + 1);
2840 reel_name[str_size] = 0;
2865 #if CONFIG_DV_DEMUXER
2955 int codec_tag,
int format,
2967 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2984 int pseudo_stream_id;
2987 st =
c->fc->streams[
c->fc->nb_streams-1];
2990 for (pseudo_stream_id = 0;
2992 pseudo_stream_id++) {
2995 int ret, dref_id = 1;
3005 }
else if (
size <= 7) {
3007 "invalid size %"PRId64
" in stsd\n",
size);
3024 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
3054 }
else if (
a.size > 0)
3083 if (
c->fc->nb_streams < 1)
3085 st =
c->fc->streams[
c->fc->nb_streams - 1];
3093 if (entries <= 0 || entries > atom.
size / 8 || entries > 1024) {
3100 "Duplicate stsd found in this track.\n");
3146 unsigned int i, entries;
3148 if (
c->trak_index < 0) {
3153 if (
c->fc->nb_streams < 1)
3155 st =
c->fc->streams[
c->fc->nb_streams-1];
3162 if ((uint64_t)entries * 12 + 4 > atom.
size)
3247 unsigned i, entries;
3249 if (
c->trak_index < 0) {
3254 if (
c->fc->nb_streams < 1)
3256 st =
c->fc->streams[
c->fc->nb_streams-1];
3289 unsigned int i, entries;
3291 if (
c->trak_index < 0) {
3296 if (
c->fc->nb_streams < 1)
3298 st =
c->fc->streams[
c->fc->nb_streams-1];
3317 if (entries >= UINT_MAX /
sizeof(
int))
3343 unsigned int i, entries, sample_size, field_size, num_bytes;
3348 if (
c->trak_index < 0) {
3353 if (
c->fc->nb_streams < 1)
3355 st =
c->fc->streams[
c->fc->nb_streams-1];
3361 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
3380 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
3397 num_bytes = (entries*field_size+4)>>3;
3415 for (
i = 0;
i < entries;
i++) {
3436 unsigned int i, entries, alloc_size = 0;
3438 int64_t total_sample_count = 0;
3442 if (
c->trak_index < 0) {
3447 if (
c->fc->nb_streams < 1)
3449 st =
c->fc->streams[
c->fc->nb_streams-1];
3457 c->fc->nb_streams-1, entries);
3463 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
3467 unsigned int sample_duration;
3468 unsigned int sample_count;
3469 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
3487 sample_count, sample_duration);
3492 if (sample_duration >
c->max_stts_delta) {
3495 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",
3496 sample_duration,
i, sample_count, st->
index);
3498 corrected_dts += (delta_magnitude < 0 ? (
int64_t)delta_magnitude : 1) * sample_count;
3500 corrected_dts += sample_duration * (
int64_t)sample_count;
3505 if (current_dts > corrected_dts) {
3506 int64_t drift = (current_dts - corrected_dts)/
FFMAX(sample_count, 1);
3508 current_dts -= correction * (uint64_t)sample_count;
3519 duration <= INT64_MAX - sc->duration_for_fps &&
3520 total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
3542 "All samples in data stream index:id [%d:%d] have zero "
3543 "duration, stream set to be discarded by default. Override "
3544 "using AVStream->discard or -discard for ffmpeg command.\n",
3558 if (
c->fc->nb_streams < 1)
3560 st =
c->fc->streams[
c->fc->nb_streams - 1];
3565 entries = atom.
size - 4;
3568 c->fc->nb_streams - 1, entries);
3601 unsigned int i, entries, ctts_count = 0;
3603 if (
c->trak_index < 0) {
3608 if (
c->fc->nb_streams < 1)
3610 st =
c->fc->streams[
c->fc->nb_streams-1];
3621 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3634 "ignoring CTTS entry with count=%d duration=%d\n",
3673 uint32_t grouping_type;
3674 uint32_t default_length;
3675 av_unused uint32_t default_group_description_index;
3676 uint32_t entry_count;
3678 if (
c->fc->nb_streams < 1)
3680 st =
c->fc->streams[
c->fc->nb_streams - 1];
3691 if (grouping_type !=
MKTAG(
's',
'y',
'n',
'c'))
3705 uint32_t description_length = default_length;
3706 if (
version >= 1 && default_length == 0)
3708 if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3709 const uint8_t nal_unit_type =
avio_r8(pb) & 0x3f;
3711 description_length -= 1;
3728 unsigned int i, entries;
3730 uint32_t grouping_type;
3734 if (
c->fc->nb_streams < 1)
3736 st =
c->fc->streams[
c->fc->nb_streams-1];
3743 if (grouping_type ==
MKTAG(
'r',
'a',
'p',
' ')) {
3746 }
else if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3787 unsigned int edit_list_index,
3788 int64_t *edit_list_media_time,
3795 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3799 if (global_timescale == 0) {
3806 if (*edit_list_duration + (uint64_t)*edit_list_media_time > INT64_MAX)
3807 *edit_list_duration = 0;
3875 if (ctts_data && *
index >= 0) {
3881 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3882 if (*ctts_index < ctts_count) {
3884 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3891 while (*
index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3895 if ((e_old[*
index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3901 if (*ctts_sample == 0) {
3903 if (*ctts_index >= 0)
3904 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3914 return *
index >= 0 ? 0 : -1;
3938 const size_t requested_size =
3955 ie= &entries[
index];
3970 int64_t* frame_duration_buffer,
3971 int frame_duration_buffer_size) {
3974 av_assert0(end_index >= 0 && end_index <= sti->nb_index_entries);
3975 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
3976 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
3989 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVCtts);
3990 const size_t requested_size =
3991 min_size_needed > *allocated_size ?
3992 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3995 if ((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVCtts) - 1)
3998 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
4003 *ctts_data = ctts_buf_new;
4008 *ctts_count = (*ctts_count) + 1;
4012 #define MAX_REORDER_DELAY 16
4018 int ctts_sample = 0;
4021 int j,
r, num_swaps;
4024 pts_buf[j] = INT64_MIN;
4032 buf_start = (buf_start + 1);
4045 while (j != buf_start) {
4048 if (pts_buf[j] < pts_buf[
r]) {
4107 if (range_size > current_sample) {
4111 current_sample -= range_size;
4133 int64_t edit_list_media_time = 0;
4134 int64_t edit_list_duration = 0;
4136 int64_t edit_list_dts_counter = 0;
4137 int64_t edit_list_dts_entry_end = 0;
4138 int64_t edit_list_start_ctts_sample = 0;
4141 int64_t empty_edits_sum_duration = 0;
4146 int64_t edit_list_start_encountered = 0;
4149 int num_discarded_begin = 0;
4150 int first_non_zero_audio_edit = -1;
4151 int packet_skip_samples = 0;
4153 int found_keyframe_after_edit = 0;
4154 int found_non_empty_edit = 0;
4187 edit_list_dts_entry_end -= msc->
dts_shift;
4191 start_dts = edit_list_dts_entry_end;
4195 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
4196 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
4198 edit_list_dts_counter = edit_list_dts_entry_end;
4199 edit_list_dts_entry_end += edit_list_duration;
4200 num_discarded_begin = 0;
4201 if (!found_non_empty_edit && edit_list_media_time == -1) {
4202 empty_edits_sum_duration += edit_list_duration;
4205 found_non_empty_edit = 1;
4210 if (first_non_zero_audio_edit < 0) {
4211 first_non_zero_audio_edit = 1;
4213 first_non_zero_audio_edit = 0;
4216 if (first_non_zero_audio_edit > 0)
4224 search_timestamp = edit_list_media_time;
4233 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
4235 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
4236 st->
index, edit_list_index, search_timestamp);
4238 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
4240 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
4241 st->
index, edit_list_index, search_timestamp);
4244 ctts_sample_old = 0;
4247 current = e_old +
index;
4248 edit_list_start_ctts_sample = ctts_sample_old;
4251 edit_list_start_encountered = 0;
4252 found_keyframe_after_edit = 0;
4253 for (; current < e_old_end; current++,
index++) {
4255 frame_duration = (current + 1 < e_old_end) ?
4256 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
4264 if (ctts_data_old && ctts_index_old < ctts_count_old) {
4265 curr_ctts = ctts_data_old[ctts_index_old].
duration;
4266 av_log(mov->
fc,
AV_LOG_TRACE,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
4267 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
4268 curr_cts += curr_ctts;
4270 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
4273 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
4274 ctts_data_old[ctts_index_old].
duration) == -1) {
4277 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
4278 ctts_data_old[ctts_index_old].
duration);
4282 ctts_sample_old = 0;
4283 edit_list_start_ctts_sample = 0;
4287 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
4289 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
4290 first_non_zero_audio_edit > 0) {
4291 packet_skip_samples = edit_list_media_time - curr_cts;
4295 edit_list_dts_counter -= packet_skip_samples;
4296 if (edit_list_start_encountered == 0) {
4297 edit_list_start_encountered = 1;
4300 if (frame_duration_buffer) {
4302 frame_duration_buffer, num_discarded_begin);
4307 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
4312 if (edit_list_start_encountered == 0) {
4313 num_discarded_begin++;
4314 frame_duration_buffer =
av_realloc(frame_duration_buffer,
4315 num_discarded_begin *
sizeof(
int64_t));
4316 if (!frame_duration_buffer) {
4320 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
4335 if (edit_list_start_encountered == 0) {
4336 edit_list_start_encountered = 1;
4339 if (frame_duration_buffer) {
4341 frame_duration_buffer, num_discarded_begin);
4354 if (!current_index_range ||
index != current_index_range->
end) {
4355 current_index_range = current_index_range ? current_index_range + 1
4359 current_index_range->
end =
index + 1;
4362 if (edit_list_start_encountered > 0) {
4363 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
4367 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
4369 if (ctts_data_old) {
4374 found_keyframe_after_edit = 1;
4377 if (ctts_sample_old != 0) {
4380 ctts_sample_old - edit_list_start_ctts_sample,
4381 ctts_data_old[ctts_index_old].
duration) == -1) {
4383 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
4384 ctts_data_old[ctts_index_old].
duration);
4419 current_index_range = current_index_range ? current_index_range + 1
4421 current_index_range->
start = 0;
4422 current_index_range->
end = 0;