70 unsigned len,
const char *key)
74 short current, total = 0;
80 snprintf(buf,
sizeof(buf),
"%d", current);
82 snprintf(buf,
sizeof(buf),
"%d/%d", current, total);
89 unsigned len,
const char *key)
98 snprintf(buf,
sizeof(buf),
"%d",
avio_r8(pb));
105 unsigned len,
const char *key)
109 snprintf(buf,
sizeof(buf),
"%d",
avio_r8(pb));
116 unsigned len,
const char *key)
133 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
134 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
135 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
136 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
137 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
138 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
139 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
140 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
141 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
142 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
143 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
144 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
145 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
146 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
147 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
148 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
152 char *dst,
int dstlen)
155 char *end = dst+dstlen-1;
158 for (i = 0; i <
len; i++) {
160 if (c < 0x80 && p < end)
213 #ifdef MOV_EXPORT_ALL_METADATA
216 char str[1024], key2[16], language[4] = {0};
217 const char *key =
NULL;
218 uint16_t langcode = 0;
219 uint32_t data_type = 0, str_size;
223 case MKTAG(0xa9,
'n',
'a',
'm'): key =
"title";
break;
224 case MKTAG(0xa9,
'a',
'u',
't'):
225 case MKTAG(0xa9,
'A',
'R',
'T'): key =
"artist";
break;
226 case MKTAG(
'a',
'A',
'R',
'T'): key =
"album_artist";
break;
227 case MKTAG(0xa9,
'w',
'r',
't'): key =
"composer";
break;
228 case MKTAG(
'c',
'p',
'r',
't'):
229 case MKTAG(0xa9,
'c',
'p',
'y'): key =
"copyright";
break;
230 case MKTAG(0xa9,
'c',
'm',
't'):
231 case MKTAG(0xa9,
'i',
'n',
'f'): key =
"comment";
break;
232 case MKTAG(0xa9,
'a',
'l',
'b'): key =
"album";
break;
233 case MKTAG(0xa9,
'd',
'a',
'y'): key =
"date";
break;
234 case MKTAG(0xa9,
'g',
'e',
'n'): key =
"genre";
break;
235 case MKTAG(
'g',
'n',
'r',
'e'): key =
"genre";
237 case MKTAG(0xa9,
't',
'o',
'o'):
238 case MKTAG(0xa9,
's',
'w',
'r'): key =
"encoder";
break;
239 case MKTAG(0xa9,
'e',
'n',
'c'): key =
"encoder";
break;
240 case MKTAG(
'd',
'e',
's',
'c'): key =
"description";
break;
241 case MKTAG(
'l',
'd',
'e',
's'): key =
"synopsis";
break;
242 case MKTAG(
't',
'v',
's',
'h'): key =
"show";
break;
243 case MKTAG(
't',
'v',
'e',
'n'): key =
"episode_id";
break;
244 case MKTAG(
't',
'v',
'n',
'n'): key =
"network";
break;
245 case MKTAG(
't',
'r',
'k',
'n'): key =
"track";
247 case MKTAG(
'd',
'i',
's',
'k'): key =
"disc";
249 case MKTAG(
't',
'v',
'e',
's'): key =
"episode_sort";
251 case MKTAG(
't',
'v',
's',
'n'): key =
"season_number";
253 case MKTAG(
's',
't',
'i',
'k'): key =
"media_type";
255 case MKTAG(
'h',
'd',
'v',
'd'): key =
"hd_video";
257 case MKTAG(
'p',
'g',
'a',
'p'): key =
"gapless_playback";
264 if (tag ==
MKTAG(
'd',
'a',
't',
'a')) {
267 str_size = data_size - 16;
270 if (atom.
type ==
MKTAG(
'c',
'o',
'v',
'r')) {
284 str_size = atom.
size;
286 #ifdef MOV_EXPORT_ALL_METADATA
288 snprintf(tmp_key, 5,
"%.4s", (
char*)&atom.
type);
298 str_size =
FFMIN3(
sizeof(str)-1, str_size, atom.
size);
301 parse(c, pb, str_size, key);
303 if (data_type == 3 || (data_type == 0 && langcode < 0x800)) {
310 if (*language && strcmp(language,
"und")) {
311 snprintf(key2,
sizeof(key2),
"%s-%s", key, language);
315 av_dlog(c->
fc,
"lang \"%3s\" ", language);
316 av_dlog(c->
fc,
"tag \"%s\" value \"%s\" atom \"%.4s\" %d %"PRId64
"\n",
317 key, str, (
char*)&atom.
type, str_size, atom.
size);
325 int i, nb_chapters, str_len,
version;
328 if ((atom.
size -= 5) < 0)
337 for (i = 0; i < nb_chapters; i++) {
344 if ((atom.
size -= 9+str_len) < 0)
354 #define MIN_DATA_ENTRY_BOX_SIZE 12
369 entries >= UINT_MAX /
sizeof(*sc->
drefs))
387 av_dlog(c->
fc,
"type %.4s size %d\n", (
char*)&dref->
type, size);
389 if (dref->
type ==
MKTAG(
'a',
'l',
'i',
's') && size > 150) {
391 uint16_t volume_len,
len;
397 volume_len =
FFMIN(volume_len, 27);
399 dref->
volume[volume_len] = 0;
405 len =
FFMIN(len, 63);
420 for (type = 0; type != -1 &&
avio_tell(pb) < next; ) {
434 if (len > volume_len && !strncmp(dref->
path, dref->
volume, volume_len)) {
436 memmove(dref->
path, dref->
path+volume_len, len);
439 for (j = 0; j <
len; j++)
440 if (dref->
path[j] ==
':')
443 }
else if (type == 0) {
450 for (j = 0; j <
len; j++)
451 if (dref->
dir[j] ==
':')
481 av_dlog(c->
fc,
"ctype= %.4s (0x%08x)\n", (
char*)&ctype, ctype);
482 av_dlog(c->
fc,
"stype= %.4s\n", (
char*)&type);
484 if (type ==
MKTAG(
'v',
'i',
'd',
'e'))
486 else if (type ==
MKTAG(
's',
'o',
'u',
'n'))
488 else if (type ==
MKTAG(
'm',
'1',
'a',
' '))
490 else if ((type ==
MKTAG(
's',
'u',
'b',
'p')) || (type ==
MKTAG(
'c',
'l',
'c',
'p')))
530 int ac3info, acmod, lfeon, bsmod;
537 bsmod = (ac3info >> 14) & 0x7;
538 acmod = (ac3info >> 11) & 0x7;
539 lfeon = (ac3info >> 10) & 0x1;
540 st->
codec->
channels = ((
int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon;
554 int eac3info, acmod, lfeon, bsmod;
565 bsmod = (eac3info >> 12) & 0x1f;
566 acmod = (eac3info >> 9) & 0x7;
567 lfeon = (eac3info >> 8) & 0x1;
621 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
624 }
else if (den != 0) {
645 char minor_ver_str[11];
646 char* comp_brands_str;
650 if (strcmp(type,
"qt "))
655 snprintf(minor_ver_str,
sizeof(minor_ver_str),
"%d", minor_ver);
658 comp_brand_size = atom.
size - 8;
659 if (comp_brand_size < 0)
661 comp_brands_str =
av_malloc(comp_brand_size + 1);
662 if (!comp_brands_str)
664 avio_read(pb, comp_brands_str, comp_brand_size);
665 comp_brands_str[comp_brand_size] = 0;
700 strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", ptm);
710 char language[4] = {0};
712 time_t creation_time;
747 time_t creation_time;
791 if ((uint64_t)atom.
size > (1<<30))
817 av_dlog(c->
fc,
"enda %d\n", little_endian);
818 if (little_endian == 1) {
842 unsigned mov_field_order;
851 if ((mov_field_order & 0xFF00) == 0x0100)
853 else if ((mov_field_order & 0xFF00) == 0x0200) {
854 switch (mov_field_order & 0xFF) {
884 if (size > INT_MAX || (uint64_t)atom.
size > INT_MAX)
906 if ((uint64_t)atom.
size > (1<<30))
917 }
else if (atom.
size > 8) {
938 if ((uint64_t)atom.
size > (1<<30))
941 if (atom.
size >= 10) {
947 if (type ==
MKTAG(
'f',
'i',
'e',
'l') && size == atom.
size)
968 if (atom.
size >= (1<<28) || atom.
size < 7)
972 if ((profile_level & 0xf0) != 0xc0)
1000 if ((uint64_t)atom.
size > (1<<30))
1017 unsigned int i, entries;
1031 if (entries >= UINT_MAX/
sizeof(int64_t))
1039 if (atom.
type ==
MKTAG(
's',
't',
'c',
'o'))
1042 else if (atom.
type ==
MKTAG(
'c',
'o',
'6',
'4'))
1074 int j, pseudo_stream_id;
1081 for (pseudo_stream_id = 0;
1083 pseudo_stream_id++) {
1122 if (
id<=0 && ((format&0xFFFF) ==
'm'+(
's'<<8) || (format&0xFFFF) ==
'T'+(
'S'<<8)))
1128 format && format !=
MKTAG(
'm',
'p',
'4',
's')) {
1141 av_dlog(c->
fc,
"size=%d 4CC= %c%c%c%c codec_type=%d\n", size,
1142 (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,
1146 unsigned int color_depth,
len;
1147 int color_greyscale;
1175 if (format ==
MKTAG(
'H',
'2',
'6',
'3') &&
1181 av_dlog(c->
fc,
"depth %d, ctab id %d\n",
1188 if ((color_depth == 2) || (color_depth == 4) ||
1189 (color_depth == 8)) {
1191 unsigned int color_start, color_count, color_end;
1192 unsigned char r,
g,
b;
1194 if (color_greyscale) {
1195 int color_index, color_dec;
1198 color_count = 1 << color_depth;
1200 color_dec = 256 / (color_count - 1);
1201 for (j = 0; j < color_count; j++) {
1202 r = g = b = color_index;
1204 (r << 16) | (g << 8) | (
b);
1205 color_index -= color_dec;
1206 if (color_index < 0)
1209 }
else if (color_table_id) {
1212 color_count = 1 << color_depth;
1213 if (color_depth == 2)
1215 else if (color_depth == 4)
1220 for (j = 0; j < color_count; j++) {
1221 r = color_table[j * 3 + 0];
1222 g = color_table[j * 3 + 1];
1223 b = color_table[j * 3 + 2];
1225 (r << 16) | (g << 8) | (
b);
1232 if ((color_start <= 255) &&
1233 (color_end <= 255)) {
1234 for (j = color_start; j <= color_end; j++) {
1247 (r << 16) | (g << 8) | (
b);
1254 int bits_per_sample,
flags;
1278 }
else if (version==2) {
1287 if (format ==
MKTAG(
'l',
'p',
'c',
'm'))
1329 if (bits_per_sample) {
1337 if (format !=
AV_RL32(
"mp4s"))
1352 }
else if (a.
size > 0)
1364 #if CONFIG_DV_DEMUXER
1434 unsigned int i, entries;
1450 if (entries >= UINT_MAX /
sizeof(*sc->
stsc_data))
1456 for (i = 0; i < entries && !pb->
eof_reached; i++) {
1474 unsigned i, entries;
1484 if (entries >= UINT_MAX /
sizeof(*sc->
stps_data))
1490 for (i = 0; i < entries && !pb->
eof_reached; i++) {
1507 unsigned int i, entries;
1519 av_dlog(c->
fc,
"keyframe_count = %d\n", entries);
1526 if (entries >= UINT_MAX /
sizeof(
int))
1532 for (i = 0; i < entries && !pb->
eof_reached; i++) {
1549 unsigned int i, entries, sample_size, field_size, num_bytes;
1561 if (atom.
type ==
MKTAG(
's',
't',
's',
'z')) {
1579 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
1586 if (entries >= UINT_MAX /
sizeof(
int) || entries >= (UINT_MAX - 4) / field_size)
1592 num_bytes = (entries*field_size+4)>>3;
1600 if (
avio_read(pb, buf, num_bytes) < num_bytes) {
1608 for (i = 0; i < entries && !pb->
eof_reached; i++) {
1626 unsigned int i, entries;
1628 int64_t total_sample_count=0;
1639 av_dlog(c->
fc,
"track[%i].stts.entries = %i\n",
1644 if (entries >= UINT_MAX /
sizeof(*sc->
stts_data))
1651 for (i = 0; i < entries && !pb->
eof_reached; i++) {
1652 int sample_duration;
1660 av_dlog(c->
fc,
"sample_count=%d, sample_duration=%d\n",
1661 sample_count, sample_duration);
1663 duration+=(int64_t)sample_duration*sample_count;
1664 total_sample_count+=sample_count;
1683 unsigned int i, entries;
1698 if (entries >= UINT_MAX /
sizeof(*sc->
ctts_data))
1704 for (i = 0; i < entries && !pb->
eof_reached; i++) {
1728 unsigned int i, entries;
1730 uint32_t grouping_type;
1740 if (grouping_type !=
MKTAG(
'r',
'a',
'p',
' '))
1748 if (entries >= UINT_MAX /
sizeof(*sc->
rap_group))
1754 for (i = 0; i < entries && !pb->
eof_reached; i++) {
1767 int64_t current_offset;
1768 int64_t current_dts = 0;
1769 unsigned int stts_index = 0;
1770 unsigned int stsc_index = 0;
1771 unsigned int stss_index = 0;
1772 unsigned int stps_index = 0;
1774 uint64_t stream_size = 0;
1794 unsigned int current_sample = 0;
1795 unsigned int stts_sample = 0;
1796 unsigned int sample_size;
1798 unsigned int rap_group_index = 0;
1799 unsigned int rap_group_sample = 0;
1836 if (rap_group_present && rap_group_index < sc->rap_group_count) {
1839 if (++rap_group_sample == sc->
rap_group[rap_group_index].
count) {
1840 rap_group_sample = 0;
1850 e->
pos = current_offset;
1852 e->
size = sample_size;
1855 av_dlog(mov->
fc,
"AVIndex stream %d, sample %d, offset %"PRIx64
", dts %"PRId64
", "
1856 "size %d, distance %d, keyframe %d\n", st->
index, current_sample,
1857 current_offset, current_dts, sample_size, distance, keyframe);
1860 current_offset += sample_size;
1861 stream_size += sample_size;
1875 unsigned chunk_samples, total = 0;
1879 unsigned count, chunk_count;
1892 count = (chunk_samples+samples-1) /
samples;
1894 count = (chunk_samples+1023) / 1024;
1897 if (i < sc->stsc_count - 1)
1901 total += chunk_count * count;
1904 av_dlog(mov->
fc,
"chunk count %d\n", total);
1921 while (chunk_samples > 0) {
1934 samples =
FFMIN(1024, chunk_samples);
1944 e->
pos = current_offset;
1949 av_dlog(mov->
fc,
"AVIndex stream %d, chunk %d, offset %"PRIx64
", dts %"PRId64
", "
1950 "size %d, duration %d\n", st->
index, i, current_offset, current_dts,
1953 current_offset +=
size;
1967 char filename[1024];
1972 src_path = strrchr(src,
'/');
1979 for (i = 0, l = strlen(ref->
path) - 1; l >= 0; l--)
1980 if (ref->
path[l] ==
'/') {
1988 if (i == ref->
nlvl_to - 1 && src_path - src <
sizeof(filename)) {
1989 memcpy(filename, src, src_path - src);
1990 filename[src_path - src] = 0;
2012 if (!st)
return AVERROR(ENOMEM);
2015 if (!sc)
return AVERROR(ENOMEM);
2047 "stream %d, error opening alias: path='%s', dir='%s', "
2048 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
2065 #if FF_API_R_FRAME_RATE
2067 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
2073 #if CONFIG_H261_DECODER
2076 #if CONFIG_H263_DECODER
2079 #if CONFIG_MPEG4_DECODER
2110 while (atom.
size > 8) {
2113 if (tag ==
MKTAG(
'h',
'd',
'l',
'r')) {
2127 int64_t disp_transform[2];
2128 int display_matrix[3][2];
2170 for (i = 0; i < 3; i++) {
2178 sc->
width = width >> 16;
2179 sc->
height = height >> 16;
2185 if (width && height &&
2186 ((display_matrix[0][0] != 65536 ||
2187 display_matrix[1][1] != 65536) &&
2188 !display_matrix[0][1] &&
2189 !display_matrix[1][0] &&
2190 !display_matrix[2][0] && !display_matrix[2][1])) {
2191 for (i = 0; i < 2; i++)
2193 (int64_t) width * display_matrix[0][i] +
2194 (int64_t) height * display_matrix[1][i] +
2195 ((int64_t) display_matrix[2][i] << 16);
2199 ((
double) disp_transform[0] * height) /
2200 ((
double) disp_transform[1] * width), INT_MAX);
2209 int flags, track_id, i;
2277 int data_offset = 0;
2278 unsigned entries, first_sample_flags = frag->
flags;
2297 av_dlog(c->
fc,
"flags 0x%x entries %d\n", flags, entries);
2328 av_dlog(c->
fc,
"first sample flags 0x%x\n", first_sample_flags);
2329 for (i = 0; i < entries && !pb->
eof_reached; i++) {
2330 unsigned sample_size = frag->
size;
2331 int sample_flags = i ? frag->
flags : first_sample_flags;
2332 unsigned sample_duration = frag->
duration;
2344 else if (!found_keyframe)
2345 keyframe = found_keyframe =
2352 av_dlog(c->
fc,
"AVIndex stream %d, sample %d, offset %"PRIx64
", dts %"PRId64
", "
2354 offset, dts, sample_size, distance, keyframe);
2356 dts += sample_duration;
2357 offset += sample_size;
2384 if (atom.
type !=
MKTAG(
'm',
'd',
'a',
't')) {
2398 long cmov_len, moov_len;
2412 cmov_len = atom.
size - 6 * 4;
2423 if (uncompress (moov_data, (uLongf *) &moov_len, (
const Bytef *)cmov_data, cmov_len) != Z_OK)
2424 goto free_and_return;
2426 goto free_and_return;
2428 atom.
size = moov_len;
2454 if ((uint64_t)edit_count*12+8 > atom.
size)
2457 for (i=0; i<edit_count; i++){
2468 if (i == 0 && time >= -1) {
2475 "a/v desync might occur, patch welcome\n");
2544 int64_t total_size = 0;
2549 atom.
size = INT64_MAX;
2554 if (atom.
size >= 8) {
2558 av_dlog(c->
fc,
"type: %08x '%.4s' parent:'%.4s' sz: %"PRId64
" %"PRId64
" %"PRId64
"\n",
2575 for (i = 0; mov_default_parse_table[i].
type; i++)
2576 if (mov_default_parse_table[i].type == a.
type) {
2591 int err =
parse(c, pb, a);
2606 total_size += a.
size;
2609 if (total_size < atom.
size && atom.
size < 0x7ffff)
2617 unsigned int offset;
2625 if ((offset + 8) > (
unsigned int)p->
buf_size)
2630 case MKTAG(
'j',
'P',
' ',
' '):
2631 case MKTAG(
'm',
'o',
'o',
'v'):
2632 case MKTAG(
'm',
'd',
'a',
't'):
2633 case MKTAG(
'p',
'n',
'o',
't'):
2634 case MKTAG(
'u',
'd',
't',
'a'):
2635 case MKTAG(
'f',
't',
'y',
'p'):
2638 case MKTAG(
'e',
'd',
'i',
'w'):
2639 case MKTAG(
'w',
'i',
'd',
'e'):
2640 case MKTAG(
'f',
'r',
'e',
'e'):
2641 case MKTAG(
'j',
'u',
'n',
'k'):
2642 case MKTAG(
'p',
'i',
'c',
't'):
2644 case MKTAG(0x82,0x82,0x7f,0x7d):
2645 case MKTAG(
's',
'k',
'i',
'p'):
2646 case MKTAG(
'u',
'u',
'i',
'd'):
2647 case MKTAG(
'p',
'r',
'f',
'l'):
2696 if (len > sample->
size-2)
2698 title_len = 2*len + 1;
2711 else if (ch == 0xfffe)
2715 if (len == 1 || len == 2)
2744 if (sc->
pb && sc->
pb != s->
pb)
2774 atom.
size = INT64_MAX;
2808 int64_t best_dts = INT64_MAX;
2819 ((msc->
pb != s->
pb && dts < best_dts) || (msc->
pb == s->
pb &&
2822 sample = current_sample;
2876 #if CONFIG_DV_DEMUXER
2911 av_dlog(s,
"stream %d, pts %"PRId64
", dts %"PRId64
", pos 0x%"PRIx64
", duration %d\n",
2923 av_dlog(s,
"stream %d, timestamp %"PRId64
", sample %d\n", st->
index, timestamp, sample);
2924 if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)
2949 int64_t seek_timestamp, timestamp;
2955 if (sample_time < 0)
2958 st = s->
streams[stream_index];
2968 if (stream_index == i)
2978 .
name =
"mov,mp4,m4a,3gp,3g2,mj2",