69 unsigned len,
const char *key)
78 snprintf(buf,
sizeof(buf),
"%d", current);
80 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
87 unsigned len,
const char *key)
96 snprintf(buf,
sizeof(buf),
"%d",
avio_r8(pb));
103 unsigned len,
const char *key)
107 snprintf(buf,
sizeof(buf),
"%d",
avio_r8(pb));
114 unsigned len,
const char *key)
131 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
132 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
133 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
134 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
135 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
136 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
137 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
138 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
139 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
140 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
141 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
142 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
143 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
144 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
145 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
146 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
150 char *dst,
int dstlen)
153 char *end = dst+dstlen-1;
156 for (i = 0; i <
len; i++) {
158 if (c < 0x80 && p < end)
169 #ifdef MOV_EXPORT_ALL_METADATA
172 char str[1024], key2[16], language[4] = {0};
173 const char *key =
NULL;
174 uint16_t str_size, langcode = 0;
175 uint32_t data_type = 0;
179 case MKTAG(0xa9,
'n',
'a',
'm'): key =
"title";
break;
180 case MKTAG(0xa9,
'a',
'u',
't'):
181 case MKTAG(0xa9,
'A',
'R',
'T'): key =
"artist";
break;
182 case MKTAG(
'a',
'A',
'R',
'T'): key =
"album_artist";
break;
183 case MKTAG(0xa9,
'w',
'r',
't'): key =
"composer";
break;
184 case MKTAG(
'c',
'p',
'r',
't'):
185 case MKTAG(0xa9,
'c',
'p',
'y'): key =
"copyright";
break;
186 case MKTAG(0xa9,
'c',
'm',
't'):
187 case MKTAG(0xa9,
'i',
'n',
'f'): key =
"comment";
break;
188 case MKTAG(0xa9,
'a',
'l',
'b'): key =
"album";
break;
189 case MKTAG(0xa9,
'd',
'a',
'y'): key =
"date";
break;
190 case MKTAG(0xa9,
'g',
'e',
'n'): key =
"genre";
break;
191 case MKTAG(
'g',
'n',
'r',
'e'): key =
"genre";
193 case MKTAG(0xa9,
't',
'o',
'o'):
194 case MKTAG(0xa9,
's',
'w',
'r'): key =
"encoder";
break;
195 case MKTAG(0xa9,
'e',
'n',
'c'): key =
"encoder";
break;
196 case MKTAG(
'd',
'e',
's',
'c'): key =
"description";
break;
197 case MKTAG(
'l',
'd',
'e',
's'): key =
"synopsis";
break;
198 case MKTAG(
't',
'v',
's',
'h'): key =
"show";
break;
199 case MKTAG(
't',
'v',
'e',
'n'): key =
"episode_id";
break;
200 case MKTAG(
't',
'v',
'n',
'n'): key =
"network";
break;
201 case MKTAG(
't',
'r',
'k',
'n'): key =
"track";
203 case MKTAG(
'd',
'i',
's',
'k'): key =
"disc";
205 case MKTAG(
't',
'v',
'e',
's'): key =
"episode_sort";
207 case MKTAG(
't',
'v',
's',
'n'): key =
"season_number";
209 case MKTAG(
's',
't',
'i',
'k'): key =
"media_type";
211 case MKTAG(
'h',
'd',
'v',
'd'): key =
"hd_video";
213 case MKTAG(
'p',
'g',
'a',
'p'): key =
"gapless_playback";
220 if (tag ==
MKTAG(
'd',
'a',
't',
'a')) {
223 str_size = data_size - 16;
232 str_size = atom.
size;
234 #ifdef MOV_EXPORT_ALL_METADATA
236 snprintf(tmp_key, 5,
"%.4s", (
char*)&atom.
type);
246 str_size =
FFMIN3(
sizeof(str)-1, str_size, atom.
size);
249 parse(c, pb, str_size, key);
251 if (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff))) {
258 if (*language && strcmp(language,
"und")) {
259 snprintf(key2,
sizeof(key2),
"%s-%s", key, language);
263 av_dlog(c->
fc,
"lang \"%3s\" ", language);
264 av_dlog(c->
fc,
"tag \"%s\" value \"%s\" atom \"%.4s\" %d %"PRId64
"\n",
265 key, str, (
char*)&atom.
type, str_size, atom.
size);
273 int i, nb_chapters, str_len,
version;
276 if ((atom.
size -= 5) < 0)
285 for (i = 0; i < nb_chapters; i++) {
292 if ((atom.
size -= 9+str_len) < 0)
304 int64_t total_size = 0;
314 if (atom.
size >= 8) {
318 av_dlog(c->
fc,
"type: %08x '%.4s' parent:'%.4s' sz: %"PRId64
" %"PRId64
" %"PRId64
"\n",
335 for (i = 0; mov_default_parse_table[i].
type; i++)
336 if (mov_default_parse_table[i].type == a.
type) {
351 int err =
parse(c, pb, a);
362 "overread end of atom '%.4s' by %"PRId64
" bytes\n",
363 (
char*)&a.
type, -left);
368 total_size += a.
size;
371 if (total_size < atom.
size && atom.
size < 0x7ffff)
391 entries >= UINT_MAX /
sizeof(*sc->
drefs))
409 av_dlog(c->
fc,
"type %.4s size %d\n", (
char*)&dref->
type, size);
411 if (dref->
type ==
MKTAG(
'a',
'l',
'i',
's') && size > 150) {
413 uint16_t volume_len,
len;
419 volume_len =
FFMIN(volume_len, 27);
421 dref->
volume[volume_len] = 0;
427 len =
FFMIN(len, 63);
442 for (type = 0; type != -1 &&
avio_tell(pb) < next; ) {
454 if (len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
456 memmove(dref->
path, dref->
path+volume_len, len);
459 for (j = 0; j <
len; j++)
460 if (dref->
path[j] ==
':')
463 }
else if (type == 0) {
470 for (j = 0; j <
len; j++)
471 if (dref->
dir[j] ==
':')
501 av_dlog(c->
fc,
"ctype= %.4s (0x%08x)\n", (
char*)&ctype, ctype);
502 av_dlog(c->
fc,
"stype= %.4s\n", (
char*)&type);
504 if (type ==
MKTAG(
'v',
'i',
'd',
'e'))
506 else if (type ==
MKTAG(
's',
'o',
'u',
'n'))
508 else if (type ==
MKTAG(
'm',
'1',
'a',
' '))
510 else if ((type ==
MKTAG(
's',
'u',
'b',
'p')) || (type ==
MKTAG(
'c',
'l',
'c',
'p')))
550 int ac3info, acmod, lfeon, bsmod;
557 bsmod = (ac3info >> 14) & 0x7;
558 acmod = (ac3info >> 11) & 0x7;
559 lfeon = (ac3info >> 10) & 0x1;
560 st->
codec->
channels = ((
int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon;
575 uint32_t
flags, layout_tag, bitmap, num_descr, label_mask;
592 if (atom.
size < 16ULL + num_descr * 20ULL)
595 av_dlog(c->
fc,
"chan: size=%ld version=%u flags=%u layout=%u bitmap=%u num_descr=%u\n",
596 atom.
size, version, flags, layout_tag, bitmap, num_descr);
599 for (i = 0; i < num_descr; i++) {
600 uint32_t label, cflags;
606 if (layout_tag == 0) {
608 if (mask_incr == 0) {
612 label_mask |= mask_incr;
649 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
652 }
else if (den != 0) {
673 char minor_ver_str[11];
674 char* comp_brands_str;
675 uint8_t type[5] = {0};
678 if (strcmp(type,
"qt "))
683 snprintf(minor_ver_str,
sizeof(minor_ver_str),
"%d", minor_ver);
686 comp_brand_size = atom.
size - 8;
687 if (comp_brand_size < 0)
689 comp_brands_str =
av_malloc(comp_brand_size + 1);
690 if (!comp_brands_str)
692 avio_read(pb, comp_brands_str, comp_brand_size);
693 comp_brands_str[comp_brand_size] = 0;
728 strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", ptm);
738 char language[4] = {0};
740 time_t creation_time;
780 time_t creation_time;
824 if ((uint64_t)atom.
size > (1<<30))
850 av_dlog(c->
fc,
"enda %d\n", little_endian);
851 if (little_endian == 1) {
875 unsigned mov_field_order;
884 if ((mov_field_order & 0xFF00) == 0x0100)
886 else if ((mov_field_order & 0xFF00) == 0x0200) {
887 switch (mov_field_order & 0xFF) {
917 if (size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
939 if ((uint64_t)atom.
size > (1<<30))
950 }
else if (atom.
size > 8) {
971 if ((uint64_t)atom.
size > (1<<30))
974 if (atom.
size >= 10) {
980 if (type ==
MKTAG(
'f',
'i',
'e',
'l') && size == atom.
size)
1003 if (atom.
size <= 40)
1007 if ((uint64_t)atom.
size > (1<<30))
1024 unsigned int i, entries;
1038 if (entries >= UINT_MAX/
sizeof(int64_t))
1046 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
1047 for (i=0; i<entries; i++)
1049 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
1050 for (i=0; i<entries; i++)
1097 int j, pseudo_stream_id;
1104 for (pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) {
1140 if (
id<=0 && ((format&0xFFFF) ==
'm'+(
's'<<8) || (format&0xFFFF) ==
'T'+(
'S'<<8)))
1146 format && format !=
MKTAG(
'm',
'p',
'4',
's')) {
1159 av_dlog(c->
fc,
"size=%d 4CC= %c%c%c%c codec_type=%d\n", size,
1160 (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,
1164 unsigned int color_depth,
len;
1165 int color_greyscale;
1194 av_dlog(c->
fc,
"depth %d, ctab id %d\n",
1201 if ((color_depth == 2) || (color_depth == 4) ||
1202 (color_depth == 8)) {
1204 unsigned int color_start, color_count, color_end;
1205 unsigned char r,
g,
b;
1207 if (color_greyscale) {
1208 int color_index, color_dec;
1211 color_count = 1 << color_depth;
1213 color_dec = 256 / (color_count - 1);
1214 for (j = 0; j < color_count; j++) {
1215 r = g = b = color_index;
1217 (r << 16) | (g << 8) | (
b);
1218 color_index -= color_dec;
1219 if (color_index < 0)
1225 color_count = 1 << color_depth;
1226 if (color_depth == 2)
1228 else if (color_depth == 4)
1233 for (j = 0; j < color_count; j++) {
1234 r = color_table[j * 3 + 0];
1235 g = color_table[j * 3 + 1];
1236 b = color_table[j * 3 + 2];
1238 (r << 16) | (g << 8) | (
b);
1245 if ((color_start <= 255) &&
1246 (color_end <= 255)) {
1247 for (j = color_start; j <= color_end; j++) {
1260 (r << 16) | (g << 8) | (
b);
1267 int bits_per_sample,
flags;
1291 }
else if (version==2) {
1300 if (format ==
MKTAG(
'l',
'p',
'c',
'm'))
1342 if (bits_per_sample) {
1350 if (format !=
AV_RL32(
"mp4s"))
1365 }
else if (a.
size > 0)
1374 #if CONFIG_DV_DEMUXER
1446 unsigned int i, entries;
1462 if (entries >= UINT_MAX /
sizeof(*sc->
stsc_data))
1469 for (i=0; i<entries; i++) {
1481 unsigned i, entries;
1491 if (entries >= UINT_MAX /
sizeof(*sc->
stps_data))
1498 for (i = 0; i < entries; i++) {
1510 unsigned int i, entries;
1522 av_dlog(c->
fc,
"keyframe_count = %d\n", entries);
1526 if (entries >= UINT_MAX /
sizeof(
int))
1534 for (i=0; i<entries; i++) {
1545 unsigned int i, entries, sample_size, field_size, num_bytes;
1557 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
1575 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
1582 if (entries >= UINT_MAX /
sizeof(
int) || entries >= (UINT_MAX - 4) / field_size)
1588 num_bytes = (entries*field_size+4)>>3;
1596 if (
avio_read(pb, buf, num_bytes) < num_bytes) {
1604 for (i=0; i<entries; i++)
1615 unsigned int i, entries;
1617 int64_t total_sample_count=0;
1628 av_dlog(c->
fc,
"track[%i].stts.entries = %i\n",
1633 if (entries >= UINT_MAX /
sizeof(*sc->
stts_data))
1643 for (i=0; i<entries; i++) {
1644 int sample_duration;
1649 if (sample_count < 0) {
1656 av_dlog(c->
fc,
"sample_count=%d, sample_duration=%d\n",
1657 sample_count, sample_duration);
1659 duration+=(int64_t)sample_duration*sample_count;
1660 total_sample_count+=sample_count;
1673 unsigned int i, entries;
1688 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
1695 for (i=0; i<entries; i++) {
1713 int64_t current_offset;
1714 int64_t current_dts = 0;
1715 unsigned int stts_index = 0;
1716 unsigned int stsc_index = 0;
1717 unsigned int stss_index = 0;
1718 unsigned int stps_index = 0;
1720 uint64_t stream_size = 0;
1740 unsigned int current_sample = 0;
1741 unsigned int stts_sample = 0;
1742 unsigned int sample_size;
1785 e->
pos = current_offset;
1787 e->
size = sample_size;
1790 av_dlog(mov->
fc,
"AVIndex stream %d, sample %d, offset %"PRIx64
", dts %"PRId64
", "
1791 "size %d, distance %d, keyframe %d\n", st->
index, current_sample,
1792 current_offset, current_dts, sample_size, distance, keyframe);
1795 current_offset += sample_size;
1796 stream_size += sample_size;
1810 unsigned chunk_samples, total = 0;
1814 unsigned count, chunk_count;
1826 count = (chunk_samples+samples-1) /
samples;
1828 count = (chunk_samples+1023) / 1024;
1831 if (i < sc->stsc_count - 1)
1835 total += chunk_count * count;
1838 av_dlog(mov->
fc,
"chunk count %d\n", total);
1855 while (chunk_samples > 0) {
1868 samples =
FFMIN(1024, chunk_samples);
1878 e->
pos = current_offset;
1883 av_dlog(mov->
fc,
"AVIndex stream %d, chunk %d, offset %"PRIx64
", dts %"PRId64
", "
1884 "size %d, duration %d\n", st->
index, i, current_offset, current_dts,
1887 current_offset +=
size;
1901 char filename[1024];
1906 src_path = strrchr(src,
'/');
1913 for (i = 0, l = strlen(ref->
path) - 1; l >= 0; l--)
1914 if (ref->
path[l] ==
'/') {
1922 if (i == ref->
nlvl_to - 1 && src_path - src <
sizeof(filename)) {
1923 memcpy(filename, src, src_path - src);
1924 filename[src_path - src] = 0;
1946 if (!st)
return AVERROR(ENOMEM);
1949 if (!sc)
return AVERROR(ENOMEM);
1988 "stream %d, error opening alias: path='%s', dir='%s', "
1989 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
2011 #if CONFIG_H261_DECODER
2014 #if CONFIG_H263_DECODER
2017 #if CONFIG_MPEG4_DECODER
2047 while (atom.
size > 8) {
2050 if (tag ==
MKTAG(
'h',
'd',
'l',
'r')) {
2064 int64_t disp_transform[2];
2065 int display_matrix[3][2];
2107 for (i = 0; i < 3; i++) {
2115 sc->
width = width >> 16;
2116 sc->
height = height >> 16;
2122 if (width && height &&
2123 ((display_matrix[0][0] != 65536 ||
2124 display_matrix[1][1] != 65536) &&
2125 !display_matrix[0][1] &&
2126 !display_matrix[1][0] &&
2127 !display_matrix[2][0] && !display_matrix[2][1])) {
2128 for (i = 0; i < 2; i++)
2130 (int64_t) width * display_matrix[0][i] +
2131 (int64_t) height * display_matrix[1][i] +
2132 ((int64_t) display_matrix[2][i] << 16);
2136 ((
double) disp_transform[0] * height) /
2137 ((
double) disp_transform[1] * width), INT_MAX);
2146 int flags, track_id, i;
2212 int data_offset = 0;
2213 unsigned entries, first_sample_flags = frag->
flags;
2232 av_dlog(c->
fc,
"flags 0x%x entries %d\n", flags, entries);
2258 if (flags & 0x001) data_offset =
avio_rb32(pb);
2259 if (flags & 0x004) first_sample_flags =
avio_rb32(pb);
2263 av_dlog(c->
fc,
"first sample flags 0x%x\n", first_sample_flags);
2264 for (i = 0; i < entries; i++) {
2265 unsigned sample_size = frag->
size;
2266 int sample_flags = i ? frag->
flags : first_sample_flags;
2267 unsigned sample_duration = frag->
duration;
2270 if (flags & 0x100) sample_duration =
avio_rb32(pb);
2271 if (flags & 0x200) sample_size =
avio_rb32(pb);
2272 if (flags & 0x400) sample_flags =
avio_rb32(pb);
2277 (flags & 0x004 && !i && !sample_flags) || sample_flags & 0x2000000))
2281 av_dlog(c->
fc,
"AVIndex stream %d, sample %d, offset %"PRIx64
", dts %"PRId64
", "
2283 offset, dts, sample_size, distance, keyframe);
2285 dts += sample_duration;
2286 offset += sample_size;
2308 if (atom.
type !=
MKTAG(
'm',
'd',
'a',
't')) {
2322 long cmov_len, moov_len;
2336 cmov_len = atom.
size - 6 * 4;
2347 if (uncompress (moov_data, (uLongf *) &moov_len, (
const Bytef *)cmov_data, cmov_len) != Z_OK)
2348 goto free_and_return;
2350 goto free_and_return;
2352 atom.
size = moov_len;
2378 if ((uint64_t)edit_count*12+8 > atom.
size)
2381 for (i=0; i<edit_count; i++){
2392 if (i == 0 && time >= -1) {
2399 "a/v desync might occur, patch welcome\n");
2465 unsigned int offset;
2473 if ((offset + 8) > (
unsigned int)p->
buf_size)
2478 case MKTAG(
'j',
'P',
' ',
' '):
2479 case MKTAG(
'm',
'o',
'o',
'v'):
2480 case MKTAG(
'm',
'd',
'a',
't'):
2481 case MKTAG(
'p',
'n',
'o',
't'):
2482 case MKTAG(
'u',
'd',
't',
'a'):
2483 case MKTAG(
'f',
't',
'y',
'p'):
2486 case MKTAG(
'e',
'd',
'i',
'w'):
2487 case MKTAG(
'w',
'i',
'd',
'e'):
2488 case MKTAG(
'f',
'r',
'e',
'e'):
2489 case MKTAG(
'j',
'u',
'n',
'k'):
2490 case MKTAG(
'p',
'i',
'c',
't'):
2492 case MKTAG(0x82,0x82,0x7f,0x7d):
2493 case MKTAG(
's',
'k',
'i',
'p'):
2494 case MKTAG(
'u',
'u',
'i',
'd'):
2495 case MKTAG(
'p',
'r',
'f',
'l'):
2544 if (len > sample->
size-2)
2546 title_len = 2*len + 1;
2559 else if (ch == 0xfffe)
2563 if (len == 1 || len == 2)
2622 ((msc->
pb != s->
pb && dts < best_dts) || (msc->
pb == s->
pb &&
2625 sample = current_sample;
2676 #if CONFIG_DV_DEMUXER
2711 av_dlog(s,
"stream %d, pts %"PRId64
", dts %"PRId64
", pos 0x%"PRIx64
", duration %d\n",
2719 int sample, time_sample;
2723 av_dlog(s,
"stream %d, timestamp %"PRId64
", sample %d\n", st->
index, timestamp, sample);
2724 if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)
2749 int64_t seek_timestamp, timestamp;
2755 if (sample_time < 0)
2758 st = s->
streams[stream_index];
2768 if (stream_index == i)
2792 if (sc->
pb && sc->
pb != s->
pb)
2811 .
name =
"mov,mp4,m4a,3gp,3g2,mj2",