50 {
"movflags",
"MOV muxer flags", offsetof(
MOVMuxContext,
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"movflags" },
52 {
"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 },
74 #define MOV_CLASS(flavor)\
75 static const AVClass flavor ## _muxer_class = {\
76 .class_name = #flavor " muxer",\
77 .item_name = av_default_item_name,\
79 .version = LIBAVUTIL_VERSION_INT,\
121 for (i = 0; i < track->
entry; i++) {
136 int i, j, entries = 0, tst = -1, oldtst = -1;
143 for (i = 0; i < track->
entry; i++) {
145 if (oldtst != -1 && tst != oldtst)
150 if (equalChunks && track->
entry) {
152 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++) {
200 int64_t curpos, entryPos;
208 for (i = 0; i < track->
entry; i++) {
240 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
257 if ((acmod & 1) && acmod != 1)
310 avio_w8(pb, (size >> (7 * i)) | 0x80);
320 for (i = 0; i < track->
entry; i++)
328 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
329 unsigned avg_bitrate;
336 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
341 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
414 uint32_t layout_tag, bitmap;
422 "lack of channel information\n");
482 int unescaped_size, seq_found = 0;
483 int level = 0, interlace = 0;
493 packet_seq = packet_entry = 1;
500 for (next = start; next <
end; start = next) {
504 size = next - start - 4;
611 if (cluster_idx >= track->
entry)
614 if (cluster_idx + 1 == track->
entry)
617 next_dts = track->
cluster[cluster_idx + 1].
dts;
629 int i, first_duration;
641 for (i = 1; i < track->
entry; i++) {
645 return first_duration;
652 uint32_t
tag = track->
tag;
736 else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
827 for (i = 0; i < 10; i++)
871 (tag ==
MKTAG(
't',
'x',
'3',
'g') ||
872 tag ==
MKTAG(
't',
'e',
'x',
't'))))
877 "Quicktime/Ipod might not play the file\n");
889 else tag =
MKTAG(
'd',
'v',
'c',
' ');
892 else tag =
MKTAG(
'd',
'v',
'p',
'p');
895 else tag =
MKTAG(
'd',
'v',
'h',
'p');
898 else tag =
MKTAG(
'd',
'v',
'h',
'6');
928 tag =
MKTAG(
'm',
'2',
'v',
'1');
933 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'4');
934 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'5');
935 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'1');
936 else if (rate == 50) tag =
MKTAG(
'x',
'd',
'v',
'a');
937 else if (rate == 60) tag =
MKTAG(
'x',
'd',
'v',
'9');
941 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'6');
942 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'7');
943 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'8');
945 if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'3');
946 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'2');
950 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'd');
951 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'e');
952 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'f');
954 if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'c');
955 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'b');
961 if (rate == 24) tag =
MKTAG(
'x',
'd',
'5',
'4');
962 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'5');
963 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'1');
964 else if (rate == 50) tag =
MKTAG(
'x',
'd',
'5',
'a');
965 else if (rate == 60) tag =
MKTAG(
'x',
'd',
'5',
'9');
969 if (rate == 24) tag =
MKTAG(
'x',
'd',
'5',
'd');
970 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'e');
971 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'f');
973 if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'c');
974 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'b');
982 static const struct {
1043 "the file may be unplayable!\n");
1050 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
1052 "the file may be unplayable!\n");
1091 tag =
MKTAG(
'w',
'm',
'a',
' ');
1121 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
1126 unsigned mov_field_order = 0;
1180 }
else if(track->
enc->
width == 1440) {
1187 av_strlcatf(compressor_name, len,
"%d", rate * (interlaced + 1));
1194 char compressor_name[32] = { 0 };
1227 avio_w8(pb, strlen(compressor_name));
1235 if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
1257 }
else if (track->
vos_len > 0)
1301 if (nb_frames > 255) {
1352 uint32_t entries = 0;
1356 ctts_entries =
av_malloc((track->
entry + 1) *
sizeof(*ctts_entries));
1357 ctts_entries[0].
count = 1;
1359 for (i = 1; i < track->
entry; i++) {
1361 ctts_entries[entries].
count++;
1365 ctts_entries[entries].
count = 1;
1369 atom_size = 16 + (entries * 8);
1374 for (i = 0; i < entries; i++) {
1386 uint32_t entries = -1;
1391 stts_entries =
av_malloc(
sizeof(*stts_entries));
1396 stts_entries = track->
entry ?
1399 for (i = 0; i < track->
entry; i++) {
1401 if (i && duration == stts_entries[entries].duration) {
1402 stts_entries[entries].
count++;
1406 stts_entries[entries].
count = 1;
1411 atom_size = 16 + (entries * 8);
1416 for (i = 0; i < entries; i++) {
1481 const char *font =
"Lucida Grande";
1521 if (track->
tag !=
MKTAG(
'c',
'6',
'0',
'8')) {
1567 const char *hdlr, *descr = NULL, *hdlr_type = NULL;
1572 descr =
"DataHandler";
1575 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
1578 descr =
"VideoHandler";
1581 descr =
"SoundHandler";
1583 if (track->
tag ==
MKTAG(
'c',
'6',
'0',
'8')) {
1585 descr =
"ClosedCaptionHandler";
1587 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) hdlr_type =
"sbtl";
1588 else hdlr_type =
"text";
1589 descr =
"SubtitleHandler";
1593 descr =
"HintHandler";
1596 descr =
"TimeCodeHandler";
1603 "Unknown hldr_type for %s / 0x%04X, writing dummy values\n",
1649 if (track->
tag ==
MKTAG(
't',
'e',
'x',
't') || track->
tag ==
MKTAG(
'c',
'6',
'0',
'8')) {
1654 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
1656 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
1686 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1694 "FATAL error, file duration too long for timebase, this file will not be\n"
1695 "playable with quicktime. Choose a different timebase or a different\n"
1696 "container format\n");
1718 int16_t d, int16_t tx, int16_t ty)
1735 int version = duration < INT32_MAX ? 0 : 1;
1757 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1775 rotation = (rot && rot->
value) ? atoi(rot->
value) : 0;
1777 if (rotation == 90) {
1779 }
else if (rotation == 180) {
1781 }
else if (rotation == 270) {
1795 sample_aspect_ratio = 1;
1842 int version = duration < INT32_MAX ? 0 : 1;
1843 int entry_size, entry_count,
size;
1844 int64_t delay, start_ct = track->
cluster[0].
cts;
1847 version |= delay < INT32_MAX ? 0 : 1;
1849 entry_size = (version == 1) ? 20 : 12;
1850 entry_count = 1 + (delay > 0);
1851 size = 24 + entry_count * entry_size;
1921 char buf[1000] =
"";
1925 NULL, NULL, 0, 0, ctx);
1953 if (track->
tag ==
MKTAG(
'r',
't',
'p',
' '))
1965 int i, has_audio = 0, has_video = 0;
1975 if (audio_profile < 0)
1976 audio_profile = 0xFF - has_audio;
1977 if (video_profile < 0)
1978 video_profile = 0xFF - has_video;
2018 int max_track_id = 1, i;
2019 int64_t max_track_len_temp, max_track_len = 0;
2028 if (max_track_len < max_track_len_temp)
2029 max_track_len = max_track_len_temp;
2030 if (max_track_id < mov->tracks[i].track_id)
2035 version = max_track_len < UINT32_MAX ? 0 : 1;
2088 int size = 16 + strlen(data);
2101 return strlen(data) + 4;
2106 const char *
value,
int lang,
int long_style)
2109 if (value && value[0]) {
2120 const char *
name,
const char *
tag,
2123 int l, lang = 0,
len, len2;
2131 snprintf(tag2,
sizeof(tag2),
"%s-", tag);
2133 len2 = strlen(t2->
key);
2147 int size = 0, tmpo = t ? atoi(t->
value) : 0;
2166 disc ?
"disc" :
"track",
2168 int size = 0, track = t ? atoi(t->
value) : 0;
2171 char *slash = strchr(t->
value,
'/');
2173 tracks = atoi(slash + 1);
2190 const char *
name,
const char *
tag,
2197 if (len != 1 && len != 4)
2202 num = atoi(t->
value);
2291 return (((str[0] - 0x60) & 0x1F) << 10) +
2292 (((str[1] - 0x60) & 0x1F) << 5) +
2293 (( str[2] - 0x60) & 0x1F);
2297 const char *
tag,
const char *str)
2306 if (!strcmp(tag,
"yrrc"))
2311 if (!strcmp(tag,
"albm") &&
2329 for (i = 0; i < nb_chapters; i++) {
2401 const char *str,
const char *lang,
int type)
2454 uint64_t chunkSize = chunk->
size;
2459 for (i = 1; i<trk->
entry; i++){
2467 chunkSize = chunk->
size;
2534 avio_printf(pb,
"<param name=\"%s\" value=\"%d\" valuetype=\"data\"/>\n", name, value);
2539 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, value);
2545 len =
FFMIN(
sizeof(buf) / 2 - 1, len);
2547 buf[2 *
len] =
'\0';
2548 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
2555 static const uint8_t uuid[] = {
2556 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
2557 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
2565 avio_printf(pb,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2566 avio_printf(pb,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
2568 avio_printf(pb,
"<meta name=\"creator\" content=\"%s\" />\n",
2578 int track_id = i + 1;
2587 avio_printf(pb,
"<%s systemBitrate=\"%d\">\n", type,
2647 MOVTrack *track, int64_t moof_offset)
2652 if (!track->
entry) {
2710 for (i = 0; i < track->
entry; i++) {
2739 for (i = 0; i < track->
entry; i++) {
2744 if (flags & MOV_TRUN_SAMPLE_FLAGS)
2756 static const uint8_t uuid[] = {
2757 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
2758 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
2777 int size = 8 + 16 + 4 + 1 + 16*
n;
2778 static const uint8_t uuid[] = {
2779 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
2780 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f
2793 for (i = 0; i <
n; i++) {
2794 int index = entry + 1 + i;
2798 if (n < mov->ism_lookahead) {
2823 MOVTrack *track, int64_t moof_offset,
2841 for (i = 0; i <
size; i++)
2850 int tracks,
int moof_size)
2861 if (tracks >= 0 && i != tracks)
2949 int has_h264 = 0, has_video = 0;
2968 minor = has_h264 ? 0x100 : 0x200;
2971 minor = has_h264 ? 0x20000 : 0x10000;
3016 int audio_kbitrate = audio_codec->
bit_rate / 1000;
3017 int video_kbitrate =
FFMIN(video_codec->
bit_rate / 1000, 800 - audio_kbitrate);
3074 int i, closed_gop = 0;
3076 for (i = 0; i < pkt->
size - 4; i++) {
3077 c = (c << 8) + pkt->
data[i];
3079 closed_gop = pkt->
data[i + 4] >> 6 & 0x01;
3080 }
else if (c == 0x100) {
3081 int temp_ref = (pkt->
data[i + 1] << 2) | (pkt->
data[i + 2] >> 6);
3082 if (!temp_ref || closed_gop)
3095 int seq = 0, entry = 0;
3098 for (next = start; next <
end; start = next) {
3112 if (!trk->
entry && !fragment) {
3119 for (i = 0; i < trk->
entry; i++)
3152 int i, first_track = -1;
3153 int64_t mdat_size = 0;
3161 int buf_size, moov_size;
3167 if (i < mov->nb_streams)
3205 if (first_track < 0)
3214 int buf_size, write_moof = 1, moof_tracks = -1;
3227 write_moof = i == first_track;
3280 unsigned int samples_in_chunk = 0;
3282 uint8_t *reformatted_data = NULL;
3286 if (duration < 0 || duration > INT_MAX) {
3287 av_log(s,
AV_LOG_ERROR,
"Application provided duration: %"PRId64
" / timestamp: %"PRId64
" is out of range for mov/mp4 format\n",
3314 static uint16_t packed_size[16] =
3315 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
3318 while (len < size && samples_in_chunk < 100) {
3319 len += packed_size[(pkt->
data[
len] >> 3) & 0x0F];
3322 if (samples_in_chunk > 1) {
3323 av_log(s,
AV_LOG_ERROR,
"fatal error, input is not a single packet, implement a AVParser for it\n");
3332 samples_in_chunk = 1;
3345 "use audio bitstream filter 'aac_adtstoasc' to fix it "
3346 "('-bsf:a aac_adtstoasc' option with ffmpeg)\n");
3417 if (pkt->
dts != pkt->
pts)
3441 reformatted_data, size);
3451 int64_t frag_duration = 0;
3504 if (!pkt->
size)
return 0;
3533 if (ret < 0)
return ret;
3554 track->
tag =
MKTAG(
't',
'e',
'x',
't');
3562 uint8_t chapter_properties[43] = { 0, 0, 0, 0, 0, 0, 0, 1, };
3565 memcpy(track->
enc->
extradata, chapter_properties,
sizeof(chapter_properties));
3621 len = strlen(
t->value);
3653 track->
tag =
MKTAG(
't',
'm',
'c',
'd');
3716 if (!enabled[i] && first[i] >= 0)
3754 int i,
ret, hint_track = 0, tmcd_track = 0;
3787 "with fragmentation and custom IO, disabling faststart\n");
3807 int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0;
3818 if (video_streams_nb != 1 || audio_streams_nb != 1 || other_streams_nb) {
3858 "so timecode metadata are now ignored\n");
3887 "codec not currently supported in container\n",
3897 if (track->
tag ==
MKTAG(
'm',
'x',
'3',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'3',
'n') ||
3898 track->
tag ==
MKTAG(
'm',
'x',
'4',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'4',
'n') ||
3899 track->
tag ==
MKTAG(
'm',
'x',
'5',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'5',
'n')) {
3905 track->
height = track->
tag >> 24 ==
'n' ? 486 : 576;
3916 "WARNING codec timebase is very high. If duration is too long,\n"
3917 "file may not be playable by quicktime. Specify a shorter timebase\n"
3918 "or choose different container.\n");
3997 mov->
time += 0x7C25B080;
4070 int i, moov_size, moov_size2;
4086 if (moov_size2 != moov_size)
4095 int ret = 0, moov_size;
4099 int read_buf_id = 0;
4111 read_buf[1] = buf + moov_size;
4120 "the second pass (faststart)\n", s->
filename);
4133 #define READ_BLOCK do { \
4134 read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
4143 n = read_size[read_buf_id];
4148 }
while (pos < pos_end);
4207 av_log(s,
AV_LOG_INFO,
"Starting second pass: moving the moov atom to the beginning of the file\n");
4218 av_log(s,
AV_LOG_ERROR,
"reserved_moov_size is too small, needed %"PRId64
" additional\n", 8-size);
4223 for (i = 0; i <
size; i++)
4253 #if CONFIG_MOV_MUXER
4258 .extensions =
"mov",
4261 .video_codec = CONFIG_LIBX264_ENCODER ?
4270 .priv_class = &mov_muxer_class,
4273 #if CONFIG_TGP_MUXER
4278 .extensions =
"3gp",
4287 .priv_class = &tgp_muxer_class,
4290 #if CONFIG_MP4_MUXER
4295 .mime_type =
"application/mp4",
4296 .extensions =
"mp4",
4299 .video_codec = CONFIG_LIBX264_ENCODER ?
4306 .priv_class = &mp4_muxer_class,
4309 #if CONFIG_PSP_MUXER
4314 .extensions =
"mp4,psp",
4317 .video_codec = CONFIG_LIBX264_ENCODER ?
4324 .priv_class = &psp_muxer_class,
4327 #if CONFIG_TG2_MUXER
4332 .extensions =
"3g2",
4341 .priv_class = &tg2_muxer_class,
4344 #if CONFIG_IPOD_MUXER
4349 .mime_type =
"application/mp4",
4350 .extensions =
"m4v,m4a",
4359 .priv_class = &ipod_muxer_class,
4362 #if CONFIG_ISMV_MUXER
4367 .mime_type =
"application/mp4",
4368 .extensions =
"ismv,isma",
4377 .priv_class = &ismv_muxer_class,
4380 #if CONFIG_F4V_MUXER
4385 .mime_type =
"application/f4v",
4386 .extensions =
"f4v",
4395 .priv_class = &f4v_muxer_class,