47 {
"movflags",
"MOV muxer flags", offsetof(
MOVMuxContext,
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"movflags" },
65 #define MOV_CLASS(flavor)\
66 static const AVClass flavor ## _muxer_class = {\
67 .class_name = #flavor " muxer",\
68 .item_name = av_default_item_name,\
70 .version = LIBAVUTIL_VERSION_INT,\
91 if (pos > UINT32_MAX) {
98 for (i=0; i<track->
entry; i++) {
111 int i, j, entries = 0, tst = -1, oldtst = -1;
118 for (i=0; i<track->
entry; i++) {
120 if(oldtst != -1 && tst != oldtst) {
126 if (equalChunks && track->
entry) {
128 sSize =
FFMAX(1, sSize);
135 for (i=0; i<track->
entry; i++) {
148 int index = 0, oldval = -1, i;
149 int64_t entryPos, curpos;
157 for (i=0; i<track->
entry; i++) {
178 int64_t curpos, entryPos;
186 for (i=0; i<track->
entry; i++) {
218 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
235 if ((acmod & 1) && acmod != 1)
272 avio_w8(pb, (size>>(7*i)) | 0x80);
279 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
286 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
291 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
350 uint32_t layout_tag, bitmap;
358 "lack of channel information\n");
411 int unescaped_size, seq_found = 0;
412 int level = 0, interlace = 0;
422 packet_seq = packet_entry = 1;
429 for (next = start; next < end; start = next) {
433 size = next - start - 4;
540 if (cluster_idx >= track->
entry)
543 if (cluster_idx + 1 == track->
entry)
546 next_dts = track->
cluster[cluster_idx + 1].
dts;
548 return next_dts - track->
cluster[cluster_idx].
dts;
553 int i, first_duration;
563 for (i = 1; i < track->
entry; i++) {
567 return first_duration;
574 uint32_t
tag = track->
tag;
627 else if(track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
721 for (i = 0; i < 10; i++)
764 (tag ==
MKTAG(
't',
'x',
'3',
'g') ||
765 tag ==
MKTAG(
't',
'e',
'x',
't'))))
770 "Quicktime/Ipod might not play the file\n");
782 else tag =
MKTAG(
'd',
'v',
'c',
' ');
785 else tag =
MKTAG(
'd',
'v',
'p',
'p');
788 else tag =
MKTAG(
'd',
'v',
'h',
'p');
791 else tag =
MKTAG(
'd',
'v',
'h',
'6');
800 static const struct {
856 "the file may be unplayable!\n");
863 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
865 "the file may be unplayable!\n");
895 tag =
MKTAG(
'w',
'm',
'a',
' ');
923 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
928 unsigned mov_field_order = 0;
970 char compressor_name[32] = { 0 };
1004 avio_w8(pb, strlen(compressor_name));
1012 if(track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
1080 uint32_t entries = 0;
1084 ctts_entries =
av_malloc((track->
entry + 1) *
sizeof(*ctts_entries));
1085 ctts_entries[0].
count = 1;
1087 for (i=1; i<track->
entry; i++) {
1089 ctts_entries[entries].
count++;
1093 ctts_entries[entries].
count = 1;
1097 atom_size = 16 + (entries * 8);
1102 for (i=0; i<entries; i++) {
1114 uint32_t entries = -1;
1119 stts_entries =
av_malloc(
sizeof(*stts_entries));
1124 stts_entries = track->
entry ?
1127 for (i=0; i<track->
entry; i++) {
1129 if (i && duration == stts_entries[entries].duration) {
1130 stts_entries[entries].
count++;
1134 stts_entries[entries].
count = 1;
1139 atom_size = 16 + (entries * 8);
1144 for (i=0; i<entries; i++) {
1242 const char *hdlr, *descr =
NULL, *hdlr_type =
NULL;
1248 descr =
"DataHandler";
1250 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
1253 descr =
"VideoHandler";
1256 descr =
"SoundHandler";
1258 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) hdlr_type =
"sbtl";
1259 else hdlr_type =
"text";
1260 descr =
"SubtitleHandler";
1263 descr =
"HintHandler";
1310 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
1340 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1348 "FATAL error, file duration too long for timebase, this file will not be\n"
1349 "playable with quicktime. Choose a different timebase or a different\n"
1350 "container format\n");
1371 int version = duration < INT32_MAX ? 0 : 1;
1390 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1425 sample_aspect_ratio = 1;
1467 int version = duration < INT32_MAX ? 0 : 1;
1468 int entry_size, entry_count,
size;
1469 int64_t delay, start_ct = track->
cluster[0].
cts;
1472 version |= delay < INT32_MAX ? 0 : 1;
1474 entry_size = (version == 1) ? 20 : 12;
1475 entry_count = 1 + (delay > 0);
1476 size = 24 + entry_count * entry_size;
1543 char buf[1000] =
"";
1578 if (track->
tag ==
MKTAG(
'r',
't',
'p',
' '))
1582 if (0.0 != sample_aspect_ratio && 1.0 != sample_aspect_ratio)
1590 int i, has_audio = 0, has_video = 0;
1600 if (audio_profile < 0)
1601 audio_profile = 0xFF - has_audio;
1602 if (video_profile < 0)
1603 video_profile = 0xFF - has_video;
1643 int max_track_id = 1, i;
1644 int64_t max_track_len_temp, max_track_len = 0;
1653 if (max_track_len < max_track_len_temp)
1654 max_track_len = max_track_len_temp;
1655 if (max_track_id < mov->tracks[i].track_id)
1660 version = max_track_len < UINT32_MAX ? 0 : 1;
1721 int size = 16 + strlen(data);
1734 return strlen(data) + 4;
1740 if (value && value[0]) {
1751 const char *
name,
const char *
tag,
1754 int l, lang = 0,
len, len2;
1762 snprintf(tag2,
sizeof(tag2),
"%s-", tag);
1764 len2 = strlen(t2->
key);
1779 int size = 0, track = t ? atoi(t->
value) : 0;
1863 return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F);
1867 const char *
tag,
const char *str)
1876 if (!strcmp(tag,
"yrrc"))
1881 if (!strcmp(tag,
"albm") &&
1899 for (i = 0; i < nb_chapters; i++) {
1968 const char *str,
const char *lang,
int type)
2067 avio_printf(pb,
"<param name=\"%s\" value=\"%d\" valuetype=\"data\"/>\n", name, value);
2072 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, value);
2078 len =
FFMIN(
sizeof(buf)/2 - 1, len);
2081 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
2089 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
2090 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
2098 avio_printf(pb,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2099 avio_printf(pb,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
2101 avio_printf(pb,
"<meta name=\"creator\" content=\"%s\" />\n",
2111 int track_id = i + 1;
2120 avio_printf(pb,
"<%s systemBitrate=\"%d\">\n", type,
2180 int64_t moof_offset)
2185 if (!track->
entry) {
2238 for (i = 0; i < track->
entry; i++) {
2262 for (i = 0; i < track->
entry; i++) {
2267 if (flags & MOV_TRUN_SAMPLE_FLAGS)
2280 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
2281 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
2300 int size = 8 + 16 + 4 + 1 + 16*n;
2302 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
2303 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f
2316 for (i = 0; i < n; i++) {
2317 int index = entry + 1 + i;
2321 if (n < mov->ism_lookahead) {
2325 for (i = 0; i < free_size - 8; i++)
2347 MOVTrack *track, int64_t moof_offset)
2364 for (i = 0; i <
size; i++)
2383 if (tracks >= 0 && i != tracks)
2391 moof_size = end - pos;
2394 if (tracks >= 0 && i != tracks)
2472 int has_h264 = 0, has_video = 0;
2489 minor = has_h264 ? 0x100 : 0x200;
2492 minor = has_h264 ? 0x20000 : 0x10000;
2535 int audio_kbitrate = audio_codec->
bit_rate / 1000;
2536 int video_kbitrate =
FFMIN(video_codec->
bit_rate / 1000, 800 - audio_kbitrate);
2593 int i, closed_gop = 0;
2595 for (i = 0; i < pkt->
size - 4; i++) {
2596 c = (c<<8) + pkt->
data[i];
2598 closed_gop = pkt->
data[i+4]>>6 & 0x01;
2599 }
else if (c == 0x100) {
2600 int temp_ref = (pkt->
data[i+1]<<2) | (pkt->
data[i+2]>>6);
2601 if (!temp_ref || closed_gop)
2614 int seq = 0, entry = 0;
2617 for (next = start; next < end; start = next) {
2631 if (!trk->
entry && !fragment) {
2638 for (i = 0; i < trk->
entry; i++)
2671 int i, first_track = -1;
2672 int64_t mdat_size = 0;
2688 if (i < mov->nb_streams)
2730 if (first_track < 0)
2739 int buf_size, write_moof = 1, moof_tracks = -1;
2752 write_moof = i == first_track;
2800 unsigned int samples_in_chunk = 0;
2823 static uint16_t packed_size[16] =
2824 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
2827 while (len < size && samples_in_chunk < 100) {
2828 len += packed_size[(pkt->
data[
len] >> 3) & 0x0F];
2831 if (samples_in_chunk > 1) {
2832 av_log(s,
AV_LOG_ERROR,
"fatal error, input is not a single packet, implement a AVParser for it\n");
2838 samples_in_chunk = 1;
2897 if (pkt->
dts != pkt->
pts)
2923 reformatted_data, size);
2937 int64_t frag_duration = 0;
2940 if (!pkt->
size)
return 0;
2970 track->
tag =
MKTAG(
't',
'e',
'x',
't');
2981 pkt.duration = end - pkt.dts;
2984 len = strlen(
t->value);
2988 memcpy(pkt.data+2,
t->value,
len);
3000 int i, hint_track = 0;
3074 "codec not currently supported in container\n", i);
3082 if (track->
tag ==
MKTAG(
'm',
'x',
'3',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'3',
'n') ||
3083 track->
tag ==
MKTAG(
'm',
'x',
'4',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'4',
'n') ||
3084 track->
tag ==
MKTAG(
'm',
'x',
'5',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'5',
'n')) {
3089 track->
height = track->
tag>>24 ==
'n' ? 486 : 576;
3094 "WARNING codec timebase is very high. If duration is too long,\n"
3095 "file may not be playable by quicktime. Specify a shorter timebase\n"
3096 "or choose different container.\n");
3154 mov->
time += 0x7C25B080;
3247 #if CONFIG_MOV_MUXER
3252 .extensions =
"mov",
3260 .
flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH,
3264 .priv_class = &mov_muxer_class,
3267 #if CONFIG_TGP_MUXER
3272 .extensions =
"3gp",
3279 .
flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH,
3281 .priv_class = &tgp_muxer_class,
3284 #if CONFIG_MP4_MUXER
3289 .mime_type =
"application/mp4",
3290 .extensions =
"mp4",
3298 .
flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH,
3300 .priv_class = &mp4_muxer_class,
3303 #if CONFIG_PSP_MUXER
3308 .extensions =
"mp4,psp",
3316 .
flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH,
3318 .priv_class = &psp_muxer_class,
3321 #if CONFIG_TG2_MUXER
3326 .extensions =
"3g2",
3333 .
flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH,
3335 .priv_class = &tg2_muxer_class,
3338 #if CONFIG_IPOD_MUXER
3343 .mime_type =
"application/mp4",
3344 .extensions =
"m4v,m4a",
3351 .
flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH,
3353 .priv_class = &ipod_muxer_class,
3356 #if CONFIG_ISMV_MUXER
3361 .mime_type =
"application/mp4",
3362 .extensions =
"ismv,isma",
3369 .
flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH,
3371 .priv_class = &ismv_muxer_class,