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);
740 bit_rates.max_bit_rate =
FFMAX(bit_rates.max_bit_rate,
742 bit_rates.buffer_size = props->buffer_size / 8;
752 int decoder_specific_info_len = track->
vos_len ? 5 + track->
vos_len : 0;
759 put_descr(pb, 0x03, 3 + 5+13 + decoder_specific_info_len + 5+1);
764 put_descr(pb, 0x04, 13 + decoder_specific_info_len);
901 "Cannot write moov atom before TrueHD packets."
902 " Set the delay_moov flag to fix this.\n");
907 if (length < 20 || length > track->
vos_len)
926 int ambisonic_order, ambi_channels, non_diegetic_channels;
947 if (ambisonic_order < 0)
950 ambi_channels = (ambisonic_order + 1LL) * (ambisonic_order + 1LL);
951 non_diegetic_channels = ch_layout.
nb_channels - ambi_channels;
952 if (non_diegetic_channels &&
953 (non_diegetic_channels != 2 ||
964 avio_w8(pb, (!!non_diegetic_channels) << 7);
969 for (
i = 0;
i < ambi_channels;
i++)
981 uint32_t layout_tag, bitmap, *channel_desc;
989 &bitmap, &channel_desc);
994 "lack of channel information\n");
1003 channel_desc =
av_malloc(
sizeof(*channel_desc));
1022 for (
int i = 0;
i < num_desc;
i++) {
1082 int unescaped_size, seq_found = 0;
1083 int level = 0, interlace = 0;
1092 packet_seq = packet_entry = 1;
1094 "moov atom written before any packets, unable to write correct "
1095 "dvc1 atom. Set the delay_moov flag to fix this.\n");
1102 for (next = start; next < end; start = next) {
1106 size = next - start - 4;
1163 uint8_t buf[7] = { 0 };
1218 if (cluster_idx >= track->
entry)
1221 if (cluster_idx + 1 == track->
entry)
1224 next_dts = track->
cluster[cluster_idx + 1].
dts;
1236 int i, first_duration;
1246 for (
i = 1;
i < track->
entry;
i++) {
1250 return first_duration;
1277 uint8_t *speaker_pos =
NULL;
1287 speaker_pos,
layout->nb_channels);
1289 char buf[128] = {0};
1344 uint32_t
tag = track->
tag;
1414 if (track->
tag ==
MKTAG(
'i',
'a',
'm',
'f'))
1451 else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'a'))
1454 else if (track->
tag ==
MKTAG(
'i',
'a',
'm',
'f'))
1455 ret = mov_write_iacb_tag(mov->
fc, pb, track);
1479 }
else if (track->
vos_len > 0)
1556 if (track->
tag ==
MKTAG(
'h',
'v',
'c',
'1'))
1570 if (track->
tag ==
MKTAG(
'h',
'v',
'c',
'1'))
1590 if (track->
tag ==
MKTAG(
'e',
'v',
'c',
'1'))
1608 if (track->
tag ==
MKTAG(
'v',
'v',
'c',
'1'))
1620 int display_width = track->
par->
width;
1648 if (track->
tag ==
MKTAG(
'A',
'V',
'd',
'h')) {
1724 }
else if (track->
par->
height == 1080) {
1739 if (rational_framerate.
den != 0)
1740 rate =
av_q2d(rational_framerate);
1757 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'v',
'4');
1758 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'5');
1759 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'1');
1760 else if (rate == 50)
tag =
MKTAG(
'x',
'd',
'v',
'a');
1761 else if (rate == 60)
tag =
MKTAG(
'x',
'd',
'v',
'9');
1765 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'v',
'6');
1766 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'7');
1767 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'8');
1769 if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'3');
1770 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'2');
1774 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'v',
'd');
1775 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'e');
1776 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'f');
1778 if (rate == 25)
tag =
MKTAG(
'x',
'd',
'v',
'c');
1779 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'v',
'b');
1785 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'5',
'4');
1786 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'5',
'5');
1787 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'5',
'1');
1788 else if (rate == 50)
tag =
MKTAG(
'x',
'd',
'5',
'a');
1789 else if (rate == 60)
tag =
MKTAG(
'x',
'd',
'5',
'9');
1793 if (rate == 24)
tag =
MKTAG(
'x',
'd',
'5',
'd');
1794 else if (rate == 25)
tag =
MKTAG(
'x',
'd',
'5',
'e');
1795 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'5',
'f');
1797 if (rate == 25)
tag =
MKTAG(
'x',
'd',
'5',
'c');
1798 else if (rate == 30)
tag =
MKTAG(
'x',
'd',
'5',
'b');
1819 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'5',
'p');
1820 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'5',
'q');
1821 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'5',
'p');
1822 else if (rate == 50)
tag =
MKTAG(
'a',
'i',
'5',
'q');
1823 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'5',
'p');
1827 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'5',
'3');
1828 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'5',
'2');
1829 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'5',
'3');
1831 if (rate == 50)
tag =
MKTAG(
'a',
'i',
'5',
'5');
1832 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'5',
'6');
1838 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'1',
'p');
1839 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'1',
'q');
1840 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'1',
'p');
1841 else if (rate == 50)
tag =
MKTAG(
'a',
'i',
'1',
'q');
1842 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'1',
'p');
1846 if (rate == 24)
tag =
MKTAG(
'a',
'i',
'1',
'3');
1847 else if (rate == 25)
tag =
MKTAG(
'a',
'i',
'1',
'2');
1848 else if (rate == 30)
tag =
MKTAG(
'a',
'i',
'1',
'3');
1850 if (rate == 25)
tag =
MKTAG(
'a',
'i',
'1',
'5');
1851 else if (rate == 50)
tag =
MKTAG(
'a',
'i',
'1',
'5');
1852 else if (rate == 60)
tag =
MKTAG(
'a',
'i',
'1',
'6');
1874 static const struct {
1925 if (
tag ==
MKTAG(
'r',
'a',
'w',
' ') &&
1929 av_log(
s,
AV_LOG_ERROR,
"%s rawvideo cannot be written to mov, output file will be unreadable\n",
1968 "the file may be unplayable!\n");
1975 tag =
MKTAG(
'm',
's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
1977 "the file may be unplayable!\n");
2002 for (
i = 0; tags && tags[
i];
i++) {
2007 return codec_tags->
tag;
2024 "Quicktime/Ipod might not play the file\n");
2050 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
2055 unsigned mov_field_order = 0;
2057 mov_field_order =
fiel_data[field_order];
2095 "Unknown codec tag '%s' utilized for TTML stream with "
2096 "index %d (track id %d)!\n",
2115 if (stereo_3d->
flags != 0) {
2120 switch (stereo_3d->
type) {
2143 int64_t sv3d_pos, svhd_pos, proj_pos;
2255 switch (stereo3d->
view) {
2263 view |= (1 << 0) | (1 << 1);
2306 if (spherical_mapping &&
2313 spherical_mapping =
NULL;
2326 if (!spherical_mapping && !stereo3d)
2333 if (spherical_mapping)
2361 uint32_t top, uint32_t bottom,
2362 uint32_t
left, uint32_t right)
2364 uint32_t cropped_width = track->
par->
width -
left - right;
2365 uint32_t cropped_height = track->
height - top - bottom;
2409 gama = (uint32_t)
lrint((
double)(1<<16) * gamma);
2440 return 12 + sd->
size;
2493 const int chroma_den = 50000;
2494 const int luma_den = 10000;
2524 const int illuminance_den = 10000;
2525 const int ambient_den = 50000;
2568 }
else if(track->
par->
width == 1440) {
2587 uint8_t ccstValue = (0 << 7) |
2604 avio_write(pb,
"urn:mpeg:mpegB:cicp:systems:auxiliary:alpha\0", 44);
2613 char compressor_name[32] = { 0 };
2638 if (uncompressed_ycbcr) {
2664 avio_w8(pb, strlen(compressor_name));
2685 for (
i = 0;
i < pal_size;
i++) {
2687 uint16_t
r = (
rgb >> 16) & 0xff;
2688 uint16_t
g = (
rgb >> 8) & 0xff;
2689 uint16_t
b =
rgb & 0xff;
2698 if (track->
tag ==
MKTAG(
'm',
'p',
'4',
'v'))
2738 }
else if (track->
vos_len > 0)
2785 if (spherical_mapping)
2806 if (stereo3d || spherical_mapping)
2830 if (sd && sd->
size >=
sizeof(uint32_t) * 4) {
2837 (top + bottom) >= track->
height) {
2841 if (top || bottom ||
left || right)
2843 }
else if (uncompressed_ycbcr)
2890 uint64_t str_size =strlen(reel_name);
2893 if (str_size >= UINT16_MAX){
2923 if (nb_frames > 255) {
2999 uint32_t entries = 0;
3006 ctts_entries[0].
count = 1;
3008 for (
i = 1;
i < track->
entry;
i++) {
3010 ctts_entries[entries].
count++;
3014 ctts_entries[entries].
count = 1;
3018 atom_size = 16 + (entries * 8);
3027 for (
i = 0;
i < entries;
i++) {
3039 uint32_t entries = -1;
3044 stts_entries =
av_malloc(
sizeof(*stts_entries));
3056 for (
i = 0;
i < track->
entry;
i++) {
3059 stts_entries[entries].
count++;
3063 stts_entries[entries].
count = 1;
3068 atom_size = 16 + (entries * 8);
3073 for (
i = 0;
i < entries;
i++) {
3100 int16_t roll_distance;
3101 int group_description_index;
3104 struct sgpd_entry *sgpd_entries =
NULL;
3124 for (
i = 0;
i < track->
entry;
i++) {
3125 int roll_samples_remaining = roll_samples;
3127 for (j =
i - 1; j >= 0; j--) {
3130 if (roll_samples_remaining <= 0)
3136 if (roll_samples_remaining > 0)
3141 if (
i &&
distance == sgpd_entries[entries].roll_distance) {
3142 sgpd_entries[entries].count++;
3145 sgpd_entries[entries].count = 1;
3146 sgpd_entries[entries].roll_distance =
distance;
3147 sgpd_entries[entries].group_description_index =
distance ? ++group : 0;
3153 sgpd_entries[entries].roll_distance = 1;
3154 sgpd_entries[entries].group_description_index = ++group;
3170 for (
i = 0;
i < entries;
i++) {
3171 if (sgpd_entries[
i].group_description_index) {
3172 avio_wb16(pb, -sgpd_entries[
i].roll_distance);
3182 for (
i = 0;
i < entries;
i++) {
3184 avio_wb32(pb, sgpd_entries[
i].group_description_index);
3257 const char *font =
"Lucida Grande";
3297 if (track->
tag !=
MKTAG(
'c',
'6',
'0',
'8')) {
3349 return track->
tag ==
MKTAG(
'c',
'7',
'0',
'8') ||
3350 track->
tag ==
MKTAG(
'c',
'6',
'0',
'8');
3356 const char *hdlr, *descr =
NULL, *hdlr_type =
NULL;
3362 descr =
"DataHandler";
3365 hdlr = (track->
mode ==
MODE_MOV) ?
"mhlr" :
"\0\0\0\0";
3368 hdlr_type = (track == &mov->
tracks[0]) ?
"pict" :
"auxv";
3369 descr =
"PictureHandler";
3372 descr =
"VideoHandler";
3376 descr =
"SoundHandler";
3380 descr =
"ClosedCaptionHandler";
3382 if (track->
tag ==
MKTAG(
't',
'x',
'3',
'g')) {
3384 }
else if (track->
tag ==
MKTAG(
'm',
'p',
'4',
's')) {
3391 descr =
"SubtitleHandler";
3395 descr =
"HintHandler";
3398 descr =
"TimeCodeHandler";
3401 descr =
"GoPro MET";
3404 "Unknown hdlr_type for %s, writing dummy values\n",
3429 descr_len = strlen(descr);
3522 avio_wb32(pb,
s->streams[stream_index]->codecpar->width);
3523 avio_wb32(pb,
s->streams[stream_index]->codecpar->height);
3628 }
else if (track->
tag ==
MKTAG(
'r',
't',
'p',
' ')) {
3630 }
else if (track->
tag ==
MKTAG(
't',
'm',
'c',
'd')) {
3635 }
else if (track->
tag ==
MKTAG(
'g',
'p',
'm',
'd')) {
3721 else if (!track->
entry)
3730 "FATAL error, file duration too long for timebase, this file will not be\n"
3731 "playable with QuickTime. Choose a different timebase with "
3732 "-video_track_timescale or a different container format\n");
3758 int16_t d, int16_t tx, int16_t ty)
3781 uint32_t *display_matrix =
NULL;
3800 if (sd && sd->
size == 9 *
sizeof(*display_matrix))
3801 display_matrix = (uint32_t *)sd->
data;
3824 else if (!track->
entry)
3841 if (display_matrix) {
3842 for (
i = 0;
i < 9;
i++)
3852 track_width_1616 = track->
par->
width * 0x10000ULL;
3857 if (!track_width_1616 ||
3859 track_width_1616 > UINT32_MAX)
3860 track_width_1616 = track->
par->
width * 0x10000ULL;
3862 if (track_width_1616 > UINT32_MAX) {
3864 track_width_1616 = 0;
3867 if (track->
height > 0xFFFF) {
3921 int entry_size, entry_count,
size;
3930 "EDTS using dts:%"PRId64
" cts:%d instead of dts:%"PRId64
" cts:%"PRId64
" tid:%d\n",
3932 start_dts, start_ct, track->
track_id);
3951 version |= delay < INT32_MAX ? 0 : 1;
3953 entry_size = (
version == 1) ? 20 : 12;
3954 entry_count = 1 + (delay > 0);
3955 size = 24 + entry_count * entry_size;
3986 start_ct = -
FFMIN(start_dts, 0);
4044 char buf[1000] =
"";
4063 const char *
tag,
const char *str)
4088 avio_write(pb, (
const unsigned char *)scheme_uri,
4089 strlen(scheme_uri));
4109 for (
int j = 0;
map.value_maps[j].disposition; j++) {
4158 int entry_backup = track->
entry;