54 {
"movflags",
"MOV muxer flags", offsetof(
MOVMuxContext,
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"movflags" },
56 {
"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 },
79 #define MOV_CLASS(flavor)\
80 static const AVClass flavor ## _muxer_class = {\
81 .class_name = #flavor " muxer",\
82 .item_name = av_default_item_name,\
84 .version = LIBAVUTIL_VERSION_INT,\
137 for (i = 0; i < track->
entry; i++) {
152 int i, j, entries = 0, tst = -1, oldtst = -1;
159 for (i = 0; i < track->
entry; i++) {
161 if (oldtst != -1 && tst != oldtst)
166 if (equalChunks && track->
entry) {
168 sSize =
FFMAX(1, sSize);
174 for (i = 0; i < track->
entry; i++) {
187 int index = 0, oldval = -1, i;
188 int64_t entryPos, curpos;
196 for (i = 0; i < track->
entry; i++) {
216 int64_t curpos, entryPos;
224 for (i = 0; i < track->
entry; i++) {
256 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
273 if ((acmod & 1) && acmod != 1)
326 avio_w8(pb, (size >> (7 * i)) | 0x80);
336 for (i = 0; i < track->
entry; i++)
344 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
345 unsigned avg_bitrate;
352 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
357 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
436 uint32_t layout_tag, bitmap;
444 "lack of channel information\n");
507 int unescaped_size, seq_found = 0;
508 int level = 0, interlace = 0;
518 packet_seq = packet_entry = 1;
525 for (next = start; next <
end; start = next) {
529 size = next - start - 4;
642 if (cluster_idx >= track->
entry)
645 if (cluster_idx + 1 == track->
entry)
648 next_dts = track->
cluster[cluster_idx + 1].
dts;
660 int i, first_duration;
672 for (i = 1; i < track->
entry; i++) {
676 return first_duration;
683 uint32_t
tag = track->
tag;
767 else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
862 for (i = 0; i < 10; i++)
907 (tag ==
MKTAG(
't',
'x',
'3',
'g') ||
908 tag ==
MKTAG(
't',
'e',
'x',
't'))))
915 "Quicktime/Ipod might not play the file\n");
927 else tag =
MKTAG(
'd',
'v',
'c',
' ');
930 else tag =
MKTAG(
'd',
'v',
'p',
'p');
933 else tag =
MKTAG(
'd',
'v',
'h',
'p');
936 else tag =
MKTAG(
'd',
'v',
'h',
'6');
966 tag =
MKTAG(
'm',
'2',
'v',
'1');
971 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'4');
972 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'5');
973 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'1');
974 else if (rate == 50) tag =
MKTAG(
'x',
'd',
'v',
'a');
975 else if (rate == 60) tag =
MKTAG(
'x',
'd',
'v',
'9');
979 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'6');
980 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'7');
981 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'8');
983 if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'3');
984 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'2');
988 if (rate == 24) tag =
MKTAG(
'x',
'd',
'v',
'd');
989 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'e');
990 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'f');
992 if (rate == 25) tag =
MKTAG(
'x',
'd',
'v',
'c');
993 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'v',
'b');
999 if (rate == 24) tag =
MKTAG(
'x',
'd',
'5',
'4');
1000 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'5');
1001 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'1');
1002 else if (rate == 50) tag =
MKTAG(
'x',
'd',
'5',
'a');
1003 else if (rate == 60) tag =
MKTAG(
'x',
'd',
'5',
'9');
1007 if (rate == 24) tag =
MKTAG(
'x',
'd',
'5',
'd');
1008 else if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'e');
1009 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'f');
1011 if (rate == 25) tag =
MKTAG(
'x',
'd',
'5',
'c');
1012 else if (rate == 30) tag =
MKTAG(
'x',
'd',
'5',
'b');
1020 static const struct {
1059 if (tag ==
MKTAG(
'r',
'a',
'w',
' ') &&
1062 av_log(s,
AV_LOG_ERROR,
"%s rawvideo cannot be written to mov, output file will be unreadable\n",
1089 "the file may be unplayable!\n");
1096 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
1098 "the file may be unplayable!\n");
1137 tag =
MKTAG(
'w',
'm',
'a',
' ');
1167 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
1172 unsigned mov_field_order = 0;
1230 }
else if(track->
enc->
width == 1440) {
1237 av_strlcatf(compressor_name, len,
"%d", rate * (interlaced + 1));
1244 char compressor_name[32] = { 0 };
1277 avio_w8(pb, strlen(compressor_name));
1285 if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
1307 }
else if (track->
vos_len > 0)
1346 uint64_t str_size =strlen(reel_name);
1349 if (str_size >= UINT16_MAX){
1371 if (nb_frames > 255) {
1429 uint32_t entries = 0;
1434 ctts_entries[0].
count = 1;
1436 for (i = 1; i < track->
entry; i++) {
1438 ctts_entries[entries].
count++;
1442 ctts_entries[entries].
count = 1;
1446 atom_size = 16 + (entries * 8);
1451 for (i = 0; i < entries; i++) {
1463 uint32_t entries = -1;
1468 stts_entries =
av_malloc(
sizeof(*stts_entries));
1473 stts_entries = track->
entry ?
1476 for (i = 0; i < track->
entry; i++) {
1478 if (i && duration == stts_entries[entries].duration) {
1479 stts_entries[entries].
count++;
1483 stts_entries[entries].
count = 1;
1488 atom_size = 16 + (entries * 8);
1493 for (i = 0; i < entries; i++) {
1558 const char *font =
"Lucida Grande";
1598 if (track->
tag !=
MKTAG(
'c',
'6',
'0',
'8')) {
1644 return track->
tag ==
MKTAG(
'c',
'7',
'0',
'8') ||
1645 track->
tag ==
MKTAG(
'c',
'6',
'0',
'8');
1650 const char *hdlr, *descr = NULL, *hdlr_type = NULL;
1655 descr =
"DataHandler";
1658 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
1661 descr =
"VideoHandler";
1664 descr =
"SoundHandler";
1668 descr =
"ClosedCaptionHandler";
1670 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) {
1672 }
else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
's')) {
1677 descr =
"SubtitleHandler";
1681 descr =
"HintHandler";
1684 descr =
"TimeCodeHandler";
1691 "Unknown hldr_type for %s / 0x%04X, writing dummy values\n",
1751 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
1753 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
1783 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1791 "FATAL error, file duration too long for timebase, this file will not be\n"
1792 "playable with quicktime. Choose a different timebase or a different\n"
1793 "container format\n");
1815 int16_t d, int16_t tx, int16_t ty)
1833 int version = duration < INT32_MAX ? 0 : 1;
1866 (version == 1) ?
avio_wb64(pb, UINT64_C(0xffffffffffffffff)) :
avio_wb32(pb, 0xffffffff);
1884 rotation = (rot && rot->
value) ? atoi(rot->
value) : 0;
1886 if (rotation == 90) {
1888 }
else if (rotation == 180) {
1890 }
else if (rotation == 270) {
1904 sample_aspect_ratio = 1;
1951 int version = duration < INT32_MAX ? 0 : 1;
1952 int entry_size, entry_count,
size;
1953 int64_t delay, start_ct = track->
cluster[0].
cts;
1956 version |= delay < INT32_MAX ? 0 : 1;
1958 entry_size = (version == 1) ? 20 : 12;
1959 entry_count = 1 + (delay > 0);
1960 size = 24 + entry_count * entry_size;
2030 char buf[1000] =
"";
2034 NULL, NULL, 0, 0, ctx);
2049 const char *
tag,
const char *str)
2103 if (track->
tag ==
MKTAG(
'r',
't',
'p',
' '))
2122 int i, has_audio = 0, has_video = 0;
2132 if (audio_profile < 0)
2133 audio_profile = 0xFF - has_audio;
2134 if (video_profile < 0)
2135 video_profile = 0xFF - has_video;
2175 int max_track_id = 1, i;
2176 int64_t max_track_len_temp, max_track_len = 0;
2185 if (max_track_len < max_track_len_temp)
2186 max_track_len = max_track_len_temp;
2187 if (max_track_id < mov->tracks[i].track_id)
2192 version = max_track_len < UINT32_MAX ? 0 : 1;
2245 int size = 16 + strlen(data);
2258 return strlen(data) + 4;
2263 const char *
value,
int lang,
int long_style)
2266 if (value && value[0]) {
2277 const char *
name,
const char *
tag,
2280 int l, lang = 0,
len, len2;
2288 snprintf(tag2,
sizeof(tag2),
"%s-", tag);
2290 len2 = strlen(t2->
key);
2304 int size = 0, tmpo = t ? atoi(t->
value) : 0;
2323 disc ?
"disc" :
"track",
2325 int size = 0, track = t ? atoi(t->
value) : 0;
2328 char *slash = strchr(t->
value,
'/');
2330 tracks = atoi(slash + 1);
2347 const char *
name,
const char *
tag,
2354 if (len != 1 && len != 4)
2359 num = atoi(t->
value);
2427 const char *
name,
const char *key)
2435 len = strlen(t->
value);
2459 return (((str[0] - 0x60) & 0x1F) << 10) +
2460 (((str[1] - 0x60) & 0x1F) << 5) +
2461 (( str[2] - 0x60) & 0x1F);
2465 const char *
tag,
const char *str)
2474 if (!strcmp(tag,
"yrrc"))
2479 if (!strcmp(tag,
"albm") &&
2497 for (i = 0; i < nb_chapters; i++) {
2502 if ((t =
av_dict_get(
c->metadata,
"title", NULL, 0))) {
2503 int len =
FFMIN(strlen(t->value), 255);
2565 const char *str,
const char *lang,
int type)
2620 uint64_t chunkSize = chunk->
size;
2625 for (i = 1; i<trk->
entry; i++){
2633 chunkSize = chunk->
size;
2703 avio_printf(pb,
"<param name=\"%s\" value=\"%d\" valuetype=\"data\"/>\n", name, value);
2708 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, value);
2714 len =
FFMIN(
sizeof(buf) / 2 - 1, len);
2716 buf[2 *
len] =
'\0';
2717 avio_printf(pb,
"<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
2724 static const uint8_t uuid[] = {
2725 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
2726 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
2734 avio_printf(pb,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2735 avio_printf(pb,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
2738 avio_printf(pb,
"<meta name=\"creator\" content=\"%s\" />\n",
2748 int track_id = i + 1;
2757 avio_printf(pb,
"<%s systemBitrate=\"%d\">\n", type,
2817 MOVTrack *track, int64_t moof_offset)
2822 if (!track->
entry) {
2880 for (i = 0; i < track->
entry; i++) {
2909 for (i = 0; i < track->
entry; i++) {
2914 if (flags & MOV_TRUN_SAMPLE_FLAGS)
2926 static const uint8_t uuid[] = {
2927 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
2928 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
2947 int size = 8 + 16 + 4 + 1 + 16*
n;
2948 static const uint8_t uuid[] = {
2949 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
2950 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f
2963 for (i = 0; i <
n; i++) {
2964 int index = entry + 1 + i;
2968 if (n < mov->ism_lookahead) {
2993 MOVTrack *track, int64_t moof_offset,
3011 for (i = 0; i <
size; i++)
3020 int tracks,
int moof_size)
3031 if (tracks >= 0 && i != tracks)
3119 int has_h264 = 0, has_video = 0;
3138 minor = has_h264 ? 0x100 : 0x200;
3141 minor = has_h264 ? 0x20000 : 0x10000;
3188 int audio_kbitrate = audio_codec->
bit_rate / 1000;
3189 int video_kbitrate =
FFMIN(video_codec->
bit_rate / 1000, 800 - audio_kbitrate);
3246 int i, closed_gop = 0;
3248 for (i = 0; i < pkt->
size - 4; i++) {
3249 c = (c << 8) + pkt->
data[i];
3251 closed_gop = pkt->
data[i + 4] >> 6 & 0x01;
3252 }
else if (c == 0x100) {
3253 int temp_ref = (pkt->
data[i + 1] << 2) | (pkt->
data[i + 2] >> 6);
3254 if (!temp_ref || closed_gop)
3267 int seq = 0, entry = 0;
3270 for (next = start; next <
end; start = next) {
3284 if (!trk->
entry && !fragment) {
3291 for (i = 0; i < trk->
entry; i++)
3324 int i, first_track = -1;
3325 int64_t mdat_size = 0;
3333 int buf_size, moov_size;
3377 if (first_track < 0)
3386 int buf_size, write_moof = 1, moof_tracks = -1;
3399 write_moof = i == first_track;
3452 unsigned int samples_in_chunk = 0;
3454 uint8_t *reformatted_data = NULL;
3458 if (duration < 0 || duration > INT_MAX) {
3459 av_log(s,
AV_LOG_ERROR,
"Application provided duration: %"PRId64
" / timestamp: %"PRId64
" is out of range for mov/mp4 format\n",
3490 static uint16_t packed_size[16] =
3491 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
3494 while (len < size && samples_in_chunk < 100) {
3495 len += packed_size[(pkt->
data[
len] >> 3) & 0x0F];
3498 if (samples_in_chunk > 1) {
3499 av_log(s,
AV_LOG_ERROR,
"fatal error, input is not a single packet, implement a AVParser for it\n");
3508 samples_in_chunk = 1;
3521 "use the audio bitstream filter 'aac_adtstoasc' to fix it "
3522 "('-bsf:a aac_adtstoasc' option with ffmpeg)\n");
3593 if (pkt->
dts != pkt->
pts)
3617 reformatted_data, size);
3627 int64_t frag_duration = 0;
3680 if (!pkt->
size)
return 0;
3709 if (ret < 0)
return ret;
3730 track->
tag =
MKTAG(
't',
'e',
'x',
't');
3738 uint8_t chapter_properties[43] = { 0, 0, 0, 0, 0, 0, 0, 1, };
3741 memcpy(track->
enc->
extradata, chapter_properties,
sizeof(chapter_properties));
3796 if ((t =
av_dict_get(
c->metadata,
"title", NULL, 0))) {
3797 const char encd[12] = {
3798 0x00, 0x00, 0x00, 0x0C,
3800 0x00, 0x00, 0x01, 0x00 };
3801 len = strlen(t->value);
3808 memcpy(
pkt.
data +
len + 2, encd,
sizeof(encd));
3834 track->
tag =
MKTAG(
't',
'm',
'c',
'd');
3902 if (!enabled[i] && first[i] >= 0)
3940 r = (rgb >> 16) & 0xFF;
3941 g = (rgb >> 8) & 0xFF;
3944 y = av_clip_uint8( 16. + 0.257 * r + 0.504 * g + 0.098 * b);
3945 cb = av_clip_uint8(128. - 0.148 * r - 0.291 * g + 0.439 * b);
3946 cr = av_clip_uint8(128. + 0.439 * r - 0.368 * g - 0.071 * b);
3948 return (y << 16) | (cr << 8) | cb;
3955 int have_palette = 0, have_size = 0;
3959 while (cur && *cur) {
3960 if (strncmp(
"palette:", cur, 8) == 0) {
3962 count = sscanf(cur + 8,
3963 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
", "
3964 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
", "
3965 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
", "
3966 "%06"PRIx32
", %06"PRIx32
", %06"PRIx32
", %06"PRIx32
"",
3967 &palette[ 0], &palette[ 1], &palette[ 2], &palette[ 3],
3968 &palette[ 4], &palette[ 5], &palette[ 6], &palette[ 7],
3969 &palette[ 8], &palette[ 9], &palette[10], &palette[11],
3970 &palette[12], &palette[13], &palette[14], &palette[15]);
3972 for (i = 0; i <
count; i++) {
3976 }
else if (!strncmp(
"size:", cur, 5)) {
3977 sscanf(cur + 5,
"%dx%d", &width, &
height);
3980 if (have_palette && have_size)
3982 cur += strcspn(cur,
"\n\r");
3983 cur += strspn(cur,
"\n\r");
3989 for (i = 0; i < 16; i++) {
4005 int i,
ret, hint_track = 0, tmcd_track = 0;
4043 "with fragmentation and custom IO, disabling faststart\n");
4063 int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0;
4074 if (video_streams_nb != 1 || audio_streams_nb != 1 || other_streams_nb) {
4114 "so timecode metadata are now ignored\n");
4143 "codec not currently supported in container\n",
4153 if (track->
tag ==
MKTAG(
'm',
'x',
'3',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'3',
'n') ||
4154 track->
tag ==
MKTAG(
'm',
'x',
'4',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'4',
'n') ||
4155 track->
tag ==
MKTAG(
'm',
'x',
'5',
'p') || track->
tag ==
MKTAG(
'm',
'x',
'5',
'n')) {
4161 track->
height = track->
tag >> 24 ==
'n' ? 486 : 576;
4177 "WARNING codec timebase is very high. If duration is too long,\n"
4178 "file may not be playable by quicktime. Specify a shorter timebase\n"
4179 "or choose different container.\n");
4256 trackj->
tag != track->
tag
4287 mov->
time += 0x7C25B080;
4360 int i, moov_size, moov_size2;
4376 if (moov_size2 != moov_size)
4385 int ret = 0, moov_size;
4389 int read_buf_id = 0;
4401 read_buf[1] = buf + moov_size;
4410 "the second pass (faststart)\n", s->
filename);
4423 #define READ_BLOCK do { \
4424 read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
4433 n = read_size[read_buf_id];
4438 }
while (pos < pos_end);
4497 av_log(s,
AV_LOG_INFO,
"Starting second pass: moving the moov atom to the beginning of the file\n");
4508 av_log(s,
AV_LOG_ERROR,
"reserved_moov_size is too small, needed %"PRId64
" additional\n", 8-size);
4542 #if CONFIG_MOV_MUXER
4547 .extensions =
"mov",
4550 .video_codec = CONFIG_LIBX264_ENCODER ?
4559 .priv_class = &mov_muxer_class,
4562 #if CONFIG_TGP_MUXER
4567 .extensions =
"3gp",
4576 .priv_class = &tgp_muxer_class,
4579 #if CONFIG_MP4_MUXER
4584 .mime_type =
"application/mp4",
4585 .extensions =
"mp4",
4588 .video_codec = CONFIG_LIBX264_ENCODER ?
4595 .priv_class = &mp4_muxer_class,
4598 #if CONFIG_PSP_MUXER
4603 .extensions =
"mp4,psp",
4606 .video_codec = CONFIG_LIBX264_ENCODER ?
4613 .priv_class = &psp_muxer_class,
4616 #if CONFIG_TG2_MUXER
4621 .extensions =
"3g2",
4630 .priv_class = &tg2_muxer_class,
4633 #if CONFIG_IPOD_MUXER
4638 .mime_type =
"application/mp4",
4639 .extensions =
"m4v,m4a",
4648 .priv_class = &ipod_muxer_class,
4651 #if CONFIG_ISMV_MUXER
4656 .mime_type =
"application/mp4",
4657 .extensions =
"ismv,isma",
4666 .priv_class = &ismv_muxer_class,
4669 #if CONFIG_F4V_MUXER
4674 .mime_type =
"application/f4v",
4675 .extensions =
"f4v",
4684 .priv_class = &f4v_muxer_class,