26 #include "config_components.h"
84 static int64_t
add_ctts_entry(
MOVCtts** ctts_data,
unsigned int* ctts_count,
unsigned int* allocated_size,
88 unsigned len,
const char *
key)
92 short current, total = 0;
98 snprintf(buf,
sizeof(buf),
"%d", current);
100 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
108 unsigned len,
const char *
key)
122 unsigned len,
const char *
key)
131 unsigned len,
const char *
key)
147 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
148 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
149 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
150 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
151 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
152 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
153 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
154 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
155 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
156 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
157 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
158 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
159 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
160 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
161 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
162 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
166 char *dst,
int dstlen)
169 char *end = dst+dstlen-1;
172 for (
i = 0;
i <
len;
i++) {
212 st =
c->fc->streams[
c->fc->nb_streams - 1];
231 char buf[200], place[100];
232 uint16_t langcode = 0;
233 double longitude, latitude, altitude;
234 const char *
key =
"location";
236 if (
len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
256 "loci too short (%u bytes left, need at least %d)\n",
len, 12);
264 snprintf(buf,
sizeof(buf),
"%+08.4f%+09.4f", latitude, longitude);
284 if (
c->ignore_chapters)
288 if (n_hmmt >
len / 4)
305 uint16_t langcode = 0;
306 uint32_t data_type = 0, str_size, str_size_alloc;
312 case MKTAG(
'@',
'P',
'R',
'M'):
key =
"premiere_version"; raw = 1;
break;
313 case MKTAG(
'@',
'P',
'R',
'Q'):
key =
"quicktime_version"; raw = 1;
break;
314 case MKTAG(
'X',
'M',
'P',
'_'):
315 if (
c->export_xmp) {
key =
"xmp"; raw = 1; }
break;
316 case MKTAG(
'a',
'A',
'R',
'T'):
key =
"album_artist";
break;
317 case MKTAG(
'a',
'k',
'I',
'D'):
key =
"account_type";
319 case MKTAG(
'a',
'p',
'I',
'D'):
key =
"account_id";
break;
320 case MKTAG(
'c',
'a',
't',
'g'):
key =
"category";
break;
321 case MKTAG(
'c',
'p',
'i',
'l'):
key =
"compilation";
323 case MKTAG(
'c',
'p',
'r',
't'):
key =
"copyright";
break;
324 case MKTAG(
'd',
'e',
's',
'c'):
key =
"description";
break;
325 case MKTAG(
'd',
'i',
's',
'k'):
key =
"disc";
327 case MKTAG(
'e',
'g',
'i',
'd'):
key =
"episode_uid";
329 case MKTAG(
'F',
'I',
'R',
'M'):
key =
"firmware"; raw = 1;
break;
330 case MKTAG(
'g',
'n',
'r',
'e'):
key =
"genre";
332 case MKTAG(
'h',
'd',
'v',
'd'):
key =
"hd_video";
334 case MKTAG(
'H',
'M',
'M',
'T'):
336 case MKTAG(
'k',
'e',
'y',
'w'):
key =
"keywords";
break;
337 case MKTAG(
'l',
'd',
'e',
's'):
key =
"synopsis";
break;
338 case MKTAG(
'l',
'o',
'c',
'i'):
340 case MKTAG(
'm',
'a',
'n',
'u'):
key =
"make";
break;
341 case MKTAG(
'm',
'o',
'd',
'l'):
key =
"model";
break;
342 case MKTAG(
'p',
'c',
's',
't'):
key =
"podcast";
344 case MKTAG(
'p',
'g',
'a',
'p'):
key =
"gapless_playback";
346 case MKTAG(
'p',
'u',
'r',
'd'):
key =
"purchase_date";
break;
347 case MKTAG(
'r',
't',
'n',
'g'):
key =
"rating";
349 case MKTAG(
's',
'o',
'a',
'a'):
key =
"sort_album_artist";
break;
350 case MKTAG(
's',
'o',
'a',
'l'):
key =
"sort_album";
break;
351 case MKTAG(
's',
'o',
'a',
'r'):
key =
"sort_artist";
break;
352 case MKTAG(
's',
'o',
'c',
'o'):
key =
"sort_composer";
break;
353 case MKTAG(
's',
'o',
'n',
'm'):
key =
"sort_name";
break;
354 case MKTAG(
's',
'o',
's',
'n'):
key =
"sort_show";
break;
355 case MKTAG(
's',
't',
'i',
'k'):
key =
"media_type";
357 case MKTAG(
't',
'r',
'k',
'n'):
key =
"track";
359 case MKTAG(
't',
'v',
'e',
'n'):
key =
"episode_id";
break;
360 case MKTAG(
't',
'v',
'e',
's'):
key =
"episode_sort";
362 case MKTAG(
't',
'v',
'n',
'n'):
key =
"network";
break;
363 case MKTAG(
't',
'v',
's',
'h'):
key =
"show";
break;
364 case MKTAG(
't',
'v',
's',
'n'):
key =
"season_number";
366 case MKTAG(0xa9,
'A',
'R',
'T'):
key =
"artist";
break;
367 case MKTAG(0xa9,
'P',
'R',
'D'):
key =
"producer";
break;
368 case MKTAG(0xa9,
'a',
'l',
'b'):
key =
"album";
break;
369 case MKTAG(0xa9,
'a',
'u',
't'):
key =
"artist";
break;
370 case MKTAG(0xa9,
'c',
'h',
'p'):
key =
"chapter";
break;
371 case MKTAG(0xa9,
'c',
'm',
't'):
key =
"comment";
break;
372 case MKTAG(0xa9,
'c',
'o',
'm'):
key =
"composer";
break;
373 case MKTAG(0xa9,
'c',
'p',
'y'):
key =
"copyright";
break;
374 case MKTAG(0xa9,
'd',
'a',
'y'):
key =
"date";
break;
375 case MKTAG(0xa9,
'd',
'i',
'r'):
key =
"director";
break;
376 case MKTAG(0xa9,
'd',
'i',
's'):
key =
"disclaimer";
break;
377 case MKTAG(0xa9,
'e',
'd',
'1'):
key =
"edit_date";
break;
378 case MKTAG(0xa9,
'e',
'n',
'c'):
key =
"encoder";
break;
379 case MKTAG(0xa9,
'f',
'm',
't'):
key =
"original_format";
break;
380 case MKTAG(0xa9,
'g',
'e',
'n'):
key =
"genre";
break;
381 case MKTAG(0xa9,
'g',
'r',
'p'):
key =
"grouping";
break;
382 case MKTAG(0xa9,
'h',
's',
't'):
key =
"host_computer";
break;
383 case MKTAG(0xa9,
'i',
'n',
'f'):
key =
"comment";
break;
384 case MKTAG(0xa9,
'l',
'y',
'r'):
key =
"lyrics";
break;
385 case MKTAG(0xa9,
'm',
'a',
'k'):
key =
"make";
break;
386 case MKTAG(0xa9,
'm',
'o',
'd'):
key =
"model";
break;
387 case MKTAG(0xa9,
'n',
'a',
'm'):
key =
"title";
break;
388 case MKTAG(0xa9,
'o',
'p',
'e'):
key =
"original_artist";
break;
389 case MKTAG(0xa9,
'p',
'r',
'd'):
key =
"producer";
break;
390 case MKTAG(0xa9,
'p',
'r',
'f'):
key =
"performers";
break;
391 case MKTAG(0xa9,
'r',
'e',
'q'):
key =
"playback_requirements";
break;
392 case MKTAG(0xa9,
's',
'r',
'c'):
key =
"original_source";
break;
393 case MKTAG(0xa9,
's',
't',
'3'):
key =
"subtitle";
break;
394 case MKTAG(0xa9,
's',
'w',
'r'):
key =
"encoder";
break;
395 case MKTAG(0xa9,
't',
'o',
'o'):
key =
"encoder";
break;
396 case MKTAG(0xa9,
't',
'r',
'k'):
key =
"track";
break;
397 case MKTAG(0xa9,
'u',
'r',
'l'):
key =
"URL";
break;
398 case MKTAG(0xa9,
'w',
'r',
'n'):
key =
"warning";
break;
399 case MKTAG(0xa9,
'w',
'r',
't'):
key =
"composer";
break;
400 case MKTAG(0xa9,
'x',
'y',
'z'):
key =
"location";
break;
403 if (
c->itunes_metadata && atom.
size > 8) {
406 if (
tag ==
MKTAG(
'd',
'a',
't',
'a') && data_size <= atom.size && data_size >= 16) {
409 str_size = data_size - 16;
412 if (!
key &&
c->found_hdlr_mdta &&
c->meta_keys) {
414 if (index < c->meta_keys_count &&
index > 0) {
416 }
else if (atom.
type !=
MKTAG(
'c',
'o',
'v',
'r')) {
418 "The index of 'data' is out of range: %"PRId32
" < 1 or >= %d.\n",
419 index,
c->meta_keys_count);
422 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r') ||
423 (
key && !strcmp(
key,
"com.apple.quicktime.artwork"))) {
429 atom.
size -= str_size;
435 }
else if (atom.
size > 4 &&
key && !
c->itunes_metadata && !raw) {
437 if (str_size > atom.
size) {
447 str_size = atom.
size;
449 if (
c->export_all && !
key) {
455 if (atom.
size < 0 || str_size >= INT_MAX/2)
460 num = (data_type >= 21 && data_type <= 23);
461 str_size_alloc = (num ? 512 : (raw ? str_size : str_size * 2)) + 1;
469 if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) {
471 }
else if (data_type == 21) {
475 else if (str_size == 2)
477 else if (str_size == 3)
479 else if (str_size == 4)
481 if (
snprintf(str, str_size_alloc,
"%d",
val) >= str_size_alloc) {
483 "Failed to store the number (%d) in string.\n",
val);
487 }
else if (data_type == 22) {
488 unsigned int val = 0;
491 else if (str_size == 2)
493 else if (str_size == 3)
495 else if (str_size == 4)
497 if (
snprintf(str, str_size_alloc,
"%u",
val) >= str_size_alloc) {
499 "Failed to store the number (%u) in string.\n",
val);
503 }
else if (data_type == 23 && str_size >= 4) {
505 if (
snprintf(str, str_size_alloc,
"%f",
val) >= str_size_alloc) {
507 "Failed to store the float32 number (%f) in string.\n",
val);
511 }
else if (data_type > 1 && data_type != 4) {
533 if (!strcmp(
key,
"encoder")) {
534 int major, minor, micro;
535 if (sscanf(str,
"HandBrake %d.%d.%d", &major, &minor, µ) == 3) {
536 c->handbrake_version = 1000000*major + 1000*minor + micro;
548 int i, nb_chapters, str_len,
version;
552 if (
c->ignore_chapters)
555 if ((atom.
size -= 5) < 0)
564 for (
i = 0;
i < nb_chapters;
i++) {
571 if ((atom.
size -= 9+str_len) < 0)
583 #define MIN_DATA_ENTRY_BOX_SIZE 12
590 if (
c->fc->nb_streams < 1)
592 st =
c->fc->streams[
c->fc->nb_streams-1];
599 entries >= UINT_MAX /
sizeof(*sc->
drefs))
614 for (
i = 0;
i < entries;
i++) {
619 if (
size < 12 || next < 0 || next > INT64_MAX -
size)
629 uint16_t volume_len,
len;
636 volume_len =
FFMIN(volume_len, 27);
640 dref->
volume[volume_len] = 0;
682 if (
len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
688 for (j =
len - 1; j >= 0; j--) {
689 if (dref->
path[j] == 0)
694 for (j = 0; j <
len; j++)
695 if (dref->
path[j] ==
':' || dref->
path[j] == 0)
698 }
else if (
type == 0) {
710 for (j = 0; j <
len; j++)
711 if (dref->
dir[j] ==
':')
747 if (
c->trak_index < 0) {
749 c->found_hdlr_mdta = 1;
754 st =
c->fc->streams[
c->fc->nb_streams-1];
769 title_size = atom.
size - 24;
770 if (title_size > 0) {
771 if (title_size >
FFMIN(INT_MAX, SIZE_MAX-1))
782 title_str[title_size] = 0;
784 int off = (!
c->isom && title_str[0] == title_size - 1);
803 int ac3info, acmod, lfeon, bsmod;
806 if (
c->fc->nb_streams < 1)
808 st =
c->fc->streams[
c->fc->nb_streams-1];
816 bsmod = (ac3info >> 14) & 0x7;
817 acmod = (ac3info >> 11) & 0x7;
818 lfeon = (ac3info >> 10) & 0x1;
837 int eac3info, acmod, lfeon, bsmod;
840 if (
c->fc->nb_streams < 1)
842 st =
c->fc->streams[
c->fc->nb_streams-1];
854 bsmod = (eac3info >> 12) & 0x1f;
855 acmod = (eac3info >> 9) & 0x7;
856 lfeon = (eac3info >> 8) & 0x1;
876 uint32_t frame_duration_code = 0;
877 uint32_t channel_layout_code = 0;
886 if (
c->fc->nb_streams < 1) {
889 st =
c->fc->streams[
c->fc->nb_streams-1];
899 frame_duration_code =
get_bits(&gb, 2);
901 channel_layout_code =
get_bits(&gb, 16);
904 (frame_duration_code == 0) ? 512 :
905 (frame_duration_code == 1) ? 1024 :
906 (frame_duration_code == 2) ? 2048 :
907 (frame_duration_code == 3) ? 4096 : 0;
909 if (channel_layout_code > 0xff) {
928 if (
c->fc->nb_streams < 1)
930 st =
c->fc->streams[
c->fc->nb_streams-1];
946 int stream_structure;
951 if (
c->fc->nb_streams < 1)
953 st =
c->fc->streams[
c->fc->nb_streams-1];
959 "Unsupported 'chnl' box with version %d, flags: %#x",
964 stream_structure =
avio_r8(pb);
967 if (stream_structure & 1) {
980 if (speaker_pos == 126) {
995 "get channel layout from speaker positions failed, %s\n",
1000 uint64_t omitted_channel_map =
avio_rb64(pb);
1002 if (omitted_channel_map) {
1004 omitted_channel_map);
1012 if (stream_structure & 2) {
1030 if (
c->fc->nb_streams < 1)
1032 st =
c->fc->streams[
c->fc->nb_streams-1];
1047 if (
c->fc->nb_streams < 1)
1049 st =
c->fc->streams[
c->fc->nb_streams-1];
1067 #define DRM_BLOB_SIZE 56
1071 uint8_t intermediate_key[20];
1072 uint8_t intermediate_iv[20];
1075 uint8_t file_checksum[20];
1076 uint8_t calculated_checksum[20];
1077 char checksum_string[2 *
sizeof(file_checksum) + 1];
1081 uint8_t *activation_bytes =
c->activation_bytes;
1082 uint8_t *fixed_key =
c->audible_fixed_key;
1091 if (!
c->aes_decrypt) {
1103 ff_data_to_hex(checksum_string, file_checksum,
sizeof(file_checksum), 1);
1107 if (!activation_bytes) {
1112 if (
c->activation_bytes_size != 4) {
1119 if (
c->audible_fixed_key_size != 16) {
1139 if (memcmp(calculated_checksum, file_checksum, 20)) {
1146 for (
i = 0;
i < 4;
i++) {
1148 if (activation_bytes[
i] !=
output[3 -
i]) {
1154 memcpy(
c->file_key,
output + 8, 16);
1170 if (
c->audible_key_size != 16) {
1175 if (
c->audible_iv_size != 16) {
1181 if (!
c->aes_decrypt) {
1185 memcpy(
c->file_key,
c->audible_key, 16);
1186 memcpy(
c->file_iv,
c->audible_iv, 16);
1196 unsigned char iv[16];
1198 memcpy(iv,
c->file_iv, 16);
1210 int comp_brand_size;
1211 char* comp_brands_str;
1212 uint8_t
type[5] = {0};
1217 if (strcmp(
type,
"qt "))
1221 c->is_still_picture_avif = !strncmp(
type,
"avif", 4);
1225 comp_brand_size = atom.
size - 8;
1226 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1228 comp_brands_str =
av_malloc(comp_brand_size + 1);
1229 if (!comp_brands_str)
1237 comp_brands_str[comp_brand_size] = 0;
1242 if (!strcmp(
type,
"aaxc")) {
1254 if (
c->found_moov) {
1276 if (index < 0 || index >= frag_index->
nb_items)
1292 if (frag_index->
current < 0 ||
1311 if (frag_index->
current < 0 ||
1326 int64_t moof_offset;
1339 if (moof_offset >=
offset)
1341 if (moof_offset <=
offset)
1379 for (j = 0; j <
s->nb_streams; j++)
1380 if (
s->streams[j]->id == frag_stream_info->
id)
1381 frag_stream =
s->streams[j];
1403 m0 = m = (
a +
b) >> 1;
1409 if (m <
b && frag_time <= timestamp)
1426 if (index < c->frag_index.nb_items &&
1433 &
c->frag_index.allocated_size,
1434 (
c->frag_index.nb_items + 1) *
1435 sizeof(*
c->frag_index.item));
1438 c->frag_index.item = item;
1442 if (!frag_stream_info)
1445 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1447 if (
c->fc->streams[
i]->id < 0) {
1452 frag_stream_info[
i].
id =
c->fc->streams[
i]->id;
1462 if (index < c->frag_index.nb_items)
1463 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1464 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1466 item = &
c->frag_index.item[
index];
1472 c->frag_index.nb_items++;
1478 int id,
int entries)
1487 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1495 c->fragment.found_tfhd = 0;
1497 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1498 c->has_looked_for_mfra = 1;
1505 "read the mfra (may be a live ismv)\n");
1509 "seekable, can not look for mfra\n");
1512 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1531 if (time > 0 && time < 2082844800) {
1539 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1556 if (
c->fc->nb_streams < 1)
1558 st =
c->fc->streams[
c->fc->nb_streams-1];
1602 if (
c->time_scale <= 0) {
1616 for (
i = 0;
i < 3;
i++) {
1637 if (
fc->nb_streams < 1)
1639 st =
fc->streams[
fc->nb_streams-1];
1664 int little_endian =
avio_rb16(pb) & 0xFF;
1666 if (little_endian == 1)
1675 int pcm_sample_size;
1680 if (atom.
size < 6) {
1690 "Unsupported 'pcmC' box with version %d, flags: %x",
1696 pcm_sample_size =
avio_r8(pb);
1698 if (
fc->nb_streams < 1)
1701 st =
fc->streams[
fc->nb_streams - 1];
1705 switch (pcm_sample_size) {
1719 switch (pcm_sample_size) {
1741 if (format_flags & 1)
1750 uint8_t *icc_profile;
1751 char color_parameter_type[5] = { 0 };
1755 if (
c->fc->nb_streams < 1)
1757 st =
c->fc->streams[
c->fc->nb_streams - 1];
1762 if (strncmp(color_parameter_type,
"nclx", 4) &&
1763 strncmp(color_parameter_type,
"nclc", 4) &&
1764 strncmp(color_parameter_type,
"prof", 4)) {
1766 color_parameter_type);
1770 if (!strncmp(color_parameter_type,
"prof", 4)) {
1783 "%s: pri %d trc %d matrix %d",
1786 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1813 unsigned mov_field_order;
1816 if (
c->fc->nb_streams < 1)
1818 st =
c->fc->streams[
c->fc->nb_streams-1];
1822 if ((mov_field_order & 0xFF00) == 0x0100)
1824 else if ((mov_field_order & 0xFF00) == 0x0200) {
1825 switch (mov_field_order & 0xFF) {
1848 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1871 }
else if (err < atom.
size) {
1885 uint64_t original_size;
1888 if (
c->fc->nb_streams < 1)
1890 st =
c->fc->streams[
c->fc->nb_streams-1];
1939 if (!
ret &&
c->fc->nb_streams >= 1) {
1951 if (
c->fc->nb_streams >= 1) {
1952 AVStream *
const st =
c->fc->streams[
c->fc->nb_streams - 1];
1963 if (
cid == 0xd4d ||
cid == 0xd4e)
1974 if (num <= 0 || den <= 0)
1978 if (den >= INT_MAX / 2)
1996 uint64_t original_size;
1997 if (
c->fc->nb_streams >= 1) {
2001 if (atom.
size == 16) {
2006 if (length == atom.
size) {
2007 const uint8_t range_value = par->
extradata[original_size + 19];
2008 switch (range_value) {
2045 if (
c->fc->nb_streams < 1)
2047 st =
c->fc->streams[
c->fc->nb_streams-1];
2049 if ((uint64_t)atom.
size > (1<<30))
2059 }
else if (atom.
size > 8) {
2073 #define ALAC_EXTRADATA_SIZE 36
2102 if (
c->fc->nb_streams < 1)
2104 st =
c->fc->streams[
c->fc->nb_streams-1];
2106 if ((uint64_t)atom.
size > (1<<30))
2109 if (atom.
size >= 10) {
2141 uint8_t profile_level;
2144 if (
c->fc->nb_streams < 1)
2146 st =
c->fc->streams[
c->fc->nb_streams-1];
2148 if (atom.
size >= (1<<28) || atom.
size < 7)
2152 if ((profile_level & 0xf0) != 0xc0)
2173 if (
c->fc->nb_streams < 1)
2175 if (atom.
size <= 40)
2177 st =
c->fc->streams[
c->fc->nb_streams-1];
2179 if ((uint64_t)atom.
size > (1<<30))
2194 unsigned int i, entries;
2196 if (
c->trak_index < 0) {
2200 if (
c->fc->nb_streams < 1)
2202 st =
c->fc->streams[
c->fc->nb_streams-1];
2224 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2227 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2248 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2249 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2281 uint8_t codec_name[32] = { 0 };
2316 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2323 !strncmp(codec_name,
"Sorenson H263", 13))
2339 int bits_per_sample,
flags;
2364 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2472 y = (ycbcr >> 16) & 0xFF;
2473 cr = (ycbcr >> 8) & 0xFF;
2480 return (
r << 16) | (
g << 8) |
b;
2485 char buf[256] = {0};
2493 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2497 for (
i = 0;
i < 16;
i++) {
2501 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba,
i != 15 ?
", " :
"");
2504 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2541 if (str_size > 0 &&
size >= (
int)str_size + 30 &&
2543 char *reel_name =
av_malloc(str_size + 1);
2547 reel_name[str_size] = 0;
2572 #if CONFIG_DV_DEMUXER
2661 int codec_tag,
int format,
2673 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2690 int pseudo_stream_id;
2693 st =
c->fc->streams[
c->fc->nb_streams-1];
2696 for (pseudo_stream_id = 0;
2698 pseudo_stream_id++) {
2701 int ret, dref_id = 1;
2711 }
else if (
size <= 7) {
2713 "invalid size %"PRId64
" in stsd\n",
size);
2730 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
2760 }
else if (
a.size > 0)
2789 if (
c->fc->nb_streams < 1)
2791 st =
c->fc->streams[
c->fc->nb_streams - 1];
2799 if (entries <= 0 || entries > atom.
size / 8 || entries > 1024) {
2806 "Duplicate stsd found in this track.\n");
2852 unsigned int i, entries;
2854 if (
c->fc->nb_streams < 1)
2856 st =
c->fc->streams[
c->fc->nb_streams-1];
2863 if ((uint64_t)entries * 12 + 4 > atom.
size)
2888 int64_t first_min =
i + 1;
2948 unsigned i, entries;
2950 if (
c->fc->nb_streams < 1)
2952 st =
c->fc->streams[
c->fc->nb_streams-1];
2985 unsigned int i, entries;
2987 if (
c->fc->nb_streams < 1)
2989 st =
c->fc->streams[
c->fc->nb_streams-1];
3008 if (entries >= UINT_MAX /
sizeof(
int))
3034 unsigned int i, entries, sample_size, field_size, num_bytes;
3039 if (
c->fc->nb_streams < 1)
3041 st =
c->fc->streams[
c->fc->nb_streams-1];
3047 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
3066 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
3083 num_bytes = (entries*field_size+4)>>3;
3101 for (
i = 0;
i < entries;
i++) {
3122 unsigned int i, entries, alloc_size = 0;
3124 int64_t total_sample_count = 0;
3125 int64_t current_dts = 0;
3126 int64_t corrected_dts = 0;
3128 if (
c->fc->nb_streams < 1)
3130 st =
c->fc->streams[
c->fc->nb_streams-1];
3138 c->fc->nb_streams-1, entries);
3144 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
3148 unsigned int sample_duration;
3149 unsigned int sample_count;
3150 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
3168 sample_count, sample_duration);
3173 if (sample_duration >
c->max_stts_delta) {
3176 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",
3177 sample_duration,
i, sample_count, st->
index);
3179 corrected_dts += (delta_magnitude < 0 ? (int64_t)delta_magnitude : 1) * sample_count;
3181 corrected_dts += sample_duration * sample_count;
3186 if (current_dts > corrected_dts) {
3187 int64_t drift = (current_dts - corrected_dts)/
FFMAX(sample_count, 1);
3189 current_dts -= correction * sample_count;
3200 duration <= INT64_MAX - sc->duration_for_fps &&
3201 total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
3223 "All samples in data stream index:id [%d:%d] have zero "
3224 "duration, stream set to be discarded by default. Override "
3225 "using AVStream->discard or -discard for ffmpeg command.\n",
3239 if (
c->fc->nb_streams < 1)
3241 st =
c->fc->streams[
c->fc->nb_streams - 1];
3246 entries = atom.
size - 4;
3249 c->fc->nb_streams - 1, entries);
3282 unsigned int i, entries, ctts_count = 0;
3284 if (
c->fc->nb_streams < 1)
3286 st =
c->fc->streams[
c->fc->nb_streams-1];
3297 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3310 "ignoring CTTS entry with count=%d duration=%d\n",
3349 uint32_t grouping_type;
3350 uint32_t default_length;
3351 av_unused uint32_t default_group_description_index;
3352 uint32_t entry_count;
3354 if (
c->fc->nb_streams < 1)
3356 st =
c->fc->streams[
c->fc->nb_streams - 1];
3367 if (grouping_type !=
MKTAG(
's',
'y',
'n',
'c'))
3381 uint32_t description_length = default_length;
3382 if (
version >= 1 && default_length == 0)
3384 if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3385 const uint8_t nal_unit_type =
avio_r8(pb) & 0x3f;
3387 description_length -= 1;
3404 unsigned int i, entries;
3406 uint32_t grouping_type;
3410 if (
c->fc->nb_streams < 1)
3412 st =
c->fc->streams[
c->fc->nb_streams-1];
3419 if (grouping_type ==
MKTAG(
'r',
'a',
'p',
' ')) {
3422 }
else if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3463 unsigned int edit_list_index,
3464 int64_t *edit_list_media_time,
3465 int64_t *edit_list_duration,
3466 int64_t global_timescale)
3471 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3475 if (global_timescale == 0) {
3508 int64_t timestamp_pts,
3511 int64_t* ctts_index,
3512 int64_t* ctts_sample)
3519 int64_t index_ctts_count;
3547 if (ctts_data && *
index >= 0) {
3553 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3554 if (*ctts_index < ctts_count) {
3556 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3563 while (*
index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3567 if ((e_old[*
index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3573 if (*ctts_sample == 0) {
3575 if (*ctts_index >= 0)
3576 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3586 return *
index >= 0 ? 0 : -1;
3610 const size_t requested_size =
3627 ie= &entries[
index];
3642 int64_t* frame_duration_buffer,
3643 int frame_duration_buffer_size) {
3646 av_assert0(end_index >= 0 && end_index <= sti->nb_index_entries);
3647 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
3648 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
3661 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVCtts);
3662 const size_t requested_size =
3663 min_size_needed > *allocated_size ?
3664 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3667 if ((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVCtts) - 1)
3670 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
3675 *ctts_data = ctts_buf_new;
3680 *ctts_count = (*ctts_count) + 1;
3684 #define MAX_REORDER_DELAY 16
3690 int ctts_sample = 0;
3693 int j,
r, num_swaps;
3696 pts_buf[j] = INT64_MIN;
3704 buf_start = (buf_start + 1);
3717 while (j != buf_start) {
3720 if (pts_buf[j] < pts_buf[
r]) {
3721 FFSWAP(int64_t, pts_buf[j], pts_buf[
r]);
3779 if (range_size > current_sample) {
3783 current_sample -= range_size;
3802 int64_t ctts_index_old = 0;
3803 int64_t ctts_sample_old = 0;
3805 int64_t edit_list_media_time = 0;
3806 int64_t edit_list_duration = 0;
3807 int64_t frame_duration = 0;
3808 int64_t edit_list_dts_counter = 0;
3809 int64_t edit_list_dts_entry_end = 0;
3810 int64_t edit_list_start_ctts_sample = 0;
3812 int64_t curr_ctts = 0;
3813 int64_t empty_edits_sum_duration = 0;
3814 int64_t edit_list_index = 0;
3817 int64_t start_dts = 0;
3818 int64_t edit_list_start_encountered = 0;
3819 int64_t search_timestamp = 0;
3820 int64_t* frame_duration_buffer =
NULL;
3821 int num_discarded_begin = 0;
3822 int first_non_zero_audio_edit = -1;
3823 int packet_skip_samples = 0;
3825 int found_keyframe_after_edit = 0;
3826 int found_non_empty_edit = 0;
3859 edit_list_dts_entry_end -= msc->
dts_shift;
3863 start_dts = edit_list_dts_entry_end;
3867 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3868 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3870 edit_list_dts_counter = edit_list_dts_entry_end;
3871 edit_list_dts_entry_end += edit_list_duration;
3872 num_discarded_begin = 0;
3873 if (!found_non_empty_edit && edit_list_media_time == -1) {
3874 empty_edits_sum_duration += edit_list_duration;
3877 found_non_empty_edit = 1;
3882 if (first_non_zero_audio_edit < 0) {
3883 first_non_zero_audio_edit = 1;
3885 first_non_zero_audio_edit = 0;
3888 if (first_non_zero_audio_edit > 0)
3896 search_timestamp = edit_list_media_time;
3905 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3907 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3908 st->
index, edit_list_index, search_timestamp);
3910 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3912 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
3913 st->
index, edit_list_index, search_timestamp);
3916 ctts_sample_old = 0;
3919 current = e_old +
index;
3920 edit_list_start_ctts_sample = ctts_sample_old;
3923 edit_list_start_encountered = 0;
3924 found_keyframe_after_edit = 0;
3925 for (; current < e_old_end; current++,
index++) {
3927 frame_duration = (current + 1 < e_old_end) ?
3928 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3936 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3937 curr_ctts = ctts_data_old[ctts_index_old].
duration;
3938 av_log(mov->
fc,
AV_LOG_TRACE,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
3939 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
3940 curr_cts += curr_ctts;
3942 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3945 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3946 ctts_data_old[ctts_index_old].
duration) == -1) {
3949 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3950 ctts_data_old[ctts_index_old].
duration);
3954 ctts_sample_old = 0;
3955 edit_list_start_ctts_sample = 0;
3959 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3961 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3962 first_non_zero_audio_edit > 0) {
3963 packet_skip_samples = edit_list_media_time - curr_cts;
3967 edit_list_dts_counter -= packet_skip_samples;
3968 if (edit_list_start_encountered == 0) {
3969 edit_list_start_encountered = 1;
3972 if (frame_duration_buffer) {
3974 frame_duration_buffer, num_discarded_begin);
3979 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
3984 if (edit_list_start_encountered == 0) {
3985 num_discarded_begin++;
3986 frame_duration_buffer =
av_realloc(frame_duration_buffer,
3987 num_discarded_begin *
sizeof(int64_t));
3988 if (!frame_duration_buffer) {
3992 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
4007 if (edit_list_start_encountered == 0) {
4008 edit_list_start_encountered = 1;
4011 if (frame_duration_buffer) {
4013 frame_duration_buffer, num_discarded_begin);
4026 if (current_index_range < msc->index_ranges ||
index != current_index_range->
end) {
4027 current_index_range++;
4030 current_index_range->
end =
index + 1;
4033 if (edit_list_start_encountered > 0) {
4034 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
4038 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
4040 if (ctts_data_old) {
4045 found_keyframe_after_edit = 1;
4048 if (ctts_sample_old != 0) {
4051 ctts_sample_old - edit_list_start_ctts_sample,
4052 ctts_data_old[ctts_index_old].
duration) == -1) {
4054 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
4055 ctts_data_old[ctts_index_old].
duration);
4090 current_index_range++;
4091 current_index_range->
start = 0;
4092 current_index_range->
end = 0;
4151 if (sg->
index == cra_index)
4152 for (uint32_t j = 0; j < sg->
count; j++)
4154 if (sg->
count > INT_MAX - sample_id)
4156 sample_id += sg->
count;
4171 int64_t current_offset;
4172 int64_t current_dts = 0;
4173 unsigned int stts_index = 0;
4174 unsigned int stsc_index = 0;
4175 unsigned int stss_index = 0;
4176 unsigned int stps_index = 0;
4178 uint64_t stream_size = 0;
4180 unsigned int ctts_count_old = sc->
ctts_count;
4187 int i, edit_start_index = 0, multiple_edits = 0;
4188 int64_t empty_duration = 0;
4193 if (
i == 0 && e->
time == -1) {
4197 edit_start_index = 1;
4198 }
else if (
i == edit_start_index && e->
time >= 0) {
4208 "not supported in fragmented MP4 files\n");
4211 "Use -advanced_editlist to correctly decode otherwise "
4212 "a/v desync might occur\n");
4237 unsigned int current_sample = 0;
4238 unsigned int stts_sample = 0;
4239 unsigned int sample_size;
4241 unsigned int rap_group_index = 0;
4242 unsigned int rap_group_sample = 0;
4260 if (ctts_data_old) {
4275 for (
i = 0;
i < ctts_count_old &&
4277 for (j = 0; j < ctts_data_old[
i].
count &&
4318 if (rap_group_present && rap_group_index < sc->rap_group_count) {
4321 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
4322 rap_group_sample = 0;
4328 && !rap_group_present
4334 if (current_offset > INT64_MAX - sample_size) {
4344 if (sample_size > 0x3FFFFFFF) {
4349 e->
pos = current_offset;
4351 e->
size = sample_size;
4354 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", "
4355 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
4356 current_offset, current_dts, sample_size,
distance, keyframe);
4361 current_offset += sample_size;
4362 stream_size += sample_size;
4378 unsigned chunk_samples, total = 0;
4385 unsigned count, chunk_count;
4400 count = (chunk_samples+1023) / 1024;
4407 total += chunk_count *
count;
4429 while (chunk_samples > 0) {
4435 "Zero bytes per frame, but %d samples per frame",