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 },
69 #define MOV_CLASS(flavor)\
70 static const AVClass flavor ## _muxer_class = {\
71 .class_name = #flavor " muxer",\
72 .item_name = av_default_item_name,\
74 .version = LIBAVUTIL_VERSION_INT,\
98 for (i = 0; i < track->
entry; i++) {
120 for (i=0; i<track->
entry; i++) {
135 int i, j, entries = 0, tst = -1, oldtst = -1;
142 for (i=0; i<track->
entry; i++) {
144 if(oldtst != -1 && tst != oldtst) {
150 if (equalChunks && track->
entry) {
152 sSize =
FFMAX(1, sSize);
159 for (i=0; i<track->
entry; i++) {
172 int index = 0, oldval = -1, i;
173 int64_t entryPos, curpos;
181 for (i=0; i<track->
entry; i++) {
202 int64_t curpos, entryPos;
210 for (i=0; i<track->
entry; i++) {
242 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
259 if ((acmod & 1) && acmod != 1)
312 avio_w8(pb, (size>>(7*i)) | 0x80);
322 for (i = 0; i < track->
entry; i++)
330 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
331 unsigned avg_bitrate;
338 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
343 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
416 uint32_t layout_tag, bitmap;
424 "lack of channel information\n");
484 int unescaped_size, seq_found = 0;
485 int level = 0, interlace = 0;
495 packet_seq = packet_entry = 1;
502 for (next = start; next <
end; start = next) {
506 size = next - start - 4;
613 if (cluster_idx >= track->
entry)
616 if (cluster_idx + 1 == track->
entry)
619 next_dts = track->
cluster[cluster_idx + 1].
dts;
621 return next_dts - track->
cluster[cluster_idx].
dts;
626 int i, first_duration;
638 for (i = 1; i < track->
entry; i++) {
642 return first_duration;
649 uint32_t
tag = track->
tag;
733 else if(track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
814 for (i = 0; i < 10; i++)
857 (tag ==
MKTAG(
't',
'x',
'3',
'g') ||
858 tag ==
MKTAG(
't',
'e',
'x',
't'))))
863 "Quicktime/Ipod might not play the file\n");
875 else tag =
MKTAG(
'd',
'v',
'c',
' ');
878 else tag =
MKTAG(
'd',
'v',
'p',
'p');
881 else tag =
MKTAG(
'd',
'v',
'h',
'p');
884 else tag =
MKTAG(
'd',
'v',
'h',
'6');
893 static const struct {
951 "the file may be unplayable!\n");
958 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
960 "the file may be unplayable!\n");
998 tag =
MKTAG(
'w',
'm',
'a',
' ');
1028 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
1033 unsigned mov_field_order = 0;
1075 char compressor_name[32] = { 0 };
1109 avio_w8(pb, strlen(compressor_name));
1117 if(track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
1156 if (nb_frames > 255) {
1218 uint32_t entries = 0;
1222 ctts_entries =
av_malloc((track->
entry + 1) *
sizeof(*ctts_entries));
1223 ctts_entries[0].
count = 1;
1225 for (i=1; i<track->
entry; i++) {
1227 ctts_entries[entries].
count++;
1231 ctts_entries[entries].
count = 1;
1235 atom_size = 16 + (entries * 8);
1240 for (i=0; i<entries; i++) {
1252 uint32_t entries = -1;
1257 stts_entries =
av_malloc(
sizeof(*stts_entries));
1262 stts_entries = track->
entry ?
1265 for (i=0; i<track->
entry; i++) {
1267 if (i && duration == stts_entries[entries].duration) {
1268 stts_entries[entries].
count++;
1272 stts_entries[entries].
count = 1;
1277 atom_size = 16 + (entries * 8);
1282 for (i=0; i<entries; i++) {
1347 const char *font =
"Lucida Grande";
1387 if (track->
tag !=
MKTAG(
'c',
'6',
'0',
'8')) {
1433 const char *hdlr, *descr =
NULL, *hdlr_type =
NULL;
1439 descr =
"DataHandler";
1441 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
1444 descr =
"VideoHandler";
1447 descr =
"SoundHandler";
1449 if (track->
tag ==
MKTAG(
'c',
'6',
'0',
'8')) {
1451 descr =
"ClosedCaptionHandler";
1453 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) hdlr_type =
"sbtl";
1454 else hdlr_type =
"text";
1455 descr =
"SubtitleHandler";
1459 descr =
"TimeCodeHandler";
1462 descr =
"HintHandler";
1466 descr =
"DataHandler";
1511 if (track->
tag ==
MKTAG(
't',
'e',
'x',
't') || track->
tag ==
MKTAG(
'c',
'6',
'0',
'8')) {
1516 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
1518 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
1548 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1556 "FATAL error, file duration too long for timebase, this file will not be\n"
1557 "playable with quicktime. Choose a different timebase or a different\n"
1558 "container format\n");
1580 int16_t d, int16_t tx, int16_t ty)
1597 int version = duration < INT32_MAX ? 0 : 1;
1617 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1635 rotation = (rot && rot->
value) ? atoi(rot->
value) : 0;
1637 if (rotation == 90) {
1639 }
else if (rotation == 180) {
1641 }
else if (rotation == 270) {
1655 sample_aspect_ratio = 1;
1703 int version = duration < INT32_MAX ? 0 : 1;
1704 int entry_size, entry_count,
size;
1705 int64_t delay, start_ct = track->
cluster[0].
cts;
1708 version |= delay < INT32_MAX ? 0 : 1;
1710 entry_size = (version == 1) ? 20 : 12;
1711 entry_count = 1 + (delay > 0);
1712 size = 24 + entry_count * entry_size;
1783 char buf[1000] =
"";
1815 if (track->
tag ==
MKTAG(
'r',
't',
'p',
' '))
1827 int i, has_audio = 0, has_video = 0;
1837 if (audio_profile < 0)
1838 audio_profile = 0xFF - has_audio;
1839 if (video_profile < 0)
1840 video_profile = 0xFF - has_video;
1880 int max_track_id = 1, i;
1881 int64_t max_track_len_temp, max_track_len = 0;
1890 if (max_track_len < max_track_len_temp)
1891 max_track_len = max_track_len_temp;
1892 if (max_track_id < mov->tracks[i].track_id)
1897 version = max_track_len < UINT32_MAX ? 0 : 1;
1950 int size = 16 + strlen(data);
1963 return strlen(data) + 4;
1969 if (value && value[0]) {
1980 const char *
name,
const char *
tag,
1983 int l, lang = 0,
len, len2;
1991 snprintf(tag2,
sizeof(tag2),
"%s-", tag);
1993 len2 = strlen(t2->
key);
2007 int size = 0, tmpo = t ? atoi(t->
value) : 0;
2026 int size = 0, track = t ? atoi(t->
value) : 0;
2044 const char *
name,
const char *
tag,
2052 num = atoi(t->
value);
2134 return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F);
2138 const char *
tag,
const char *str)
2147 if (!strcmp(tag,
"yrrc"))
2152 if (!strcmp(tag,
"albm") &&
2170 for (i = 0; i < nb_chapters; i++) {
2242 const char *str,
const char *lang,
int type)
2295 uint64_t chunkSize = chunk->
size;
2300 for(i=1; i<trk->
entry; i++){
2308 chunkSize = chunk->
size;
2360 if(i < s->nb_streams){
2383 avio_printf(pb,
"<param name=\"%s\" value=\"%d\" valuetype=\"data\"/>\n", name, value);
2388 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, value);
2394 len =
FFMIN(
sizeof(buf)/2 - 1, len);
2397 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
2405 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
2406 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
2414 avio_printf(pb,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2415 avio_printf(pb,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
2417 avio_printf(pb,
"<meta name=\"creator\" content=\"%s\" />\n",
2427 int track_id = i + 1;
2436 avio_printf(pb,
"<%s systemBitrate=\"%d\">\n", type,
2496 int64_t moof_offset)
2501 if (!track->
entry) {
2556 for (i = 0; i < track->
entry; i++) {
2580 for (i = 0; i < track->
entry; i++) {
2585 if (flags & MOV_TRUN_SAMPLE_FLAGS)
2598 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
2599 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
2618 int size = 8 + 16 + 4 + 1 + 16*
n;
2620 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
2621 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f
2634 for (i = 0; i <
n; i++) {
2635 int index = entry + 1 + i;
2639 if (n < mov->ism_lookahead) {
2643 for (i = 0; i < free_size - 8; i++)
2665 MOVTrack *track, int64_t moof_offset)
2682 for (i = 0; i <
size; i++)
2701 if (tracks >= 0 && i != tracks)
2709 moof_size =
end - pos;
2712 if (tracks >= 0 && i != tracks)
2790 int has_h264 = 0, has_video = 0;
2807 minor = has_h264 ? 0x100 : 0x200;
2810 minor = has_h264 ? 0x20000 : 0x10000;
2855 int audio_kbitrate = audio_codec->
bit_rate / 1000;
2856 int video_kbitrate =
FFMIN(video_codec->
bit_rate / 1000, 800 - audio_kbitrate);
2913 int i, closed_gop = 0;
2915 for (i = 0; i < pkt->
size - 4; i++) {
2916 c = (c<<8) + pkt->
data[i];
2918 closed_gop = pkt->
data[i+4]>>6 & 0x01;
2919 }
else if (c == 0x100) {
2920 int temp_ref = (pkt->
data[i+1]<<2) | (pkt->
data[i+2]>>6);
2921 if (!temp_ref || closed_gop)
2934 int seq = 0, entry = 0;
2937 for (next = start; next <
end; start = next) {
2951 if (!trk->
entry && !fragment) {
2958 for (i = 0; i < trk->
entry; i++)
3006 int i, first_track = -1;
3007 int64_t mdat_size = 0;
3015 int buf_size, moov_size;
3021 if (i < mov->nb_streams)
3059 if (first_track < 0)
3068 int buf_size, write_moof = 1, moof_tracks = -1;
3081 write_moof = i == first_track;
3129 unsigned int samples_in_chunk = 0;
3152 static uint16_t packed_size[16] =
3153 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
3156 while (len < size && samples_in_chunk < 100) {
3157 len += packed_size[(pkt->
data[
len] >> 3) & 0x0F];
3160 if (samples_in_chunk > 1) {
3161 av_log(s,
AV_LOG_ERROR,
"fatal error, input is not a single packet, implement a AVParser for it\n");
3170 samples_in_chunk = 1;
3242 if (pkt->
dts != pkt->
pts)
3268 reformatted_data, size);
3278 int64_t frag_duration = 0;
3281 if (!pkt->
size)
return 0;
3330 if (!pkt->
size)
return 0;
3359 if (ret < 0)
return ret;
3380 track->
tag =
MKTAG(
't',
'e',
'x',
't');
3438 len = strlen(
t->value);
3473 track->
tag =
MKTAG(
't',
'm',
'c',
'd');
3498 int i, hint_track = 0, tmcd_track = 0;
3585 "so timecode metadata are now ignored\n");
3611 "codec not currently supported in container\n", i);
3619 if (track->
tag ==
MKTAG(
'm',
'x',
'3',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'3',
'n') ||
3620 track->
tag ==
MKTAG(
'm',
'x',
'4',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'4',
'n') ||
3621 track->
tag ==
MKTAG(
'm',
'x',
'5',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'5',
'n')) {
3626 track->
height = track->
tag>>24 ==
'n' ? 486 : 576;
3637 "WARNING codec timebase is very high. If duration is too long,\n"
3638 "file may not be playable by quicktime. Specify a shorter timebase\n"
3639 "or choose different container.\n");
3708 mov->
time += 0x7C25B080;
3767 int i, moov_size, moov_size2;
3783 if (moov_size2 != moov_size)
3792 int ret = 0, moov_size;
3796 int read_buf_id = 0;
3808 read_buf[1] = buf + moov_size;
3817 "the second pass (faststart)\n", s->
filename);
3830 #define READ_BLOCK do { \
3831 read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
3840 n = read_size[read_buf_id];
3845 }
while (pos < pos_end);
3893 av_log(s,
AV_LOG_INFO,
"Starting second pass: moving header on top of the file\n");
3904 av_log(s,
AV_LOG_ERROR,
"reserved_moov_size is too small, needed %"PRId64
" additional\n", 8-size);
3909 for(i=0; i<
size; i++)
3951 #if CONFIG_MOV_MUXER
3956 .extensions =
"mov",
3959 .video_codec = CONFIG_LIBX264_ENCODER ?
3968 .priv_class = &mov_muxer_class,
3971 #if CONFIG_TGP_MUXER
3976 .extensions =
"3gp",
3985 .priv_class = &tgp_muxer_class,
3988 #if CONFIG_MP4_MUXER
3993 .mime_type =
"application/mp4",
3994 .extensions =
"mp4",
3997 .video_codec = CONFIG_LIBX264_ENCODER ?
4004 .priv_class = &mp4_muxer_class,
4007 #if CONFIG_PSP_MUXER
4012 .extensions =
"mp4,psp",
4015 .video_codec = CONFIG_LIBX264_ENCODER ?
4022 .priv_class = &psp_muxer_class,
4025 #if CONFIG_TG2_MUXER
4030 .extensions =
"3g2",
4039 .priv_class = &tg2_muxer_class,
4042 #if CONFIG_IPOD_MUXER
4047 .mime_type =
"application/mp4",
4048 .extensions =
"m4v,m4a",
4057 .priv_class = &ipod_muxer_class,
4060 #if CONFIG_ISMV_MUXER
4065 .mime_type =
"application/mp4",
4066 .extensions =
"ismv,isma",
4075 .priv_class = &ismv_muxer_class,
4078 #if CONFIG_F4V_MUXER
4083 .mime_type =
"application/f4v",
4084 .extensions =
"f4v",
4093 .priv_class = &f4v_muxer_class,