47 {
"movflags",
"MOV muxer flags", offsetof(
MOVMuxContext,
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"movflags" },
49 {
"moov_size",
"maximum moov size so it can be placed at the begin", offsetof(
MOVMuxContext, reserved_moov_size),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, 0 },
68 #define MOV_CLASS(flavor)\
69 static const AVClass flavor ## _muxer_class = {\
70 .class_name = #flavor " muxer",\
71 .item_name = av_default_item_name,\
73 .version = LIBAVUTIL_VERSION_INT,\
97 for (i = 0; i < track->
entry; i++) {
119 for (i=0; i<track->
entry; i++) {
134 int i, j, entries = 0, tst = -1, oldtst = -1;
141 for (i=0; i<track->
entry; i++) {
143 if(oldtst != -1 && tst != oldtst) {
149 if (equalChunks && track->
entry) {
151 sSize =
FFMAX(1, sSize);
158 for (i=0; i<track->
entry; i++) {
171 int index = 0, oldval = -1, i;
172 int64_t entryPos, curpos;
180 for (i=0; i<track->
entry; i++) {
201 int64_t curpos, entryPos;
209 for (i=0; i<track->
entry; i++) {
241 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
258 if ((acmod & 1) && acmod != 1)
311 avio_w8(pb, (size>>(7*i)) | 0x80);
321 for (i = 0; i < track->
entry; i++)
329 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
330 unsigned avg_bitrate;
337 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
342 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
415 uint32_t layout_tag, bitmap;
423 "lack of channel information\n");
483 int unescaped_size, seq_found = 0;
484 int level = 0, interlace = 0;
494 packet_seq = packet_entry = 1;
501 for (next = start; next <
end; start = next) {
505 size = next - start - 4;
612 if (cluster_idx >= track->
entry)
615 if (cluster_idx + 1 == track->
entry)
618 next_dts = track->
cluster[cluster_idx + 1].
dts;
620 return next_dts - track->
cluster[cluster_idx].
dts;
625 int i, first_duration;
637 for (i = 1; i < track->
entry; i++) {
641 return first_duration;
648 uint32_t
tag = track->
tag;
732 else if(track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
813 for (i = 0; i < 10; i++)
856 (tag ==
MKTAG(
't',
'x',
'3',
'g') ||
857 tag ==
MKTAG(
't',
'e',
'x',
't'))))
862 "Quicktime/Ipod might not play the file\n");
874 else tag =
MKTAG(
'd',
'v',
'c',
' ');
877 else tag =
MKTAG(
'd',
'v',
'p',
'p');
880 else tag =
MKTAG(
'd',
'v',
'h',
'p');
883 else tag =
MKTAG(
'd',
'v',
'h',
'6');
892 static const struct {
950 "the file may be unplayable!\n");
957 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
959 "the file may be unplayable!\n");
997 tag =
MKTAG(
'w',
'm',
'a',
' ');
1027 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
1032 unsigned mov_field_order = 0;
1074 char compressor_name[32] = { 0 };
1108 avio_w8(pb, strlen(compressor_name));
1116 if(track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
1155 if (nb_frames > 255) {
1217 uint32_t entries = 0;
1221 ctts_entries =
av_malloc((track->
entry + 1) *
sizeof(*ctts_entries));
1222 ctts_entries[0].
count = 1;
1224 for (i=1; i<track->
entry; i++) {
1226 ctts_entries[entries].
count++;
1230 ctts_entries[entries].
count = 1;
1234 atom_size = 16 + (entries * 8);
1239 for (i=0; i<entries; i++) {
1251 uint32_t entries = -1;
1256 stts_entries =
av_malloc(
sizeof(*stts_entries));
1261 stts_entries = track->
entry ?
1264 for (i=0; i<track->
entry; i++) {
1266 if (i && duration == stts_entries[entries].duration) {
1267 stts_entries[entries].
count++;
1271 stts_entries[entries].
count = 1;
1276 atom_size = 16 + (entries * 8);
1281 for (i=0; i<entries; i++) {
1346 const char *font =
"Lucida Grande";
1386 if (track->
tag !=
MKTAG(
'c',
'6',
'0',
'8')) {
1432 const char *hdlr, *descr =
NULL, *hdlr_type =
NULL;
1438 descr =
"DataHandler";
1440 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
1443 descr =
"VideoHandler";
1446 descr =
"SoundHandler";
1448 if (track->
tag ==
MKTAG(
'c',
'6',
'0',
'8')) {
1450 descr =
"ClosedCaptionHandler";
1452 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) hdlr_type =
"sbtl";
1453 else hdlr_type =
"text";
1454 descr =
"SubtitleHandler";
1458 descr =
"TimeCodeHandler";
1461 descr =
"HintHandler";
1465 descr =
"DataHandler";
1510 if (track->
tag ==
MKTAG(
't',
'e',
'x',
't') || track->
tag ==
MKTAG(
'c',
'6',
'0',
'8')) {
1515 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
1517 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
1547 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1555 "FATAL error, file duration too long for timebase, this file will not be\n"
1556 "playable with quicktime. Choose a different timebase or a different\n"
1557 "container format\n");
1579 int16_t d, int16_t tx, int16_t ty)
1596 int version = duration < INT32_MAX ? 0 : 1;
1616 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1634 rotation = (rot && rot->
value) ? atoi(rot->
value) : 0;
1636 if (rotation == 90) {
1638 }
else if (rotation == 180) {
1640 }
else if (rotation == 270) {
1654 sample_aspect_ratio = 1;
1702 int version = duration < INT32_MAX ? 0 : 1;
1703 int entry_size, entry_count,
size;
1704 int64_t delay, start_ct = track->
cluster[0].
cts;
1707 version |= delay < INT32_MAX ? 0 : 1;
1709 entry_size = (version == 1) ? 20 : 12;
1710 entry_count = 1 + (delay > 0);
1711 size = 24 + entry_count * entry_size;
1782 char buf[1000] =
"";
1814 if (track->
tag ==
MKTAG(
'r',
't',
'p',
' '))
1826 int i, has_audio = 0, has_video = 0;
1836 if (audio_profile < 0)
1837 audio_profile = 0xFF - has_audio;
1838 if (video_profile < 0)
1839 video_profile = 0xFF - has_video;
1879 int max_track_id = 1, i;
1880 int64_t max_track_len_temp, max_track_len = 0;
1889 if (max_track_len < max_track_len_temp)
1890 max_track_len = max_track_len_temp;
1891 if (max_track_id < mov->tracks[i].track_id)
1896 version = max_track_len < UINT32_MAX ? 0 : 1;
1949 int size = 16 + strlen(data);
1962 return strlen(data) + 4;
1968 if (value && value[0]) {
1979 const char *
name,
const char *
tag,
1982 int l, lang = 0,
len, len2;
1990 snprintf(tag2,
sizeof(tag2),
"%s-", tag);
1992 len2 = strlen(t2->
key);
2006 int size = 0, tmpo = t ? atoi(t->
value) : 0;
2025 int size = 0, track = t ? atoi(t->
value) : 0;
2043 const char *
name,
const char *
tag,
2051 num = atoi(t->
value);
2133 return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F);
2137 const char *
tag,
const char *str)
2146 if (!strcmp(tag,
"yrrc"))
2151 if (!strcmp(tag,
"albm") &&
2169 for (i = 0; i < nb_chapters; i++) {
2241 const char *str,
const char *lang,
int type)
2294 uint64_t chunkSize = chunk->
size;
2299 for(i=1; i<trk->
entry; i++){
2307 chunkSize = chunk->
size;
2359 if(i < s->nb_streams){
2382 avio_printf(pb,
"<param name=\"%s\" value=\"%d\" valuetype=\"data\"/>\n", name, value);
2387 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, value);
2393 len =
FFMIN(
sizeof(buf)/2 - 1, len);
2396 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
2404 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
2405 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
2413 avio_printf(pb,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2414 avio_printf(pb,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
2416 avio_printf(pb,
"<meta name=\"creator\" content=\"%s\" />\n",
2426 int track_id = i + 1;
2435 avio_printf(pb,
"<%s systemBitrate=\"%d\">\n", type,
2495 int64_t moof_offset)
2500 if (!track->
entry) {
2553 for (i = 0; i < track->
entry; i++) {
2577 for (i = 0; i < track->
entry; i++) {
2582 if (flags & MOV_TRUN_SAMPLE_FLAGS)
2595 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
2596 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
2615 int size = 8 + 16 + 4 + 1 + 16*n;
2617 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
2618 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f
2631 for (i = 0; i < n; i++) {
2632 int index = entry + 1 + i;
2636 if (n < mov->ism_lookahead) {
2640 for (i = 0; i < free_size - 8; i++)
2662 MOVTrack *track, int64_t moof_offset)
2679 for (i = 0; i <
size; i++)
2698 if (tracks >= 0 && i != tracks)
2706 moof_size =
end - pos;
2709 if (tracks >= 0 && i != tracks)
2787 int has_h264 = 0, has_video = 0;
2804 minor = has_h264 ? 0x100 : 0x200;
2807 minor = has_h264 ? 0x20000 : 0x10000;
2852 int audio_kbitrate = audio_codec->
bit_rate / 1000;
2853 int video_kbitrate =
FFMIN(video_codec->
bit_rate / 1000, 800 - audio_kbitrate);
2910 int i, closed_gop = 0;
2912 for (i = 0; i < pkt->
size - 4; i++) {
2913 c = (c<<8) + pkt->
data[i];
2915 closed_gop = pkt->
data[i+4]>>6 & 0x01;
2916 }
else if (c == 0x100) {
2917 int temp_ref = (pkt->
data[i+1]<<2) | (pkt->
data[i+2]>>6);
2918 if (!temp_ref || closed_gop)
2931 int seq = 0, entry = 0;
2934 for (next = start; next <
end; start = next) {
2948 if (!trk->
entry && !fragment) {
2955 for (i = 0; i < trk->
entry; i++)
3003 int i, first_track = -1;
3004 int64_t mdat_size = 0;
3012 int buf_size, moov_size;
3018 if (i < mov->nb_streams)
3056 if (first_track < 0)
3065 int buf_size, write_moof = 1, moof_tracks = -1;
3078 write_moof = i == first_track;
3126 unsigned int samples_in_chunk = 0;
3149 static uint16_t packed_size[16] =
3150 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
3153 while (len < size && samples_in_chunk < 100) {
3154 len += packed_size[(pkt->
data[
len] >> 3) & 0x0F];
3157 if (samples_in_chunk > 1) {
3158 av_log(s,
AV_LOG_ERROR,
"fatal error, input is not a single packet, implement a AVParser for it\n");
3167 samples_in_chunk = 1;
3239 if (pkt->
dts != pkt->
pts)
3265 reformatted_data, size);
3275 int64_t frag_duration = 0;
3278 if (!pkt->
size)
return 0;
3327 if (!pkt->
size)
return 0;
3356 if (ret < 0)
return ret;
3377 track->
tag =
MKTAG(
't',
'e',
'x',
't');
3435 len = strlen(
t->value);
3470 track->
tag =
MKTAG(
't',
'm',
'c',
'd');
3495 int i, hint_track = 0, tmcd_track = 0;
3582 "so timecode metadata are now ignored\n");
3608 "codec not currently supported in container\n", i);
3616 if (track->
tag ==
MKTAG(
'm',
'x',
'3',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'3',
'n') ||
3617 track->
tag ==
MKTAG(
'm',
'x',
'4',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'4',
'n') ||
3618 track->
tag ==
MKTAG(
'm',
'x',
'5',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'5',
'n')) {
3623 track->
height = track->
tag>>24 ==
'n' ? 486 : 576;
3630 "WARNING codec timebase is very high. If duration is too long,\n"
3631 "file may not be playable by quicktime. Specify a shorter timebase\n"
3632 "or choose different container.\n");
3701 mov->
time += 0x7C25B080;
3760 int i, moov_size, moov_size2;
3776 if (moov_size2 != moov_size)
3785 int ret = 0, moov_size;
3789 int read_buf_id = 0;
3801 read_buf[1] = buf + moov_size;
3810 "the second pass (faststart)\n", s->
filename);
3823 #define READ_BLOCK do { \
3824 read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
3833 n = read_size[read_buf_id];
3838 }
while (pos < pos_end);
3886 av_log(s,
AV_LOG_INFO,
"Starting second pass: moving header on top of the file\n");
3897 av_log(s,
AV_LOG_ERROR,
"reserved_moov_size is too small, needed %"PRId64
" additional\n", 8-size);
3902 for(i=0; i<
size; i++)
3944 #if CONFIG_MOV_MUXER
3949 .extensions =
"mov",
3952 .video_codec = CONFIG_LIBX264_ENCODER ?
3961 .priv_class = &mov_muxer_class,
3964 #if CONFIG_TGP_MUXER
3969 .extensions =
"3gp",
3978 .priv_class = &tgp_muxer_class,
3981 #if CONFIG_MP4_MUXER
3986 .mime_type =
"application/mp4",
3987 .extensions =
"mp4",
3990 .video_codec = CONFIG_LIBX264_ENCODER ?
3997 .priv_class = &mp4_muxer_class,
4000 #if CONFIG_PSP_MUXER
4005 .extensions =
"mp4,psp",
4008 .video_codec = CONFIG_LIBX264_ENCODER ?
4015 .priv_class = &psp_muxer_class,
4018 #if CONFIG_TG2_MUXER
4023 .extensions =
"3g2",
4032 .priv_class = &tg2_muxer_class,
4035 #if CONFIG_IPOD_MUXER
4040 .mime_type =
"application/mp4",
4041 .extensions =
"m4v,m4a",
4050 .priv_class = &ipod_muxer_class,
4053 #if CONFIG_ISMV_MUXER
4058 .mime_type =
"application/mp4",
4059 .extensions =
"ismv,isma",
4068 .priv_class = &ismv_muxer_class,
4071 #if CONFIG_F4V_MUXER
4076 .mime_type =
"application/f4v",
4077 .extensions =
"f4v",
4086 .priv_class = &f4v_muxer_class,