50 {
"movflags",
"MOV muxer flags", offsetof(
MOVMuxContext,
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"movflags" },
71 #define MOV_CLASS(flavor)\
72 static const AVClass flavor ## _muxer_class = {\
73 .class_name = #flavor " muxer",\
74 .item_name = av_default_item_name,\
76 .version = LIBAVUTIL_VERSION_INT,\
110 for (i = 0; i < track->
entry; i++) {
123 int i, j, entries = 0, tst = -1, oldtst = -1;
130 for (i = 0; i < track->
entry; i++) {
132 if (oldtst != -1 && tst != oldtst)
137 if (equalChunks && track->
entry) {
139 sSize =
FFMAX(1, sSize);
145 for (i = 0; i < track->
entry; i++) {
158 int index = 0, oldval = -1, i;
159 int64_t entryPos, curpos;
167 for (i = 0; i < track->
entry; i++) {
187 int64_t curpos, entryPos;
195 for (i = 0; i < track->
entry; i++) {
227 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
244 if ((acmod & 1) && acmod != 1)
281 avio_w8(pb, (size >> (7 * i)) | 0x80);
288 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
295 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
300 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
359 uint32_t layout_tag, bitmap;
367 "lack of channel information\n");
420 int unescaped_size, seq_found = 0;
421 int level = 0, interlace = 0;
431 packet_seq = packet_entry = 1;
438 for (next = start; next < end; start = next) {
442 size = next - start - 4;
549 if (cluster_idx >= track->
entry)
552 if (cluster_idx + 1 == track->
entry)
555 next_dts = track->
cluster[cluster_idx + 1].
dts;
557 return next_dts - track->
cluster[cluster_idx].
dts;
562 int i, first_duration;
572 for (i = 1; i < track->
entry; i++) {
576 return first_duration;
583 uint32_t
tag = track->
tag;
636 else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
740 for (i = 0; i < 10; i++)
784 (tag ==
MKTAG(
't',
'x',
'3',
'g') ||
785 tag ==
MKTAG(
't',
'e',
'x',
't'))))
790 "Quicktime/Ipod might not play the file\n");
802 else tag =
MKTAG(
'd',
'v',
'c',
' ');
805 else tag =
MKTAG(
'd',
'v',
'p',
'p');
808 else tag =
MKTAG(
'd',
'v',
'h',
'p');
811 else tag =
MKTAG(
'd',
'v',
'h',
'6');
820 static const struct {
876 "the file may be unplayable!\n");
883 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
885 "the file may be unplayable!\n");
924 tag =
MKTAG(
'w',
'm',
'a',
' ');
954 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
959 unsigned mov_field_order = 0;
1001 char compressor_name[32] = { 0 };
1035 avio_w8(pb, strlen(compressor_name));
1043 if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
1065 }
else if (track->
vos_len > 0)
1132 uint32_t entries = 0;
1136 ctts_entries =
av_malloc((track->
entry + 1) *
sizeof(*ctts_entries));
1137 ctts_entries[0].
count = 1;
1139 for (i = 1; i < track->
entry; i++) {
1141 ctts_entries[entries].
count++;
1145 ctts_entries[entries].
count = 1;
1149 atom_size = 16 + (entries * 8);
1154 for (i = 0; i < entries; i++) {
1166 uint32_t entries = -1;
1171 stts_entries =
av_malloc(
sizeof(*stts_entries));
1176 stts_entries = track->
entry ?
1179 for (i = 0; i < track->
entry; i++) {
1181 if (i && duration == stts_entries[entries].duration) {
1182 stts_entries[entries].
count++;
1186 stts_entries[entries].
count = 1;
1191 atom_size = 16 + (entries * 8);
1196 for (i = 0; i < entries; i++) {
1294 const char *hdlr, *descr =
NULL, *hdlr_type =
NULL;
1299 descr =
"DataHandler";
1302 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
1305 descr =
"VideoHandler";
1308 descr =
"SoundHandler";
1310 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) hdlr_type =
"sbtl";
1311 else hdlr_type =
"text";
1312 descr =
"SubtitleHandler";
1315 descr =
"HintHandler";
1318 descr =
"TimeCodeHandler";
1325 "Unknown hldr_type for %s / 0x%04X, writing dummy values\n",
1373 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
1375 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
1405 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1413 "FATAL error, file duration too long for timebase, this file will not be\n"
1414 "playable with quicktime. Choose a different timebase or a different\n"
1415 "container format\n");
1436 int version = duration < INT32_MAX ? 0 : 1;
1457 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1492 sample_aspect_ratio = 1;
1533 int version = duration < INT32_MAX ? 0 : 1;
1534 int entry_size, entry_count,
size;
1535 int64_t delay, start_ct = track->
cluster[0].
cts;
1538 version |= delay < INT32_MAX ? 0 : 1;
1540 entry_size = (version == 1) ? 20 : 12;
1541 entry_count = 1 + (delay > 0);
1542 size = 24 + entry_count * entry_size;
1608 char buf[1000] =
"";
1643 if (track->
tag ==
MKTAG(
'r',
't',
'p',
' '))
1647 if (0.0 != sample_aspect_ratio && 1.0 != sample_aspect_ratio)
1655 int i, has_audio = 0, has_video = 0;
1665 if (audio_profile < 0)
1666 audio_profile = 0xFF - has_audio;
1667 if (video_profile < 0)
1668 video_profile = 0xFF - has_video;
1708 int max_track_id = 1, i;
1709 int64_t max_track_len_temp, max_track_len = 0;
1718 if (max_track_len < max_track_len_temp)
1719 max_track_len = max_track_len_temp;
1720 if (max_track_id < mov->tracks[i].track_id)
1725 version = max_track_len < UINT32_MAX ? 0 : 1;
1786 int size = 16 + strlen(data);
1799 return strlen(data) + 4;
1804 const char *value,
int lang,
int long_style)
1807 if (value && value[0]) {
1818 const char *
name,
const char *
tag,
1821 int l, lang = 0,
len, len2;
1829 snprintf(tag2,
sizeof(tag2),
"%s-", tag);
1831 len2 = strlen(t2->
key);
1846 int size = 0, track = t ? atoi(t->
value) : 0;
1931 return (((str[0] - 0x60) & 0x1F) << 10) +
1932 (((str[1] - 0x60) & 0x1F) << 5) +
1933 (( str[2] - 0x60) & 0x1F);
1937 const char *
tag,
const char *str)
1946 if (!strcmp(tag,
"yrrc"))
1951 if (!strcmp(tag,
"albm") &&
1969 for (i = 0; i < nb_chapters; i++) {
2038 const char *str,
const char *lang,
int type)
2137 avio_printf(pb,
"<param name=\"%s\" value=\"%d\" valuetype=\"data\"/>\n", name, value);
2142 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, value);
2148 len =
FFMIN(
sizeof(buf) / 2 - 1, len);
2150 buf[2 *
len] =
'\0';
2151 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
2159 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
2160 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
2168 avio_printf(pb,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2169 avio_printf(pb,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
2171 avio_printf(pb,
"<meta name=\"creator\" content=\"%s\" />\n",
2181 int track_id = i + 1;
2190 avio_printf(pb,
"<%s systemBitrate=\"%d\">\n", type,
2250 MOVTrack *track, int64_t moof_offset)
2255 if (!track->
entry) {
2313 for (i = 0; i < track->
entry; i++) {
2342 for (i = 0; i < track->
entry; i++) {
2347 if (flags & MOV_TRUN_SAMPLE_FLAGS)
2360 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
2361 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
2380 int size = 8 + 16 + 4 + 1 + 16*n;
2382 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
2383 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f
2396 for (i = 0; i < n; i++) {
2397 int index = entry + 1 + i;
2401 if (n < mov->ism_lookahead) {
2405 for (i = 0; i < free_size - 8; i++)
2427 MOVTrack *track, int64_t moof_offset,
2445 for (i = 0; i <
size; i++)
2454 int tracks,
int moof_size)
2465 if (tracks >= 0 && i != tracks)
2553 int has_h264 = 0, has_video = 0;
2572 minor = has_h264 ? 0x100 : 0x200;
2575 minor = has_h264 ? 0x20000 : 0x10000;
2620 int audio_kbitrate = audio_codec->
bit_rate / 1000;
2621 int video_kbitrate =
FFMIN(video_codec->
bit_rate / 1000, 800 - audio_kbitrate);
2678 int i, closed_gop = 0;
2680 for (i = 0; i < pkt->
size - 4; i++) {
2681 c = (c << 8) + pkt->
data[i];
2683 closed_gop = pkt->
data[i + 4] >> 6 & 0x01;
2684 }
else if (c == 0x100) {
2685 int temp_ref = (pkt->
data[i + 1] << 2) | (pkt->
data[i + 2] >> 6);
2686 if (!temp_ref || closed_gop)
2699 int seq = 0, entry = 0;
2702 for (next = start; next < end; start = next) {
2716 if (!trk->
entry && !fragment) {
2723 for (i = 0; i < trk->
entry; i++)
2756 int i, first_track = -1;
2757 int64_t mdat_size = 0;
2773 if (i < mov->nb_streams)
2814 if (first_track < 0)
2823 int buf_size, write_moof = 1, moof_tracks = -1;
2836 write_moof = i == first_track;
2889 unsigned int samples_in_chunk = 0;
2912 static uint16_t packed_size[16] =
2913 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
2916 while (len < size && samples_in_chunk < 100) {
2917 len += packed_size[(pkt->
data[
len] >> 3) & 0x0F];
2920 if (samples_in_chunk > 1) {
2921 av_log(s,
AV_LOG_ERROR,
"fatal error, input is not a single packet, implement a AVParser for it\n");
2927 samples_in_chunk = 1;
2997 if (pkt->
dts != pkt->
pts)
3021 reformatted_data, size);
3035 int64_t frag_duration = 0;
3068 uint8_t chapter_properties[43] = { 0, 0, 0, 0, 0, 0, 0, 1, };
3071 track->
tag =
MKTAG(
't',
'e',
'x',
't');
3081 memcpy(track->
enc->
extradata, chapter_properties,
sizeof(chapter_properties));
3089 pkt.duration = end - pkt.dts;
3092 len = strlen(
t->value);
3098 memcpy(pkt.data + 2,
t->value,
len);
3150 if (!enabled[i] && first[i] >= 0)
3186 int i, hint_track = 0;
3219 "with fragmentation and custom IO, disabling faststart\n");
3277 "codec not currently supported in container\n", i);
3285 if (track->
tag ==
MKTAG(
'm',
'x',
'3',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'3',
'n') ||
3286 track->
tag ==
MKTAG(
'm',
'x',
'4',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'4',
'n') ||
3287 track->
tag ==
MKTAG(
'm',
'x',
'5',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'5',
'n')) {
3292 track->
height = track->
tag >> 24 ==
'n' ? 486 : 576;
3297 "WARNING codec timebase is very high. If duration is too long,\n"
3298 "file may not be playable by quicktime. Specify a shorter timebase\n"
3299 "or choose different container.\n");
3360 mov->
time += 0x7C25B080;
3414 int i, moov_size, moov_size2;
3430 if (moov_size2 != moov_size)
3439 int ret = 0, moov_size;
3443 int read_buf_id = 0;
3455 read_buf[1] = buf + moov_size;
3464 "the second pass (faststart)\n", s->
filename);
3477 #define READ_BLOCK do { \
3478 read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
3487 n = read_size[read_buf_id];
3492 }
while (pos < pos_end);
3538 av_log(s,
AV_LOG_INFO,
"Starting second pass: moving the moov atom to the beginning of the file\n");
3571 #if CONFIG_MOV_MUXER
3576 .extensions =
"mov",
3588 .priv_class = &mov_muxer_class,
3591 #if CONFIG_TGP_MUXER
3596 .extensions =
"3gp",
3605 .priv_class = &tgp_muxer_class,
3608 #if CONFIG_MP4_MUXER
3613 .mime_type =
"application/mp4",
3614 .extensions =
"mp4",
3624 .priv_class = &mp4_muxer_class,
3627 #if CONFIG_PSP_MUXER
3632 .extensions =
"mp4,psp",
3642 .priv_class = &psp_muxer_class,
3645 #if CONFIG_TG2_MUXER
3650 .extensions =
"3g2",
3659 .priv_class = &tg2_muxer_class,
3662 #if CONFIG_IPOD_MUXER
3667 .mime_type =
"application/mp4",
3668 .extensions =
"m4v,m4a",
3677 .priv_class = &ipod_muxer_class,
3680 #if CONFIG_ISMV_MUXER
3685 .mime_type =
"application/mp4",
3686 .extensions =
"ismv,isma",
3695 .priv_class = &ismv_muxer_class,
3698 #if CONFIG_F4V_MUXER
3703 .mime_type =
"application/f4v",
3704 .extensions =
"f4v",
3713 .priv_class = &f4v_muxer_class,