24 #include "config_components.h"
83 {
"frag_interleave",
"Interleave samples within fragments (max number of consecutive samples, lower is tighter interleaving, but with more overhead)", offsetof(
MOVMuxContext, frag_interleave),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM },
89 {
"movflags",
"MOV muxer flags", offsetof(
MOVMuxContext,
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, .unit =
"movflags" },
93 {
"delay_moov",
"Delay writing the initial moov until the first fragment is cut, or until the first fragment flush", 0,
AV_OPT_TYPE_CONST, {.i64 =
FF_MOV_FLAG_DELAY_MOOV}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, .unit =
"movflags" },
103 {
"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, .unit = 0 },
112 {
"write_colr",
"Write colr atom even if the color info is unspecified (Experimental, may be renamed or changed, do not use from scripts)", 0,
AV_OPT_TYPE_CONST, {.i64 =
FF_MOV_FLAG_WRITE_COLR}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, .unit =
"movflags" },
114 {
"hybrid_fragmented",
"For recoverability, write a fragmented file that is converted to non-fragmented at the end.", 0,
AV_OPT_TYPE_CONST, {.i64 =
FF_MOV_FLAG_HYBRID_FRAGMENTED}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, .unit =
"movflags" },
124 {
"write_prft",
"Write producer reference time box with specified time source", offsetof(
MOVMuxContext, write_prft),
AV_OPT_TYPE_INT, {.i64 =
MOV_PRFT_NONE}, 0,
MOV_PRFT_NB-1,
AV_OPT_FLAG_ENCODING_PARAM, .unit =
"prft"},
132 .
class_name =
"mov/mp4/tgp/psp/tg2/ipod/ismv/f4v muxer",
199 for (
i = 0;
i < track->
entry;
i++) {
214 int i, j, entries = 0, tst = -1, oldtst = -1;
221 for (
i = 0;
i < track->
entry;
i++) {
223 if (oldtst != -1 && tst != oldtst)
228 if (equalChunks && track->
entry) {
230 sSize =
FFMAX(1, sSize);
236 for (
i = 0;
i < track->
entry;
i++) {
249 int index = 0, oldval = -1,
i;
258 for (
i = 0;
i < track->
entry;
i++) {
286 for (
i = 0;
i < track->
entry;
i++) {
303 uint8_t leading, dependent, reference, redundancy;
308 for (
i = 0;
i < track->
entry;
i++) {
317 avio_w8(pb, (leading << 6) | (dependent << 4) |
318 (reference << 2) | redundancy);
328 uint8_t *dyn_buf =
NULL;
406 "Cannot write moov atom before AC3 packets."
407 " Set the delay_moov flag to fix this.\n");
411 if (
info->substream[0].bsid > 8) {
413 "RealAudio AC-3/DolbyNet with bsid %d is not defined by the "
414 "ISOBMFF specification in ETSI TS 102 366!\n",
415 info->substream[0].bsid);
419 if (
info->ac3_bit_rate_code < 0) {
421 "No valid AC3 bit rate code for data rate of %d!\n",
479 if (!
info->ec3_done) {
534 while (cumul_size !=
pkt->
size) {
544 info->substream[parent].num_dep_sub++;
560 info->substream[parent].chan_loc |= (
get_bits(&gbc, 16) >> 5) & 0x1f;
578 if (!
info->num_blocks) {
589 if (
info->num_blocks != 6)
593 info->num_blocks = 0;
612 "Cannot write moov atom before EAC3 packets parsed.\n");
617 size = 2 + ((34 * (
info->num_ind_sub + 1) + 7) >> 3);
626 for (
i = 0;
i <=
info->num_ind_sub;
i++) {
636 if (!
info->substream[
i].num_dep_sub) {
716 if (!bit_rates.avg_bit_rate) {
725 if (props && props->avg_bitrate) {
726 bit_rates.avg_bit_rate = props->avg_bitrate;
729 }
else if (props && props->max_bitrate) {
730 bit_rates.avg_bit_rate = props->max_bitrate;
736 bit_rates.avg_bit_rate);
741 if (!props->avg_bitrate)
742 bit_rates.avg_bit_rate = props->avg_bitrate;
743 bit_rates.max_bit_rate =
FFMAX(bit_rates.max_bit_rate,
745 bit_rates.buffer_size = props->buffer_size / 8;
755 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
762 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
767 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
904 "Cannot write moov atom before TrueHD packets."
905 " Set the delay_moov flag to fix this.\n");
910 if (length < 20 || length > track->
vos_len)
929 int ambisonic_order, ambi_channels, non_diegetic_channels;
950 if (ambisonic_order < 0)
953 ambi_channels = (ambisonic_order + 1LL) * (ambisonic_order + 1LL);
954 non_diegetic_channels = ch_layout.
nb_channels - ambi_channels;
955 if (non_diegetic_channels &&
956 (non_diegetic_channels != 2 ||
967 avio_w8(pb, (!!non_diegetic_channels) << 7);
972 for (
i = 0;
i < ambi_channels;
i++)
984 uint32_t layout_tag, bitmap, *channel_desc;
992 &bitmap, &channel_desc);
997 "lack of channel information\n");
1006 channel_desc =
av_malloc(
sizeof(*channel_desc));
1025 for (
int i = 0;
i < num_desc;
i++) {
1085 int unescaped_size, seq_found = 0;
1086 int level = 0, interlace = 0;
1095 packet_seq = packet_entry = 1;
1097 "moov atom written before any packets, unable to write correct "
1098 "dvc1 atom. Set the delay_moov flag to fix this.\n");
1105 for (next = start; next < end; start = next) {
1109 size = next - start - 4;
1166 uint8_t buf[7] = { 0 };
1221 if (cluster_idx >= track->
entry)
1224 if (cluster_idx + 1 == track->
entry)
1227 next_dts = track->
cluster[cluster_idx + 1].
dts;
1239 int i, first_duration;
1249 for (
i = 1;
i < track->
entry;
i++) {
1253 return first_duration;
1280 uint8_t *speaker_pos =
NULL;
1290 speaker_pos,
layout->nb_channels);
1292 char buf[128] = {0};
1347 uint32_t
tag = track->
tag;
1417 if (track->
tag ==
MKTAG(
'i',
'a',
'm',
'f'))
1454 else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
1457 else if (track->
tag ==
MKTAG(
'i',
'a',
'm',
'f'))
1458 ret = mov_write_iacb_tag(mov->
fc, pb, track);
1482 }
else if (track->
vos_len > 0)
1559 if (track->
tag ==
MKTAG(
'h',
'v',
'c',
'1'))
1573 if (track->
tag ==
MKTAG(
'h',
'v',
'c',
'1'))
1593 if (track->
tag ==
MKTAG(
'e',
'v',
'c',
'1'))
1611 if (track->
tag ==
MKTAG(
'v',
'v',
'c',
'1'))
1623 int display_width = track->
par->
width;
1651 if (track->
tag ==
MKTAG(
'A',
'V',
'd',
'h')) {
1727 }
else if (track->
par->
height == 1080) {
1742 if (rational_framerate.
den != 0)
1743 rate =
av_q2d(rational_framerate);
1760 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'v',
'4');
1761 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'5');
1762 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'1');
1763 else if (rate == 50)
tag =
MKTAG(
'x',
'd',
'v',
'a');
1764 else if (rate == 60)
tag =
MKTAG(
'x',
'd',
'v',
'9');
1768 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'v',
'6');
1769 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'7');
1770 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'8');
1772 if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'3');
1773 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'2');
1777 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'v',
'd');
1778 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'e');
1779 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'f');
1781 if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'c');
1782 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'b');
1788 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'5',
'4');
1789 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'5',
'5');
1790 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'5',
'1');
1791 else if (rate == 50)
tag =
MKTAG(
'x',
'd',
'5',
'a');
1792 else if (rate == 60)
tag =
MKTAG(
'x',
'd',
'5',
'9');
1796 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'5',
'd');
1797 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'5',
'e');
1798 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'5',
'f');
1800 if (rate == 25)
tag =
MKTAG(
'x',
'd',
'5',
'c');
1801 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'5',
'b');
1822 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'5',
'p');
1823 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'5',
'q');
1824 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'5',
'p');
1825 else if (rate == 50)
tag =
MKTAG(
'a',
'i',
'5',
'q');
1826 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'5',
'p');
1830 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'5',
'3');
1831 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'5',
'2');
1832 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'5',
'3');
1834 if (rate == 50)
tag =
MKTAG(
'a',
'i',
'5',
'5');
1835 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'5',
'6');
1841 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'1',
'p');
1842 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'1',
'q');
1843 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'1',
'p');
1844 else if (rate == 50)
tag =
MKTAG(
'a',
'i',
'1',
'q');
1845 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'1',
'p');
1849 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'1',
'3');
1850 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'1',
'2');
1851 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'1',
'3');
1853 if (rate == 25)
tag =
MKTAG(
'a',
'i',
'1',
'5');
1854 else if (rate == 50)
tag =
MKTAG(
'a',
'i',
'1',
'5');
1855 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'1',
'6');
1877 static const struct {
1928 if (
tag ==
MKTAG(
'r',
'a',
'w',
' ') &&
1932 av_log(
s,
AV_LOG_ERROR,
"%s rawvideo cannot be written to mov, output file will be unreadable\n",
1971 "the file may be unplayable!\n");
1978 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
1980 "the file may be unplayable!\n");
2005 for (
i = 0; tags && tags[
i];
i++) {
2010 return codec_tags->
tag;
2027 "Quicktime/Ipod might not play the file\n");
2053 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
2058 unsigned mov_field_order = 0;
2060 mov_field_order =
fiel_data[field_order];
2098 "Unknown codec tag '%s' utilized for TTML stream with "
2099 "index %d (track id %d)!\n",
2118 if (stereo_3d->
flags != 0) {
2123 switch (stereo_3d->
type) {
2146 int64_t sv3d_pos, svhd_pos, proj_pos;
2258 switch (stereo3d->
view) {
2266 view |= (1 << 0) | (1 << 1);
2309 if (spherical_mapping &&
2316 spherical_mapping =
NULL;
2329 if (!spherical_mapping && !stereo3d)
2336 if (spherical_mapping)
2364 uint32_t top, uint32_t bottom,
2365 uint32_t
left, uint32_t right)
2367 uint32_t cropped_width = track->
par->
width -
left - right;
2368 uint32_t cropped_height = track->
height - top - bottom;
2412 gama = (uint32_t)
lrint((
double)(1<<16) * gamma);
2443 return 12 + sd->
size;
2496 const int chroma_den = 50000;
2497 const int luma_den = 10000;
2527 const int illuminance_den = 10000;
2528 const int ambient_den = 50000;
2571 }
else if(track->
par->
width == 1440) {
2590 uint8_t ccstValue = (0 << 7) |
2607 avio_write(pb,
"urn:mpeg:mpegB:cicp:systems:auxiliary:alpha\0", 44);
2616 char compressor_name[32] = { 0 };
2641 if (uncompressed_ycbcr) {
2667 avio_w8(pb, strlen(compressor_name));
2688 for (
i = 0;
i < pal_size;
i++) {
2690 uint16_t
r = (
rgb >> 16) & 0xff;
2691 uint16_t
g = (
rgb >> 8) & 0xff;
2692 uint16_t
b =
rgb & 0xff;
2701 if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
2741 }
else if (track->
vos_len > 0)
2788 if (spherical_mapping)
2809 if (stereo3d || spherical_mapping)
2833 if (sd && sd->
size >=
sizeof(uint32_t) * 4) {
2840 (top + bottom) >= track->
height) {
2844 if (top || bottom ||
left || right)
2846 }
else if (uncompressed_ycbcr)
2893 uint64_t str_size =strlen(reel_name);
2896 if (str_size >= UINT16_MAX){
2926 if (nb_frames > 255) {
3002 uint32_t entries = 0;
3009 ctts_entries[0].
count = 1;
3011 for (
i = 1;
i < track->
entry;
i++) {
3013 ctts_entries[entries].
count++;
3017 ctts_entries[entries].
count = 1;
3021 atom_size = 16 + (entries * 8);
3030 for (
i = 0;
i < entries;
i++) {
3042 uint32_t entries = -1;
3047 stts_entries =
av_malloc(
sizeof(*stts_entries));
3059 for (
i = 0;
i < track->
entry;
i++) {
3062 stts_entries[entries].
count++;
3066 stts_entries[entries].
count = 1;
3071 atom_size = 16 + (entries * 8);
3076 for (
i = 0;
i < entries;
i++) {
3103 int16_t roll_distance;
3104 int group_description_index;
3107 struct sgpd_entry *sgpd_entries =
NULL;
3127 for (
i = 0;
i < track->
entry;
i++) {
3128 int roll_samples_remaining = roll_samples;
3130 for (j =
i - 1; j >= 0; j--) {
3133 if (roll_samples_remaining <= 0)
3139 if (roll_samples_remaining > 0)
3144 if (
i &&
distance == sgpd_entries[entries].roll_distance) {
3145 sgpd_entries[entries].count++;
3148 sgpd_entries[entries].count = 1;
3149 sgpd_entries[entries].roll_distance =
distance;
3150 sgpd_entries[entries].group_description_index =
distance ? ++group : 0;
3156 sgpd_entries[entries].roll_distance = 1;
3157 sgpd_entries[entries].group_description_index = ++group;
3173 for (
i = 0;
i < entries;
i++) {
3174 if (sgpd_entries[
i].group_description_index) {
3175 avio_wb16(pb, -sgpd_entries[
i].roll_distance);
3185 for (
i = 0;
i < entries;
i++) {
3187 avio_wb32(pb, sgpd_entries[
i].group_description_index);
3261 const char *font =
"Lucida Grande";
3301 if (track->
tag !=
MKTAG(
'c',
'6',
'0',
'8')) {
3353 return track->
tag ==
MKTAG(
'c',
'7',
'0',
'8') ||
3354 track->
tag ==
MKTAG(
'c',
'6',
'0',
'8');
3360 const char *hdlr, *descr =
NULL, *hdlr_type =
NULL;
3366 descr =
"DataHandler";
3369 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
3372 hdlr_type = (track == &mov->
tracks[0]) ?
"pict" :
"auxv";
3373 descr =
"PictureHandler";
3376 descr =
"VideoHandler";
3380 descr =
"SoundHandler";
3384 descr =
"ClosedCaptionHandler";
3386 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) {
3388 }
else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
's')) {
3395 descr =
"SubtitleHandler";
3399 descr =
"HintHandler";
3402 descr =
"TimeCodeHandler";
3405 descr =
"GoPro MET";
3408 "Unknown hdlr_type for %s, writing dummy values\n",
3433 descr_len = strlen(descr);
3526 avio_wb32(pb,
s->streams[stream_index]->codecpar->width);
3527 avio_wb32(pb,
s->streams[stream_index]->codecpar->height);
3632 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
3634 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
3639 }
else if (track->
tag ==
MKTAG(
'g',
'p',
'm',
'd')) {
3725 else if (!track->
entry)
3734 "FATAL error, file duration too long for timebase, this file will not be\n"
3735 "playable with QuickTime. Choose a different timebase with "
3736 "-video_track_timescale or a different container format\n");
3762 int16_t d, int16_t tx, int16_t ty)
3785 uint32_t *display_matrix =
NULL;
3804 if (sd && sd->
size == 9 *
sizeof(*display_matrix))
3805 display_matrix = (uint32_t *)sd->
data;
3828 else if (!track->
entry)
3845 if (display_matrix) {
3846 for (
i = 0;
i < 9;
i++)
3856 track_width_1616 = track->
par->
width * 0x10000ULL;
3861 if (!track_width_1616 ||
3863 track_width_1616 > UINT32_MAX)
3864 track_width_1616 = track->
par->
width * 0x10000ULL;
3866 if (track_width_1616 > UINT32_MAX) {
3868 track_width_1616 = 0;
3871 if (track->
height > 0xFFFF) {
3925 int entry_size, entry_count,
size;
3934 "EDTS using dts:%"PRId64
" cts:%d instead of dts:%"PRId64
" cts:%"PRId64
" tid:%d\n",
3936 start_dts, start_ct, track->
track_id);
3955 version |= delay < INT32_MAX ? 0 : 1;
3957 entry_size = (
version == 1) ? 20 : 12;
3958 entry_count = 1 + (delay > 0);
3959 size = 24 + entry_count * entry_size;
3990 start_ct = -
FFMIN(start_dts, 0);
4048 char buf[1000] =
"";
4067 const char *
tag,
const char *str)
4092 avio_write(pb, (
const unsigned char *)scheme_uri,
4093 strlen(scheme_uri));
4113 for (
int j = 0;
map.value_maps[j].disposition; j++) {