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);
804 int ac3info, acmod, lfeon, bsmod;
807 if (
c->fc->nb_streams < 1)
809 st =
c->fc->streams[
c->fc->nb_streams-1];
820 bsmod = (ac3info >> 14) & 0x7;
821 acmod = (ac3info >> 11) & 0x7;
822 lfeon = (ac3info >> 10) & 0x1;
842 int eac3info, acmod, lfeon, bsmod;
845 if (
c->fc->nb_streams < 1)
847 st =
c->fc->streams[
c->fc->nb_streams-1];
863 bsmod = (eac3info >> 12) & 0x1f;
864 acmod = (eac3info >> 9) & 0x7;
865 lfeon = (eac3info >> 8) & 0x1;
885 uint32_t frame_duration_code = 0;
886 uint32_t channel_layout_code = 0;
895 if (
c->fc->nb_streams < 1) {
898 st =
c->fc->streams[
c->fc->nb_streams-1];
908 frame_duration_code =
get_bits(&gb, 2);
910 channel_layout_code =
get_bits(&gb, 16);
913 (frame_duration_code == 0) ? 512 :
914 (frame_duration_code == 1) ? 1024 :
915 (frame_duration_code == 2) ? 2048 :
916 (frame_duration_code == 3) ? 4096 : 0;
918 if (channel_layout_code > 0xff) {
937 if (
c->fc->nb_streams < 1)
939 st =
c->fc->streams[
c->fc->nb_streams-1];
955 int stream_structure;
960 if (
c->fc->nb_streams < 1)
962 st =
c->fc->streams[
c->fc->nb_streams-1];
968 "Unsupported 'chnl' box with version %d, flags: %#x",
973 stream_structure =
avio_r8(pb);
976 if (stream_structure & 1) {
989 if (speaker_pos == 126) {
1004 "get channel layout from speaker positions failed, %s\n",
1009 uint64_t omitted_channel_map =
avio_rb64(pb);
1011 if (omitted_channel_map) {
1013 omitted_channel_map);
1021 if (stream_structure & 2) {
1039 if (
c->fc->nb_streams < 1)
1041 st =
c->fc->streams[
c->fc->nb_streams-1];
1056 if (
c->fc->nb_streams < 1)
1058 st =
c->fc->streams[
c->fc->nb_streams-1];
1076 #define DRM_BLOB_SIZE 56
1080 uint8_t intermediate_key[20];
1081 uint8_t intermediate_iv[20];
1084 uint8_t file_checksum[20];
1085 uint8_t calculated_checksum[20];
1086 char checksum_string[2 *
sizeof(file_checksum) + 1];
1090 uint8_t *activation_bytes =
c->activation_bytes;
1091 uint8_t *fixed_key =
c->audible_fixed_key;
1100 if (!
c->aes_decrypt) {
1112 ff_data_to_hex(checksum_string, file_checksum,
sizeof(file_checksum), 1);
1116 if (!activation_bytes) {
1121 if (
c->activation_bytes_size != 4) {
1128 if (
c->audible_fixed_key_size != 16) {
1148 if (memcmp(calculated_checksum, file_checksum, 20)) {
1155 for (
i = 0;
i < 4;
i++) {
1157 if (activation_bytes[
i] !=
output[3 -
i]) {
1163 memcpy(
c->file_key,
output + 8, 16);
1179 if (
c->audible_key_size != 16) {
1184 if (
c->audible_iv_size != 16) {
1190 if (!
c->aes_decrypt) {
1194 memcpy(
c->file_key,
c->audible_key, 16);
1195 memcpy(
c->file_iv,
c->audible_iv, 16);
1205 unsigned char iv[16];
1207 memcpy(iv,
c->file_iv, 16);
1219 int comp_brand_size;
1220 char* comp_brands_str;
1221 uint8_t
type[5] = {0};
1225 if (
c->fc->nb_streams) {
1232 if (strcmp(
type,
"qt "))
1236 c->is_still_picture_avif = !strncmp(
type,
"avif", 4);
1240 comp_brand_size = atom.
size - 8;
1241 if (comp_brand_size < 0 || comp_brand_size == INT_MAX)
1243 comp_brands_str =
av_malloc(comp_brand_size + 1);
1244 if (!comp_brands_str)
1252 comp_brands_str[comp_brand_size] = 0;
1257 if (!strcmp(
type,
"aaxc")) {
1269 if (
c->found_moov) {
1291 if (index < 0 || index >= frag_index->
nb_items)
1307 if (frag_index->
current < 0 ||
1326 if (frag_index->
current < 0 ||
1341 int64_t moof_offset;
1354 if (moof_offset >=
offset)
1356 if (moof_offset <=
offset)
1394 for (j = 0; j <
s->nb_streams; j++)
1395 if (
s->streams[j]->id == frag_stream_info->
id)
1396 frag_stream =
s->streams[j];
1418 m0 = m = (
a +
b) >> 1;
1424 if (m <
b && frag_time <= timestamp)
1441 if (index < c->frag_index.nb_items &&
1448 &
c->frag_index.allocated_size,
1449 (
c->frag_index.nb_items + 1) *
1450 sizeof(*
c->frag_index.item));
1453 c->frag_index.item = item;
1457 if (!frag_stream_info)
1460 for (
i = 0;
i <
c->fc->nb_streams;
i++) {
1462 if (
c->fc->streams[
i]->id < 0) {
1467 frag_stream_info[
i].
id =
c->fc->streams[
i]->id;
1478 if (index < c->frag_index.nb_items)
1479 memmove(
c->frag_index.item +
index + 1,
c->frag_index.item +
index,
1480 (
c->frag_index.nb_items -
index) *
sizeof(*
c->frag_index.item));
1482 item = &
c->frag_index.item[
index];
1488 c->frag_index.nb_items++;
1494 int id,
int entries)
1503 if (frag_stream_info && frag_stream_info->
index_entry >= 0)
1511 c->fragment.found_tfhd = 0;
1513 if (!
c->has_looked_for_mfra &&
c->use_mfra_for > 0) {
1514 c->has_looked_for_mfra = 1;
1521 "read the mfra (may be a live ismv)\n");
1525 "seekable, can not look for mfra\n");
1528 c->fragment.moof_offset =
c->fragment.implicit_offset =
avio_tell(pb) - 8;
1547 if (time > 0 && time < 2082844800) {
1555 if ((int64_t)(time * 1000000ULL) / 1000000 != time) {
1572 if (
c->fc->nb_streams < 1)
1574 st =
c->fc->streams[
c->fc->nb_streams-1];
1618 if (
c->time_scale <= 0) {
1632 for (
i = 0;
i < 3;
i++) {
1653 if (
fc->nb_streams < 1)
1655 st =
fc->streams[
fc->nb_streams-1];
1680 int little_endian =
avio_rb16(pb) & 0xFF;
1682 if (little_endian == 1)
1691 int pcm_sample_size;
1696 if (atom.
size < 6) {
1706 "Unsupported 'pcmC' box with version %d, flags: %x",
1712 pcm_sample_size =
avio_r8(pb);
1714 if (
fc->nb_streams < 1)
1717 st =
fc->streams[
fc->nb_streams - 1];
1721 switch (pcm_sample_size) {
1735 switch (pcm_sample_size) {
1757 if (format_flags & 1)
1766 char color_parameter_type[5] = { 0 };
1770 if (
c->fc->nb_streams < 1)
1772 st =
c->fc->streams[
c->fc->nb_streams - 1];
1777 if (strncmp(color_parameter_type,
"nclx", 4) &&
1778 strncmp(color_parameter_type,
"nclc", 4) &&
1779 strncmp(color_parameter_type,
"prof", 4)) {
1781 color_parameter_type);
1785 if (!strncmp(color_parameter_type,
"prof", 4)) {
1801 "%s: pri %d trc %d matrix %d",
1804 if (!strncmp(color_parameter_type,
"nclx", 4)) {
1831 unsigned mov_field_order;
1834 if (
c->fc->nb_streams < 1)
1836 st =
c->fc->streams[
c->fc->nb_streams-1];
1840 if ((mov_field_order & 0xFF00) == 0x0100)
1842 else if ((mov_field_order & 0xFF00) == 0x0200) {
1843 switch (mov_field_order & 0xFF) {
1866 if (
size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
1889 }
else if (err < atom.
size) {
1903 uint64_t original_size;
1906 if (
c->fc->nb_streams < 1)
1908 st =
c->fc->streams[
c->fc->nb_streams-1];
1957 if (!
ret &&
c->fc->nb_streams >= 1) {
1969 if (
c->fc->nb_streams >= 1) {
1970 AVStream *
const st =
c->fc->streams[
c->fc->nb_streams - 1];
1981 if (
cid == 0xd4d ||
cid == 0xd4e)
1992 if (num <= 0 || den <= 0)
1996 if (den >= INT_MAX / 2)
2014 uint64_t original_size;
2015 if (
c->fc->nb_streams >= 1) {
2019 if (atom.
size == 16) {
2024 if (length == atom.
size) {
2025 const uint8_t range_value = par->
extradata[original_size + 19];
2026 switch (range_value) {
2063 if (
c->fc->nb_streams < 1)
2065 st =
c->fc->streams[
c->fc->nb_streams-1];
2067 if ((uint64_t)atom.
size > (1<<30))
2077 }
else if (atom.
size > 8) {
2091 #define ALAC_EXTRADATA_SIZE 36
2120 if (
c->fc->nb_streams < 1)
2122 st =
c->fc->streams[
c->fc->nb_streams-1];
2124 if ((uint64_t)atom.
size > (1<<30))
2127 if (atom.
size >= 10) {
2159 uint8_t profile_level;
2162 if (
c->fc->nb_streams < 1)
2164 st =
c->fc->streams[
c->fc->nb_streams-1];
2166 if (atom.
size >= (1<<28) || atom.
size < 7)
2170 if ((profile_level & 0xf0) != 0xc0)
2191 if (
c->fc->nb_streams < 1)
2193 if (atom.
size <= 40)
2195 st =
c->fc->streams[
c->fc->nb_streams-1];
2197 if ((uint64_t)atom.
size > (1<<30))
2212 unsigned int i, entries;
2214 if (
c->trak_index < 0) {
2218 if (
c->fc->nb_streams < 1)
2220 st =
c->fc->streams[
c->fc->nb_streams-1];
2242 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
2245 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
2271 ((
format & 0xFFFF) ==
'm' + (
's' << 8) ||
2272 (
format & 0xFFFF) ==
'T' + (
'S' << 8)))
2309 uint8_t codec_name[32] = { 0 };
2344 if (!strncmp(codec_name,
"Planar Y'CbCr 8-bit 4:2:0", 25)) {
2351 !strncmp(codec_name,
"Sorenson H263", 13))
2367 int bits_per_sample,
flags;
2392 (compatible_brands && strstr(compatible_brands->
value,
"qt ")) ||
2502 y = (ycbcr >> 16) & 0xFF;
2503 cr = (ycbcr >> 8) & 0xFF;
2510 return (
r << 16) | (
g << 8) |
b;
2515 char buf[256] = {0};
2523 snprintf(buf,
sizeof(buf),
"size: %dx%d\n",
2527 for (
i = 0;
i < 16;
i++) {
2531 av_strlcatf(buf,
sizeof(buf),
"%06"PRIx32
"%s", rgba,
i != 15 ?
", " :
"");
2534 if (
av_strlcat(buf,
"\n",
sizeof(buf)) >=
sizeof(buf))
2571 if (str_size > 0 &&
size >= (
int)str_size + 30 &&
2573 char *reel_name =
av_malloc(str_size + 1);
2577 reel_name[str_size] = 0;
2602 #if CONFIG_DV_DEMUXER
2692 int codec_tag,
int format,
2704 : codec_tag !=
MKTAG(
'j',
'p',
'e',
'g')))) {
2721 int pseudo_stream_id;
2724 st =
c->fc->streams[
c->fc->nb_streams-1];
2727 for (pseudo_stream_id = 0;
2729 pseudo_stream_id++) {
2732 int ret, dref_id = 1;
2742 }
else if (
size <= 7) {
2744 "invalid size %"PRId64
" in stsd\n",
size);
2761 "size=%"PRId64
" 4CC=%s codec_type=%d\n",
size,
2791 }
else if (
a.size > 0)
2820 if (
c->fc->nb_streams < 1)
2822 st =
c->fc->streams[
c->fc->nb_streams - 1];
2830 if (entries <= 0 || entries > atom.
size / 8 || entries > 1024) {
2837 "Duplicate stsd found in this track.\n");
2883 unsigned int i, entries;
2885 if (
c->fc->nb_streams < 1)
2887 st =
c->fc->streams[
c->fc->nb_streams-1];
2894 if ((uint64_t)entries * 12 + 4 > atom.
size)
2919 int64_t first_min =
i + 1;
2979 unsigned i, entries;
2981 if (
c->fc->nb_streams < 1)
2983 st =
c->fc->streams[
c->fc->nb_streams-1];
3016 unsigned int i, entries;
3018 if (
c->fc->nb_streams < 1)
3020 st =
c->fc->streams[
c->fc->nb_streams-1];
3039 if (entries >= UINT_MAX /
sizeof(
int))
3065 unsigned int i, entries, sample_size, field_size, num_bytes;
3070 if (
c->fc->nb_streams < 1)
3072 st =
c->fc->streams[
c->fc->nb_streams-1];
3078 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
3097 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
3114 num_bytes = (entries*field_size+4)>>3;
3132 for (
i = 0;
i < entries;
i++) {
3153 unsigned int i, entries, alloc_size = 0;
3155 int64_t total_sample_count = 0;
3156 int64_t current_dts = 0;
3157 int64_t corrected_dts = 0;
3159 if (
c->fc->nb_streams < 1)
3161 st =
c->fc->streams[
c->fc->nb_streams-1];
3169 c->fc->nb_streams-1, entries);
3175 if (entries >= INT_MAX /
sizeof(*sc->
stts_data))
3179 unsigned int sample_duration;
3180 unsigned int sample_count;
3181 unsigned int min_entries =
FFMIN(
FFMAX(
i + 1, 1024 * 1024), entries);
3199 sample_count, sample_duration);
3204 if (sample_duration >
c->max_stts_delta) {
3207 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",
3208 sample_duration,
i, sample_count, st->
index);
3210 corrected_dts += (delta_magnitude < 0 ? (int64_t)delta_magnitude : 1) * sample_count;
3212 corrected_dts += sample_duration * sample_count;
3217 if (current_dts > corrected_dts) {
3218 int64_t drift = (current_dts - corrected_dts)/
FFMAX(sample_count, 1);
3220 current_dts -= correction * sample_count;
3231 duration <= INT64_MAX - sc->duration_for_fps &&
3232 total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
3254 "All samples in data stream index:id [%d:%d] have zero "
3255 "duration, stream set to be discarded by default. Override "
3256 "using AVStream->discard or -discard for ffmpeg command.\n",
3270 if (
c->fc->nb_streams < 1)
3272 st =
c->fc->streams[
c->fc->nb_streams - 1];
3277 entries = atom.
size - 4;
3280 c->fc->nb_streams - 1, entries);
3313 unsigned int i, entries, ctts_count = 0;
3315 if (
c->fc->nb_streams < 1)
3317 st =
c->fc->streams[
c->fc->nb_streams-1];
3328 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
3341 "ignoring CTTS entry with count=%d duration=%d\n",
3380 uint32_t grouping_type;
3381 uint32_t default_length;
3382 av_unused uint32_t default_group_description_index;
3383 uint32_t entry_count;
3385 if (
c->fc->nb_streams < 1)
3387 st =
c->fc->streams[
c->fc->nb_streams - 1];
3398 if (grouping_type !=
MKTAG(
's',
'y',
'n',
'c'))
3412 uint32_t description_length = default_length;
3413 if (
version >= 1 && default_length == 0)
3415 if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3416 const uint8_t nal_unit_type =
avio_r8(pb) & 0x3f;
3418 description_length -= 1;
3435 unsigned int i, entries;
3437 uint32_t grouping_type;
3441 if (
c->fc->nb_streams < 1)
3443 st =
c->fc->streams[
c->fc->nb_streams-1];
3450 if (grouping_type ==
MKTAG(
'r',
'a',
'p',
' ')) {
3453 }
else if (grouping_type ==
MKTAG(
's',
'y',
'n',
'c')) {
3494 unsigned int edit_list_index,
3495 int64_t *edit_list_media_time,
3496 int64_t *edit_list_duration,
3497 int64_t global_timescale)
3502 *edit_list_media_time = msc->
elst_data[edit_list_index].
time;
3506 if (global_timescale == 0) {
3539 int64_t timestamp_pts,
3542 int64_t* ctts_index,
3543 int64_t* ctts_sample)
3550 int64_t index_ctts_count;
3578 if (ctts_data && *
index >= 0) {
3584 for (index_ctts_count = 0; index_ctts_count < *
index; index_ctts_count++) {
3585 if (*ctts_index < ctts_count) {
3587 if (ctts_data[*ctts_index].
count == *ctts_sample) {
3594 while (*
index >= 0 && (*ctts_index) >= 0 && (*ctts_index) < ctts_count) {
3598 if ((e_old[*
index].timestamp + ctts_data[*ctts_index].
duration) <= timestamp_pts &&
3604 if (*ctts_sample == 0) {
3606 if (*ctts_index >= 0)
3607 *ctts_sample = ctts_data[*ctts_index].
count - 1;
3617 return *
index >= 0 ? 0 : -1;
3641 const size_t requested_size =
3658 ie= &entries[
index];
3673 int64_t* frame_duration_buffer,
3674 int frame_duration_buffer_size) {
3677 av_assert0(end_index >= 0 && end_index <= sti->nb_index_entries);
3678 for (
i = 0;
i < frame_duration_buffer_size;
i++) {
3679 end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 -
i];
3692 const size_t min_size_needed = (*ctts_count + 1) *
sizeof(
MOVCtts);
3693 const size_t requested_size =
3694 min_size_needed > *allocated_size ?
3695 FFMAX(min_size_needed, 2 * (*allocated_size)) :
3698 if ((
unsigned)(*ctts_count) >= UINT_MAX /
sizeof(
MOVCtts) - 1)
3701 ctts_buf_new =
av_fast_realloc(*ctts_data, allocated_size, requested_size);
3706 *ctts_data = ctts_buf_new;
3711 *ctts_count = (*ctts_count) + 1;
3715 #define MAX_REORDER_DELAY 16
3721 int ctts_sample = 0;
3724 int j,
r, num_swaps;
3727 pts_buf[j] = INT64_MIN;
3735 buf_start = (buf_start + 1);
3748 while (j != buf_start) {
3751 if (pts_buf[j] < pts_buf[
r]) {
3752 FFSWAP(int64_t, pts_buf[j], pts_buf[
r]);
3810 if (range_size > current_sample) {
3814 current_sample -= range_size;
3833 int64_t ctts_index_old = 0;
3834 int64_t ctts_sample_old = 0;
3836 int64_t edit_list_media_time = 0;
3837 int64_t edit_list_duration = 0;
3838 int64_t frame_duration = 0;
3839 int64_t edit_list_dts_counter = 0;
3840 int64_t edit_list_dts_entry_end = 0;
3841 int64_t edit_list_start_ctts_sample = 0;
3843 int64_t curr_ctts = 0;
3844 int64_t empty_edits_sum_duration = 0;
3845 int64_t edit_list_index = 0;
3848 int64_t start_dts = 0;
3849 int64_t edit_list_start_encountered = 0;
3850 int64_t search_timestamp = 0;
3851 int64_t* frame_duration_buffer =
NULL;
3852 int num_discarded_begin = 0;
3853 int first_non_zero_audio_edit = -1;
3854 int packet_skip_samples = 0;
3856 int found_keyframe_after_edit = 0;
3857 int found_non_empty_edit = 0;
3890 edit_list_dts_entry_end -= msc->
dts_shift;
3894 start_dts = edit_list_dts_entry_end;
3898 av_log(mov->
fc,
AV_LOG_DEBUG,
"Processing st: %d, edit list %"PRId64
" - media time: %"PRId64
", duration: %"PRId64
"\n",
3899 st->
index, edit_list_index, edit_list_media_time, edit_list_duration);
3901 edit_list_dts_counter = edit_list_dts_entry_end;
3902 edit_list_dts_entry_end += edit_list_duration;
3903 num_discarded_begin = 0;
3904 if (!found_non_empty_edit && edit_list_media_time == -1) {
3905 empty_edits_sum_duration += edit_list_duration;
3908 found_non_empty_edit = 1;
3913 if (first_non_zero_audio_edit < 0) {
3914 first_non_zero_audio_edit = 1;
3916 first_non_zero_audio_edit = 0;
3919 if (first_non_zero_audio_edit > 0)
3927 search_timestamp = edit_list_media_time;
3936 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3938 "st: %d edit list: %"PRId64
" Missing key frame while searching for timestamp: %"PRId64
"\n",
3939 st->
index, edit_list_index, search_timestamp);
3941 &
index, &ctts_index_old, &ctts_sample_old) < 0) {
3943 "st: %d edit list %"PRId64
" Cannot find an index entry before timestamp: %"PRId64
".\n",
3944 st->
index, edit_list_index, search_timestamp);
3947 ctts_sample_old = 0;
3950 current = e_old +
index;
3951 edit_list_start_ctts_sample = ctts_sample_old;
3954 edit_list_start_encountered = 0;
3955 found_keyframe_after_edit = 0;
3956 for (; current < e_old_end; current++,
index++) {
3958 frame_duration = (current + 1 < e_old_end) ?
3959 ((current + 1)->timestamp - current->
timestamp) : edit_list_duration;
3967 if (ctts_data_old && ctts_index_old < ctts_count_old) {
3968 curr_ctts = ctts_data_old[ctts_index_old].
duration;
3969 av_log(mov->
fc,
AV_LOG_TRACE,
"stts: %"PRId64
" ctts: %"PRId64
", ctts_index: %"PRId64
", ctts_count: %"PRId64
"\n",
3970 curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
3971 curr_cts += curr_ctts;
3973 if (ctts_sample_old == ctts_data_old[ctts_index_old].
count) {
3976 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3977 ctts_data_old[ctts_index_old].
duration) == -1) {
3980 ctts_data_old[ctts_index_old].
count - edit_list_start_ctts_sample,
3981 ctts_data_old[ctts_index_old].
duration);
3985 ctts_sample_old = 0;
3986 edit_list_start_ctts_sample = 0;
3990 if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
3992 curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
3993 first_non_zero_audio_edit > 0) {
3994 packet_skip_samples = edit_list_media_time - curr_cts;
3998 edit_list_dts_counter -= packet_skip_samples;
3999 if (edit_list_start_encountered == 0) {
4000 edit_list_start_encountered = 1;
4003 if (frame_duration_buffer) {
4005 frame_duration_buffer, num_discarded_begin);
4010 av_log(mov->
fc,
AV_LOG_DEBUG,
"skip %d audio samples from curr_cts: %"PRId64
"\n", packet_skip_samples, curr_cts);
4015 if (edit_list_start_encountered == 0) {
4016 num_discarded_begin++;
4017 frame_duration_buffer =
av_realloc(frame_duration_buffer,
4018 num_discarded_begin *
sizeof(int64_t));
4019 if (!frame_duration_buffer) {
4023 frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
4038 if (edit_list_start_encountered == 0) {
4039 edit_list_start_encountered = 1;
4042 if (frame_duration_buffer) {
4044 frame_duration_buffer, num_discarded_begin);
4057 if (current_index_range < msc->index_ranges ||
index != current_index_range->
end) {
4058 current_index_range++;
4061 current_index_range->
end =
index + 1;
4064 if (edit_list_start_encountered > 0) {
4065 edit_list_dts_counter = edit_list_dts_counter + frame_duration;
4069 if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) &&
4071 if (ctts_data_old) {
4076 found_keyframe_after_edit = 1;
4079 if (ctts_sample_old != 0) {
4082 ctts_sample_old - edit_list_start_ctts_sample,
4083 ctts_data_old[ctts_index_old].
duration) == -1) {
4085 ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
4086 ctts_data_old[ctts_index_old].
duration);
4121 current_index_range++;
4122 current_index_range->
start = 0;
4123 current_index_range->
end = 0;
4182 if (sg->
index == cra_index)
4183 for (uint32_t j = 0; j < sg->
count; j++)
4185 if (sg->
count > INT_MAX - sample_id)
4187 sample_id += sg->
count;
4202 int64_t current_offset;
4203 int64_t current_dts = 0;
4204 unsigned int stts_index = 0;
4205 unsigned int stsc_index = 0;
4206 unsigned int stss_index = 0;
4207 unsigned int stps_index = 0;
4209 uint64_t stream_size = 0;
4211 unsigned int ctts_count_old = sc->
ctts_count;
4218 int i, edit_start_index = 0, multiple_edits = 0;
4219 int64_t empty_duration = 0;
4224 if (
i == 0 && e->
time == -1) {
4228 edit_start_index = 1;
4229 }
else if (
i == edit_start_index && e->
time >= 0) {
4239 "not supported in fragmented MP4 files\n");
4242 "Use -advanced_editlist to correctly decode otherwise "
4243 "a/v desync might occur\n");
4268 unsigned int current_sample = 0;
4269 unsigned int stts_sample = 0;
4270 unsigned int sample_size;
4272 unsigned int rap_group_index = 0;
4273 unsigned int rap_group_sample = 0;
4291 if (ctts_data_old) {
4306 for (
i = 0;
i < ctts_count_old &&
4308 for (j = 0; j < ctts_data_old[
i].
count &&
4349 if (rap_group_present && rap_group_index < sc->rap_group_count) {
4352 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
4353 rap_group_sample = 0;
4359 && !rap_group_present
4365 if (current_offset > INT64_MAX - sample_size) {
4375 if (sample_size > 0x3FFFFFFF) {
4380 e->
pos = current_offset;
4382 e->
size = sample_size;
4385 av_log(mov->
fc,
AV_LOG_TRACE,
"AVIndex stream %d, sample %u, offset %"PRIx64
", dts %"PRId64
", "
4386 "size %u, distance %u, keyframe %d\n", st->
index, current_sample,
4387 current_offset, current_dts, sample_size,
distance, keyframe);
4392 current_offset += sample_size;
4393 stream_size += sample_size;
4409 unsigned chunk_samples, total = 0;
4416 unsigned count, chunk_count;
4431 count = (chunk_samples+1023) / 1024;
4438 total += chunk_count *
count;