53 {
"movflags",
"MOV muxer flags", offsetof(
MOVMuxContext,
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"movflags" },
55 {
"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 },
77 #define MOV_CLASS(flavor)\
78 static const AVClass flavor ## _muxer_class = {\
79 .class_name = #flavor " muxer",\
80 .item_name = av_default_item_name,\
82 .version = LIBAVUTIL_VERSION_INT,\
124 for (i = 0; i < track->
entry; i++) {
139 int i, j, entries = 0, tst = -1, oldtst = -1;
146 for (i = 0; i < track->
entry; i++) {
148 if (oldtst != -1 && tst != oldtst)
153 if (equalChunks && track->
entry) {
155 sSize =
FFMAX(1, sSize);
161 for (i = 0; i < track->
entry; i++) {
174 int index = 0, oldval = -1, i;
175 int64_t entryPos, curpos;
183 for (i = 0; i < track->
entry; i++) {
203 int64_t curpos, entryPos;
211 for (i = 0; i < track->
entry; i++) {
243 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
260 if ((acmod & 1) && acmod != 1)
313 avio_w8(pb, (size >> (7 * i)) | 0x80);
323 for (i = 0; i < track->
entry; i++)
331 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
332 unsigned avg_bitrate;
339 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
344 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
423 uint32_t layout_tag, bitmap;
431 "lack of channel information\n");
494 int unescaped_size, seq_found = 0;
495 int level = 0, interlace = 0;
505 packet_seq = packet_entry = 1;
512 for (next = start; next <
end; start = next) {
516 size = next - start - 4;
629 if (cluster_idx >= track->
entry)
632 if (cluster_idx + 1 == track->
entry)
635 next_dts = track->
cluster[cluster_idx + 1].
dts;
647 int i, first_duration;
659 for (i = 1; i < track->
entry; i++) {
663 return first_duration;
670 uint32_t
tag = track->
tag;
754 else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
849 for (i = 0; i < 10; i++)
894 (tag ==
MKTAG(
't',
'x',
'3',
'g') ||
895 tag ==
MKTAG(
't',
'e',
'x',
't'))))
900 "Quicktime/Ipod might not play the file\n");
912 else tag =
MKTAG(
'd',
'v',
'c',
' ');
915 else tag =
MKTAG(
'd',
'v',
'p',
'p');
918 else tag =
MKTAG(
'd',
'v',
'h',
'p');
921 else tag =
MKTAG(
'd',
'v',
'h',
'6');
951 tag =
MKTAG(
'm',
'2',
'v',
'1');
956 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'4');
957 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'5');
958 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'1');
959 else if (rate == 50) tag =
MKTAG(
'x',
'd',
'v',
'a');
960 else if (rate == 60) tag =
MKTAG(
'x',
'd',
'v',
'9');
964 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'6');
965 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'7');
966 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'8');
968 if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'3');
969 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'2');
973 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'd');
974 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'e');
975 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'f');
977 if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'c');
978 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'b');
984 if (rate == 24) tag =
MKTAG(
'x',
'd',
'5',
'4');
985 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'5');
986 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'1');
987 else if (rate == 50) tag =
MKTAG(
'x',
'd',
'5',
'a');
988 else if (rate == 60) tag =
MKTAG(
'x',
'd',
'5',
'9');
992 if (rate == 24) tag =
MKTAG(
'x',
'd',
'5',
'd');
993 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'e');
994 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'f');
996 if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'c');
997 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'b');
1005 static const struct {
1044 if (tag ==
MKTAG(
'r',
'a',
'w',
' ') &&
1047 av_log(s,
AV_LOG_ERROR,
"%s rawvideo cannot be written to mov, output file will be unreadable\n",
1074 "the file may be unplayable!\n");
1081 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
1083 "the file may be unplayable!\n");
1122 tag =
MKTAG(
'w',
'm',
'a',
' ');
1152 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
1157 unsigned mov_field_order = 0;
1215 }
else if(track->
enc->
width == 1440) {
1222 av_strlcatf(compressor_name, len,
"%d", rate * (interlaced + 1));
1229 char compressor_name[32] = { 0 };
1262 avio_w8(pb, strlen(compressor_name));
1270 if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
1292 }
else if (track->
vos_len > 0)
1336 if (nb_frames > 255) {
1387 uint32_t entries = 0;
1392 ctts_entries[0].
count = 1;
1394 for (i = 1; i < track->
entry; i++) {
1396 ctts_entries[entries].
count++;
1400 ctts_entries[entries].
count = 1;
1404 atom_size = 16 + (entries * 8);
1409 for (i = 0; i < entries; i++) {
1421 uint32_t entries = -1;
1426 stts_entries =
av_malloc(
sizeof(*stts_entries));
1431 stts_entries = track->
entry ?
1434 for (i = 0; i < track->
entry; i++) {
1436 if (i && duration == stts_entries[entries].duration) {
1437 stts_entries[entries].
count++;
1441 stts_entries[entries].
count = 1;
1446 atom_size = 16 + (entries * 8);
1451 for (i = 0; i < entries; i++) {
1516 const char *font =
"Lucida Grande";
1556 if (track->
tag !=
MKTAG(
'c',
'6',
'0',
'8')) {
1602 return track->
tag ==
MKTAG(
'c',
'7',
'0',
'8') ||
1603 track->
tag ==
MKTAG(
'c',
'6',
'0',
'8');
1608 const char *hdlr, *descr = NULL, *hdlr_type = NULL;
1613 descr =
"DataHandler";
1616 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
1619 descr =
"VideoHandler";
1622 descr =
"SoundHandler";
1626 descr =
"ClosedCaptionHandler";
1628 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) {
1630 }
else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
's')) {
1635 descr =
"SubtitleHandler";
1639 descr =
"HintHandler";
1642 descr =
"TimeCodeHandler";
1649 "Unknown hldr_type for %s / 0x%04X, writing dummy values\n",
1700 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
1702 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
1732 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1740 "FATAL error, file duration too long for timebase, this file will not be\n"
1741 "playable with quicktime. Choose a different timebase or a different\n"
1742 "container format\n");
1764 int16_t d, int16_t tx, int16_t ty)
1782 int version = duration < INT32_MAX ? 0 : 1;
1815 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1833 rotation = (rot && rot->
value) ? atoi(rot->
value) : 0;
1835 if (rotation == 90) {
1837 }
else if (rotation == 180) {
1839 }
else if (rotation == 270) {
1853 sample_aspect_ratio = 1;
1900 int version = duration < INT32_MAX ? 0 : 1;
1901 int entry_size, entry_count,
size;
1902 int64_t delay, start_ct = track->
cluster[0].
cts;
1905 version |= delay < INT32_MAX ? 0 : 1;
1907 entry_size = (version == 1) ? 20 : 12;
1908 entry_count = 1 + (delay > 0);
1909 size = 24 + entry_count * entry_size;
1979 char buf[1000] =
"";
1983 NULL, NULL, 0, 0, ctx);
2011 if (track->
tag ==
MKTAG(
'r',
't',
'p',
' '))
2029 int i, has_audio = 0, has_video = 0;
2039 if (audio_profile < 0)
2040 audio_profile = 0xFF - has_audio;
2041 if (video_profile < 0)
2042 video_profile = 0xFF - has_video;
2082 int max_track_id = 1, i;
2083 int64_t max_track_len_temp, max_track_len = 0;
2092 if (max_track_len < max_track_len_temp)
2093 max_track_len = max_track_len_temp;
2094 if (max_track_id < mov->tracks[i].track_id)
2099 version = max_track_len < UINT32_MAX ? 0 : 1;
2152 int size = 16 + strlen(data);
2165 return strlen(data) + 4;
2170 const char *
value,
int lang,
int long_style)
2173 if (value && value[0]) {
2184 const char *
name,
const char *
tag,
2187 int l, lang = 0,
len, len2;
2195 snprintf(tag2,
sizeof(tag2),
"%s-", tag);
2197 len2 = strlen(t2->
key);
2211 int size = 0, tmpo = t ? atoi(t->
value) : 0;
2230 disc ?
"disc" :
"track",
2232 int size = 0, track = t ? atoi(t->
value) : 0;
2235 char *slash = strchr(t->
value,
'/');
2237 tracks = atoi(slash + 1);
2254 const char *
name,
const char *
tag,
2261 if (len != 1 && len != 4)
2266 num = atoi(t->
value);
2357 return (((str[0] - 0x60) & 0x1F) << 10) +
2358 (((str[1] - 0x60) & 0x1F) << 5) +
2359 (( str[2] - 0x60) & 0x1F);
2363 const char *
tag,
const char *str)
2372 if (!strcmp(tag,
"yrrc"))
2377 if (!strcmp(tag,
"albm") &&
2395 for (i = 0; i < nb_chapters; i++) {
2400 if ((t =
av_dict_get(
c->metadata,
"title", NULL, 0))) {
2401 int len =
FFMIN(strlen(t->value), 255);
2462 const char *str,
const char *lang,
int type)
2517 uint64_t chunkSize = chunk->
size;
2522 for (i = 1; i<trk->
entry; i++){
2530 chunkSize = chunk->
size;
2600 avio_printf(pb,
"<param name=\"%s\" value=\"%d\" valuetype=\"data\"/>\n", name, value);
2605 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, value);
2611 len =
FFMIN(
sizeof(buf) / 2 - 1, len);
2613 buf[2 *
len] =
'\0';
2614 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
2621 static const uint8_t uuid[] = {
2622 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
2623 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
2631 avio_printf(pb,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2632 avio_printf(pb,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
2635 avio_printf(pb,
"<meta name=\"creator\" content=\"%s\" />\n",
2645 int track_id = i + 1;
2654 avio_printf(pb,
"<%s systemBitrate=\"%d\">\n", type,
2714 MOVTrack *track, int64_t moof_offset)
2719 if (!track->
entry) {
2777 for (i = 0; i < track->
entry; i++) {
2806 for (i = 0; i < track->
entry; i++) {
2811 if (flags & MOV_TRUN_SAMPLE_FLAGS)
2823 static const uint8_t uuid[] = {
2824 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
2825 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
2844 int size = 8 + 16 + 4 + 1 + 16*
n;
2845 static const uint8_t uuid[] = {
2846 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
2847 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f
2860 for (i = 0; i <
n; i++) {
2861 int index = entry + 1 + i;
2865 if (n < mov->ism_lookahead) {
2890 MOVTrack *track, int64_t moof_offset,
2908 for (i = 0; i <
size; i++)
2917 int tracks,
int moof_size)
2928 if (tracks >= 0 && i != tracks)
3016 int has_h264 = 0, has_video = 0;
3035 minor = has_h264 ? 0x100 : 0x200;
3038 minor = has_h264 ? 0x20000 : 0x10000;
3085 int audio_kbitrate = audio_codec->
bit_rate / 1000;
3086 int video_kbitrate =
FFMIN(video_codec->
bit_rate / 1000, 800 - audio_kbitrate);
3143 int i, closed_gop = 0;
3145 for (i = 0; i < pkt->
size - 4; i++) {
3146 c = (c << 8) + pkt->
data[i];
3148 closed_gop = pkt->
data[i + 4] >> 6 & 0x01;
3149 }
else if (c == 0x100) {
3150 int temp_ref = (pkt->
data[i + 1] << 2) | (pkt->
data[i + 2] >> 6);
3151 if (!temp_ref || closed_gop)
3164 int seq = 0, entry = 0;
3167 for (next = start; next <
end; start = next) {
3181 if (!trk->
entry && !fragment) {
3188 for (i = 0; i < trk->
entry; i++)
3221 int i, first_track = -1;
3222 int64_t mdat_size = 0;
3230 int buf_size, moov_size;
3274 if (first_track < 0)
3283 int buf_size, write_moof = 1, moof_tracks = -1;
3296 write_moof = i == first_track;
3349 unsigned int samples_in_chunk = 0;
3351 uint8_t *reformatted_data = NULL;
3355 if (duration < 0 || duration > INT_MAX) {
3356 av_log(s,
AV_LOG_ERROR,
"Application provided duration: %"PRId64
" / timestamp: %"PRId64
" is out of range for mov/mp4 format\n",
3387 static uint16_t packed_size[16] =
3388 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
3391 while (len < size && samples_in_chunk < 100) {
3392 len += packed_size[(pkt->
data[
len] >> 3) & 0x0F];
3395 if (samples_in_chunk > 1) {
3396 av_log(s,
AV_LOG_ERROR,
"fatal error, input is not a single packet, implement a AVParser for it\n");
3405 samples_in_chunk = 1;
3418 "use audio bitstream filter 'aac_adtstoasc' to fix it "
3419 "('-bsf:a aac_adtstoasc' option with ffmpeg)\n");
3490 if (pkt->
dts != pkt->
pts)
3514 reformatted_data, size);
3524 int64_t frag_duration = 0;
3577 if (!pkt->
size)
return 0;
3606 if (ret < 0)
return ret;
3627 track->
tag =
MKTAG(
't',
'e',
'x',
't');
3635 uint8_t chapter_properties[43] = { 0, 0, 0, 0, 0, 0, 0, 1, };
3638 memcpy(track->
enc->
extradata, chapter_properties,
sizeof(chapter_properties));
3693 if ((t =
av_dict_get(
c->metadata,
"title", NULL, 0))) {
3694 len = strlen(t->value);
3726 track->
tag =
MKTAG(
't',
'm',
'c',
'd');
3791 if (!enabled[i] && first[i] >= 0)
3829 r = (rgb >> 16) & 0xFF;
3830 g = (rgb >> 8) & 0xFF;
3833 y = av_clip_uint8( 16. + 0.257 * r + 0.504 * g + 0.098 * b);
3834 cb = av_clip_uint8(128. - 0.148 * r - 0.291 * g + 0.439 * b);
3835 cr = av_clip_uint8(128. + 0.439 * r - 0.368 * g - 0.071 * b);
3837 return (y << 16) | (cr << 8) | cb;
3844 int have_palette = 0, have_size = 0;
3848 while (cur && *cur) {
3849 if (strncmp(
"palette:", cur, 8) == 0) {
3851 count = sscanf(cur + 8,
3852 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
", "
3853 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
", "
3854 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
", "
3855 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
"",
3856 &palette[ 0], &palette[ 1], &palette[ 2], &palette[ 3],
3857 &palette[ 4], &palette[ 5], &palette[ 6], &palette[ 7],
3858 &palette[ 8], &palette[ 9], &palette[10], &palette[11],
3859 &palette[12], &palette[13], &palette[14], &palette[15]);
3861 for (i = 0; i <
count; i++) {
3865 }
else if (!strncmp(
"size:", cur, 5)) {
3866 sscanf(cur + 5,
"%dx%d", &width, &
height);
3869 if (have_palette && have_size)
3871 cur += strcspn(cur,
"\n\r");
3872 cur += strspn(cur,
"\n\r");
3878 for (i = 0; i < 16; i++) {
3894 int i,
ret, hint_track = 0, tmcd_track = 0;
3931 "with fragmentation and custom IO, disabling faststart\n");
3951 int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0;
3962 if (video_streams_nb != 1 || audio_streams_nb != 1 || other_streams_nb) {
4002 "so timecode metadata are now ignored\n");
4031 "codec not currently supported in container\n",
4041 if (track->
tag ==
MKTAG(
'm',
'x',
'3',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'3',
'n') ||
4042 track->
tag ==
MKTAG(
'm',
'x',
'4',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'4',
'n') ||
4043 track->
tag ==
MKTAG(
'm',
'x',
'5',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'5',
'n')) {
4049 track->
height = track->
tag >> 24 ==
'n' ? 486 : 576;
4065 "WARNING codec timebase is very high. If duration is too long,\n"
4066 "file may not be playable by quicktime. Specify a shorter timebase\n"
4067 "or choose different container.\n");
4144 trackj->
tag != track->
tag
4175 mov->
time += 0x7C25B080;
4248 int i, moov_size, moov_size2;
4264 if (moov_size2 != moov_size)
4273 int ret = 0, moov_size;
4277 int read_buf_id = 0;
4289 read_buf[1] = buf + moov_size;
4298 "the second pass (faststart)\n", s->
filename);
4311 #define READ_BLOCK do { \
4312 read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
4321 n = read_size[read_buf_id];
4326 }
while (pos < pos_end);
4385 av_log(s,
AV_LOG_INFO,
"Starting second pass: moving the moov atom to the beginning of the file\n");
4396 av_log(s,
AV_LOG_ERROR,
"reserved_moov_size is too small, needed %"PRId64
" additional\n", 8-size);
4401 for (i = 0; i <
size; i++)
4431 #if CONFIG_MOV_MUXER
4436 .extensions =
"mov",
4439 .video_codec = CONFIG_LIBX264_ENCODER ?
4448 .priv_class = &mov_muxer_class,
4451 #if CONFIG_TGP_MUXER
4456 .extensions =
"3gp",
4465 .priv_class = &tgp_muxer_class,
4468 #if CONFIG_MP4_MUXER
4473 .mime_type =
"application/mp4",
4474 .extensions =
"mp4",
4477 .video_codec = CONFIG_LIBX264_ENCODER ?
4484 .priv_class = &mp4_muxer_class,
4487 #if CONFIG_PSP_MUXER
4492 .extensions =
"mp4,psp",
4495 .video_codec = CONFIG_LIBX264_ENCODER ?
4502 .priv_class = &psp_muxer_class,
4505 #if CONFIG_TG2_MUXER
4510 .extensions =
"3g2",
4519 .priv_class = &tg2_muxer_class,
4522 #if CONFIG_IPOD_MUXER
4527 .mime_type =
"application/mp4",
4528 .extensions =
"m4v,m4a",
4537 .priv_class = &ipod_muxer_class,
4540 #if CONFIG_ISMV_MUXER
4545 .mime_type =
"application/mp4",
4546 .extensions =
"ismv,isma",
4555 .priv_class = &ismv_muxer_class,
4558 #if CONFIG_F4V_MUXER
4563 .mime_type =
"application/f4v",
4564 .extensions =
"f4v",
4573 .priv_class = &f4v_muxer_class,